00001 
00004 #ifndef STORAGE_MANAGER_H
00005 #define STORAGE_MANAGER_H
00006 
00007 #include "vectors.h"
00008 #include "timer.h"
00009 #include "hazy_model.h"
00010 #include "postgres_util.h"
00011 
00012 
00019 
00020 template<class T>
00021 struct sParse_IDvec {
00022   int id;
00023   T f;
00024   static int parse_tuple(PGresult *res, int index, sParse_IDvec<T> &c) {
00025     c.id = atoi(PQgetvalue(res, index, 0));
00026     std::string f_vec = PQgetvalue(res, index, 1);
00027     int r = c.f.fromPSQL(f_vec);
00028     return r;
00029   }
00030 };
00031 
00032 
00038 typedef int key; 
00039 typedef int sClass;
00040 
00045 struct storage_spec {
00046   
00047   bool bRebuild;
00048   
00049   std::string entity_table_name;
00050   
00055   hazy_model::strategy strategy;
00056 
00057   int unique_id;
00058 };
00059 
00060 template <class T> 
00061 class Storage_Manager {
00062  protected:
00063   std::string entity_table_name;
00064   Hazy_Database *db_conn;
00065   
00066  public:
00070   Storage_Manager() {db_conn = NULL;}
00075   Storage_Manager(Hazy_Database *db_conn) {this->db_conn = db_conn;}
00076   
00081   virtual void resort(struct hazy_model &m) = 0;
00082   
00088   virtual void incrementalUpdate(struct hazy_model &m, double &waste_time) = 0;
00089   
00090   
00091   
00092   
00093   
00100   virtual void insertEntity(struct hazy_model &m, key e, T f) = 0; 
00101   
00102   
00103   
00104   
00105   
00106   
00112   virtual void loadFromFile(struct hazy_model &m, const char* szFileName); 
00113   
00118   virtual int loadFromDatabase(struct hazy_model &m);
00119   
00120   
00121   
00122   
00129   virtual void getEntityClass(key e, sClass &c, struct hazy_model &m) = 0;
00130   
00138   virtual void getNumInClass(sClass c, int &nClass, struct hazy_model &m, double& waste_time) = 0;
00139   
00143   virtual ~Storage_Manager();
00144 };
00145 
00146 #include "storage_manager.hxx"
00147 #endif