00001 #ifndef _ots_ConfigurationTree_h_
00002 #define _ots_ConfigurationTree_h_
00003
00004 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationView.h"
00005
00006
00007 #include <iostream>
00008 #include <string>
00009 #include <set>
00010
00011
00012 namespace ots
00013 {
00014
00015 class ConfigurationManager;
00016 class ConfigurationBase;
00017 class ConfigurationView;
00018
00019
00020 template<typename T>
00021 struct identity { typedef T type; };
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class ConfigurationTree
00039 {
00040 friend class ConfigurationGUISupervisor;
00041
00042 public:
00043
00044
00045
00046
00047 ConfigurationTree ();
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 ConfigurationTree (const ConfigurationManager* const& configMgr, const ConfigurationBase* const &config);
00065 ~ConfigurationTree (void);
00066
00067 ConfigurationTree& operator=(const ConfigurationTree& a)
00068 {
00069 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR ConfigManager: " << configMgr_ << " configuration: " << configuration_ << std::endl;
00070
00071
00072
00073 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00074 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00075 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00076 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00077 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00078 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00079 std::cout << __PRETTY_FUNCTION__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - SO YOUR CODE IS WRONG! Crashing now." << std::endl;
00080 exit(0);
00081
00082
00083
00084 configMgr_ = a.configMgr_;
00085 configuration_ = a.configuration_;
00086
00087
00088
00089
00090
00091 configView_ = a.configView_;
00092 std::cout << __PRETTY_FUNCTION__ << "OPERATOR COPY CONSTRUCTOR" << std::endl;
00093 return *this;
00094 };
00095
00096
00097 static const std::string DISCONNECTED_VALUE;
00098 static const std::string VALUE_TYPE_DISCONNECTED;
00099 static const std::string VALUE_TYPE_NODE;
00100
00101 static const std::string NODE_TYPE_GROUP_TABLE;
00102 static const std::string NODE_TYPE_TABLE;
00103 static const std::string NODE_TYPE_GROUP_LINK;
00104 static const std::string NODE_TYPE_UID_LINK;
00105 static const std::string NODE_TYPE_VALUE;
00106 static const std::string NODE_TYPE_UID;
00107
00108
00109
00110
00111
00112
00113
00114
00115 template<class T>
00116 void getValue(T& value) const
00117 {
00118 if(row_ != ConfigurationView::INVALID && col_ != ConfigurationView::INVALID)
00119 {
00120
00121 try
00122 {
00123 ConfigurationTree valueAsTreeNode = getValueAsTreeNode();
00124
00125 __MOUT__ << "Success following path to tree node!" << std::endl;
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 value = handleValidateValueForColumn(configView_,
00136 valueAsTreeNode.getValueAsString(),col_,identity<T>());
00137
00138 __MOUT__ << "Successful value!" << std::endl;
00139 return;
00140 }
00141 catch(...)
00142 {
00143
00144 }
00145
00146
00147 configView_->getValue(value,row_,col_);
00148 }
00149 else if(row_ == ConfigurationView::INVALID && col_ == ConfigurationView::INVALID)
00150 throw std::runtime_error("Requesting getValue on config node level. Must be a value node.");
00151 else if(row_ == ConfigurationView::INVALID)
00152 {
00153 std::cout << __COUT_HDR_FL__ << std::endl;
00154 throw std::runtime_error("Malformed ConfigurationTree");
00155 }
00156 else if(col_ == ConfigurationView::INVALID)
00157 throw std::runtime_error("Requesting getValue on uid node level. Must be a value node.");
00158 else
00159 {
00160 std::cout << __COUT_HDR_FL__ << std::endl;
00161 throw std::runtime_error("Impossible");
00162 }
00163 }
00164
00165
00166 void getValue (std::string& value) const;
00167
00168
00169
00170
00171
00172 template<class T>
00173 T getValue(void) const
00174 {
00175 T value;
00176
00177
00178
00179
00180
00181
00182
00183
00184 ConfigurationTree::getValue<T>(value);
00185 return value;
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 }
00206
00207
00208 std::string getValue (void) const;
00209
00210 private:
00211 template<typename T>
00212 T handleValidateValueForColumn(const ConfigurationView* configView, std::string value, unsigned int col, ots::identity<T>) const
00213 {
00214 if(!configView)
00215 {
00216 __SS__ << "Null configView" << std::endl;
00217 __MOUT_ERR__ << ss.str();
00218 throw std::runtime_error(ss.str());
00219 }
00220 std::cout << "210:::::" << "handleValidateValueForColumn<T>" << std::endl;
00221 return configView->validateValueForColumn<T>(
00222 value,col);
00223 }
00224
00225 std::string handleValidateValueForColumn(const ConfigurationView* configView, std::string value, unsigned int col, ots::identity<std::string>) const
00226 {
00227 if(!configView)
00228 {
00229 __SS__ << "Null configView" << std::endl;
00230 __MOUT_ERR__ << ss.str();
00231 throw std::runtime_error(ss.str());
00232 }
00233 std::cout << "210:::::" << "handleValidateValueForColumn<string>" << std::endl;
00234 return configView->validateValueForColumn(
00235 value,col);
00236 }
00237
00238 public:
00239
00240
00241 ConfigurationTree getNode (const std::string& nodeName, bool doNotThrowOnBrokenUIDLinks=false) const;
00242 ConfigurationTree getBackNode ( std::string nodeName, unsigned int backSteps=1) const;
00243
00244
00245
00246 const std::string& getConfigurationName (void) const;
00247 const ConfigurationVersion& getConfigurationVersion (void) const;
00248 const time_t& getConfigurationCreationTime(void) const;
00249 std::vector<std::string> getChildrenNames (void) const;
00250 std::vector<std::pair<std::string,ConfigurationTree> > getChildren (std::map<std::string /*relative-path*/, std::string /*value*/> filterMap = std::map<std::string /*relative-path*/, std::string /*value*/>()) const;
00251 std::map<std::string,ConfigurationTree> getChildrenMap (void) const;
00252 std::string getEscapedValue (void) const;
00253 const std::string& getValueAsString (bool returnLinkTableValue=false) const;
00254 const std::string& getUIDAsString (void) const;
00255 const std::string& getValueDataType (void) const;
00256 const std::string& getValueType (void) const;
00257 const std::string& getValueName (void) const;
00258 std::string getNodeType (void) const;
00259 const std::string& getDisconnectedTableName (void) const;
00260 const std::string& getDisconnectedLinkID (void) const;
00261 const std::string& getChildLinkIndex (void) const;
00262 std::vector<std::string> getFixedChoices (void) const;
00263
00264 public:
00265
00266
00267
00268 bool isDefaultValue (void) const;
00269 bool isConfigurationNode (void) const;
00270 bool isValueNode (void) const;
00271 bool isDisconnected (void) const;
00272 bool isLinkNode (void) const;
00273 bool isGroupLinkNode (void) const;
00274 bool isUIDLinkNode (void) const;
00275 bool isUIDNode (void) const;
00276
00277
00278 void print (const unsigned int &depth = -1, std::ostream &out = std::cout) const;
00279
00280
00281 friend std::ostream& operator<< (std::ostream& out, const ConfigurationTree& t)
00282 {
00283 out << t.getValueAsString();
00284 return out;
00285 }
00286
00287 protected:
00288 const unsigned int& getRow (void) const;
00289 const unsigned int& getColumn (void) const;
00290 const ViewColumnInfo& getColumnInfo (void) const;
00291
00292
00293 struct RecordField
00294 {
00295 RecordField(const std::string &table, const std::string &uid,
00296 const std::string &columnName, const std::string &relativePath,
00297 const ViewColumnInfo *columnInfo)
00298 :tableName_(table)
00299 ,columnName_(columnName)
00300 ,relativePath_(relativePath)
00301 ,columnInfo_(columnInfo)
00302 {}
00303
00304 std::string tableName_, columnName_, relativePath_;
00305
00306
00307 const ViewColumnInfo *columnInfo_;
00308 };
00309 std::vector<ConfigurationTree::RecordField> getCommonFields(const std::vector<std::string /*relative-path*/> &recordList, const std::vector<std::string /*relative-path*/> &fieldAcceptList, const std::vector<std::string /*relative-path*/> &fieldRejectList, unsigned int depth = -1) const;
00310 std::set<std::string > getUniqueValuesForField(const std::vector<std::string /*relative-path*/> &recordList, const std::string &fieldName) const;
00311
00312 private:
00313
00314 ConfigurationTree(const ConfigurationManager* const& configMgr, const ConfigurationBase* const& config, const std::string& groupId, const ConfigurationBase* const& linkParentConfig, const std::string &linkColName, const std::string &linkColValue, const std::string& disconnectedTargetName, const std::string& disconnectedLinkID, const std::string &childLinkIndex, const unsigned int row = ConfigurationView::INVALID, const unsigned int col = ConfigurationView::INVALID);
00315
00316 static ConfigurationTree recurse (const ConfigurationTree& t, const std::string& childPath, bool doNotThrowOnBrokenUIDLinks);
00317 static void recursivePrint(const ConfigurationTree& t, unsigned int depth, std::ostream &out, std::string space);
00318 static bool wildCardMatch (const std::string& needle, const std::string& haystack);
00319
00320 void recursiveGetCommonFields(std::vector<ConfigurationTree::RecordField> &fieldCandidateList, std::vector<int> &fieldCount, const std::vector<std::string /*relative-path*/> &fieldAcceptList, const std::vector<std::string /*relative-path*/> &fieldRejectList, unsigned int depth, const std::string &relativePathBase, bool inFirstRecord) const;
00321 ConfigurationTree getValueAsTreeNode (void) const;
00322
00323
00324
00325
00326
00327
00328
00329 const ConfigurationManager* configMgr_;
00330 const ConfigurationBase* configuration_;
00331 const std::string groupId_;
00332 const ConfigurationBase* linkParentConfig_;
00333 const std::string linkColName_;
00334 const std::string linkColValue_;
00335 const std::string disconnectedTargetName_;
00336 const std::string disconnectedLinkID_;
00337 const std::string childLinkIndex_;
00338 const unsigned int row_;
00339 const unsigned int col_;
00340 const ConfigurationView* configView_;
00341
00342 };
00343 }
00344
00345 #endif