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
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _JCCL_CONFIG_ELEMENT_H_
00034 #define _JCCL_CONFIG_ELEMENT_H_
00035
00036 #include <jccl/jcclConfig.h>
00037 #include <vector>
00038
00039 #include <sstream>
00040 #include <cppdom/cppdom.h>
00041 #include <vpr/Util/Assert.h>
00042
00043 #include <jccl/Config/ConfigElementPtr.h>
00044 #include <jccl/Config/ConfigDefinitionPtr.h>
00045
00046 namespace jccl
00047 {
00048
00055 class JCCL_CLASS_API ConfigElement
00056 {
00057 public:
00059 ConfigElement();
00060
00064 ConfigElement(ConfigDefinitionPtr def);
00065
00067 ConfigElement(const ConfigElement& c);
00068
00074 ~ConfigElement();
00075
00076 bool isValid() const;
00077
00084 bool initFromNode(cppdom::NodePtr elementNode);
00085
00087 ConfigElement& operator=(const ConfigElement& c);
00088
00092 bool operator==(const ConfigElement& c) const;
00093
00095 bool operator!=(const ConfigElement& c) const;
00096
00098 bool operator<(const ConfigElement& c) const;
00099
00111 ConfigElementPtr getChildElement(const std::string &path);
00112
00118 friend JCCL_API(std::ostream&) operator<<(std::ostream& out,
00119 const ConfigElement& self);
00120
00132 unsigned int getNum(const std::string& property) const;
00133
00140 std::string getName() const;
00141
00149 std::string getFullName() const;
00150
00154 unsigned int getVersion() const;
00155
00157 std::string getID() const;
00158
00173 template<class T>
00174 T getProperty(const std::string& prop, int ind) const
00175 {
00176 std::string prop_string = getPropertyString(prop,ind);
00177
00178 T ret_val = T();
00179 std::istringstream iss(prop_string);
00180 iss >> ret_val;
00181 return ret_val;
00182 }
00183
00184
00185
00186
00187 #if defined(_MSC_VER) && _MSC_VER == 1300
00188 template<>
00189 std::string getProperty<std::string>(const std::string& prop, int ind) const
00190 {
00191 std::string prop_string = getPropertyString(prop,ind);
00192 return prop_string;
00193 }
00194
00199 template<>
00200 bool getProperty<bool>(const std::string& prop, int ind) const
00201 {
00202 return getProperty_bool(prop, ind);
00203 }
00204
00205 template<>
00206 ConfigElementPtr getProperty<ConfigElementPtr>(const std::string& prop,
00207 int ind) const
00208 {
00209 return getProperty_ElementPtr(prop, ind);
00210 }
00211 #endif
00212
00221 #if defined(_MSC_VER) && _MSC_VER == 1300
00222 template<class T>
00223 T getProperty(const std::string& prop) const
00224 {
00225 return getProperty<T>(prop, 0);
00226 }
00227 #else
00228 template<class T>
00229 T getProperty(const std::string& prop) const;
00230 #endif
00231
00241 template<class T>
00242 bool setProperty(const std::string& prop, const int ind, T val)
00243 {
00244 cppdom::NodePtr cdata_node = getPropertyCdataNode(prop, ind, true);
00245 vprASSERT(cdata_node.get() != NULL && "Autogrow failed");
00246
00247 std::ostringstream oss;
00248 oss << val;
00249 cdata_node->setCdata(oss.str());
00250 return true;
00251 }
00252
00256 bool setProperty(const std::string& prop, const int ind, bool val);
00257
00259 bool setProperty(const std::string& prop, const int ind,
00260 ConfigElementPtr val);
00261
00270 std::vector<std::string> getElementPtrDependencies() const;
00271
00278 std::vector<jccl::ConfigElementPtr> getChildElements() const;
00279
00283 void setDefinition(ConfigDefinitionPtr d);
00284
00286 ConfigDefinitionPtr getConfigDefinition();
00287
00288 cppdom::NodePtr getNode() const;
00289
00290 protected:
00299 std::string getPropertyString(const std::string& prop, int ind) const;
00300
00310 cppdom::NodePtr getPropertyCdataNode(const std::string& prop, int ind,
00311 bool autoCreate) const;
00312
00318 bool getProperty_bool(const std::string& prop, int ind) const;
00319
00325 ConfigElementPtr getProperty_ElementPtr(const std::string& prop,
00326 int ind) const;
00327
00328 protected:
00329 cppdom::NodePtr mNode;
00330 ConfigDefinitionPtr mDef;
00331 bool mValid;
00332 };
00333
00334 #if ! defined(_MSC_VER) || _MSC_VER > 1300
00335 template<>
00336 inline std::string ConfigElement::getProperty<std::string>(const std::string& prop, int ind) const
00337 {
00338 std::string prop_string = getPropertyString(prop,ind);
00339 return prop_string;
00340 }
00341
00346 template<>
00347 inline bool ConfigElement::getProperty<bool>(const std::string& prop, int ind) const
00348 {
00349 return getProperty_bool(prop, ind);
00350 }
00351
00356 template<>
00357 inline ConfigElementPtr ConfigElement::getProperty<ConfigElementPtr>(const std::string& prop, int ind) const
00358 {
00359 return getProperty_ElementPtr(prop,ind);
00360 }
00361
00362 template<class T>
00363 inline T ConfigElement::getProperty(const std::string& prop) const
00364 {
00365 return getProperty<T>(prop, 0);
00366 }
00367 #endif
00368
00369 }
00370
00371 #endif