storage_manager.h

Go to the documentation of this file.
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 // TODO, it can get the names as well...
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; // primary key change it
00039 typedef int sClass;
00040 
00045 struct storage_spec {
00046   // This indicates whether the model needs to be rebuilt or is an existing model.
00047   bool bRebuild;
00048   // entity table name in the database
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   // ************** Load Methods
00091   // Insert tuple: This only populates the internal table.
00092   // THIS DOES NOT DO SORTING. If you build the table using this function
00093   // THEN YOU NEED TO CALL RESORT.
00100   virtual void insertEntity(struct hazy_model &m, key e, T f) = 0; 
00101   
00102   // this is the incremental maintenance call on adding in a new feature.
00103   // virtual void addEntity(struct hazy_model &m, key e, T f) = 0;
00104   
00105   // Repeated inserts. Overload for bulk loading.
00106   // TODO: Make strongly typed FVector/SVector!  
00112   virtual void loadFromFile(struct hazy_model &m, const char* szFileName); 
00113   // This fails if there is no db connection in the constructor...
00118   virtual int loadFromDatabase(struct hazy_model &m);
00119   
00120   // **********************
00121   // Read Methods
00122   // Single Entity Read
00129   virtual void getEntityClass(key e, sClass &c, struct hazy_model &m) = 0;
00130   // All Members Read
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

Generated on Wed Dec 15 10:46:15 2010 for Hazy_System by  doxygen 1.4.7