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