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

vdbl_row.h

Go to the documentation of this file.
00001 // Row 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_ROW_H
00031 #define __VDBL_ROW_H
00032 
00033 #include <algorithm>
00034 #include <map>
00035 #include <vdbl_config.h>
00036 #include <vdbl_types.h>
00037 #include <vdbl_col.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 static _VDBL_col ___empty_col_return;
00047 
00049 
00053 class _VDBL_row
00054 { 
00055 private:
00057   typedef std::map<_VDBL_colid, _VDBL_col> _R_map;
00058 
00060   _R_map _R_i;
00061 
00062 public:
00066   _VDBL_row() : _R_i() {}
00070   _VDBL_row(const _VDBL_row& __r) : _R_i(__r._R_i) {}
00074   virtual ~_VDBL_row() {}
00075 
00081   const _VDBL_col& get_col(const _VDBL_colid& _id, bool& error) const
00082   {
00083     _R_map::const_iterator __i(_R_i.find(_id));
00084 
00085     if(__i == _R_i.end())
00086     {
00087       error = true;
00088       return ___empty_col_return;
00089     }
00090     else
00091     {
00092       error = false;
00093       return (*__i).second;
00094     }
00095   }
00096 
00102   _VDBL_col& get_col(const _VDBL_colid& _id, bool& error)
00103   {
00104     _R_map::iterator __i(_R_i.find(_id));
00105 
00106     if(__i == _R_i.end())
00107     {
00108       error = true;
00109       return ___empty_col_return;
00110     }
00111     else
00112     {
00113       error = false;
00114       return (*__i).second;
00115     }
00116   }
00117 
00121   bool has_col(const _VDBL_colid& _id) const
00122   {
00123     _R_map::const_iterator __i(_R_i.find(_id));
00124     return __i != _R_i.end();
00125   }
00126 
00131   bool insert(const _VDBL_colid& _id, const _VDBL_col& _col)
00132   {
00133     _R_map::iterator __i(_R_i.find(_id));
00134     if(__i != _R_i.end())
00135       return false;
00136     else
00137     {
00138       _R_i.insert(std::make_pair(_id,_col));
00139       return true;
00140     }
00141   }
00142 
00148   bool drop(const _VDBL_colid& _id)
00149   {
00150     _R_map::iterator __i(_R_i.find(_id));
00151     if(__i == _R_i.end())
00152       return false;
00153     else
00154     {
00155       _R_i.erase(__i);
00156       return true;
00157     }
00158   }
00159 
00165   void update(const _VDBL_colid& _id, const _VDBL_col& _col)
00166   {
00167     _R_map::iterator __i(_R_i.find(_id));
00168     if(__i != _R_i.end())
00169       _R_i.erase(__i);
00170     _R_i.insert(std::make_pair(_id,_col));
00171   }
00172 };
00173 
00175 
00179 class row : public _VDBL_row
00180 {
00181 private:
00182   typedef _VDBL_row _Base;
00183 public:
00184   typedef _VDBL_colid id;
00185   typedef _VDBL_col col;
00186 
00190   row() : _Base() {}
00194   row(const row& __r) : _Base(__r) {}
00198   row(const _Base& __r) : _Base(__r) {}
00199 
00203   row& operator=(const row& _x)
00204   {
00205     return *(row*)&(this->_Base::operator=(_x));
00206   }
00207 
00211   row& operator=(const _Base& _x)
00212   {
00213     return *(row*)&(this->_Base::operator=(_x));
00214   }
00215 };
00216 
00217 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00218 #pragma reset woff 1209
00219 #endif
00220 
00221 __VDBL_END_NAMESPACE
00222 
00223 #endif /* __VDBL_ROW_H */
00224 
00225 // Local Variables:
00226 // mode:C++
00227 // End:

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