Changeset 6425 for code/trunk/src/libraries
- Timestamp:
- Dec 27, 2009, 2:30:06 AM (15 years ago)
- Location:
- code/trunk/src/libraries/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/ConfigFileManager.cc
r6422 r6425 58 58 } 59 59 60 std::stringgetConfig(const std::string& classname, const std::string& varname)60 const std::string& getConfig(const std::string& classname, const std::string& varname) 61 61 { 62 62 return ConfigFileManager::getInstance().getValue(ConfigFileType::Settings, classname, varname, "", true); … … 94 94 ////////////////////////// 95 95 96 void ConfigFileEntryValue::setValue(const std::string& value) 97 { 98 if (!this->bString_) 99 this->value_ = value; 96 void ConfigFileEntryValue::update() 97 { 98 // Make sure we remove the quotes when bString changes 99 if (this->bString_) 100 this->value_ = stripEnclosingQuotes(this->value_); 101 // Assemble the entry line 102 this->fileEntry_ = this->getKeyString() + " = "; 103 if (this->bString_) 104 this->fileEntry_ += '"' + addSlashes(this->value_) + '"'; 100 105 else 101 this->value_ = '"' + addSlashes(stripEnclosingQuotes(value)) + '"'; 102 } 103 104 std::string ConfigFileEntryValue::getValue() const 105 { 106 if (!this->bString_) 107 return this->value_; 108 else 109 return removeSlashes(stripEnclosingQuotes(this->value_)); 110 } 111 112 std::string ConfigFileEntryValue::getFileEntry() const 113 { 114 if (this->additionalComment_.empty()) 115 return (this->name_ + '=' + this->value_); 116 else 117 return (this->name_ + '=' + this->value_ + " " + this->additionalComment_); 106 this->fileEntry_ += this->value_; 107 if (!this->additionalComment_.empty()) 108 this->fileEntry_ += ' ' + this->additionalComment_; 118 109 } 119 110 … … 122 113 // ConfigFileEntryVectorValue // 123 114 //////////////////////////////// 124 std::string ConfigFileEntryVectorValue::getFileEntry() const 125 { 126 if (this->additionalComment_.empty()) 127 return (this->name_ + '[' + multi_cast<std::string>(this->index_) + ']' + '=' + this->value_); 128 else 129 return (this->name_ + '[' + multi_cast<std::string>(this->index_) + "]=" + this->value_ + ' ' + this->additionalComment_); 115 void ConfigFileEntryVectorValue::update() 116 { 117 this->keyString_ = this->name_ + '[' + multi_cast<std::string>(this->index_) + ']'; 118 ConfigFileEntryValue::update(); 130 119 } 131 120 -
code/trunk/src/libraries/core/ConfigFileManager.h
r6417 r6425 58 58 59 59 _CoreExport bool config(const std::string& classname, const std::string& varname, const std::string& value); // tolua_export 60 _CoreExport std::stringgetConfig(const std::string& classname, const std::string& varname); // tolua_export60 _CoreExport const std::string& getConfig(const std::string& classname, const std::string& varname); // tolua_export 61 61 _CoreExport bool tconfig(const std::string& classname, const std::string& varname, const std::string& value); 62 62 _CoreExport void reloadConfig(); … … 74 74 virtual ~ConfigFileEntry() {}; 75 75 virtual void setValue(const std::string& value) = 0; 76 virtual std::stringgetValue() const = 0;76 virtual const std::string& getValue() const = 0; 77 77 virtual const std::string& getName() const = 0; 78 78 virtual void setComment(const std::string& comment) = 0; 79 79 virtual unsigned int getIndex() const { return 0; } 80 80 virtual void setString(bool bString) = 0; 81 virtual std::stringgetFileEntry() const = 0;81 virtual const std::string& getFileEntry() const = 0; 82 82 }; 83 83 … … 94 94 , bString_(bString) 95 95 , additionalComment_(additionalComment) 96 {} 96 { this->update(); } 97 97 98 inline virtual ~ConfigFileEntryValue() {} 98 99 … … 101 102 102 103 inline virtual void setComment(const std::string& comment) 103 { this->additionalComment_ = comment; } 104 105 virtual void setValue(const std::string& value); 106 virtual std::string getValue() const; 107 108 inline bool isString() const 109 { return this->bString_; } 110 inline void setString(bool bString) 111 { this->bString_ = bString; } 112 113 virtual std::string getFileEntry() const; 104 { this->additionalComment_ = comment; this->update(); } 105 106 inline virtual void setValue(const std::string& value) 107 { this->value_ = value; this->update(); } 108 inline virtual const std::string& getValue() const 109 { return this->value_; } 110 111 inline void virtual setString(bool bString) 112 { this->bString_ = bString; this->update(); } 113 114 inline virtual const std::string& getFileEntry() const 115 { return this->fileEntry_; } 116 117 inline virtual const std::string& getKeyString() const 118 { return this->name_; } 114 119 115 120 protected: 116 std::string name_; 121 virtual void update(); 122 123 const std::string name_; 117 124 std::string value_; 125 std::string additionalComment_; 126 std::string fileEntry_; 118 127 bool bString_; 119 std::string additionalComment_; 120 }; 121 122 123 /////////////////////////////// 128 }; 129 130 131 //////////////////////////////// 124 132 // ConfigFileEntryVectorValue // 125 /////////////////////////////// 133 //////////////////////////////// 126 134 class _CoreExport ConfigFileEntryVectorValue : public ConfigFileEntryValue 127 135 { 128 136 public: 129 inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, bString, additionalComment), index_(index) {} 130 inline virtual ~ConfigFileEntryVectorValue() {} 131 132 inline virtual unsigned int getIndex() const 137 inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") 138 : ConfigFileEntryValue(name, value, bString, additionalComment) 139 , index_(index) 140 { this->update(); /*No virtual calls in base class ctor*/ } 141 142 inline ~ConfigFileEntryVectorValue() {} 143 144 inline unsigned int getIndex() const 133 145 { return this->index_; } 134 146 135 virtual std::string getFileEntry() const; 136 137 private: 147 inline const std::string& getKeyString() const 148 { return this->keyString_; } 149 150 private: 151 void update(); 152 138 153 unsigned int index_; 154 std::string keyString_; 139 155 }; 140 156 … … 157 173 inline virtual void setValue(const std::string& value) 158 174 {} 159 inline virtual std::string getValue() const 175 inline virtual const std::string& getValue() const 176 { return BLANKSTRING; } 177 178 inline void setString(bool bString) 179 {} 180 181 inline virtual const std::string& getFileEntry() const 160 182 { return this->comment_; } 161 183 162 inline void setString(bool bString) {} 163 164 inline virtual std::string getFileEntry() const 165 { return this->comment_; } 184 inline virtual const std::string& getKeyString() const 185 { return BLANKSTRING; } 166 186 167 187 private: … … 193 213 inline void setValue(const std::string& name, const std::string& value, bool bString) 194 214 { this->getEntry(name, value, bString)->setValue(value); } 195 inline std::stringgetValue(const std::string& name, const std::string& fallback, bool bString)215 inline const std::string& getValue(const std::string& name, const std::string& fallback, bool bString) 196 216 { return this->getEntry(name, fallback, bString)->getValue(); } 197 217 198 218 inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString) 199 219 { this->getEntry(name, index, value, bString)->setValue(value); } 200 inline std::stringgetValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)220 inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 201 221 { return this->getEntry(name, index, fallback, bString)->getValue(); } 202 222 … … 252 272 inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString) 253 273 { this->getSection(section)->setValue(name, value, bString); this->save(); } 254 inline std::stringgetValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString)274 inline const std::string& getValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 255 275 { const std::string& output = this->getSection(section)->getValue(name, fallback, bString); this->saveIfUpdated(); return output; } 256 276 257 277 inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString) 258 278 { this->getSection(section)->setValue(name, index, value, bString); this->save(); } 259 inline std::stringgetValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)279 inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 260 280 { const std::string& output = this->getSection(section)->getValue(name, index, fallback, bString); this->saveIfUpdated(); return output; } 261 281 … … 304 324 inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value, bool bString) 305 325 { this->getFile(type)->setValue(section, name, value, bString); } 306 inline std::stringgetValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString)326 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString) 307 327 { return this->getFile(type)->getValue(section, name, fallback, bString); } 308 328 309 329 inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString) 310 330 { this->getFile(type)->setValue(section, name, index, value, bString); } 311 inline std::stringgetValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)331 inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 312 332 { return this->getFile(type)->getValue(section, name, index, fallback, bString); } 313 333
Note: See TracChangeset
for help on using the changeset viewer.