Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

vdbl_viewdbase.h

Go to the documentation of this file.
00001 // View database class implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2003 Hermann Schichl
00004 //
00005 // This file is part of the Vienna Database Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the Library GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // Library GNU General Public License for more details.
00015 
00016 // As a special exception, you may use this file as part of a free software
00017 // library without restriction.  Specifically, if other files instantiate
00018 // templates or use macros or inline functions from this file, or you compile
00019 // this file and link it with other files to produce an executable, this
00020 // file does not by itself cause the resulting executable to be covered by
00021 // the Library GNU General Public License.  This exception does not however
00022 // invalidate any other reasons why the executable file might be covered by
00023 // the Library GNU General Public License.
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     // should check user first
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     // should check the user here
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     // should check user here
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     // should check user here
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 /* __VDBL_VIEWDBASE_H */
00239 
00240 // Local Variables:
00241 // mode:C++
00242 // End:

Generated on Tue Nov 4 01:29:11 2003 for Vienna Database Library by doxygen1.2.18