| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef DATATYPECENTER_H |
| 21 |
#define DATATYPECENTER_H |
| 22 |
|
| 23 |
#include "tDataType.h" |
| 24 |
#include "dltree.h" |
| 25 |
#include "tDataTypeBool.h" |
| 26 |
|
| 27 |
class DataTypeReasoner; |
| 28 |
|
| 29 |
class DataTypeCenter |
| 30 |
{ |
| 31 |
public: |
| 32 |
|
| 33 |
typedef std::vector<TDataType*> TypesVector; |
| 34 |
|
| 35 |
|
| 36 |
typedef TypesVector::iterator iterator; |
| 37 |
|
| 38 |
typedef TypesVector::const_iterator const_iterator; |
| 39 |
|
| 40 |
protected: |
| 41 |
|
| 42 |
TypesVector Types; |
| 43 |
|
| 44 |
protected: |
| 45 |
|
| 46 |
void RegisterDataType ( TDataType* p ) { Types.push_back(p); } |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
TDataType* getNumberDataType ( void ) const { return *begin(); } |
| 52 |
|
| 53 |
TDataType* getStringDataType ( void ) const { return *(begin()+1); } |
| 54 |
|
| 55 |
TDataType* getRealDataType ( void ) const { return *(begin()+2); } |
| 56 |
|
| 57 |
TDataType* getBoolDataType ( void ) const { return *(begin()+3); } |
| 58 |
|
| 59 |
TDataType* getTimeDataType ( void ) const { return *(begin()+4); } |
| 60 |
|
| 61 |
TDataType* getTypeByName ( const std::string& name ) const; |
| 62 |
|
| 63 |
|
| 64 |
TDataType* getTypeBySample ( const TDataEntry* sample ) const |
| 65 |
{ |
| 66 |
const TDataEntry* type = sample->isBasicDataType() ? sample : sample->getType(); |
| 67 |
|
| 68 |
for ( const_iterator p = begin(), p_end = end(); p < p_end; ++p ) |
| 69 |
if ( type == (*p)->getType() ) |
| 70 |
return *p; |
| 71 |
|
| 72 |
return nullptr; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
static DLTree* wrap ( const TDataEntry* t ) { return createEntry ( DATAEXPR, const_cast<TDataEntry*>(t) ); } |
| 79 |
|
| 80 |
static TDataEntry* unwrap ( const DLTree* t ) { return static_cast<TDataEntry*>(t->Element().getNE()); } |
| 81 |
|
| 82 |
public: |
| 83 |
|
| 84 |
DataTypeCenter ( void ) |
| 85 |
{ |
| 86 |
|
| 87 |
RegisterDataType(new TDataType("number")); |
| 88 |
RegisterDataType(new TDataType("string")); |
| 89 |
RegisterDataType(new TDataType("real")); |
| 90 |
RegisterDataType(new TDataTypeBool()); |
| 91 |
RegisterDataType(new TDataType("time")); |
| 92 |
|
| 93 |
RegisterDataType(new TDataType(" ")); |
| 94 |
} |
| 95 |
|
| 96 |
~DataTypeCenter(); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
iterator begin ( void ) { return Types.begin(); } |
| 102 |
|
| 103 |
iterator end ( void ) { return Types.end(); } |
| 104 |
|
| 105 |
const_iterator begin ( void ) const { return Types.begin(); } |
| 106 |
|
| 107 |
const_iterator end ( void ) const { return Types.end(); } |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
DLTree* getNumberType ( void ) const { return wrap(getNumberDataType()->getType()); } |
| 113 |
|
| 114 |
DLTree* getStringType ( void ) const { return wrap(getStringDataType()->getType()); } |
| 115 |
|
| 116 |
DLTree* getRealType ( void ) const { return wrap(getRealDataType()->getType()); } |
| 117 |
|
| 118 |
DLTree* getBoolType ( void ) const { return wrap(getBoolDataType()->getType()); } |
| 119 |
|
| 120 |
DLTree* getTimeType ( void ) const { return wrap(getTimeDataType()->getType()); } |
| 121 |
|
| 122 |
DLTree* getFreshDataType ( void ) const { return wrap((*(begin()+5))->getType()); } |
| 123 |
|
| 124 |
|
| 125 |
DLTree* getDataValue ( const std::string& name, const DLTree* sample ) const |
| 126 |
{ |
| 127 |
TDataType* type = isConst(sample) ? |
| 128 |
getStringDataType() : |
| 129 |
getTypeBySample(unwrap(sample)); |
| 130 |
|
| 131 |
return wrap(type->get(name)); |
| 132 |
} |
| 133 |
|
| 134 |
DLTree* getDataType ( const std::string& name ) |
| 135 |
{ return wrap(getTypeByName(name)->getType()); } |
| 136 |
|
| 137 |
DLTree* getDataType ( const std::string&, DLTree* expr ) |
| 138 |
{ return expr; } |
| 139 |
|
| 140 |
|
| 141 |
DLTree* getIntervalFacetExpr ( DLTree* val, bool min, bool excl ) |
| 142 |
{ |
| 143 |
|
| 144 |
TDataEntry* value = unwrap(val); |
| 145 |
|
| 146 |
TDataEntry* ret = getTypeBySample(value)->getExpr(); |
| 147 |
|
| 148 |
ret->getFacet()->update ( min, excl, value->getComp() ); |
| 149 |
deleteTree(val); |
| 150 |
return wrap(ret); |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
void initDataTypeReasoner ( DataTypeReasoner& DTReasoner ) const; |
| 157 |
|
| 158 |
void setLocked ( bool val ); |
| 159 |
}; |
| 160 |
|
| 161 |
#endif |