Changeset 7373 for code/branches/doc/src/libraries/core
- Timestamp:
- Sep 7, 2010, 11:24:47 PM (14 years ago)
- Location:
- code/branches/doc/src/libraries/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/core/ConfigFileManager.cc
r7284 r7373 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of ConfigFileManager and its helper classes. 32 */ 33 29 34 #include "ConfigFileManager.h" 30 35 … … 43 48 // ConfigFileEntryValue // 44 49 ////////////////////////// 45 50 /** 51 @brief Updates the string that will be stored in the file after one of it's components (name, value, comment) has changed. 52 */ 46 53 void ConfigFileEntryValue::update() 47 54 { … … 63 70 // ConfigFileEntryVectorValue // 64 71 //////////////////////////////// 72 /** 73 @brief Updates the string that will be stored in the file after one of it's components (name, value, index, comment) has changed. 74 */ 65 75 void ConfigFileEntryVectorValue::update() 66 76 { … … 73 83 // ConfigFileSection // 74 84 /////////////////////// 85 /** 86 @brief Destructor: Deletes all entries. 87 */ 75 88 ConfigFileSection::~ConfigFileSection() 76 89 { … … 79 92 } 80 93 94 /** 95 @brief Deletes all elements of a config vector if their index is greater or equal to @a startindex. 96 97 @param name The name of the vector 98 @param startindex The index of the first element that will be deleted 99 */ 81 100 void ConfigFileSection::deleteVectorEntries(const std::string& name, unsigned int startindex) 82 101 { … … 95 114 } 96 115 116 /** 117 @brief Returns the size of a config vector. 118 @param name The name of the vector 119 */ 97 120 unsigned int ConfigFileSection::getVectorSize(const std::string& name) const 98 121 { … … 108 131 } 109 132 133 /** 134 @brief Returns the title and comment of the section as it will be stored in the file. 135 */ 110 136 std::string ConfigFileSection::getFileEntry() const 111 137 { … … 116 142 } 117 143 144 /** 145 @brief Returns the entry with given name (or NULL if it doesn't exist). 146 147 @param name The name of the entry 148 */ 118 149 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name) const 119 150 { … … 126 157 } 127 158 159 /** 160 @brief Returns the entry of a vector element with given name and index (or NULL if it doesn't exist). 161 162 @param name The name of the vector 163 @param index The index of the element in the vector 164 */ 128 165 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name, unsigned int index) const 129 166 { … … 136 173 } 137 174 175 /** 176 @brief Returns the iterator to the entry with given name. If the entry doesn't exist, it is created using the fallback value. 177 178 @param name The name of the entry 179 @param fallback The value that will be used if the entry doesn't exist 180 @param bString If true, the value is treated as string which means some special treatment of special characters. 181 */ 138 182 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString) 139 183 { … … 152 196 } 153 197 198 /** 199 @brief Returns the iterator to the entry of a vector element with given name and index. If the entry doesn't exist, it is created using the fallback value. 200 201 @param name The name of the vector 202 @param index The index of the element in the vector 203 @param fallback The value that will be used if the entry doesn't exist 204 @param bString If true, the value is treated as string which means some special treatment of special characters. 205 */ 154 206 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 155 207 { … … 178 230 const char* ConfigFile::DEFAULT_CONFIG_FOLDER = "defaultConfig"; 179 231 232 /** 233 @brief Constructor: Initializes the config file. 234 @param filename The file-name of this config file 235 @param bCopyFallbackFile If true, the default config file is copied into the config-directory before loading the file 236 */ 180 237 ConfigFile::ConfigFile(const std::string& filename, bool bCopyFallbackFile) 181 238 : filename_(filename) … … 185 242 } 186 243 244 /** 245 @brief Destructor: Deletes all sections and entries. 246 */ 187 247 ConfigFile::~ConfigFile() 188 248 { … … 190 250 } 191 251 252 /** 253 @brief Loads the config file from the hard-disk and reads the sections and their values. 254 */ 192 255 void ConfigFile::load() 193 256 { … … 318 381 } 319 382 383 /** 384 @brief Writes the sections and values to the hard-disk. 385 */ 320 386 void ConfigFile::save() const 321 387 { … … 323 389 } 324 390 391 /** 392 @brief Writes the sections and values to a given file on the hard-disk. 393 */ 325 394 void ConfigFile::saveAs(const std::string& filename) const 326 395 { … … 354 423 } 355 424 425 /** 426 @brief Deletes all sections (which again delete all their values) and clears the list of sections. 427 */ 356 428 void ConfigFile::clear() 357 429 { … … 361 433 } 362 434 363 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 364 { 365 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, fallback, bString); 366 this->saveIfUpdated(); 367 return output; 368 } 369 370 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 371 { 372 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, index, fallback, bString); 373 this->saveIfUpdated(); 374 return output; 375 } 376 435 /** 436 @brief Deletes all elements of a config vector if their index is greater or equal to @a startindex. 437 438 @param section The name of the section 439 @param name The name of the vector 440 @param startindex The index of the first element that will be deleted 441 */ 377 442 void ConfigFile::deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex) 378 443 { … … 384 449 } 385 450 451 /** 452 @brief Returns a pointer to the section with given name (or NULL if the section doesn't exist). 453 */ 386 454 ConfigFileSection* ConfigFile::getSection(const std::string& section) const 387 455 { … … 392 460 } 393 461 462 /** 463 @brief Returns a pointer to the section with given name. If it doesn't exist, the section is created. 464 */ 394 465 ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& section) 395 466 { … … 403 474 } 404 475 476 /** 477 @brief Saves the config file if it was updated (or if any of its sections were updated). 478 */ 405 479 void ConfigFile::saveIfUpdated() 406 480 { … … 442 516 SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0; 443 517 518 /** 519 @brief Constructor: Activates the console commands. 520 */ 444 521 SettingsConfigFile::SettingsConfigFile(const std::string& filename) 445 522 : ConfigFile(filename) … … 452 529 } 453 530 531 /** 532 @brief Destructor: Deactivates the console commands. 533 */ 454 534 SettingsConfigFile::~SettingsConfigFile() 455 535 { … … 461 541 } 462 542 543 /** 544 @brief Loads the config file and updates the @ref ConfigValueContainer "config value containers". 545 */ 463 546 void SettingsConfigFile::load() 464 547 { … … 467 550 } 468 551 552 /** 553 @brief Changes the file-name. 554 */ 469 555 void SettingsConfigFile::setFilename(const std::string& filename) 470 556 { … … 472 558 } 473 559 560 /** 561 @brief Registers a new @ref ConfigValueContainer "config value container". 562 */ 474 563 void SettingsConfigFile::addConfigValueContainer(ConfigValueContainer* container) 475 564 { … … 481 570 } 482 571 572 /** 573 @brief Unregisters a @ref ConfigValueContainer "config value container". 574 */ 483 575 void SettingsConfigFile::removeConfigValueContainer(ConfigValueContainer* container) 484 576 { … … 500 592 } 501 593 594 /** 595 @brief Updates all @ref ConfigValueContainer "config value containers". 596 */ 502 597 void SettingsConfigFile::updateConfigValues() 503 598 { 599 // todo: can this be done more efficiently? looks like some identifiers will be updated multiple times. 600 504 601 for (ContainerMap::const_iterator it = this->containers_.begin(); it != this->containers_.end(); ++it) 505 602 { … … 509 606 } 510 607 608 /** 609 @brief Removes entries and sections from the file that don't exist anymore (i.e. if there's no corresponding @ref ConfigValueContainer "config value container"). 610 @param bCleanComments If true, comments are also removed from the file 611 */ 511 612 void SettingsConfigFile::clean(bool bCleanComments) 512 613 { … … 558 659 } 559 660 661 /** 662 @brief Console-command: Changes the value of an entry and stores it the file. 663 664 @param section The section of the config value 665 @param entry The name of the config value 666 @param value The new value 667 */ 560 668 void SettingsConfigFile::config(const std::string& section, const std::string& entry, const std::string& value) 561 669 { … … 564 672 } 565 673 674 /** 675 @brief Console-command: Changes the value of an entry, but doesn't store it in the file (it's only a temporary change). 676 677 @param section The section of the config value 678 @param entry The name of the config value 679 @param value The new value 680 */ 566 681 void SettingsConfigFile::tconfig(const std::string& section, const std::string& entry, const std::string& value) 567 682 { … … 570 685 } 571 686 687 /** 688 @brief Changes the value of an entry, depending on @a function, either by using "set" or "tset" 689 690 @param section The section of the config value 691 @param entry The name of the config value 692 @param value The new value 693 @param function The function ("set" or "tset") that will be used to change the value. 694 */ 572 695 bool SettingsConfigFile::configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&)) 573 696 { … … 586 709 } 587 710 711 /** 712 @brief Console-command: Returns the value of a given entry. 713 714 @param section The section of the config value 715 @param entry The name of the config value 716 */ 588 717 std::string SettingsConfigFile::getConfig(const std::string& section, const std::string& entry) 589 718 { … … 611 740 ConfigFileManager* ConfigFileManager::singletonPtr_s = 0; 612 741 742 /// Constructor: Initializes the array of config files with NULL. 613 743 ConfigFileManager::ConfigFileManager() 614 744 { … … 616 746 } 617 747 748 /// Destructor: Deletes the config files. 618 749 ConfigFileManager::~ConfigFileManager() 619 750 { … … 623 754 } 624 755 756 /// Defines the file-name for the config file of a given type (settings, calibration, etc.). 625 757 void ConfigFileManager::setFilename(ConfigFileType::Value type, const std::string& filename) 626 758 { -
code/branches/doc/src/libraries/core/ConfigFileManager.h
r7363 r7373 30 30 @file 31 31 @ingroup Config ConfigFile 32 @brief Declaration of ConfigFileManager and its helper classes. 32 33 */ 33 34 … … 51 52 // ConfigFileEntry // 52 53 ///////////////////// 54 /** 55 @brief This class represents an entry in the config file. 56 57 This class is pure virtual. Use one of the derived classes to define the type of the entry. 58 */ 53 59 class _CoreExport ConfigFileEntry 54 60 { 55 61 public: 62 /// Destructor 56 63 virtual ~ConfigFileEntry() {}; 64 65 /// Changes the value of the entry. 57 66 virtual void setValue(const std::string& value) = 0; 67 /// Returns the value of the entry. 58 68 virtual const std::string& getValue() const = 0; 69 70 /// Returns the name of the entry 59 71 virtual const std::string& getName() const = 0; 72 73 /// Changes the comment of the entry (will be placed after the value) 60 74 virtual void setComment(const std::string& comment) = 0; 75 76 /// Returns the index of the entry in a vector (used only if it is a vector) 61 77 virtual unsigned int getIndex() const { return 0; } 78 79 /// Defines if this entry is treated as string which means some special treatment of special characters. 62 80 virtual void setString(bool bString) = 0; 81 82 /// Returns the line as it will be stored in the config file. 63 83 virtual const std::string& getFileEntry() const = 0; 64 84 }; … … 68 88 // ConfigFileEntryValue // 69 89 ////////////////////////// 90 /** 91 @brief This class represents a normal value in the config file. 92 */ 70 93 class _CoreExport ConfigFileEntryValue : public ConfigFileEntry 71 94 { 72 95 public: 96 /** 97 @brief Constructor: Initializes the entry. 98 99 @param name The name of the entry 100 @param value The value of the entry 101 @param bString If true, the value is treated as string which means some special treatment of special characters. 102 @param additionalComment An optional comment that will be placed behind the value in the config file 103 */ 73 104 inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") 74 105 : name_(name) … … 78 109 { this->update(); } 79 110 111 /// Destructor 80 112 inline virtual ~ConfigFileEntryValue() {} 81 113 … … 97 129 { return this->fileEntry_; } 98 130 131 /// Returns the "key" of the value (in this case it's just the name of the entry, but for vectors it's different) 99 132 inline virtual const std::string& getKeyString() const 100 133 { return this->name_; } … … 103 136 virtual void update(); 104 137 105 const std::string name_; 106 std::string value_; 107 std::string additionalComment_; 108 std::string fileEntry_; 109 bool bString_; 138 const std::string name_; ///< The name of the value 139 std::string value_; ///< The value 140 std::string additionalComment_; ///< The additional comment 141 std::string fileEntry_; ///< The string as it will be stored in the config file 142 bool bString_; ///< If true, the value is treated as string which means some special treatment of special characters. 110 143 }; 111 144 … … 114 147 // ConfigFileEntryVectorValue // 115 148 //////////////////////////////// 149 /** 150 @brief Subclass of ConfigFileEntryValue, represents an element of a vector. 151 */ 116 152 class _CoreExport ConfigFileEntryVectorValue : public ConfigFileEntryValue 117 153 { 118 154 public: 155 /** 156 @brief Constructor: Initializes the entry. 157 158 @param name The name of the vector 159 @param index The index of the element in the vector 160 @param value The value of the element 161 @param bString If true, the value is treated as string which means some special treatment of special characters. 162 @param additionalComment An optional comment that will be placed behind the value in the config file 163 */ 119 164 inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") 120 165 : ConfigFileEntryValue(name, value, bString, additionalComment) … … 122 167 { this->update(); /*No virtual calls in base class ctor*/ } 123 168 169 /// Destructor 124 170 inline ~ConfigFileEntryVectorValue() {} 125 171 … … 127 173 { return this->index_; } 128 174 175 /// Returns the "key" of the value (the name of the vector plus the index of the element) 129 176 inline const std::string& getKeyString() const 130 177 { return this->keyString_; } … … 133 180 void update(); 134 181 135 unsigned int index_; 136 std::string keyString_; 182 unsigned int index_; ///< The index of the element in the vector 183 std::string keyString_; ///< The full name of the entry (the name of the vector plus the index of the element) 137 184 }; 138 185 … … 141 188 // ConfigFileEntryComment // 142 189 //////////////////////////// 190 /** 191 @brief This class represents a line in the config file which contains only a comment. 192 */ 143 193 class _CoreExport ConfigFileEntryComment : public ConfigFileEntry 144 194 { 145 195 public: 196 /// Constructor: Initializes the object. 146 197 inline ConfigFileEntryComment(const std::string& comment) : comment_(comment) {} 198 199 /// Destructor 147 200 inline virtual ~ConfigFileEntryComment() {} 148 201 … … 164 217 { return this->comment_; } 165 218 166 inline virtual const std::string& getKeyString() const167 { return BLANKSTRING; }168 169 219 private: 170 std::string comment_; 220 std::string comment_; ///< The comment 171 221 }; 172 222 … … 175 225 // ConfigFileSection // 176 226 /////////////////////// 227 /** 228 @brief Represents a section in a config file. 229 230 A section has a name and a list of config values. 231 */ 177 232 class _CoreExport ConfigFileSection 178 233 { … … 181 236 182 237 public: 238 /** 239 @brief Constructor: Initializes the section. 240 241 @param name The name of the section 242 @param additionalComment An additional comment placed after the title of the section in the config file 243 */ 183 244 inline ConfigFileSection(const std::string& name, const std::string& additionalComment = "") 184 245 : name_(name) … … 188 249 ~ConfigFileSection(); 189 250 251 /// Returns the name of the section. 190 252 inline const std::string& getName() const 191 253 { return this->name_; } 192 254 255 /// Changes the comment which is placed after the title of the section in the config file. 193 256 inline void setComment(const std::string& comment) 194 257 { this->additionalComment_ = comment; } 195 258 259 /** 260 @brief Stores a value in the section. If the entry doesn't exist, it's created. 261 262 @param name The name of the entry 263 @param value The new value 264 @param bString If true, the value is treated as string which means some special treatment of special characters. 265 */ 196 266 inline void setValue(const std::string& name, const std::string& value, bool bString) 197 267 { this->getOrCreateEntry(name, value, bString)->setValue(value); } 268 /** 269 @brief Returns the value of a given entry in the section. Returns a blank string if the value doesn't exist. 270 271 @param name The name of the entry 272 @param bString If true, the value is treated as string which means some special treatment of special characters. 273 */ 198 274 inline const std::string& getValue(const std::string& name, bool bString) 199 275 { … … 201 277 if (entry) 202 278 { 203 entry->setString(bString); 279 entry->setString(bString); // if the entry was loaded from the config file, we have to tell it if it's a string 204 280 return entry->getValue(); 205 281 } 206 282 return BLANKSTRING; 207 283 } 284 /** 285 @brief Returns the value of a given entry in the section. If it doesn't exist, the entry is created using the fallback value. 286 287 @param name The name of the entry 288 @param fallback The value that will be used if the entry doesn't exist 289 @param bString If true, the value is treated as string which means some special treatment of special characters. 290 */ 208 291 inline const std::string& getOrCreateValue(const std::string& name, const std::string& fallback, bool bString) 209 292 { return this->getOrCreateEntry(name, fallback, bString)->getValue(); } 210 293 294 /** 295 @brief Stores the value of an element of a vector in the section. If the entry doesn't exist, it's created. 296 297 @param name The name of the vector 298 @param index The index of the element in the vector 299 @param value The new value 300 @param bString If true, the value is treated as string which means some special treatment of special characters. 301 */ 211 302 inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString) 212 303 { this->getOrCreateEntry(name, index, value, bString)->setValue(value); } 304 /** 305 @brief Returns the value of a given element of a vector in the section. Returns a blank string if the value doesn't exist. 306 307 @param name The name of the vector 308 @param index The index of the element in the vector 309 @param bString If true, the value is treated as string which means some special treatment of special characters. 310 */ 213 311 inline const std::string& getValue(const std::string& name, unsigned int index, bool bString) 214 312 { … … 216 314 if (entry) 217 315 { 218 entry->setString(bString); 316 entry->setString(bString); // if the entry was loaded from the config file, we have to tell it if it's a string 219 317 return entry->getValue(); 220 318 } 221 319 return BLANKSTRING; 222 320 } 321 /** 322 @brief Returns the value of a given element of a vector in the section. If it doesn't exist, the entry is created using the fallback value. 323 324 @param name The name of the vector 325 @param index The index of the element in the vector 326 @param fallback The value that will be used if the entry doesn't exist 327 @param bString If true, the value is treated as string which means some special treatment of special characters. 328 */ 223 329 inline const std::string& getOrCreateValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 224 330 { return this->getOrCreateEntry(name, index, fallback, bString)->getValue(); } … … 230 336 231 337 private: 338 /// Returns the list of entries in this section. 232 339 std::list<ConfigFileEntry*>& getEntries() 233 340 { return this->entries_; } 341 /// Returns the begin-iterator of the list of entries in this section. 234 342 std::list<ConfigFileEntry*>::const_iterator getEntriesBegin() const 235 343 { return this->entries_.begin(); } 344 /// Returns the end-iterator of the list of entries in this section. 236 345 std::list<ConfigFileEntry*>::const_iterator getEntriesEnd() const 237 346 { return this->entries_.end(); } … … 241 350 242 351 ConfigFileEntry* getEntry(const std::string& name) const; 352 /** 353 @brief Returns the entry with given name. If it doesn't exist, the entry is created using the fallback value. 354 355 @param name The name of the entry 356 @param fallback The value that will be used if the entry doesn't exist 357 @param bString If true, the value is treated as string which means some special treatment of special characters. 358 */ 243 359 inline ConfigFileEntry* getOrCreateEntry(const std::string& name, const std::string& fallback, bool bString) 244 360 { return (*this->getOrCreateEntryIterator(name, fallback, bString)); } 361 245 362 ConfigFileEntry* getEntry(const std::string& name, unsigned int index) const; 363 /** 364 @brief Returns the entry that contains an element of a vector with given name. If it doesn't exist, the entry is created using the fallback value. 365 366 @param name The name of the entry 367 @param index The index of the element in the vector 368 @param fallback The value that will be used if the entry doesn't exist 369 @param bString If true, the value is treated as string which means some special treatment of special characters. 370 */ 246 371 inline ConfigFileEntry* getOrCreateEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 247 372 { return (*this->getOrCreateEntryIterator(name, index, fallback, bString)); } 248 373 249 std::string name_; 250 std::string additionalComment_; 251 std::list<ConfigFileEntry*> entries_; 252 bool bUpdated_; 374 std::string name_; ///< The name of the section 375 std::string additionalComment_; ///< The additional comment which is placed after the title of the section in the config file 376 std::list<ConfigFileEntry*> entries_; ///< The list of entries in this section 377 bool bUpdated_; ///< True if an entry is created 253 378 }; 254 379 … … 257 382 // ConfigFile // 258 383 //////////////// 384 /** 385 @brief This class represents a config file, which is stored on the hard-disk and contains config values in different sections. 386 387 It provides an interface to manipulate the sections and values. 388 */ 259 389 class _CoreExport ConfigFile 260 390 { … … 268 398 virtual void clear(); 269 399 400 /// Returns the file-name of this config file 270 401 inline const std::string& getFilename() 271 402 { return this->filename_; } 272 403 404 /** 405 @brief Stores a value in the config file. If the entry or its section doesn't exist, it's created. 406 407 @param section The name of the section 408 @param name The name of the entry 409 @param value The new value 410 @param bString If true, the value is treated as string which means some special treatment of special characters. 411 */ 273 412 inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString) 274 413 { … … 276 415 this->save(); 277 416 } 417 /** 418 @brief Returns the value of a given entry in the config file. Returns a blank string if the value doesn't exist. 419 420 @param section The name of the section 421 @param name The name of the entry 422 @param bString If true, the value is treated as string which means some special treatment of special characters. 423 */ 278 424 inline const std::string& getValue(const std::string& section, const std::string& name, bool bString) 279 425 { … … 281 427 return (sectionPtr ? sectionPtr->getValue(name, bString) : BLANKSTRING); 282 428 } 283 const std::string& getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString); 284 429 /** 430 @brief Returns the value of a given entry in the config file. If it doesn't exist, the entry is created using the fallback value. 431 432 @param section The name of the section 433 @param name The name of the entry 434 @param fallback The value that will be used if the entry doesn't exist 435 @param bString If true, the value is treated as string which means some special treatment of special characters. 436 */ 437 inline const std::string& getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 438 { 439 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, fallback, bString); 440 this->saveIfUpdated(); 441 return output; 442 } 443 444 /** 445 @brief Stores the value of an element of a vector in the config file. If the entry or its section doesn't exist, it's created. 446 447 @param section The name of the section 448 @param name The name of the vector 449 @param index The index of the element in the vector 450 @param value The new value 451 @param bString If true, the value is treated as string which means some special treatment of special characters. 452 */ 285 453 inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString) 286 454 { … … 288 456 this->save(); 289 457 } 458 /** 459 @brief Returns the value of a given element of a vector in the config file. Returns a blank string if the value doesn't exist. 460 461 @param section The name of the section 462 @param name The name of the vector 463 @param index The index of the element in the vector 464 @param bString If true, the value is treated as string which means some special treatment of special characters. 465 */ 290 466 inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, bool bString) 291 467 { … … 293 469 return (sectionPtr ? sectionPtr->getValue(name, index, bString) : BLANKSTRING); 294 470 } 295 const std::string& getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString); 471 /** 472 @brief Returns the value of a given element of a vector in the config file. If it doesn't exist, the entry is created using the fallback value. 473 474 @param section The name of the section 475 @param name The name of the vector 476 @param index The index of the element in the vector 477 @param fallback The value that will be used if the entry doesn't exist 478 @param bString If true, the value is treated as string which means some special treatment of special characters. 479 */ 480 const std::string& getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 481 { 482 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, index, fallback, bString); 483 this->saveIfUpdated(); 484 return output; 485 } 296 486 297 487 void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0); 488 /** 489 @brief Returns the size of a config vector. 490 @param section The section of the vector 491 @param name The name of the vector 492 */ 298 493 inline unsigned int getVectorSize(const std::string& section, const std::string& name) const 299 494 { … … 302 497 } 303 498 304 static const char* DEFAULT_CONFIG_FOLDER; 499 static const char* DEFAULT_CONFIG_FOLDER; ///< The folder where the default config files will be stored 305 500 306 501 protected: … … 308 503 ConfigFileSection* getOrCreateSection(const std::string& section); 309 504 310 std::list<ConfigFileSection*> sections_; 505 std::list<ConfigFileSection*> sections_; ///< A list of sections in this config file 311 506 312 507 private: 313 508 void saveIfUpdated(); 314 const std::string filename_; 315 const bool bCopyFallbackFile_; 316 bool bUpdated_; 509 510 const std::string filename_; ///< The filename of this config file 511 const bool bCopyFallbackFile_; ///< If true, the default config file is copied into the config-directory before loading the file 512 bool bUpdated_; ///< Becomes true if a section is added 317 513 }; 318 514 … … 321 517 // SettingsConfigFile // 322 518 //////////////////////// 519 /** 520 @brief Child class of ConfigFile, used to store the settings of the game. 521 522 In addition to ConfigFile, this class provides an interface to manipulate the settings 523 with console commands and to cache entries in instances of ConfigValueContainer. 524 525 SettingsConfigFile is a Singleton, meaning there's only one instance of this class 526 (and thus only one config file that stores settings). 527 */ 323 528 class _CoreExport SettingsConfigFile // tolua_export 324 529 : public ConfigFile, public Singleton<SettingsConfigFile> … … 343 548 void removeConfigValueContainer(ConfigValueContainer* container); 344 549 550 /// Returns a set containing the names of all sections in this config file. 345 551 inline const std::set<std::string>& getSectionNames() 346 552 { return this->sectionNames_; } 553 /// Returns the lower-bound-iterator of the @ref ConfigValueContainer "config value containers" for the given section. 347 554 inline ContainerMap::const_iterator getContainerLowerBound(const std::string section) 348 555 { return this->containers_.lower_bound(section); } 556 /// Returns the upper-bound-iterator of the @ref ConfigValueContainer "config value containers" for the given section. 349 557 inline ContainerMap::const_iterator getContainerUpperBound(const std::string section) 350 558 { return this->containers_.upper_bound(section); } … … 356 564 bool configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&)); 357 565 358 ContainerMap containers_; 359 std::set<std::string> sectionNames_; 360 static SettingsConfigFile* singletonPtr_s; 566 ContainerMap containers_; ///< Stores all @ref ConfigValueContainer "config value containers" 567 std::set<std::string> sectionNames_; ///< Stores all section names 568 static SettingsConfigFile* singletonPtr_s; ///< The singleton pointer 361 569 }; // tolua_export 362 570 … … 365 573 // ConfigFileManager // 366 574 /////////////////////// 575 /** 576 @brief Manages the different config files (settings, calibration, etc). Implemented as Singleton. 577 */ 367 578 class _CoreExport ConfigFileManager : public Singleton<ConfigFileManager> 368 579 { … … 374 585 void setFilename(ConfigFileType::Value type, const std::string& filename); 375 586 587 /// Returns the config file of a given type (settings, calibration, etc.) 376 588 inline ConfigFile* getConfigFile(ConfigFileType::Value type) 377 589 { … … 381 593 382 594 private: 383 ConfigFileManager(const ConfigFileManager&); 384 385 boost::array<ConfigFile*, 3> configFiles_; 386 static ConfigFileManager* singletonPtr_s; 595 ConfigFileManager(const ConfigFileManager&); ///< Copy-constructor: not implemented 596 597 boost::array<ConfigFile*, 3> configFiles_; ///< Stores the config files for each type in an array (must have the same size like ConfigFileType::Value) 598 static ConfigFileManager* singletonPtr_s; ///< Stores the singleton-pointer 387 599 }; 388 600 } // tolua_export -
code/branches/doc/src/libraries/core/OrxonoxClass.cc
r6417 r7373 41 41 namespace orxonox 42 42 { 43 /** @brief Constructor: Sets the default values. */ 43 /** 44 @brief Constructor: Sets the default values. 45 */ 44 46 OrxonoxClass::OrxonoxClass() 45 47 { … … 53 55 } 54 56 55 /** @brief Destructor: Deletes, if existing, the list of the parents. */ 57 /** 58 @brief Destructor: Removes the object from the object-lists, notifies all @ref WeakPtr "weak pointers" that this object is being deleted. 59 */ 56 60 OrxonoxClass::~OrxonoxClass() 57 61 { … … 72 76 } 73 77 74 /** @brief Deletes the object if no smart pointers point to this object. Otherwise schedules the object to be deleted as soon as possible. */ 78 /** 79 @brief Deletes the object if no @ref orxonox::SmartPtr "smart pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible. 80 */ 75 81 void OrxonoxClass::destroy() 76 82 { … … 85 91 } 86 92 93 /** 94 @brief Removes this object from the object-lists. 95 */ 87 96 void OrxonoxClass::unregisterObject() 88 97 { … … 92 101 } 93 102 94 / ** @brief Returns true if the objects class is of the given type or a derivative. */103 /// Returns true if the object's class is of the given type or a derivative. 95 104 bool OrxonoxClass::isA(const Identifier* identifier) 96 105 { return this->getIdentifier()->isA(identifier); } 97 / ** @brief Returns true if the objects class is exactly of the given type. */106 /// Returns true if the object's class is exactly of the given type. 98 107 bool OrxonoxClass::isExactlyA(const Identifier* identifier) 99 108 { return this->getIdentifier()->isExactlyA(identifier); } 100 / ** @brief Returns true if the objects class is a child of the given type. */109 /// Returns true if the object's class is a child of the given type. 101 110 bool OrxonoxClass::isChildOf(const Identifier* identifier) 102 111 { return this->getIdentifier()->isChildOf(identifier); } 103 / ** @brief Returns true if the objects class is a direct child of the given type. */112 /// Returns true if the object's class is a direct child of the given type. 104 113 bool OrxonoxClass::isDirectChildOf(const Identifier* identifier) 105 114 { return this->getIdentifier()->isDirectChildOf(identifier); } 106 / ** @brief Returns true if the objects class is a parent of the given type. */115 /// Returns true if the object's class is a parent of the given type. 107 116 bool OrxonoxClass::isParentOf(const Identifier* identifier) 108 117 { return this->getIdentifier()->isParentOf(identifier); } 109 / ** @brief Returns true if the objects class is a direct parent of the given type. */118 /// Returns true if the object's class is a direct parent of the given type. 110 119 bool OrxonoxClass::isDirectParentOf(const Identifier* identifier) 111 120 { return this->getIdentifier()->isDirectParentOf(identifier); } 112 121 113 122 114 / ** @brief Returns true if the objects class is of the given type or a derivative. */123 /// Returns true if the object's class is of the given type or a derivative. 115 124 bool OrxonoxClass::isA(const OrxonoxClass* object) 116 125 { return this->getIdentifier()->isA(object->getIdentifier()); } 117 / ** @brief Returns true if the objects class is exactly of the given type. */126 /// Returns true if the object's class is exactly of the given type. 118 127 bool OrxonoxClass::isExactlyA(const OrxonoxClass* object) 119 128 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 120 / ** @brief Returns true if the objects class is a child of the given type. */129 /// Returns true if the object's class is a child of the given type. 121 130 bool OrxonoxClass::isChildOf(const OrxonoxClass* object) 122 131 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 123 / ** @brief Returns true if the objects class is a direct child of the given type. */132 /// Returns true if the object's class is a direct child of the given type. 124 133 bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object) 125 134 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 126 / ** @brief Returns true if the objects class is a parent of the given type. */135 /// Returns true if the object's class is a parent of the given type. 127 136 bool OrxonoxClass::isParentOf(const OrxonoxClass* object) 128 137 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 129 / ** @brief Returns true if the objects class is a direct child of the given type. */138 /// Returns true if the object's class is a direct child of the given type. 130 139 bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object) 131 140 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } -
code/branches/doc/src/libraries/core/OrxonoxClass.h
r7372 r7373 63 63 64 64 The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass. 65 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 65 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the 66 MetaObjectList, as well as to provide an interface for SmartPtr and WeakPtr. 66 67 */ 67 68 class _CoreExport OrxonoxClass … … 96 97 bool isDirectParentOf(const Identifier* identifier); 97 98 99 /// Returns true if the object's class is of the given type or a derivative. 98 100 template <class B> inline bool isA(const SubclassIdentifier<B>* identifier) 99 101 { return this->isA(*identifier); } 102 /// Returns true if the object's class is exactly of the given type. 100 103 template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier) 101 104 { return this->isExactlyA(*identifier); } 105 /// Returns true if the object's class is a child of the given type. 102 106 template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier) 103 107 { return this->isChildOf(*identifier); } 108 /// Returns true if the object's class is a direct child of the given type. 104 109 template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier) 105 110 { return this->isDirectChildOf(*identifier); } 111 /// Returns true if the object's class is a parent of the given type. 106 112 template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier) 107 113 { return this->isParentOf(*identifier); } 114 /// Returns true if the object's class is a direct parent of the given type. 108 115 template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier) 109 116 { return this->isDirectParentOf(*identifier); } … … 118 125 virtual void clone(OrxonoxClass*& item) {} 119 126 127 /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object. 120 128 inline unsigned int getReferenceCount() const 121 129 { return this->referenceCount_; } … … 146 154 147 155 protected: 156 /// This virtual function is called if destroy() is called and no SmartPtr points to this object. Used in some cases to create a new SmartPtr to prevent destruction. 148 157 virtual void preDestroy() {} 149 158 … … 169 178 { this->weakPointers_.erase(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 170 179 171 Identifier* identifier_; //!< The Identifier of the object172 std::set<const Identifier*>* parents_; //!< List of all parents of the object173 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in174 int referenceCount_; //!< Counts the references from smart pointers to this object175 bool requestedDestruction_; //!< Becomes true after someone called delete on this object176 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies)180 Identifier* identifier_; //!< The Identifier of the object 181 std::set<const Identifier*>* parents_; //!< List of all parents of the object 182 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 183 int referenceCount_; //!< Counts the references from smart pointers to this object 184 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 185 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies) 177 186 178 187 /// 'Fast map' that holds this-pointers of all derived types -
code/branches/doc/src/libraries/core/SmartPtr.h
r7363 r7373 37 37 @file 38 38 @ingroup Object SmartPtr 39 @brief Definition of SmartPtr<T>. 40 41 @anchor SmartPtrExample 42 43 orxonox::SmartPtr is an implementation of a smart pointer - it wraps a pointer to an 44 object and keeps this object alive until no SmartPtr points to this object anymore. 45 In contrast to orxonox::SharedPtr, SmartPtr works only with classes that are derived 46 from orxonox::OrxonoxClass, because it's an intrusive implementation, meaning the 47 reference counter is stored in the object itself. 48 49 It's possible to use normal pointers and smart pointers to an object simultaneously. 50 You don't have to use SmartPtr all the time, you can create a SmartPtr for an object 51 at any time and also convert it back to a normal pointer if you like. This is possible 52 because the reference counter is stored in the object itself and not in SmartPtr (in 53 contrast to SharedPtr). 54 55 @b Important: If you want to delete an object, you must not use @c delete @c object but 56 rather @c object->destroy(). This function will check if there are smart pointers 57 pointing to the object. If yes, the object will be kept alive until all smart pointes 58 are destroyed. If no, the object is deleted instantly. 59 60 If all smart pointers that point to an object are destroyed, but you never called 61 @c object->destroy() before, the object will not be deleted! All a SmartPtr will do 62 is to really just keep an object alive, but it will not delete it automatically 63 unless you tried to destroy it before. 64 65 Example: 66 @code 67 class MyClass // class declaration 68 { 69 public: 70 void setObject(OtherClass* object) // passes a normal pointer which will be stored in a SmartPtr 71 { this->object_ = object; } 72 73 OtherClass* getObject() const // converts the SmartPtr to a normal pointer and returns it 74 { return this->object_; } 75 76 private: 77 SmartPtr<OtherClass> object_; // a pointer to an instance of OtherClass is stored in a SmartPtr 78 }; 79 @endcode 80 In this example we assume that OtherClass is a child of OrxonoxClass. We don't care 81 about the inheritance of MyClass though. 82 83 Now we create an instance of MyClass and assign a pointer to an instance of OtherClass: 84 @code 85 MyClass* myclass = new MyClass(); // create an instance of MyClass 86 OtherClass* object = new OtherClass(); // create an instance of OtherClass 87 myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass 88 89 object->destroy(); // we try to destroy object, but there's still a SmartPtr pointing at it. 90 91 # object still exists at this point (because a SmartPtr points at it) 92 93 delete myclass; // now we delete myclass, which also destroys the SmartPtr 94 95 # object doesn't exist anymore (because the SmartPtr is now destroyed) 96 @endcode 97 98 Now we look at the same example, but we first delete myclass, then destroy object: 99 @code 100 MyClass* myclass = new MyClass(); // create an instance of MyClass 101 OtherClass* object = new OtherClass(); // create an instance of OtherClass 102 myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass 103 104 delete myclass; // we delete myclass, which also destroys the SmartPtr 105 106 # object still exists at this point (because destroy() was not called yet) 107 108 object->destroy(); // now we try to destroy object, which works instantly 109 110 # object doesn't exist anymore (because we just destroyed it) 111 @endcode 112 113 Note that in any case @c object->destroy() has to be called to delete the object. 114 However if a SmartPtr points at it, the destruction is delayed until all SmartPtr 115 are destroyed. 39 116 */ 40 117 … … 52 129 namespace orxonox 53 130 { 131 /** 132 @brief A smart pointer which wraps a pointer to an object and keeps this object alive as long as the smart pointer exists. 133 134 @see See @ref SmartPtrExample "this description" for more information and an example. 135 */ 54 136 template <class T> 55 137 class SmartPtr 56 138 { 57 139 public: 140 /// Constructor: Initializes the smart pointer with a null pointer. 58 141 inline SmartPtr() : pointer_(0), base_(0) 59 142 { 60 143 } 61 144 145 /// Constructor: Used to explicitly initialize the smart pointer with a null pointer 62 146 inline SmartPtr(int) : pointer_(0), base_(0) 63 147 { 64 148 } 65 149 150 /// Constructor: Initializes the smart pointer with a pointer to an object. @param pointer The pointer @param bAddRef If true, the reference counter is increased. Don't set this to false unless you know exactly what you're doing! (for example to avoid circular references if the @c this pointer of the possessing object is stored) 66 151 inline SmartPtr(T* pointer, bool bAddRef = true) : pointer_(pointer), base_(pointer) 67 152 { … … 70 155 } 71 156 157 /// Copy-constructor 72 158 inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_), base_(other.base_) 73 159 { … … 76 162 } 77 163 164 /// Copy-constructor for smart pointers to objects of another class. 78 165 template <class O> 79 166 inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get()), base_(other.base_) … … 83 170 } 84 171 172 /// Constructor: Initializes the smart pointer with the pointer that is stored in a WeakPtr. 85 173 template <class O> 86 174 inline SmartPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.getBase()) … … 90 178 } 91 179 180 /// Destructor: Decrements the reference counter. 92 181 inline ~SmartPtr() 93 182 { … … 96 185 } 97 186 187 /// Used to assign a null pointer. 98 188 inline SmartPtr& operator=(int) 99 189 { … … 102 192 } 103 193 194 /// Assigns a new pointer. 104 195 inline SmartPtr& operator=(T* pointer) 105 196 { … … 108 199 } 109 200 201 /// Assigns the wrapped pointer of another SmartPtr. 110 202 inline SmartPtr& operator=(const SmartPtr& other) 111 203 { … … 114 206 } 115 207 208 /// Assigns the wrapped pointer of a SmartPtr of another class 116 209 template <class O> 117 210 inline SmartPtr& operator=(const SmartPtr<O>& other) … … 121 214 } 122 215 216 /// Assigns the wrapped pointer of a WeakPtr. 123 217 template <class O> 124 218 inline SmartPtr& operator=(const WeakPtr<O>& other) … … 128 222 } 129 223 224 /// Returns the wrapped pointer as @c T* 130 225 inline T* get() const 131 226 { … … 133 228 } 134 229 230 /// Returns the wrapped pointer as @c OrxonoxClass* 135 231 inline OrxonoxClass* getBase() const 136 232 { … … 138 234 } 139 235 236 /// Implicitly converts the SmartPtr to a pointer of type @c T* 140 237 inline operator T*() const 141 238 { … … 143 240 } 144 241 242 /// Overloaded operator, returns a pointer to the stored object. 145 243 inline T* operator->() const 146 244 { … … 149 247 } 150 248 249 /// Overloaded operator, returns a reference to the stored object. 151 250 inline T& operator*() const 152 251 { … … 155 254 } 156 255 256 /// Returns true if the wrapped pointer is NULL. 157 257 inline bool operator!() const 158 258 { … … 160 260 } 161 261 262 /// Swaps the contents of two smart pointers. 162 263 inline void swap(SmartPtr& other) 163 264 { … … 174 275 } 175 276 277 /// Resets the smart pointer (equivalent to assigning a NULL pointer). 176 278 inline void reset() 177 279 { … … 180 282 181 283 private: 182 T* pointer_; 183 OrxonoxClass* base_; 284 T* pointer_; ///< The wrapped pointer to an object of type @a T 285 OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, SmartPtr couln't be used with forward declarations) 184 286 }; 185 287 288 /// Swaps the contents of two smart pointers. 186 289 template <class T> 187 290 void swap(SmartPtr<T>& a, SmartPtr<T>& b) … … 190 293 } 191 294 295 /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>. 192 296 template <class T, class U> 193 297 SmartPtr<T> static_pointer_cast(const SmartPtr<U>& p) … … 196 300 } 197 301 302 /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>. 198 303 template <class T, class U> 199 304 SmartPtr<T> const_pointer_cast(const SmartPtr<U>& p) … … 202 307 } 203 308 309 /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>. 204 310 template <class T, class U> 205 311 SmartPtr<T> dynamic_pointer_cast(const SmartPtr<U>& p) -
code/branches/doc/src/libraries/core/WeakPtr.h
r7363 r7373 32 32 @file 33 33 @ingroup Object SmartPtr 34 @brief Definition of WeakPtr<T>. 35 36 @anchor WeakPtrExample 37 38 A WeakPtr wraps a pointer to an object. If the object gets deleted, the WeakPtr becomes 39 NULL. This can be used to store pointers to objects without knowing when they will be 40 destroyed. 41 42 WeakPtr works only with objects that are derived from orxonox::OrxonoxClass, because 43 WeakPtr is intrusive and registers itself in the stored object, to get a notification if 44 the object is being deleted. 45 46 Example: 47 @code 48 MyClass* object = new MyClass(); // create an instance of MyClass 49 50 WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object 51 52 if (pointer) // checks if pointer is not NULL (which is true) 53 pointer->someFunction(); // calls MyClass::someFunction() 54 55 object->destroy(); // calls destroy() which deletes the object 56 57 if (pointer) // checks if pointer is not NULL (which is now false) 58 pointer->someFunction(); // this will not be executed 59 @endcode 60 In this example we assumed that MyClass is derived of OrxonoxClass (otherwise it couldn't 61 be used with a WeakPtr). 62 63 A callback can be registerd with the WeakPtr that will be called if the object gets deleted. 64 @code 65 void myCallback() // definition of the callback function 66 { 67 COUT(0) << "Object destroyed" << std::endl; 68 } 69 70 MyClass* object = new MyClass(); // create an instance of MyClass 71 72 WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object 73 74 pointer.setCallback(createFunctor(&myCallback)); // defines a callback 75 76 object->destroy(); // calls destroy() which deletes the object. prints "Object destroyed" to the console 77 @endcode 34 78 */ 35 79 … … 46 90 namespace orxonox 47 91 { 92 /** 93 @brief WeakPtr wraps a pointer to an object, which becomes NULL if the object is deleted. 94 95 @see See @ref WeakPtrExample "this description" for more information and an example. 96 */ 48 97 template <class T> 49 98 class WeakPtr … … 52 101 53 102 public: 103 /// Constructor: Initializes the weak pointer with a null pointer. 54 104 inline WeakPtr() : pointer_(0), base_(0), callback_(0) 55 105 { 56 106 } 57 107 108 /// Constructor: Used to explicitly initialize the weak pointer with a null pointer 58 109 inline WeakPtr(int) : pointer_(0), base_(0), callback_(0) 59 110 { 60 111 } 61 112 113 /// Constructor: Initializes the weak pointer with a pointer to an object. 62 114 inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0) 63 115 { … … 66 118 } 67 119 120 /// Copy-constructor 68 121 inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(0) 69 122 { … … 72 125 } 73 126 127 /// Copy-constructor for weak pointers to objects of another class. 74 128 template <class O> 75 129 inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_), callback_(0) … … 79 133 } 80 134 135 /// Destructor 81 136 inline ~WeakPtr() 82 137 { … … 86 141 } 87 142 143 /// Used to assign a null pointer. 88 144 inline WeakPtr& operator=(int) 89 145 { … … 92 148 } 93 149 150 /// Assigns a new pointer. 94 151 inline WeakPtr& operator=(T* pointer) 95 152 { … … 98 155 } 99 156 157 /// Assigns the wrapped pointer of another WeakPtr. 100 158 inline WeakPtr& operator=(const WeakPtr& other) 101 159 { … … 104 162 } 105 163 164 /// Assigns the wrapped pointer of a WeakPtr of another class 106 165 template <class O> 107 166 inline WeakPtr& operator=(const WeakPtr<O>& other) … … 111 170 } 112 171 172 /// Returns the wrapped pointer as @c T* 113 173 inline T* get() const 114 174 { … … 116 176 } 117 177 178 /// Returns the wrapped pointer as @c OrxonoxClass* 118 179 inline OrxonoxClass* getBase() const 119 180 { … … 121 182 } 122 183 184 /// Implicitly converts the WeakPtr to a pointer of type @c T* 123 185 inline operator T*() const 124 186 { … … 126 188 } 127 189 190 /// Overloaded operator, returns a pointer to the stored object. 128 191 inline T* operator->() const 129 192 { … … 132 195 } 133 196 197 /// Overloaded operator, returns a reference to the stored object. 134 198 inline T& operator*() const 135 199 { … … 138 202 } 139 203 204 /// Returns true if the wrapped pointer is NULL. 140 205 inline bool operator!() const 141 206 { … … 143 208 } 144 209 210 /// Swaps the contents of two weak pointers. 145 211 inline void swap(WeakPtr& other) 146 212 { … … 167 233 } 168 234 235 /// Resets the weak pointer (equivalent to assigning a NULL pointer). 169 236 inline void reset() 170 237 { … … 172 239 } 173 240 241 /// Registers a callback that will be executed if the stored object is destroyed. 174 242 inline void setCallback(const FunctorPtr& callback) 175 243 { … … 177 245 } 178 246 247 /// Returns the registered callback. 179 248 inline const FunctorPtr& getCallback() const 180 249 { … … 183 252 184 253 private: 254 /// Will be called by OrxonoxClass::~OrxonoxClass() if the stored object is deleted. Resets the wrapped pointer and executes the callback. 185 255 inline void objectDeleted() 186 256 { … … 191 261 } 192 262 193 T* pointer_; 194 OrxonoxClass* base_; 195 FunctorPtr callback_; 263 T* pointer_; ///< The wrapped pointer to an object of type @a T 264 OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, WeakPtr couln't be used with forward declarations) 265 FunctorPtr callback_; ///< This callback will be executed if the stored object is deleted 196 266 }; 197 267 268 /// Swaps the contents of two weak pointers. 198 269 template <class T> 199 270 void swap(WeakPtr<T>& a, WeakPtr<T>& b) … … 202 273 } 203 274 275 /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>. 204 276 template <class T, class U> 205 277 WeakPtr<T> static_pointer_cast(const WeakPtr<U>& p) … … 208 280 } 209 281 282 /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>. 210 283 template <class T, class U> 211 284 WeakPtr<T> const_pointer_cast(const WeakPtr<U>& p) … … 214 287 } 215 288 289 /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>. 216 290 template <class T, class U> 217 291 WeakPtr<T> dynamic_pointer_cast(const WeakPtr<U>& p)
Note: See TracChangeset
for help on using the changeset viewer.