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_JOINVIEW_H
00031 #define __VDBL_JOINVIEW_H
00032
00033 #include <iostream>
00034 #include <vdbl_table.h>
00035 #include <vdbl_view.h>
00036
00037 __VDBL_BEGIN_NAMESPACE
00038
00039 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00040 #pragma set woff 1209
00041 #endif
00042
00043 class _VDBL_joinview : public _VDBL_view
00044 {
00045 private:
00046 typedef _VDBL_view _Base;
00047
00048 typedef std::pair<_VDBL_tableid,_VDBL_colid> _V_colref;
00049 typedef std::map<_VDBL_tableid, _VDBL_rowid> _V_rowref;
00050 typedef std::map<std::pair<_VDBL_rowid,_VDBL_tableid>, _VDBL_col> _V_colentry;
00051 typedef std::map<_V_colref, _V_colentry> _V_colcache;
00052 typedef std::vector<_V_rowref> _V_rows;
00053 typedef std::vector<_V_colref> _V_cols;
00054
00055 private:
00056 std::map<_VDBL_tableid,_VDBL_table *> _V_t;
00057 const _VDBL_context* _V_ctx;
00058
00059 std::map<_VDBL_tableid,unsigned int> _V_lastchg;
00060
00061 _V_colcache _V_cc;
00062
00063 protected:
00064 _V_rows _V_r;
00065 _V_cols _V_c;
00066
00067 private:
00068 std::map<std::string,_V_colref> _V_colnames;
00069
00070 friend class _VDBL_table;
00071
00072 public:
00073 typedef _Base::default_const_iterator defaults_const_iterator;
00074
00075 protected:
00076 std::pair<_VDBL_tableid,_VDBL_colid>
00077 _next_def_col(const _VDBL_tableid& _t, const _VDBL_colid& _c) const
00078 {
00079 std::cerr << "standard_view: _next_def_col NYI!" << std::endl;
00080 return std::make_pair(0,0);
00081 }
00082
00083 std::pair<_VDBL_tableid,_VDBL_colid>
00084 _prev_def_col(const _VDBL_tableid& _t, const _VDBL_colid& _c) const
00085 {
00086 std::cerr << "standard_view: _prev_def_col NYI!" << std::endl;
00087 return std::make_pair(0,0);
00088 }
00089
00090 std::pair<_VDBL_tableid,_VDBL_colid>
00091 _next_col(const _VDBL_tableid& _t, const _VDBL_rowid& _r,
00092 const _VDBL_colid& _c) const
00093 {
00094 std::cerr << "standard_view: _next_col NYI!" << std::endl;
00095 return std::make_pair(0,0);
00096 }
00097
00098 std::pair<_VDBL_tableid,_VDBL_colid>
00099 _prev_col(const _VDBL_tableid& _t, const _VDBL_rowid& _r,
00100 const _VDBL_colid& _c) const
00101 {
00102 std::cerr << "standard_view: _prev_col NYI!" << std::endl;
00103 return std::make_pair(0,0);
00104 }
00105
00106 std::pair<_VDBL_tableid,_VDBL_rowid>
00107 _next_row(const _VDBL_tableid& _t, const _VDBL_rowid& _r) const
00108 {
00109 std::cerr << "standard_view: _next_row NYI!" << std::endl;
00110 return std::make_pair(0,0);
00111 }
00112
00113 std::pair<_VDBL_tableid,_VDBL_rowid>
00114 _prev_row(const _VDBL_tableid& _t, const _VDBL_rowid& _r) const
00115 {
00116 std::cerr << "standard_view: _prev_row NYI!" << std::endl;
00117 return std::make_pair(0,0);
00118 }
00119
00120 public:
00121 _VDBL_joinview(const _VDBL_tableid& __ti, _VDBL_table* __t,
00122 const _VDBL_context& __c, _V_enum __e)
00123 : _Base(__e), _V_t(), _V_ctx(&__c),
00124 _V_lastchg(), _V_cc(), _V_r(), _V_c(), _V_colnames()
00125 {
00126 _V_t.insert(std::make_pair(__ti,__t));
00127 _VDBL_table::col_const_iterator __x;
00128 for(__x = __t->col_begin(); __x != __t->col_end(); ++__x)
00129 _V_colnames.insert(std::make_pair((*__x).first,
00130 std::make_pair(__ti,(*__x).second)));
00131 _V_lastchg.insert(std::make_pair(__ti,__t->get_change_ctr()));
00132 }
00133
00134 _VDBL_joinview(const std::vector<std::pair<_VDBL_tableid,_VDBL_table *> >&
00135 __t, const _VDBL_context& __c, _V_enum __e)
00136 : _Base(__e), _V_t(), _V_ctx(&__c), _V_cc(), _V_r(), _V_c(),
00137 _V_colnames()
00138 {
00139 std::vector<std::pair<_VDBL_tableid,_VDBL_table *> >::const_iterator
00140 __y;
00141 for(__y = __t.begin(); __y != __t.end(); ++__y)
00142 {
00143 _V_t.insert(std::make_pair((*__y).first, (*__y).second));
00144 _VDBL_table::col_const_iterator __x;
00145 for(__x = (*__y).second->col_begin();
00146 __x != (*__y).second->col_end(); ++__x)
00147 {
00148 const std::string &s((*__x).first);
00149 if(_V_colnames.find(s) != _V_colnames.end())
00150 _V_colnames.insert(std::make_pair(s,
00151 std::make_pair((*__x).second, (*__y).first)));
00152
00153 }
00154 _V_lastchg.insert(std::make_pair((*__y).first,
00155 (*__y).second->get_change_ctr()));
00156 }
00157 }
00158
00159 _VDBL_joinview(const _VDBL_joinview& __v)
00160 : _Base(__v), _V_t(__v._V_t), _V_ctx(__v._V_ctx),
00161 _V_cc(__v._V_cc), _V_r(__v._V_r), _V_c(__v._V_c),
00162 _V_colnames(__v._V_colnames)
00163 {}
00164
00165
00166 virtual ~_VDBL_joinview() {}
00167
00168 public:
00169 const std::type_info& get_colinfo(const std::string& _C_n,
00170 triple<bool,_VDBL_colid,_VDBL_colflags>& _r) const
00171 {
00172 std::map<std::string,_V_colref>::const_iterator __x(_V_colnames.find(_C_n));
00173 if(__x == _V_colnames.end())
00174 {
00175 _r = make_triple(false, _VDBL_colid(), _VDBL_colflags());
00176 return typeid(void);
00177 }
00178 const _V_colref& _cr((*__x).second);
00179 typedef std::pair<_VDBL_colid,_VDBL_tableid> _V_colref;
00180 std::map<_VDBL_tableid,_VDBL_table *>::const_iterator
00181 __y(_V_t.find(_cr.second));
00182 if(__y == _V_t.end())
00183 {
00184 std::cerr << "Corrupted view detected! Table entry not found for stored ID!" << std::endl;
00185 throw "VDBL: Programming error";
00186 }
00187 return (*__y).second->get_colinfo(_C_n, _r);
00188 }
00189
00190 bool insert(const std::vector<_T_colspec>& _row)
00191 {
00192 if(view_type() != V_window)
00193 return false;
00196 std::map<_VDBL_tableid,_VDBL_table *>::iterator __x(_V_t.begin());
00197 return (*__x).second->insert_row(_row);
00198 }
00199
00200 bool remove(std::pair<_VDBL_tableid,_VDBL_rowid> _r)
00201 {
00202 if(view_type() != V_window)
00203 return false;
00206 std::map<_VDBL_tableid,_VDBL_table *>::iterator __x(_V_t.begin());
00207 if(_r.first != (*__x).first)
00208 return false;
00209 return (*__x).second->remove(_r.second);
00210 }
00211
00212 bool has_col(const std::string& _C_n) const
00213 {
00214 std::map<std::string,_V_colref>::const_iterator __x(_V_colnames.find(_C_n));
00215 return __x != _V_colnames.end();
00216 }
00217
00218 std::pair<_VDBL_tableid,_VDBL_colid> get_col_id(const std::string& _C_n) const
00219 {
00220 std::map<std::string,_V_colref>::const_iterator __x(_V_colnames.find(_C_n));
00221 if(__x == _V_colnames.end())
00222 return std::make_pair(_VDBL_tableid(),_VDBL_colid());
00223 return (*__x).second;
00224 }
00225
00226 const _VDBL_row& get_row(const std::pair<_VDBL_tableid,_VDBL_rowid>& _ri,
00227 bool& error) const
00228 {
00229 std::map<_VDBL_tableid,_VDBL_table *>::const_iterator
00230 __x(_V_t.find(_ri.first));
00231 return (*__x).second->get_row(_ri.second, error);
00232 }
00233
00234 const _VDBL_col& get_col(const std::pair<_VDBL_tableid,_VDBL_rowid>& _ri,
00235 const _VDBL_colid& _ci, _VDBL_row const *& __r,
00236 bool& error) const
00237 {
00238 std::map<_VDBL_tableid,_VDBL_table *>::const_iterator
00239 __x(_V_t.find(_ri.first));
00240 const _VDBL_row& _r((*__x).second->get_row(_ri.second, error));
00241 if(error)
00242 return ___empty_col_return;
00243 _rr = &_r;
00244 const _VDBL_col& _c(_r.get_col(_ci, error));
00245 if(error)
00246 return (*__x).second->get_def(_ci, error);
00247 else
00248 return _c;
00249 }
00250
00251 template <class _R>
00252 bool get_raw_ptr(const std::pair<_VDBL_tableid,_VDBL_rowid>& _ri,
00253 const _VDBL_colid& _ci, _R const *& r) const
00254 {
00255 bool error;
00256 const VDBL_row* _rr;
00257 vdbl::col c(get_col(_ri, _ci, _rr, error));
00258 if(error)
00259 return false;
00260 c.setcontext(_V_ctx, _rr);
00261 c.get_ptr(r);
00262 return true;
00263 }
00264
00265 template <class _R>
00266 bool get(const std::pair<_VDBL_tableid,_VDBL_rowid>& _ri,
00267 const _VDBL_colid& _ci, _R& r) const
00268 {
00269 bool error;
00270 const VDBL_row* _rr;
00271 vdbl::col c(get_col(_ri, _ci, _rr, error));
00272 if(error)
00273 return false;
00274 c.setcontext(_V_ctx, _rr);
00275 c.get(r);
00276 return true;
00277 }
00278
00279 const _VDBL_col& get_def(const std::pair<_VDBL_tableid,_VDBL_colid>& _ri,
00280 bool& error) const
00281 {
00282 std::map<_VDBL_tableid,_VDBL_table *>::const_iterator
00283 __x(_V_t.find(_ri.first));
00284 return (*__x).second->get_def(_ri.second, error);
00285 }
00286
00287 default_const_iterator defaults_begin() const
00288 {
00289 return default_const_iterator();
00290 }
00291
00292 default_const_iterator defaults_end() const
00293 {
00294 return default_const_iterator();
00295 }
00296
00297 col_const_iterator cols_begin(const _VDBL_rowid& _r) const
00298 {
00299 return col_const_iterator();
00300 }
00301
00302 col_const_iterator cols_end(const _VDBL_rowid& _r) const
00303 {
00304 return col_const_iterator();
00305 }
00306
00307 row_const_iterator rows_begin() const
00308 {
00309 return row_const_iterator();
00310 }
00311
00312 row_const_iterator rows_end() const
00313 {
00314 return row_const_iterator();
00315 }
00316 };
00317
00318 class join_view : public _VDBL_joinview
00319 {
00320 typedef _VDBL_joinview _Base;
00321
00322 public:
00323 typedef _V_enum view_enum;
00324
00325 public:
00326 join_view(const _VDBL_tableid& __ti, _VDBL_table* __t,
00327 const _VDBL_context& __c, _V_enum __e = V_transparent)
00328 : _VDBL_joinview(__ti,__t,__c,__e) {}
00329
00330 join_view(const join_view& _v) : _VDBL_joinview(_v) {}
00331
00332 template <class _R>
00333 bool get(const tableid& _ti, const rowid& _ri, const colid& _ci, _R& r) const
00334 { return _Base::get(std::make_pair(_ti, _ri), _ci, r); }
00335
00336 template <class _R>
00337 bool get(const rowid& _ri, const std::string& _c, _R& r) const
00338 { std::pair<tableid,colid> _tci(get_col_id(_c));
00339 return _Base::get(std::make_pair(_tci.first, _ri), _tci.second, r); }
00340
00341 template <class _R>
00342 bool get(const rowid& _ri, const char* _c, _R& r) const
00343 { return get(_ri, std::string(_c), r); }
00344 };
00345
00346 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00347 #pragma reset woff 1209
00348 #endif
00349
00350 __VDBL_END_NAMESPACE
00351
00352 #endif
00353
00354
00355
00356