00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #ifndef __VDBL_VIEWDBASE_H
00031 #define __VDBL_VIEWDBASE_H
00032
00033 #include <algorithm>
00034 #include <map>
00035 #include <vdbl_config.h>
00036 #include <vdbl_database.h>
00037
00038 __VDBL_BEGIN_NAMESPACE
00039
00040 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00041 #pragma set woff 1209
00042 #endif
00043
00045
00050 class _VDBL_viewdbase
00051 {
00052 private:
00053 typedef std::map<std::string, _VDBL_tableid> _D_view_names;
00054 typedef std::map<_VDBL_tableid, _VDBL_view*> _D_views;
00055
00057 _D_view_names _D_vn;
00059 _D_views _D_v;
00060
00061 public:
00065 _VDBL_tableid get_tableid(const std::string& _C_i) const
00066 {
00067
00068 _D_view_names::const_iterator __t(_D_vn.find(_C_i));
00069 if(__t == _D_vn.end())
00070 return _VDBL_tableid();
00071 else
00072 return (*__t).second;
00073 }
00074
00075 public:
00079 bool has_view(const _VDBL_tableid& _C_i) const
00080 {
00081 _D_views::const_iterator __v(_D_v.find(_C_i));
00082 if(__v == _D_v.end())
00083 return false;
00084 else
00085 return true;
00086 }
00087
00091 bool has_view(const std::string& _C_i) const
00092 { return has_view(get_tableid(_C_i)); }
00093
00097 _VDBL_view* get_view(const _VDBL_tableid& _C_i) const
00098 {
00099
00100 _D_views::const_iterator __v(_D_v.find(_C_i));
00101 if(__v == _D_v.end())
00102 return NULL;
00103 return (*__v).second;
00104 }
00105
00109 _VDBL_view* get_view(const std::string& _C_i) const
00110 { return get_view(get_tableid(_C_i)); }
00111
00115 _VDBL_viewdbase() : _D_vn(), _D_v() {}
00116
00122 _VDBL_viewdbase(const _VDBL_database& _db, const _VDBL_userid& uid,
00123 const _VDBL_context& __c)
00124 : _D_vn(_db._D_tn), _D_v()
00125 {
00126
00127 for(_VDBL_database::_D_tables::const_iterator __x = _db._D_t.begin();
00128 __x != _db._D_t.end(); ++__x)
00129 {
00130 _D_v.insert(std::make_pair((*__x).first,
00131 _db.get_table_view((*__x).first, __c, V_frozen)));
00132 }
00133 }
00134
00142 template <template <class _C, class _A> class _SqCtr, class _Al>
00143 _VDBL_viewdbase(const _VDBL_database& _db, const _VDBL_userid& uid,
00144 const _VDBL_context& __c,
00145 const _SqCtr<std::pair<_VDBL_tableid,_VDBL_rowid>,_Al>& __an)
00146 : _D_vn(_db._D_tn), _D_v()
00147 {
00148
00149 for(_VDBL_database::_D_tables::const_iterator __x = _db._D_t.begin();
00150 __x != _db._D_t.end(); ++__x)
00151 {
00152 _D_v.insert(std::make_pair((*__x).first,
00153 _db.get_table_view((*__x).first, __c, V_frozen, __an)));
00154 }
00155 }
00156
00160 virtual ~_VDBL_viewdbase()
00161 {
00162 for(_D_views::iterator __x = _D_v.begin(); __x != _D_v.end(); ++__x)
00163 delete (*__x).second;
00164 }
00165 };
00166
00168
00175 class viewdbase : public _VDBL_viewdbase
00176 {
00177 private:
00178 typedef _VDBL_viewdbase _Base;
00179
00180 public:
00181 typedef _VDBL_view view;
00182
00183 public:
00187 bool has_view(const char* _C_i) const
00188 { return _Base::has_view(std::string(_C_i)); }
00192 viewbase* get_view(const char* _C_i) const
00193 { return (viewbase*)_Base::get_view(std::string(_C_i)); }
00197 viewbase* get_view(const std::string& _C_i) const
00198 { return (viewbase*)_Base::get_view(_C_i); }
00199
00203 viewdbase() : _Base() {}
00204
00210 viewdbase(const database& db, const userid& uid, const context& c)
00211 : _Base(db,uid,c) {}
00212
00221 template <template <class _C, class _A> class _SqCtr, class _Al>
00222 viewdbase(const database& db, const userid& uid, const context& c,
00223 const _SqCtr<std::pair<tableid,rowid>,_Al>& __an)
00224 : _Base(db,uid,c,__an) {}
00225
00229 virtual ~viewdbase() {}
00230 };
00231
00232 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00233 #pragma reset woff 1209
00234 #endif
00235
00236 __VDBL_END_NAMESPACE
00237
00238 #endif
00239
00240
00241
00242