00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __STORAGE_HPP
00014 #define __STORAGE_HPP
00015 #include <basix/exception.hpp>
00016 #include <basix/string.hpp>
00017 #include <basix/vector.hpp>
00018
00020
00021 namespace mmx {
00022 class storage_rep;
00023 class storage;
00024
00025 class storage_rep: public rep_struct {
00026 public:
00027 virtual void write (const string& var, const string& val) const = 0;
00028 virtual string read (const string& var) const = 0;
00029 virtual void lock (const string& var) const = 0;
00030 virtual void unlock (const string& var) const = 0;
00031
00032 virtual storage get_branch (const string& br) const = 0;
00033 virtual bool has_branch (const string& br) const = 0;
00034 virtual string get_file (const string& name) const = 0;
00035 virtual bool has_file (const string& name) const = 0;
00036
00037 virtual vector<string> retrieve_data () const = 0;
00038 virtual vector<string> retrieve_branches () const = 0;
00039 virtual vector<string> retrieve_files () const = 0;
00040
00041 public:
00042 inline storage_rep () {}
00043 inline virtual ~storage_rep () {}
00044 friend class storage;
00045 };
00046
00047 class storage {
00048 INDIRECT_PROTO (storage, storage_rep)
00049 public:
00050 inline storage (): rep (NULL) {}
00051 friend class storage_rep;
00052 };
00053 INDIRECT_NULL_IMPL (storage, storage_rep)
00054
00055 HARD_TO_EXACT_IDENTITY_SUGAR(,storage)
00056 HARD_TO_TRUE_IDENTITY_SUGAR(,storage)
00057 inline syntactic flatten (const storage& st) { return "storage"; }
00058
00059 storage disk_storage ();
00061 storage disk_storage (const string& root);
00063 storage cached_storage (const storage& st);
00065
00066 inline void write (const storage& st, const string& var, const string& val) {
00067 st->write (var, val); }
00069 inline string read (const storage& st, const string& var) {
00070 return st->read (var); }
00072 inline void lock (const storage& st, const string& var) {
00073 st->lock (var); }
00075 inline void unlock (const storage& st, const string& var) {
00076 st->unlock (var); }
00078
00079 inline storage get_branch (const storage& st, const string& br) {
00080 return st->get_branch (br); }
00082 inline bool has_branch (const storage& st, const string& br) {
00083 return st->has_branch (br); }
00085 inline string get_file (const storage& st, const string& orig) {
00086 return st->get_file (orig); }
00088 inline bool has_file (const storage& st, const string& orig) {
00089 return st->has_file (orig); }
00091
00092 inline vector<string> retrieve_data (const storage& st) {
00093 return st->retrieve_data (); }
00095 inline vector<string> retrieve_branches (const storage& st) {
00096 return st->retrieve_branches (); }
00098 inline vector<string> retrieve_files (const storage& st) {
00099 return st->retrieve_files (); }
00101
00102 inline vector<generic> retrieve_data_bis (const storage& st) {
00103 return as<vector<generic> > (st->retrieve_data ()); }
00105 inline vector<generic> retrieve_branches_bis (const storage& st) {
00106 return as<vector<generic> > (st->retrieve_branches ()); }
00108 inline vector<generic> retrieve_files_bis (const storage& st) {
00109 return as<vector<generic> > (st->retrieve_files ()); }
00111
00112 }
00113 #endif // __STORAGE_HPP