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

vdbl_expression.h

Go to the documentation of this file.
00001 // Expression 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_EXPRESSION_H
00031 #define __VDBL_EXPRESSION_H
00032 
00033 #include <algorithm>
00034 #include <map>
00035 #include <vector>
00036 #include <typeinfo>
00037 #include <vdbl_config.h>
00038 #include <vdbl_types.h>
00039 #include <vdbl_context.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 
00047 class _VDBL_eval_expr
00048 {
00049 public:
00050 }
00051 
00052 class _VDBL_expression
00053 {
00054 public:
00055   _VDBL_expression() {}
00056   virtual ~_VDBL_expression() {}
00057 
00058   virtual const type_info& result_type() VDBL_PURE_VIRTUAL
00059 };
00060 
00061 class _VDBL_exprrow : public _VDBL_expression
00062 {
00063   std::string _E_r;            // row name
00064   std::string _E_t;            // table name
00065 
00066 public:
00067   _VDBL_exprrow(const std::string& __r, const std) : _C_r(__r) {}
00068   _VDBL_exprrow(const _VDBL_exprrow& _e) : _C_r(_e._C_r) {}
00069   ~_VDBL_exprrow() {}
00070 
00071   virtual const _VDBL_alltype_base* operator()(const _VDBL_database& _d,
00072                                           const _VDBL_context* _ctx) const
00073     {}
00074 };
00075 
00076 class _VDBL_exprcol : public _VDBL_expression
00077 {
00078   std::string _E_c;            // col name
00079   std::string _E_t;            // table name
00080 
00081 public:
00082   _VDBL_exprcol(const std::string& __c, const std::string& __t)
00083                                         : _E_c(__c), _E_t(__t) {}
00084   _VDBL_exprcol(const _VDBL_exprcol& _e) : _E_c(_e._E_c), _E_t(_e._E_t) {}
00085   ~_VDBL_exprcol() {}
00086 
00087   virtual const std::auto_ptr<_VDBL_alltype_base>
00088           operator()(const _VDBL_database& _d, const _VDBL_context* _ctx) const
00089     {}
00090 };
00091 
00092 class _VDBL_exprequal : public _VDBL_expression
00093 {
00094 private:
00095   std::auto_ptr<_VDBL_expression> _EQ_a, _EQ_b;
00096 
00097 public:
00098   _VDBL_exprequal(const std::auto_ptr<_VDBL_expression>& _A,
00099                   const std::auto_ptr<_VDBL_expression>& _B)
00100                                          : _EQ_a(_A), _EQ_b(_B)
00101     {
00102       if(_A->result_type() != _B->result_type())
00103       {
00104         std::cerr << "VDBL exprequal: comparing different types!" <<
00105                 std::endl;
00106         throw "VDBL expression: type mismatch!";
00107       }
00108     }
00109 
00110   const std::auto_ptr<_VDBL_alltype_base> operator()(const _VDBL_database& _d,
00111                                   const _VDBL_context* _ctx) const
00112   {
00113     return std::auto_ptr<_VDBL_alltype_base>
00114         (new _VDBL_alltype<bool>(*(*_EQ_a)(_d, _ctx) == *(*_EQ_b)(_d, _ctx)));
00115   }
00116 };
00117 
00118 class _VDBL_exprneql : public _VDBL_expression
00119 {
00120 private:
00121   std::auto_ptr<_VDBL_expression> _EQ_a, _EQ_b;
00122 
00123 public:
00124   _VDBL_exprneql(const std::auto_ptr<_VDBL_expression>& _A,
00125                  const std::auto_ptr<_VDBL_expression>& _B)
00126                                          : _EQ_a(_A), _EQ_b(_B)
00127     {
00128       if(_A->result_type() != _B->result_type())
00129       {
00130         std::cerr << "VDBL exprequal: comparing different types!" <<
00131                 std::endl;
00132         throw "VDBL expression: type mismatch!";
00133       }
00134     }
00135 
00136   const std::auto_ptr<_VDBL_alltype_base> operator()(const _VDBL_database& _d,
00137                                   const _VDBL_context* _ctx) const
00138   {
00139     return std::auto_ptr<_VDBL_alltype_base>
00140         (new _VDBL_alltype<bool>(*(*_EQ_a)(_d, _ctx) != *(*_EQ_b)(_d, _ctx)));
00141   }
00142 };
00143 
00144 inline std::auto_ptr<_VDBL_expression> row(const std::string& __row,
00145                                            const std::string& __table)
00146 { return std::auto_ptr<_VDBL_expression>(new _VDBL_exprrow(__row, __table)); }
00147 
00148 inline std::auto_ptr<_VDBL_expression> row(const char* __row,
00149                                            const char* __table)
00150 { return row(std::string(__row), std::string(__table)); }
00151 
00152 inline std::auto_ptr<_VDBL_expression> col(const std::string& __col,
00153                              const std::string& __table)
00154 { return std::auto_ptr<_VDBL_expression>(new _VDBL_exprcol(__col, __table)); }
00155 
00156 inline std::auto_ptr<_VDBL_expression> col(const char* __col,
00157                                            const char* __table)
00158 { return col(std::string(__col), std::string(__table)); }
00159 
00160 inline std::auto_ptr<_VDBL_expression> operator==
00161                         (const std::auto_ptr<_VDBL_expression>& _a,
00162                          const std::auto_ptr<_VDBL_expression>& _b)
00163 {
00164   return std::auto_ptr<_VDBL_expression>(new _VDBL_exprequal(_a, _b));
00165 }
00166 
00167 typedef std::auto_ptr<_VDBL_expression> expression;
00168 
00169 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00170 #pragma reset woff 1209
00171 #endif
00172 
00173 __VDBL_END_NAMESPACE
00174 
00175 #endif /* __VDBL_EXPRESSION_H */
00176 
00177 // Local Variables:
00178 // mode:C++
00179 // End:

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