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