00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #ifndef __VDBL_VIEWDBASE_H
00032 #define __VDBL_VIEWDBASE_H
00033
00034 #include <algorithm>
00035 #include <map>
00036 #include <vdbl_config.h>
00037 #include <vdbl_database.h>
00038
00039 __VDBL_BEGIN_NAMESPACE
00040
00041 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00042 #pragma set woff 1209
00043 #endif
00044
00046
00051 class _VDBL_viewdbase
00052 {
00053 private:
00054 typedef std::map<std::string, _VDBL_tableid> _D_view_names;
00055 typedef std::map<_VDBL_tableid, _VDBL_view*> _D_views;
00056
00058 const _VDBL_database* _D_db;
00060 _D_view_names _D_vn;
00062 _D_views _D_v;
00064 _VDBL_userid _D_uid;
00066 const _VDBL_context* _D_ctx;
00068 _V_enum _D_viewtype;
00069 public:
00073 _VDBL_tableid get_tableid(const std::string& _C_i) const
00074 {
00075
00076 _D_view_names::const_iterator __t(_D_vn.find(_C_i));
00077 if(__t == _D_vn.end())
00078 {
00079 if(_D_viewtype == V_window)
00080 return _D_db->get_tableid(_C_i, _D_uid);
00081 else
00082 return _VDBL_tableid();
00083 }
00084 else
00085 return (*__t).second;
00086 }
00087
00088 public:
00092 bool has_view(const _VDBL_tableid& _C_i) const
00093 {
00094 _D_views::const_iterator __v(_D_v.find(_C_i));
00095 if(__v == _D_v.end())
00096 {
00097 if(_D_viewtype == V_window)
00098 return _D_db->has_table(_C_i, _D_uid);
00099 else
00100 return false;
00101 }
00102 else
00103 return true;
00104 }
00105
00109 bool has_view(const std::string& _C_i) const
00110 { return has_view(get_tableid(_C_i)); }
00111
00115 _VDBL_view* get_view(const _VDBL_tableid& _C_i) const
00116 {
00117
00118 _D_views::const_iterator __v(_D_v.find(_C_i));
00119 if(__v == _D_v.end())
00120 {
00121 if(_D_viewtype == V_window)
00122 {
00123 _VDBL_viewdbase* tthis = const_cast<_VDBL_viewdbase*>(this);
00124
00125 if(_D_db->has_table(_C_i, _D_uid))
00126 {
00127
00128 _VDBL_view* __v(_D_db->get_table_view(_C_i, *_D_ctx, _D_viewtype));
00129 tthis->_D_v.insert(std::make_pair(_C_i, __v));
00130 tthis->_D_vn = _D_db->_D_tn;
00131 return __v;
00132 }
00133 else
00134 return NULL;
00135 }
00136 else
00137 return NULL;
00138 }
00139 return (*__v).second;
00140 }
00141
00145 _VDBL_view* get_view(const std::string& _C_i) const
00146 { return get_view(get_tableid(_C_i)); }
00147
00151 _VDBL_viewdbase() : _D_db(NULL), _D_vn(), _D_v(), _D_uid(), _D_ctx(NULL),
00152 _D_viewtype(V_frozen) {}
00153
00159 _VDBL_viewdbase(const _VDBL_database& _db, const _VDBL_userid& uid,
00160 const _VDBL_context& __c, const _V_enum& __e = V_frozen)
00161 : _D_db(&_db), _D_vn(_db._D_tn), _D_v(),
00162 _D_uid(uid), _D_ctx(&__c), _D_viewtype(__e)
00163 {
00164 if(_D_viewtype != V_window)
00165 {
00166
00167 for(_VDBL_database::_D_tables::const_iterator __x = _db._D_t.begin();
00168 __x != _db._D_t.end(); ++__x)
00169 {
00170 _D_v.insert(std::make_pair((*__x).first,
00171 _db.get_table_view((*__x).first, __c, _D_viewtype)));
00172 }
00173 }
00174 }
00175
00183 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00184 _VDBL_viewdbase(const _VDBL_database& _db, const _VDBL_userid& uid,
00185 const _VDBL_context& __c,
00186 const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an,
00187 const _V_enum& __e = V_frozen)
00188 : _D_db(&_db), _D_vn(_db._D_tn), _D_v(),
00189 _D_uid(uid), _D_ctx(&__c), _D_viewtype(__e)
00190 {
00191
00192 for(_VDBL_database::_D_tables::const_iterator __x = _db._D_t.begin();
00193 __x != _db._D_t.end(); ++__x)
00194 {
00195 _D_v.insert(std::make_pair((*__x).first,
00196 _db.get_table_view((*__x).first, __c, _D_viewtype, __an)));
00197 }
00198 }
00199
00203 virtual ~_VDBL_viewdbase()
00204 {
00205 for(_D_views::iterator __x = _D_v.begin(); __x != _D_v.end(); ++__x)
00206 delete (*__x).second;
00207 }
00208
00213 bool add_table_view(const _VDBL_tableid& __t, const std::string& __s,
00214 const _VDBL_context& __c)
00215 {
00216 if(!_D_db) return false;
00217
00218 if(has_view(__t)) return true;
00219 _D_v.insert(std::make_pair(__t,
00220 _D_db->get_table_view(__t, __c, _D_viewtype)));
00221 _D_vn.insert(std::make_pair(__s, __t));
00222 return true;
00223 }
00224
00231 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00232 bool add_table_view(const _VDBL_tableid& __t, const std::string& __s,
00233 const _VDBL_context& __c,
00234 const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00235 {
00236 if(!_D_db) return false;
00237
00238 if(has_view(__t)) return true;
00239 _D_v.insert(std::make_pair(__t,
00240 _D_db->get_table_view(__t, __c, _D_viewtype, __an)));
00241 _D_vn.insert(std::make_pair(__s, __t));
00242 return true;
00243 }
00244
00249 bool add_table_view(const std::string& __s, const _VDBL_context& __c)
00250 {
00251 if(!_D_db) return false;
00252
00253 _VDBL_tableid __t(_D_db->get_tableid(__s, _D_uid));
00254 return add_table_view(__t, __s, __c);
00255 }
00256
00263 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00264 bool add_table_view(const std::string& __s, const _VDBL_context& __c,
00265 const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00266 {
00267 if(!_D_db) return false;
00268
00269 _VDBL_tableid __t(_D_db->get_tableid(__s, _D_uid));
00270 return add_table_view(__t, __s, __c, __an);
00271 }
00272
00277 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00278 bool add_visible(const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00279 {
00280 if(!_D_db) return false;
00281
00282 for(_D_views::iterator __x = _D_v.begin(); __x != _D_v.end(); ++__x)
00283 _D_db->add_to_table_view((*__x).second, (*__x).first, __an);
00284 return true;
00285 }
00286
00291 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00292 bool rm_visible(const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00293 {
00294 if(!_D_db) return false;
00295
00296 for(_D_views::iterator __x = _D_v.begin(); __x != _D_v.end(); ++__x)
00297 _D_db->rm_from_table_view((*__x).second, (*__x).first, __an);
00298 return true;
00299 }
00300 };
00301
00303
00310 class viewdbase : public _VDBL_viewdbase
00311 {
00312 private:
00313 typedef _VDBL_viewdbase _Base;
00314
00315 public:
00316 typedef _VDBL_view view;
00317
00318 public:
00322 bool has_view(const char* _C_i) const
00323 { return _Base::has_view(std::string(_C_i)); }
00327 viewbase* get_view(const char* _C_i) const
00328 { return (viewbase*)_Base::get_view(std::string(_C_i)); }
00332 viewbase* get_view(const std::string& _C_i) const
00333 { return (viewbase*)_Base::get_view(_C_i); }
00334
00338 viewdbase() : _Base() {}
00339
00346 viewdbase(const database& db, const userid& uid, const context& c,
00347 view_enum e = V_frozen)
00348 : _Base(db,uid,c,e) {}
00349
00359 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00360 viewdbase(const database& db, const userid& uid, const context& c,
00361 const _SqCtr<std::pair<tableid,rowid>,_Al>& __an,
00362 view_enum e = V_frozen)
00363 : _Base(db,uid,c,__an,e) {}
00364
00368 virtual ~viewdbase() {}
00369
00374 bool add_table_view(const _VDBL_tableid& __t, const std::string& __s,
00375 const _VDBL_context& __c)
00376 {
00377 return _Base::add_table_view(__t, __s, __c);
00378 }
00379
00386 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00387 bool add_table_view(const _VDBL_tableid& __t, const std::string& __s,
00388 const _VDBL_context& __c,
00389 const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00390 {
00391 return _Base::add_table_view(__t, __s, __c, __an);
00392 }
00393
00398 bool add_table_view(const std::string& __s, const _VDBL_context& __c)
00399 {
00400 return _Base::add_table_view(__s, __c);
00401 }
00402
00409 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00410 bool add_table_view(const std::string& __s, const _VDBL_context& __c,
00411 const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00412 {
00413 return _Base::add_table_view(__s, __c, __an);
00414 }
00415
00420 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00421 bool add_visible(const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00422 {
00423 return _Base::add_visible(__an);
00424 }
00425
00430 template <template <class _TC, class _TA> class _SqCtr, class _Al>
00431 bool rm_visible(const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00432 {
00433 return _Base::rm_visible(__an);
00434 }
00435 };
00436
00437 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00438 #pragma reset woff 1209
00439 #endif
00440
00441 __VDBL_END_NAMESPACE
00442
00443 #endif
00444
00445
00446
00447