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

vdbl_col.h

Go to the documentation of this file.
00001 // Column 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_COL_H
00031 #define __VDBL_COL_H
00032 
00033 #include <stddef.h>
00034 #include <typeinfo>
00035 #include <iostream>
00036 #include <vdbl_config.h>
00037 #include <vdbl_types.h>
00038 #include <vdbl_context.h>
00039 #include <vdbl_alltype.h>
00040 
00041 __VDBL_BEGIN_NAMESPACE
00042 
00043 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00044 #pragma set woff 1209
00045 #endif
00046 
00053 template <class _C>
00054 inline std::ostream& print_it(std::ostream& o, const _C& t)
00055 {
00056   return o << t;
00057 }
00058 
00059 
00060 class _VDBL_row;
00061 class row;
00062 
00064 
00072 class __VDBL_colbase
00073 {
00074 public:
00076 
00079   __VDBL_colbase() {}
00080   __VDBL_colbase(const __VDBL_colbase& __v) {}
00081   virtual ~__VDBL_colbase() {}
00083 
00087   virtual __VDBL_colbase* new_copy() const { return new __VDBL_colbase(*this); }
00088 
00092   virtual void setcontext(const context* _c, const _VDBL_row* _r) VDBL_PURE_VIRTUAL
00093 
00099   virtual void get_copy(_VDBL_alltype_base* c) const VDBL_PURE_VIRTUAL
00100 
00104   virtual void def_copy(_VDBL_alltype_base* d) const VDBL_PURE_VIRTUAL
00105 
00110   virtual const std::type_info& return_type_id() const VDBL_PURE_VIRTUAL
00111 
00116   virtual std::ostream& print_contents(std::ostream& o) const VDBL_PURE_VIRTUAL
00117 };
00118 
00120 
00130 template <class _R>
00131 class _VDBL_colbase : public __VDBL_colbase
00132 {
00133 public:
00135   typedef _R return_type;
00136   typedef _VDBL_colbase<_R> _Self;
00137   typedef __VDBL_colbase _Base;
00138 
00140 
00143   _VDBL_colbase() {}
00144   _VDBL_colbase(const _Self& __c) {}
00145   virtual ~_VDBL_colbase() {}
00147 
00151   virtual _Self* new_copy() const { return new _VDBL_colbase(*this); }
00152   
00156   virtual void setcontext(const context* _c, const _VDBL_row* _r) VDBL_PURE_VIRTUAL
00157 
00161   virtual void get(return_type& c) const VDBL_PURE_VIRTUAL
00162 
00166   virtual void def(return_type& d) const VDBL_PURE_VIRTUAL
00167 
00172   virtual void get_ptr(return_type const *& c) const VDBL_PURE_VIRTUAL
00173 
00179   virtual void get_copy(return_type*& c) const
00180   { c = new return_type(); get(*c); }
00181 
00187   virtual void def_copy(return_type*& d) const
00188   { d = new return_type(); def(*d); }
00189 
00196   virtual void get_copy(_VDBL_alltype_base*& v) const
00197   {
00198     return_type *c = new return_type();
00199     get(*c);
00200     v = (_VDBL_alltype_base *) new _VDBL_alltype<return_type>(c);
00201   }
00202 
00209   virtual void def_copy(_VDBL_alltype_base*& v) const
00210   {
00211     return_type *d = new return_type();
00212     def(*d);
00213     v = (_VDBL_alltype_base *) new _VDBL_alltype<return_type>(d);
00214   }
00215 
00220   virtual const std::type_info& return_type_id() const
00221   { return typeid(return_type); }
00222 
00227   virtual std::ostream& print_contents(std::ostream& o) const VDBL_PURE_VIRTUAL
00228 };
00229 
00231 
00241 class _VDBL_col
00242 {
00243 private:
00247   __VDBL_colbase* _C_p;
00248 
00249 public:
00251   _VDBL_col() : _C_p(NULL) {}
00253   _VDBL_col(const _VDBL_col& __c);
00260   explicit _VDBL_col(__VDBL_colbase* __p) : _C_p(__p) {}
00261 
00267   template <class _RR>
00268   explicit _VDBL_col(const _RR& _c);
00269   
00271   virtual ~_VDBL_col();
00272 
00274   void setcontext(const context* _c, const _VDBL_row* _r);
00275 
00283   template <class _R>
00284   void set(_VDBL_colbase<_R>* _p) { _C_p = (__VDBL_colbase*)_p; }
00285 
00289   template <class _R>
00290   void get(_R& c) const;
00291 
00295   template <class _R>
00296   void def(_R& d) const;
00297 
00302   template <class _R>
00303   void get_ptr(_R const *& c) const;
00304 
00310   template <class _R>
00311   void get_copy(_R*& p) const;
00312 
00318   template <class _R>
00319   void def_copy(_R*& p) const;
00320 
00327   void get_copy(_VDBL_alltype_base*& v) const;
00328 
00335   void def_copy(_VDBL_alltype_base*& d) const;
00336 
00341   const std::type_info& return_type_id() const
00342   { return _C_p->return_type_id(); }
00343 
00348   const __VDBL_colbase* get_ptr_to_val() const
00349   { return _C_p; }
00350 
00356   friend std::ostream& operator<<(std::ostream& o, const _VDBL_col& c);
00357 };
00358 
00359 inline std::ostream& operator<<(std::ostream& o, const _VDBL_col& c)
00360 {
00361   return c._C_p->print_contents(o);
00362 }
00363 
00364 template <class _RR>
00365 inline _VDBL_col::_VDBL_col(const _RR& _c)
00366         { _C_p = (__VDBL_colbase*)(((__VDBL_colbase*)(&_c))->new_copy()); }
00367 
00368 inline _VDBL_col::_VDBL_col(const _VDBL_col& __c)
00369         { _C_p = __c._C_p ? __c._C_p->new_copy() : NULL; }
00370 
00371 inline _VDBL_col::~_VDBL_col() { delete _C_p; }
00372 
00373 inline void _VDBL_col::setcontext(const context* _c, const _VDBL_row* _r) { _C_p->setcontext(_c, _r); }
00374 
00375 template <class _R>
00376 inline void _VDBL_col::get(_R& c) const { ((_VDBL_colbase<_R>*)_C_p)->get(c); }
00377 
00378 template <class _R>
00379 inline void _VDBL_col::def(_R& c) const { ((_VDBL_colbase<_R>*)_C_p)->def(c); }
00380 
00381 template <class _R>
00382 inline void _VDBL_col::get_ptr(_R const *& c) const
00383 { ((_VDBL_colbase<_R>*)_C_p)->get_ptr(c); }
00384 
00385 template <class _R>
00386 inline void _VDBL_col::get_copy(_R*& c) const
00387 { ((_VDBL_colbase<_R>*)_C_p)->get_copy(c); }
00388 
00389 template <class _R>
00390 inline void _VDBL_col::def_copy(_R*& c) const
00391 { ((_VDBL_colbase<_R>*)_C_p)->def_copy(c); }
00392 
00393 inline void _VDBL_col::get_copy(_VDBL_alltype_base*& v) const
00394 { _C_p->get_copy(v); }
00395 
00396 inline void _VDBL_col::def_copy(_VDBL_alltype_base*& v) const
00397 { _C_p->def_copy(v); }
00398 
00400 
00404 template <class _T>
00405 class _VDBL_stdcol : public _VDBL_colbase<_T>
00406 {
00407 private:
00408   typedef _VDBL_colbase<_T> _Base;
00409   typedef _VDBL_stdcol<_T> _Self;
00410 
00411   typedef typename _Base::return_type return_type;
00412 
00413   typedef _T type;      
00414 
00415   type _C_t;            
00416 
00417 public:
00419 
00422   _VDBL_stdcol() : _Base(), _C_t() {}
00423   _VDBL_stdcol(const _Self& __c) : _Base(__c), _C_t(__c._C_t) {}
00424   virtual ~_VDBL_stdcol() {}
00426 
00430   _VDBL_stdcol(const type& __t) : _Base(), _C_t(__t) {}
00431   
00432   _Self* new_copy() const { return new _Self(*this); }
00433 
00437   void set(const _Self& _p) { _C_t = _p._C_t; }
00438 
00443   void setcontext(const context* _c, const _VDBL_row* _r) {}
00444 
00445   void get(type& c) const { c = _C_t; }
00446   
00453   void def(type& d) const { d = _C_t; }
00454 
00455   void get_ptr(type const *& c) const { c = &_C_t; }
00456   
00457   void get_copy(return_type*& c) const
00458   { c = new return_type(_C_t); }
00459 
00460   void def_copy(return_type*& d) const
00461   { d = new return_type(_C_t); }
00462 
00463   void get_copy(_VDBL_alltype_base*& v) const
00464   {
00465     return_type *c;
00466     get_copy(c);
00467     v = (_VDBL_alltype_base *) new _VDBL_alltype<return_type>(c);
00468   }
00469 
00470   void def_copy(_VDBL_alltype_base*& v) const
00471   {
00472     return_type *d;
00473     def_copy(d);
00474     v = (_VDBL_alltype_base *) new _VDBL_alltype<return_type>(d);
00475   }
00476 
00480   void set(const type& __t) { _C_t = __t; }
00481 
00487   void set_default(const type& __t) { _C_t = __t; }
00488 
00492   const type& get_val() const { return _C_t; }
00493 
00494   std::ostream& print_contents(std::ostream& o) const { return o << _C_t; }
00495 };
00496 
00498 
00505 template <class _C, class _M, class _R>
00506 class _VDBL_mthdcol : public _VDBL_colbase<_R>
00507 {
00508 private:
00509   typedef _VDBL_colbase<_R> _Base;
00510   typedef _VDBL_mthdcol<_C,_M,_R> _Self;
00511 
00512   typedef typename _Base::return_type return_type;
00513 
00514   typedef _M method;
00515   typedef _R type;
00516   typedef _C real_context;
00517 
00518   method _C_m;      
00519 
00520 public:
00522 
00525   _VDBL_mthdcol() : _Base(), _C_m() {}
00526   _VDBL_mthdcol(const _Self& __c) : _Base(__c), _C_m(__c._C_m) {}
00527   virtual ~_VDBL_mthdcol() {}
00529   
00533   _VDBL_mthdcol(const method& __m) : _Base(), _C_m(__m) {}
00534   
00535   _Self* new_copy() const { return new _Self(*this); }
00536 
00541   virtual void setcontext(const context* _c, const _VDBL_row* _r)
00542         { _C_m.setcontext((real_context*)_c, (const row*) _r); }
00543 
00544   void get(type& c) const
00546   { c = _C_m(); }
00547 
00548   void get_ptr(type const *& c) const
00550   { c = NULL; }
00551 
00552   void def(type& d) const
00554   { d = _C_m.def(); }
00555   
00556   void get_copy(return_type*& c) const
00557   { c = new return_type(_C_m()); }
00558 
00559   void def_copy(return_type*& d) const
00560   { d = new return_type(_C_m.def()); }
00561 
00562   std::ostream& print_contents(std::ostream& o) const { return o << _C_m(); }
00563 };
00564 
00566 
00570 typedef _VDBL_col col;
00571 
00573 
00577 typedef _VDBL_stdcol<mixtype> standard_col;
00578 
00580 
00584 template <class _R>
00585 class col_base : public _VDBL_colbase<_R>
00586 {
00587 public:
00588   typedef _R return_type;
00589 };
00590 
00592 
00597 template <class _T>
00598 class typed_col : public _VDBL_stdcol<_T>
00599 {
00600 private:
00601   typedef _VDBL_stdcol<_T> _Base;
00602   typedef typed_col<_T> _Self;
00603 public:
00604   typedef _T type;
00605   typedef _T return_type;
00606 
00607   typed_col() : _Base() {}
00608   typed_col(const _T& __t) : _Base(__t) {}
00609   typed_col(const _Self& __t) : _Base(__t) {}
00610 
00611   virtual ~typed_col() {}
00612 };
00613 
00615 
00630 template <class _M>
00631 class method_col : public _VDBL_mthdcol<typename _M::context, _M,
00632                                         typename _M::return_type>
00633 {
00634 private:
00635   typedef _VDBL_mthdcol<typename _M::context, _M, typename _M::return_type>
00636                                                                         _Base;
00637   typedef method_col<_M> _Self;
00638 
00639 public:
00640   typedef _M method;
00641   typedef typename _M::return_type return_type;
00642   typedef typename _M::context context;
00643 
00644   method_col() : _Base() {}
00645   method_col(const _Self& __m) : _Base(__m) {}
00646   method_col(const method& __m) : _Base(__m) {}
00647 
00648   virtual ~method_col() {}
00649 };
00650 
00651 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00652 #pragma reset woff 1209
00653 #endif
00654 
00655 __VDBL_END_NAMESPACE
00656 
00657 #endif /* __VDBL_COL_H */
00658 
00659 // Local Variables:
00660 // mode:C++
00661 // End:

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