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

DataClass.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 
00021 #ifndef __DataClass_H
00022 #define __DataClass_H
00023 
00024 #include <iostream>
00025 
00026 #include <QString>
00027 #include "sql.h"
00028 
00029 class DataClass;
00030 typedef bool (*CompareDC)(const DataClass*, const DataClass*);
00031 
00032 // Generic container class for data from a database
00033 class DataClass // Abstract
00034 {
00035 public: // Data Types
00036         // When adding a new class also modify the getClassName() method in DataClass.cpp
00037         enum ClassName {DATA_CLASS
00038                                           ,INSTITUTE_CLASS
00039                                           ,PROGRAMME_CLASS
00040                                           ,MODULE_CLASS
00041                                           ,FACULTY_CLASS
00042                                           ,DEPARTMENT_CLASS
00043                                           ,STAFF_CLASS
00044                                           ,ROOM_CLASS
00045                                           ,MOD_LEC_ALLOC_CLASS
00046                                           ,MOD_LEC_ENROL_CLASS
00047                                           ,TIMESLOT_CLASS
00048                                           };
00049 protected: // Properties
00050         int id;
00051         QString errorMsg;
00052         ClassName p_rtti;
00053         DataClass * parent;
00054 public: // Constants
00055         static const int NOT_ON_DB;
00056         static const int NO_PARENT;
00057 
00058 public: // Methods
00059         // Constructor
00060         DataClass(int pID=NO_PARENT);
00061 
00062         virtual ~DataClass(){};
00063 
00064         
00065         // Get & Set Methods
00066         inline int getID()                   {return id;}
00067         virtual QString getDescription() const =0;
00068         inline DataClass * getParent()       {return parent;}
00069         inline int getParentID();
00070         // Utility methods
00071         QString getClassName();
00072         inline ClassName rtti()              {return p_rtti;}
00073         inline bool isParent(DataClass *);
00074         virtual QString getSortValue()const;
00075 
00076         // Simple diagnostic methods
00077         inline QString Dump()                {return getClassName() + ": " + getDescription();}
00078         
00079         // General database methods
00080         static bool unique(int uniqueSQL);
00081         // A general uniqueness test method that will always return true.
00082         static bool uniqueTrue(QString, int){return true;}
00083         int save(int insertSQL, int updateSQL, int errorSQL);
00084 
00085         // Compare Methods used for qSort calls and the like
00086         static bool dcCompareCI(const DataClass *p1, const DataClass * p2);
00087         static bool dcCompareCS(const DataClass *p1, const DataClass * p2);
00088 
00089 protected: // Methods
00090         // Specific database modification methods
00091         virtual int bindPKey(int preparedSQL){sql::Instance()->bind(0,id,preparedSQL); return 1;}
00092         virtual void bindValues(int preparedSQL, int start)=0;
00093         int insert  (int insertSQL, int errorSQL);
00094         int update  (int updateSQL, int errorSQL);
00095         virtual int remove  (int deleteSQL, int errorSQL);
00096 //      int exec    (int execSQL, int errorSQL);
00097 //      void dbError(int errorSQL, int errorID);
00098 };
00099 
00100 inline bool DataClass::isParent(DataClass * p)
00101 {
00102         if (p == 0)
00103                 return false;
00104         if (p == parent)
00105                 return true;
00106         return parent->isParent(p);
00107 }
00108 
00109 inline int DataClass::getParentID()
00110 {
00111         if (parent == 0)
00112                 return NO_PARENT;
00113         else
00114                 return parent->getID();
00115 }
00116 #endif

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