| 1 | gezelter | 1490 | #ifndef __GENERICDATA_H__ | 
| 2 |  |  | #define __GENERICDATA_H__ | 
| 3 |  |  |  | 
| 4 |  |  | #include <algorithm> | 
| 5 |  |  | #include <string> | 
| 6 |  |  | #include <vector> | 
| 7 |  |  |  | 
| 8 |  |  | #define ZCONSTIME_ID            "ZCONSTIME" | 
| 9 |  |  | #define ZCONSPARADATA_ID    "ZCONSPARA" | 
| 10 |  |  | #define ZCONSFILENAME_ID     "ZCONSFILENAME" | 
| 11 |  |  | #define ZCONSTOL_ID              "ZCONSTOL" | 
| 12 |  |  | #define ZCONSFORCEPOLICY_ID "ZCONSFORCEPOLICY" | 
| 13 |  |  | #define ZCONSGAP_ID "ZCONSGAP" | 
| 14 |  |  | #define ZCONSFIXTIME_ID "ZCONSFIXTIME" | 
| 15 |  |  | #define ZCONSUSINGSMD_ID "ZCONSUSINGSMD" | 
| 16 |  |  |  | 
| 17 |  |  | #define CHIVALUE_ID "CHIVALUE" | 
| 18 |  |  | #define INTEGRALOFCHIDT_ID "INTEGRALOFCHIDT" | 
| 19 |  |  | #define ETAVALUE_ID "ETAVALUE" | 
| 20 |  |  |  | 
| 21 |  |  | using namespace std; | 
| 22 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 23 |  |  | //Declaration of GenericData | 
| 24 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 25 |  |  | class GenericData | 
| 26 |  |  | { | 
| 27 |  |  | public: | 
| 28 |  |  | GenericData(); | 
| 29 |  |  | GenericData(const GenericData& rhs)  {  id = rhs.getID(); } | 
| 30 |  |  | GenericData& operator =(const GenericData& rhs); | 
| 31 |  |  | virtual ~GenericData() {} | 
| 32 |  |  |  | 
| 33 |  |  | const string& getID() const {  return id; } | 
| 34 |  |  | void setID(const string& rhs)     {  id = rhs;  } | 
| 35 |  |  |  | 
| 36 |  |  | protected: | 
| 37 |  |  | string id; | 
| 38 |  |  | }; | 
| 39 |  |  |  | 
| 40 |  |  | /** | 
| 41 |  |  | * Something we can improve it here is to use template | 
| 42 |  |  | */ | 
| 43 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 44 |  |  | //Declaration of IntData | 
| 45 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 46 |  |  | class IntData : public GenericData{ | 
| 47 |  |  |  | 
| 48 |  |  | public: | 
| 49 |  |  |  | 
| 50 |  |  | double getData()         { return data; } | 
| 51 |  |  | void setData(int rhs) { data = rhs;  } | 
| 52 |  |  |  | 
| 53 |  |  | protected: | 
| 54 |  |  | int data; | 
| 55 |  |  | }; | 
| 56 |  |  |  | 
| 57 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 58 |  |  | //Declaration of DoubleData | 
| 59 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 60 |  |  | class DoubleData : public GenericData{ | 
| 61 |  |  |  | 
| 62 |  |  | public: | 
| 63 |  |  |  | 
| 64 |  |  | double getData()         { return data; } | 
| 65 |  |  | void setData(double rhs) { data = rhs;  } | 
| 66 |  |  |  | 
| 67 |  |  | protected: | 
| 68 |  |  | double data; | 
| 69 |  |  | }; | 
| 70 |  |  |  | 
| 71 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 72 |  |  | //Declaration of StringData | 
| 73 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 74 |  |  | class StringData : public GenericData{ | 
| 75 |  |  |  | 
| 76 |  |  | public: | 
| 77 |  |  | const string& getData() const  {  return data; } | 
| 78 |  |  | void setData(const string& rhs) {  data = rhs;  } | 
| 79 |  |  | protected: | 
| 80 |  |  | string data; | 
| 81 |  |  | }; | 
| 82 |  |  |  | 
| 83 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 84 |  |  | //Declaration of BoolData | 
| 85 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 86 |  |  | class BoolData : public GenericData{ | 
| 87 |  |  | public: | 
| 88 |  |  | bool getData() const  {  return data; } | 
| 89 |  |  | void setData(const bool rhs) {  data = rhs;  } | 
| 90 |  |  | protected: | 
| 91 |  |  | bool data; | 
| 92 |  |  |  | 
| 93 |  |  | }; | 
| 94 |  |  |  | 
| 95 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 96 |  |  | //Declaration of ZConsParaData | 
| 97 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 98 |  |  | struct ZConsParaItem { | 
| 99 |  |  | int zconsIndex; | 
| 100 |  |  | bool havingZPos; | 
| 101 |  |  | double zPos; | 
| 102 |  |  | double kRatio; | 
| 103 |  |  | bool havingCantVel; | 
| 104 |  |  | double cantVel; | 
| 105 |  |  | }; | 
| 106 |  |  |  | 
| 107 |  |  | class ZConsParaData : public GenericData{ | 
| 108 |  |  |  | 
| 109 |  |  | public: | 
| 110 |  |  | ZConsParaData(); | 
| 111 |  |  | void addItem(ZConsParaItem& item) {data.push_back(item);} | 
| 112 |  |  | vector<ZConsParaItem>* getData() {return &data;} | 
| 113 |  |  | void setData(vector<ZConsParaItem>& theData) {data = theData;} | 
| 114 |  |  | void sortByIndex(); | 
| 115 |  |  | bool isIndexUnique(); | 
| 116 |  |  |  | 
| 117 |  |  | private: | 
| 118 |  |  | vector<ZConsParaItem> data; | 
| 119 |  |  | }; | 
| 120 |  |  |  | 
| 121 |  |  | class ZConsParaSortCriterion{ | 
| 122 |  |  | public: | 
| 123 |  |  | bool operator ()(const ZConsParaItem& item1, const ZConsParaItem& item2){ | 
| 124 |  |  | return item1.zconsIndex < item2.zconsIndex; | 
| 125 |  |  | } | 
| 126 |  |  |  | 
| 127 |  |  | }; | 
| 128 |  |  |  | 
| 129 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 130 |  |  | //Declaration of IntData | 
| 131 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 132 |  |  | class DoubleArrayData : public GenericData{ | 
| 133 |  |  |  | 
| 134 |  |  | public: | 
| 135 |  |  | vector<double> getData() const  {  return data; } | 
| 136 |  |  | void setData(double* source, int num){ | 
| 137 |  |  | data.clear(); | 
| 138 |  |  | for(int i = 0; i < num; i++) | 
| 139 |  |  | data.push_back(source[i]); | 
| 140 |  |  | } | 
| 141 |  |  | protected: | 
| 142 |  |  | vector<double> data; | 
| 143 |  |  | }; | 
| 144 |  |  |  | 
| 145 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 146 |  |  | //Declaration of AtomData | 
| 147 |  |  | //////////////////////////////////////////////////////////////////////////////// | 
| 148 |  |  | struct AtomInfo : public GenericData{ | 
| 149 |  |  | public: | 
| 150 |  |  | string AtomType; | 
| 151 |  |  | double pos[3]; | 
| 152 |  |  | double dipole[3]; | 
| 153 |  |  | }; | 
| 154 |  |  |  | 
| 155 |  |  | class AtomData : public GenericData{ | 
| 156 |  |  | public: | 
| 157 |  |  | ~AtomData(); | 
| 158 |  |  | void addAtomInfo(AtomInfo* info) {data.push_back(info);} | 
| 159 |  |  | void clearAllAtomInfo(); | 
| 160 |  |  | AtomInfo* beginAtomInfo(vector<AtomInfo*>::iterator& i){ | 
| 161 |  |  | i = data.begin(); | 
| 162 |  |  | return i != data.end()? *i : NULL; | 
| 163 |  |  | } | 
| 164 |  |  | AtomInfo* nextAtomInfo(vector<AtomInfo*>::iterator& i){ | 
| 165 |  |  | ++i; | 
| 166 |  |  | return i != data.end()? *i: NULL; | 
| 167 |  |  | } | 
| 168 |  |  | vector<AtomInfo*> getData() {return data;} | 
| 169 |  |  | int getSize() {return data.size();} | 
| 170 |  |  | protected: | 
| 171 |  |  | vector<AtomInfo*> data; | 
| 172 |  |  | }; | 
| 173 |  |  |  | 
| 174 |  |  | #endif |