// // aegis - project change supervisor // Copyright (C) 2001, 2002, 2004-2006, 2008, 2012, 2014 Peter Miller // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, or (at // your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // #include #include #include #include format_version_list::~format_version_list() { // FIXME: use reference vounted format_version // to fix this huge memory leak. } format_version_list::format_version_list(void) : item(NULL), length(0), maximum(0) { } format_version_list::format_version_list(const format_version_list &rhs) : item(NULL), length(0), maximum(0) { for (size_t j = 0; j < rhs.length; ++j) append(rhs[j]); } void format_version_list::swap(format_version_list &rhs) { std::swap(item, rhs.item); std::swap(length, rhs.length); std::swap(maximum, rhs.maximum); } format_version_list & format_version_list::operator=(const format_version_list &rhs) { format_version_list(rhs).swap(*this); return *this; } void format_version_list::validate(void) const { assert(valid()); } bool format_version_list::valid(void) const { for (size_t j = 0; j < length; ++j) if (!item[j]->valid()) return false; return true; } void format_version_list::append(format_version *fvp) { if (length >= maximum) { maximum = maximum * 2 + 8; format_version **new_item = new format_version * [maximum]; for (size_t j = 0; j < length; ++j) new_item[j] = item[j]; delete [] item; item = new_item; } item[length++] = fvp; } static int cmp(const void *va, const void *vb) { format_version *a; format_version *b; a = *(format_version **)va; b = *(format_version **)vb; if (a->when < b->when) return -1; if (a->when > b->when) return 1; return 0; } void format_version_list::sort_by_date(void) { qsort(item, length, sizeof(item[0]), cmp); } // vim: set ts=8 sw=4 et :