00001 #ifndef _VOBJECTSTORE_HH_
00002 #define _VOBJECTSTORE_HH_
00003
00004 #include <vos/vos/vosdefs.hh>
00005 #include <vos/vos/vobject.hh>
00006 #include <vos/vos/site.hh>
00007 #include <vos/vos/message.hh>
00008 #include <vos/vos/vobjectstore.hh>
00009 #include <vos/vutil/timer.hh>
00010
00011 namespace VOS {
00012
00013
00014
00015 class VOS_API VobjectStore
00016 {
00017 public:
00018
00019 struct Entry
00020 {
00021 Entry() { }
00022 Entry(const Entry& e)
00023 : vobject(e.vobject), types(e.types), mb(e.mb),
00024 pos(e.pos), savechildren(e.savechildren), blocks(e.blocks),
00025 acls(e.acls)
00026 { }
00027
00028 ~Entry() {}
00029
00030
00031 VUtil::vRef<Vobject> vobject;
00032
00033
00034 std::set<std::string> types;
00035
00036
00037
00038 VUtil::vRef<MessageBlock> mb;
00039
00040
00041
00042 int pos;
00043
00044
00045 bool savechildren;
00046
00047
00048
00049
00050
00051
00052
00053 std::map<std::string, std::string> blocks;
00054
00055
00056 std::map< std::string, std::vector<std::string> > acls;
00057 };
00058
00059 struct PCR
00060 {
00061 std::string context;
00062 std::string child;
00063 };
00064
00065 protected:
00066 VUtil::vRef<Site> ls;
00067 std::map<std::string, Entry*> vobjectTable;
00068 std::deque<Entry*> vobjectorder;
00069
00070 public:
00071
00072
00073
00074 VobjectStore(Site& loadsite);
00075
00076 VobjectStore(const VobjectStore& store);
00077
00078 virtual ~VobjectStore();
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 virtual int addVobject(Vobject* v, bool portable = true, bool saveChildren = true);
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 virtual int addVobject(Vobject* v, const std::set<std::string>& types,
00102 MessageBlock* mb, bool saveChildren);
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 virtual int addVobject(Vobject* v, const std::deque<std::string>& types,
00115 MessageBlock* mb, bool saveChildren);
00116
00117 virtual int addVobject(Vobject* v, TypeSetIterator types,
00118 MessageBlock* mb, bool saveChildren);
00119
00120
00121
00122
00123 virtual int numVobjects();
00124
00125
00126
00127
00128
00129 virtual Entry* getVobject(const std::string& name);
00130
00131
00132
00133
00134
00135 virtual Entry* getVobject(int pos);
00136
00137
00138
00139
00140 virtual void removeVobject(const std::string& name);
00141
00142
00143
00144
00145 virtual void removeVobject(int pos);
00146
00147
00148 virtual void clear();
00149
00150
00151
00152
00153
00154 virtual VUtil::vRef<Site> getTargetSite();
00155
00156
00157
00158
00159
00160 virtual void addStore(VobjectStore* vs);
00161 };
00162
00163 typedef std::map<std::string, void*> ImpExpEnv;
00164
00165 class VOS_API VobjectInput : public virtual VobjectStore
00166 {
00167 public:
00168 VobjectInput(Site& ls) : VobjectStore(ls) { }
00169 VobjectInput(const VobjectStore& v) : VobjectStore(v) { }
00170 virtual ~VobjectInput() { };
00171
00172
00173 virtual void readVobjects(std::istream& input,
00174 ImpExpEnv& environment) = 0;
00175
00176
00177
00178
00179
00180 virtual void readVobjects(unsigned char* buffer, unsigned int size,
00181 ImpExpEnv& environment) = 0;
00182
00183 };
00184
00185 class VOS_API VobjectOutput : public virtual VobjectStore
00186 {
00187 public:
00188 VobjectOutput(Site& ls) : VobjectStore(ls) { }
00189 VobjectOutput(const VobjectStore& vs) : VobjectStore(vs) { }
00190 virtual ~VobjectOutput() { }
00191
00192
00193
00194 virtual void writeVobjects(std::ostream& output,
00195 ImpExpEnv& environment) = 0;
00196
00197
00198
00199
00200
00201
00202
00203 virtual void writeVobjects(unsigned char** buffer,
00204 unsigned int* size,
00205 ImpExpEnv& environment) = 0;
00206 };
00207
00208 class VOS_API VobjectStoreLoader
00209 {
00210 public:
00211 virtual ~VobjectStoreLoader() { }
00212
00213 virtual std::string getLoaderDescription() = 0;
00214
00215 virtual bool isSupportedLoadFormat(unsigned char* buffer, unsigned int size) = 0;
00216 virtual bool isSupportedLoadFormat(std::istream& input) = 0;
00217
00218 virtual VobjectStore* loadVobjects(Site& ls,
00219 unsigned char* buffer, unsigned int size,
00220 ImpExpEnv& environment) = 0;
00221 virtual VobjectStore* loadVobjects(Site& ls,
00222 std::istream& input,
00223 ImpExpEnv& environment) = 0;
00224 };
00225
00226 class VOS_API VobjectStoreSaver
00227 {
00228 public:
00229 virtual ~VobjectStoreSaver() { }
00230
00231 virtual std::string getFileExtension(const std::string& filetype) = 0;
00232 virtual bool isSupportedSaveFormat(const std::string& filetype) = 0;
00233 virtual std::string getSaverDescription() = 0;
00234
00235 virtual void saveVobjects(VobjectStore* store,
00236 const std::string& filetype,
00237 unsigned char** buffer, unsigned int* size,
00238 ImpExpEnv& environment) = 0;
00239 virtual void saveVobjects(VobjectStore* store,
00240 const std::string& filetype,
00241 std::ostream& output,
00242 ImpExpEnv& environment) = 0;
00243 };
00244
00245 class VOS_API UnsupportedFiletypeError : public std::runtime_error
00246 {
00247 public:
00248 UnsupportedFiletypeError(const std::string& s) : runtime_error(s) { };
00249 };
00250
00251 class VOS_API FileAccessError : public std::runtime_error
00252 {
00253 public:
00254 FileAccessError(const std::string& s) : runtime_error(s) { };
00255 };
00256
00257 class VOS_API VobjectImportExport
00258 {
00259 private:
00260 static std::vector<VobjectStoreLoader*>& loaders();
00261 static std::vector<VobjectStoreSaver*>& savers();
00262
00263 VobjectImportExport() { }
00264
00265 public:
00266 static void addLoader(VobjectStoreLoader* l);
00267 static void addSaver(VobjectStoreSaver* s);
00268
00269 static const std::vector<VobjectStoreLoader*>& getLoaders();
00270 static const std::vector<VobjectStoreSaver*>& getSavers();
00271
00272 static VobjectStoreLoader* selectLoader(unsigned char* buffer, unsigned int size);
00273 static VobjectStoreLoader* selectLoader(std::istream& input);
00274
00275 static VobjectStore* load(Site& ls, unsigned char* buffer, unsigned int size,
00276 VobjectStoreLoader** l = 0);
00277 static VobjectStore* load(Site& ls, unsigned char* buffer, unsigned int size,
00278 ImpExpEnv& environment,
00279 VobjectStoreLoader** l = 0);
00280
00281
00282 static VobjectStore* load(Site& ls, std::istream& input,
00283 VobjectStoreLoader** l = 0);
00284 static VobjectStore* load(Site& ls, std::istream& input,
00285 ImpExpEnv& environment,
00286 VobjectStoreLoader** l = 0);
00287
00288
00289 static VobjectStore* loadFile(Site& ls, const std::string& filename,
00290 VobjectStoreLoader** l = 0);
00291 static VobjectStore* loadFile(Site& ls, const std::string& filename,
00292 ImpExpEnv& environment,
00293 VobjectStoreLoader** l = 0);
00294
00295
00296 static VobjectStoreSaver* selectSaver(const std::string& filetype);
00297
00298 static void save(VobjectStore* vs, const std::string& filetype,
00299 unsigned char** buffer, unsigned int* size,
00300 VobjectStoreSaver** s = 0);
00301 static void save(VobjectStore* vs, const std::string& filetype,
00302 unsigned char** buffer, unsigned int* size,
00303 ImpExpEnv& environment,
00304 VobjectStoreSaver** s = 0);
00305
00306
00307 static void save(VobjectStore* vs, const std::string& filetype,
00308 std::ostream& out,
00309 VobjectStoreSaver** s = 0);
00310 static void save(VobjectStore* vs, const std::string& filetype,
00311 std::ostream& out,
00312 ImpExpEnv& environment,
00313 VobjectStoreSaver** s = 0);
00314
00315
00316 static void saveFile(VobjectStore* vs,
00317 const std::string& filetype,
00318 const std::string& filename,
00319 VobjectStoreSaver** s = 0);
00320 static void saveFile(VobjectStore* vs,
00321 const std::string& filetype,
00322 const std::string& filename,
00323 ImpExpEnv& environment,
00324 VobjectStoreSaver** s = 0);
00325 };
00326
00327
00328 }
00329
00330 #endif