Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

dbList.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Graeme Foster                                   *
00003  *   email    foster.graeme@gmail.com                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "dbList.h"
00022 
00023 dbList::dbList()
00024 {
00025         pdcList = new QList<DataClass * >();
00026 }
00027 
00028 dbList::dbList(QList<DataClass * > * p_dcList)
00029 {
00030         pdcList = p_dcList;
00031 }
00032 
00033 // Access methods
00034 QList<DataClass * > * dbList::list()
00035 {
00036         return pdcList;
00037 }
00038 
00039 QList<DataClass * > * dbList::allChildren(DataClass * parent, bool deep)
00040 {
00041         if (deep)
00042                 return allChildrenDeep(parent);
00043                 
00044         QList<DataClass * > * pChildren = new QList<DataClass * >();
00045         for (int i = 0; i<size(); i++)
00046                 if (pdcList->at(i)->getParent() == parent)
00047                         pChildren->append(pdcList->at(i));
00048         return pChildren;
00049 }
00050 
00051 QList<DataClass * > * dbList::allChildrenDeep(DataClass * parent)
00052 {
00053         QList<DataClass * > * pChildren = new QList<DataClass * >();
00054         DataClass * obj, * objParent;
00055         for (int i = 0; i<size(); i++)
00056         {
00057                 obj = pdcList->at(i);
00058                 objParent = obj->getParent();
00059                 while (objParent != 0)
00060                 {
00061                         if (objParent == parent)
00062                         {
00063                                 pChildren->append(obj);
00064                                 break;
00065                         }
00066                         objParent = objParent->getParent();
00067                 }
00068         }
00069         return pChildren;
00070 }
00071 
00072 // Modification methods
00073 DataClass * dbList::remove(int posn)
00074 {
00075         if (posn < 0 || posn >= pdcList->size())
00076                 return 0;
00077         else
00078         {
00079                 DataClass * dc = pdcList->at(posn);
00080                 pdcList->removeAt(posn);
00081                 return  dc;
00082         }
00083 }
00084 
00085 // Info Methods
00086 DataClass * dbList::at(int posn)
00087 {
00088         if (posn < 0 || posn >= pdcList->size())
00089                 return 0;
00090         else
00091         {
00092                 return  pdcList->at(posn);
00093         }
00094 }
00095 
00096 void dbList::dump()
00097 {
00098         std::cout << "      DataClass: ";
00099         if (pdcList->size() == 0)
00100                 std::cout << "List is empty" << "\n";
00101         else
00102                 std::cout << pdcList->at(0)->rtti() << "\n";
00103         for (int i = 0; i<pdcList->size(); i++)
00104                 std::cout << pdcList->at(i)->getDescription().toStdString() << "\n";
00105 }

Generated on Thu Apr 6 16:27:17 2006 for time-table by  doxygen 1.4.4