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

dbListManager.h

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 #ifndef __DB_LIST_MANAGER_H
00021 #define __DB_LIST_MANAGER_H
00022 
00023 #include "dbList.h"
00024 #include "sql.h"
00025 
00026 #include "../DataClasses/DataClass.h"
00027 #include "../DataClasses/Institute.h"
00028 #include "../DataClasses/Programme.h"
00029 #include "../DataClasses/Module.h"
00030 #include "../DataClasses/Faculty.h"
00031 #include "../DataClasses/Department.h"
00032 #include "../DataClasses/Staff.h"
00033 #include "../DataClasses/Room.h"
00034 #include "../DataClasses/ModLecAlloc.h"
00035 #include "../DataClasses/TimeSlot.h"
00036 
00037 #include "../ModelClasses/RootModel.h"
00038 #include "../ItemClasses/RootItem.h"
00039 
00040 class RootModel;
00041 
00053 class dbListManager
00054 {
00055         public:
00063                 enum registeredLists
00064                         {regInstitute  = 1
00065                         ,regProgramme  = 2
00066                         ,regModule     = 4
00067                         ,regFaculty    = 8
00068                         ,regDepartment = 16
00069                         ,regStaff      = 32
00070                         ,regRoom       = 64
00071                         ,regMLAlloc    = 128
00072                         ,regTimeSlot   = 256
00073                         };
00074         
00086         class registeredModels
00087         {
00088                 public:
00089                         RootModel * pModel;     
00090                         QList<dbList *> listOfLists; 
00091                         registeredModels(RootModel * model){pModel = model;} 
00092                         void registerList(dbList * list){listOfLists.append(list);} 
00093                         bool listIsMember(dbList * list){return listOfLists.contains(list);} 
00094                         void dump(); 
00095         }; // end of nested class registeredModels
00096 
00097         private: // Singleton Instance
00098                 static dbListManager * _instance;        
00099         private: // Properties
00100                 sql* dbConn;    
00101                 dbList * pInstituteList;        
00102                 dbList * pProgrammeList;        
00103                 dbList * pModuleList;           
00104                 dbList * pFacultyList;          
00105                 dbList * pDepartmentList;       
00106                 dbList * pStaffList;                    
00107                 dbList * pRoomList;                     
00108                 dbList * pMLAllocList;          
00109                 dbList * pTimeSlotList;         
00110 
00117                 QList<registeredModels *> pRegisteredModels; 
00118         private: // methods
00120                 dbListManager();
00122                 dbListManager(dbListManager & clone);
00123         public:  // static methods
00124                 static dbListManager * Instance();      
00125         public: // member functions
00126                 // RegisterModel functions
00128                 void registerModel(RootModel * model, int lists);
00129 
00130                 // Access functions, returns the list as a dbList container
00131                 inline dbList * InstituteList(){return pInstituteList;} 
00132                 inline dbList * ProgrammeList(){return pProgrammeList;} 
00133                 inline dbList * ModuleList(){return pModuleList;}                       
00134                 inline dbList * FacultyList(){return pFacultyList;}             
00135                 inline dbList * DepartmentList(){return pDepartmentList;}
00136                 inline dbList * StaffList(){return pStaffList;}                         
00137                 inline dbList * RoomList(){return pRoomList;}                           
00138                 inline dbList * MLAllocList(){return pMLAllocList;}             
00139                 inline dbList * TimeSlotList(){return pTimeSlotList;}           
00140                 // Access functions cont., returns the list as a QList container
00143                 QList<Institute * >  * getInstituteList()
00144                         {return List<Institute *>(pInstituteList->list());}
00147                 QList<Programme * >  * getProgrammeList()
00148                         {return List<Programme *>(pProgrammeList->list());}
00154                 QList<Programme * >  * getProgrammeList(Institute * inst)
00155                         {if (inst == 0) return getProgrammeList();
00156                          else return List<Programme *>(pProgrammeList->allChildren(inst));}
00161                 QList<Module * >     * getModuleList()
00162                         {return List<Module *>(pModuleList->list());}
00168                 QList<Module * >     * getModuleList(Programme * prog)
00169                         {return List<Module *>(pModuleList->allChildren(prog));}
00174                 QList<Faculty * >    * getFacultyList()
00175                         {return List<Faculty *>(pFacultyList->list());}
00181                 QList<Faculty * >    * getFacultyList(Institute * inst)
00182                         {if (inst == 0) return getFacultyList();
00183                          else return List<Faculty *>(pFacultyList->allChildren(inst));}
00188                 QList<Department * > * getDepartmentList()
00189                         {return List<Department*>(pDepartmentList->list());}
00195                 QList<Department * > * getDepartmentList(Faculty * faculty)
00196                         {if (faculty == 0) return getDepartmentList();
00197                          else return List<Department*>(pDepartmentList->allChildren(faculty));}
00203                 QList<Department * > * getDepartmentList(Institute * inst)
00204                         {if (inst == 0) return getDepartmentList();
00205                          else return List<Department*>(pDepartmentList->allChildren(inst,true));}
00210                 QList<Staff * >      * getStaffList()
00211                         {return List<Staff*>(pStaffList->list());}
00217                 QList<Staff * >      * getStaffList(Department * dept)
00218                         {if (dept == 0) return getStaffList();
00219                          else return List<Staff*>(pStaffList->allChildren(dept,true));}
00225                 QList<Staff * > * getStaffList(Institute * inst)
00226                         {if (inst == 0) return getStaffList();
00227                          else return List<Staff*>(pStaffList->allChildren(inst,true));}
00232                 QList<Room * >       * getRoomList()
00233                         {return List<Room *>(pRoomList->list());}
00239                 QList<Room * >       * getRoomList(Institute * inst)
00240                         {return List<Room *>(pRoomList->allChildren(inst));}
00245                 QList<ModLecAlloc * >       * getMLAllocList()
00246                         {return List<ModLecAlloc*>(pMLAllocList->list());}
00252                 QList<ModLecAlloc * >       * getMLAllocList(Programme * prog)
00253                         {return List<ModLecAlloc*>(pMLAllocList->allChildren(prog));}
00259                 QList<ModLecAlloc * >       * getMLAllocList(Institute * inst)
00260                         {return List<ModLecAlloc*>(pMLAllocList->allChildren(inst, true));}
00261 
00266                 QList<TimeSlot * >          * getTimeSlotList()
00267                         {return List<TimeSlot *>(pTimeSlotList->list());}
00273                 QList<TimeSlot * >          * getTimeSlotList(Institute * inst)
00274                         {return List<TimeSlot *>(pTimeSlotList->allChildren(inst));}
00275                 
00276                 // Object Location methods, returns an object from its ID
00283                 Institute * getInstituteFromID(int id)          {return getObjFromID<Institute *>(pInstituteList,id);}
00290                 Programme * getProgrammeFromID(int id)          {return getObjFromID<Programme *>(pProgrammeList,id);}
00297                 Module * getModuleFromID(int id)                                {return getObjFromID<Module *>(pModuleList,id);}
00304                 Faculty * getFacultyFromID(int id)                      {return getObjFromID<Faculty *>(pFacultyList,id);}
00311                 Department * getDepartmentFromID(int id)        {return getObjFromID<Department *>(pDepartmentList,id);}
00318                 Staff  * getStaffFromID(int id)                         {return getObjFromID<Staff *>(pStaffList,id);}
00325                 Room * getRoomFromID(int id)                                    {return getObjFromID<Room *>(pRoomList,id);}
00332                 ModLecAlloc * getMLAllocFromID(int id)          {return getObjFromID<ModLecAlloc *>(pMLAllocList,id);}
00339                 // Object Location methods cont., returns an object from its name
00340                 Institute  * getInstFromName(QString &InstName){return getObjFromName(getInstituteList(),InstName);}
00350                 Programme  * getProgFromName(Institute * instObj, QString &ProgName){return getObjFromName(getProgrammeList(instObj),ProgName);}
00360                 Department * getDeptFromName(Institute * instObj, QString &deptName){return getObjFromName(getDepartmentList(instObj),deptName);}
00361                 
00362                 // Insert, Update and delete action functions
00371                 void insert(RootItem * item, dbList * list, QModelIndex & index, CompareDC lessThan);
00381                 void update(RootItem * item, dbList * list, CompareRI compare);
00391                 void remove(RootItem * item, dbList * list, bool cascade=true);
00392 
00393                 // diagnostic functions
00398                 void dump(bool details = false);
00399                 
00400         private: // member functions
00401                 // Creation methods
00405                 void newInstitute  ();
00410                 void newProgramme  (Institute  * parent);
00415                 void newModule     (Programme  * parent);
00420                 void newFaculty    (Institute  * parent);
00425                 void newDepartment (Faculty    * parent);
00430                 void newStaff      (Department * parent);
00435                 void newRoom       (Institute  * parent);
00439                 void newAlloc      ();
00443                 void newTimeSlot   ();
00444                 
00452                 void updateRMInsert(dbList * list, RootItem * item, QModelIndex & index, int posn);
00459                 void updateRMUpdate(dbList * list, DataClass * dcObj, CompareRI compare);
00465                 void updateRMDelete(dbList * list, DataClass * dcObj);
00471                 void removeAllChilden(DataClass * dcObj);
00478                 void removeChild(DataClass * dcObj, dbList * list);
00488                 template<typename T>
00489                 QList<T> * List(QList<DataClass*> * list);
00496                 template<typename T>
00497                 T getObjFromID(dbList* pList, int id);
00504                 template<typename T>
00505                 T getObjFromName(QList<T>* list, QString &name);
00506 };
00507 
00508 template<typename T>
00509 QList<T> * dbListManager::List(QList<DataClass*> * list)
00510 {
00511         QList<T> * theList = new QList<T>();
00512         for (int i = 0; i < list->size(); i++)
00513         {
00514                 theList->append(static_cast<T>(list->at(i)));
00515         }
00516         return theList;
00517 }
00518 
00519 template<typename T>
00520 T dbListManager::getObjFromID(dbList* pList, int id)
00521 {
00522         for (int i=0; i<pList->size(); i++)
00523         {
00524                 if (pList->at(i)->getID() == id)
00525                         return static_cast<T>(pList->at(i));
00526         }
00527         return 0;
00528 }
00529 
00530 template<typename T>
00531 T dbListManager::getObjFromName(QList<T>* list, QString &name)
00532 {
00533         T instObj = 0;
00534         for (int i = 0; i<list->size(); i++)
00535         {
00536                 if (list->at(i)->getName().compare(name)==0)
00537                 {
00538                         instObj = list->at(i);
00539                         break;
00540                 }
00541         } // end for loop through each object in the list
00542         return instObj;
00543 }
00544 
00545 #endif

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