00001
00002 #ifndef RDBMODEL_ASSERTION_H
00003 #define RDBMODEL_ASSERTION_H
00004 #include <vector>
00005 #include <string>
00006 #include "rdbModel/Rdb.h"
00007 #include "rdbModel/Management/Visitor.h"
00008 #include "rdbModel/Tables/Column.h"
00009
00010 namespace rdbModel{
00011
00012 class Table;
00013
00014 enum OPTYPE {
00015 OPTYPEundefined = 0,
00016 OPTYPEor = 1,
00017 OPTYPEand,
00018 OPTYPEnot,
00019 OPTYPEexists,
00020 OPTYPEisNull,
00021 OPTYPEisEmpty,
00022 OPTYPEequal,
00023 OPTYPEnotEqual,
00024 OPTYPElessThan,
00025 OPTYPEgreaterThan,
00026 OPTYPElessOrEqual,
00027 OPTYPEgreaterOrEqual,
00028 OPTYPElast
00029 };
00030
00031
00056 class Assertion {
00057 public:
00058 class Operator;
00059
00060 public:
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 class Operator {
00072 public:
00073 Operator() : m_opType(OPTYPEundefined) {};
00074 ~Operator();
00075
00078 Operator(OPTYPE type, const std::string& leftArg,
00079 const std::string& rightArg,
00080 FIELDTYPE leftType, FIELDTYPE rightType);
00081
00083 Operator(OPTYPE type, const std::string& tableName, Operator* child=0);
00084
00086 Operator(OPTYPE type, const std::vector<Operator*>& children,
00087 bool keepChildren = false);
00088
00090 Operator(Operator* op, Row* toBe);
00091
00093 bool appendChild(Operator* child);
00094
00097 bool validCompareOp(Table* table) const;
00098
00101 bool isCompareOp() const {return (m_opType >= OPTYPEisNull);}
00102
00104 const std::string* getCompareArgs() const;
00105
00107 const std::string& getTableName() const;
00108
00110 const FIELDTYPE* getCompareArgTypes() const;
00111
00113 const std::vector<Operator* >& getChildren() const;
00114
00115 OPTYPE getOpType() const {return m_opType;}
00116
00118 bool getToBe() const {return m_toBe;}
00119
00121 bool getOld() const {return m_old;}
00122
00124 bool verify(Row& old, Row& toBe, Table* t) const;
00125
00126
00127
00128 private:
00130 bool verifyCompare(Row& old, Row& toBe, Table* t) const;
00131
00133 bool compareTs(const std::string* vals, OPTYPE type) const;
00134
00136 bool compareInt(const std::string* vals, OPTYPE type) const;
00137
00139 bool compareFloat(const std::string* vals, OPTYPE type) const;
00140
00142 bool compareString(const std::string* vals, OPTYPE type) const;
00143
00144 OPTYPE m_opType;
00145
00155 std::string m_compareArgs[2];
00156 FIELDTYPE m_compareType[2];
00157
00159 std::string m_tableName;
00160
00161 bool m_keepChildren;
00162
00164 std::vector<Operator* > m_operands;
00165
00168 bool m_toBe;
00169
00172 bool m_old;
00173 };
00174
00180 Assertion(Operator* op = 0, Table* myTable=0, bool keepOp=false) :
00181 m_op(op), m_myTable(myTable), m_keepOp(keepOp)
00182 { m_compiled.clear(); m_name.clear();};
00183
00189 Assertion(const Assertion* orig, Row* toBe);
00190
00191 ~Assertion();
00192
00193 Visitor::VisitorState accept(Visitor* v);
00194
00195 Operator* getOperator() const {return m_op;}
00197 const std::string& getPrecompiled() const {return m_compiled;}
00198
00201 bool getToBe() const {return m_op->getToBe();}
00202
00205 bool getOld() const {return m_op->getOld();}
00206
00207 const std::string& getName() const {return m_name;}
00208 void setName(const std::string& name) {m_name = name;}
00209
00216 bool verify(Row& old, Row& toBe) const;
00217
00218 private:
00220 Operator* m_op;
00221 Table* m_myTable;
00224 bool m_keepOp;
00226 std::string m_name;
00227
00230 std::string m_compiled;
00231
00232 };
00233 }
00234 #endif
00235