Changeset 2344 for code/branches/objecthierarchy2/src/core
- Timestamp:
- Dec 4, 2008, 8:28:14 PM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src/core
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/core/CommandExecutor.cc
r1784 r2344 53 53 } 54 54 55 ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command )55 ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit) 56 56 { 57 57 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName()); … … 61 61 } 62 62 63 // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier 64 if (command && bDeleteAtExit) 65 { 66 CommandExecutor::getInstance().consoleCommandExternals_.insert(command); 67 } 63 68 64 69 CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command; … … 647 652 } 648 653 } 654 655 void CommandExecutor::destroyExternalCommands() 656 { 657 for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin(); 658 it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it) 659 delete *it; 660 } 649 661 } -
code/branches/objecthierarchy2/src/core/CommandExecutor.h
r1771 r2344 51 51 static const CommandEvaluation& getLastEvaluation(); 52 52 53 static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command );53 static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false); 54 54 static ConsoleCommand* getConsoleCommandShortcut(const std::string& name); 55 55 static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name); … … 68 68 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 69 69 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); } 70 71 static void destroyExternalCommands(); 70 72 71 73 private: … … 101 103 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_; 102 104 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_; 105 std::set<ConsoleCommand*> consoleCommandExternals_; 103 106 }; // tolua_export 104 107 } // tolua_export -
code/branches/objecthierarchy2/src/core/CommandLine.cc
r2105 r2344 83 83 CommandLine::~CommandLine() 84 84 { 85 for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin(); 86 it != cmdLineArgs_.end(); ++it) 87 { 88 delete it->second; 89 } 85 CommandLine::destroyAllArguments(); 90 86 } 91 87 … … 98 94 static CommandLine instance; 99 95 return instance; 96 } 97 98 /** 99 @brief 100 Destroys all command line arguments. This should be called at the end 101 of main. Do not use before that. 102 */ 103 void CommandLine::destroyAllArguments() 104 { 105 for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin(); 106 it != _getInstance().cmdLineArgs_.end(); ++it) 107 delete it->second; 108 _getInstance().cmdLineArgs_.clear(); 100 109 } 101 110 -
code/branches/objecthierarchy2/src/core/CommandLine.h
r2103 r2344 155 155 } 156 156 157 static void destroyAllArguments(); 157 158 158 159 private: … … 179 180 //! Holds all pointers to the arguments and serves as a search map by name. 180 181 std::map<std::string, CommandLineArgument*> cmdLineArgs_; 181 //! Search map by chortcut for the arguments.182 //! Search map by shortcut for the arguments. 182 183 std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_; 183 184 }; -
code/branches/objecthierarchy2/src/core/ConsoleCommand.h
r2087 r2344 64 64 65 65 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ 66 orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command )66 orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true) 67 67 68 68 -
code/branches/objecthierarchy2/src/core/Core.cc
r2171 r2344 46 46 bool Core::bIsMaster_s = false; 47 47 48 Core* Core::singletonRef_s = 0; 49 48 50 /** 49 51 @brief Constructor: Registers the object and sets the config-values. … … 53 55 { 54 56 RegisterRootObject(Core); 57 58 assert(singletonRef_s == 0); 59 singletonRef_s = this; 60 55 61 this->setConfigValues(); 56 isCreatingCoreSettings() = false;57 62 } 58 63 … … 62 67 Core::~Core() 63 68 { 64 isCreatingCoreSettings() = true; 65 } 66 67 /** 68 @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value. 69 */ 70 bool& Core::isCreatingCoreSettings() 71 { 72 static bool bCreatingCoreSettings = true; 73 return bCreatingCoreSettings; 74 } 75 76 /** 77 @brief Returns a unique instance of Core. 78 @return The instance 79 */ 80 Core& Core::getInstance() 81 { 82 // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class 83 //if (Core::isCreatingCoreSettings()) 84 //{ 85 // isCreatingCoreSettings() = false; 86 // //instance.setConfigValues(); 87 //} 88 89 static bool firstTime = true; 90 if (firstTime) 91 isCreatingCoreSettings() = true; 92 93 static Core instance; 94 return instance; 69 assert(singletonRef_s); 70 singletonRef_s = 0; 95 71 } 96 72 … … 140 116 int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) 141 117 { 142 if (!Core::isCreatingCoreSettings())118 switch (device) 143 119 { 144 switch (device) 145 { 146 case OutputHandler::LD_All: 147 return Core::getInstance().softDebugLevel_; 148 case OutputHandler::LD_Console: 149 return Core::getInstance().softDebugLevelConsole_; 150 case OutputHandler::LD_Logfile: 151 return Core::getInstance().softDebugLevelLogfile_; 152 case OutputHandler::LD_Shell: 153 return Core::getInstance().softDebugLevelShell_; 154 default: 155 assert(0); 156 } 120 case OutputHandler::LD_All: 121 return Core::getInstance().softDebugLevel_; 122 case OutputHandler::LD_Console: 123 return Core::getInstance().softDebugLevelConsole_; 124 case OutputHandler::LD_Logfile: 125 return Core::getInstance().softDebugLevelLogfile_; 126 case OutputHandler::LD_Shell: 127 return Core::getInstance().softDebugLevelShell_; 128 default: 129 assert(0); 130 return 2; 157 131 } 158 159 // Return a constant value while we're creating the object160 return 2;161 132 } 162 133 … … 168 139 void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) 169 140 { 170 if (!Core::isCreatingCoreSettings()) 171 { 172 if (device == OutputHandler::LD_All) 173 Core::getInstance().softDebugLevel_ = level; 174 else if (device == OutputHandler::LD_Console) 175 Core::getInstance().softDebugLevelConsole_ = level; 176 else if (device == OutputHandler::LD_Logfile) 177 Core::getInstance().softDebugLevelLogfile_ = level; 178 else if (device == OutputHandler::LD_Shell) 179 Core::getInstance().softDebugLevelShell_ = level; 141 if (device == OutputHandler::LD_All) 142 Core::getInstance().softDebugLevel_ = level; 143 else if (device == OutputHandler::LD_Console) 144 Core::getInstance().softDebugLevelConsole_ = level; 145 else if (device == OutputHandler::LD_Logfile) 146 Core::getInstance().softDebugLevelLogfile_ = level; 147 else if (device == OutputHandler::LD_Shell) 148 Core::getInstance().softDebugLevelShell_ = level; 180 149 181 OutputHandler::setSoftDebugLevel(device, level); 182 } 150 OutputHandler::setSoftDebugLevel(device, level); 183 151 } 184 152 … … 188 156 const std::string& Core::getLanguage() 189 157 { 190 if (!Core::isCreatingCoreSettings()) 191 return Core::getInstance().language_; 192 193 return Language::getLanguage().defaultLanguage_; 158 return Core::getInstance().language_; 194 159 } 195 160 -
code/branches/objecthierarchy2/src/core/Core.h
r2171 r2344 40 40 #include "CorePrereqs.h" 41 41 42 #include <cassert> 42 43 #include "OrxonoxClass.h" 43 44 #include "util/OutputHandler.h" … … 49 50 { 50 51 public: 51 static Core& getInstance();52 static bool& isCreatingCoreSettings();52 Core(); 53 ~Core(); 53 54 void setConfigValues(); 54 55 void debugLevelChanged(); 55 56 void languageChanged(); 56 57 57 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 58 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 58 static Core& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 59 60 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 61 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 59 62 static const std::string& getLanguage(); 60 static void resetLanguage();63 static void resetLanguage(); 61 64 62 65 // fast access global variables. … … 73 76 74 77 private: 78 Core(const Core&); 75 79 void resetLanguageIntern(); 76 77 Core();78 Core(const Core& other);79 virtual ~Core();80 80 81 81 int softDebugLevel_; //!< The debug level … … 90 90 static bool bIsStandalone_s; 91 91 static bool bIsMaster_s; 92 93 static Core* singletonRef_s; 92 94 }; 93 95 } -
code/branches/objecthierarchy2/src/core/CorePrereqs.h
r2173 r2344 133 133 class LanguageEntry; 134 134 class Loader; 135 class LuaBind; 135 136 class MetaObjectList; 136 137 class MetaObjectListElement; -
code/branches/objecthierarchy2/src/core/Identifier.cc
r2171 r2344 93 93 for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it) 94 94 delete (it->second); 95 for (std::vector<Functor*>::iterator it = this->constructionCallbacks_.begin(); it != this->constructionCallbacks_.end(); ++it) 96 delete *it; 97 } 98 99 /** 100 @brief Returns the identifier map with the names as received by typeid(). This is only used internally. 101 */ 102 std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap() 103 { 104 static std::map<std::string, Identifier*> identifiers; //!< The map to store all Identifiers. 105 return identifiers; 95 106 } 96 107 … … 103 114 Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal) 104 115 { 105 static std::map<std::string, Identifier*> identifiers; //!< The map to store all Identifiers. 106 std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name); 107 108 if (it != identifiers.end()) 116 std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name); 117 118 if (it != getTypeIDIdentifierMap().end()) 109 119 { 110 120 // There is already an entry: return it and delete the proposal … … 115 125 { 116 126 // There is no entry: put the proposal into the map and return it 117 identifiers[name] = proposal;127 getTypeIDIdentifierMap()[name] = proposal; 118 128 return proposal; 119 129 } … … 192 202 void Identifier::destroyAllIdentifiers() 193 203 { 194 for (std::map<std::string, Identifier*>::iterator it = Identifier::get IdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)204 for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it) 195 205 delete (it->second); 196 206 } -
code/branches/objecthierarchy2/src/core/Identifier.h
r2171 r2344 257 257 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 258 258 259 static void destroyAllIdentifiers(); 260 259 261 protected: 260 262 Identifier(); … … 299 301 } 300 302 303 static std::map<std::string, Identifier*>& getTypeIDIdentifierMap(); 304 301 305 void initialize(std::set<const Identifier*>* parents); 302 303 static void destroyAllIdentifiers();304 306 305 307 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to -
code/branches/objecthierarchy2/src/core/Language.cc
r2171 r2344 87 87 // ### Language ### 88 88 // ############################### 89 90 Language* Language::singletonRef_s = 0; 91 89 92 /** 90 93 @brief Constructor: Reads the default language file and sets some values. … … 92 95 Language::Language() 93 96 { 97 assert(singletonRef_s == 0); 98 singletonRef_s = this; 99 94 100 this->defaultLanguage_ = "default"; 95 101 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; … … 106 112 for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it) 107 113 delete (it->second); 108 } 109 110 /** 111 @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function. 112 @return The reference to the only existing instance 113 */ 114 Language& Language::getLanguage() 115 { 116 static Language instance = Language(); 117 return instance; 114 115 assert(singletonRef_s); 116 singletonRef_s = 0; 118 117 } 119 118 -
code/branches/objecthierarchy2/src/core/Language.h
r2171 r2344 50 50 #include <map> 51 51 #include <string> 52 #include <cassert> 52 53 53 54 #define AddLanguageEntry(label, fallbackstring) \ … … 116 117 117 118 public: 118 static Language& getLanguage(); 119 Language(); 120 ~Language(); 121 122 static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; } 119 123 void addEntry(const LanguageEntryLabel& label, const std::string& entry); 120 124 const std::string& getLocalisation(const LanguageEntryLabel& label) const; 121 125 122 126 private: 123 Language(); 124 Language(const Language& language); // don't copy 125 virtual ~Language(); 127 Language(const Language&); 126 128 127 129 void readDefaultLanguageFile(); … … 134 136 std::string defaultLocalisation_; //!< The returned string, if an entry unavailable entry is requested 135 137 std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels 138 139 static Language* singletonRef_s; 136 140 }; 137 141 } -
code/branches/objecthierarchy2/src/core/Loader.cc
r2171 r2344 120 120 121 121 // let Lua work this out: 122 LuaBind *lua = LuaBind::getInstance();123 lua ->clearLuaOutput();124 lua ->loadFile(file->getFilename(), true);125 lua ->run();122 LuaBind& lua = LuaBind::getInstance(); 123 lua.clearLuaOutput(); 124 lua.loadFile(file->getFilename(), true); 125 lua.run(); 126 126 127 127 try … … 135 135 ticpp::Document xmlfile; 136 136 //xmlfile.ToDocument(); 137 xmlfile.Parse(lua ->getLuaOutput(), true);137 xmlfile.Parse(lua.getLuaOutput(), true); 138 138 139 139 ticpp::Element rootElement; -
code/branches/objecthierarchy2/src/core/LuaBind.cc
r2087 r2344 40 40 namespace orxonox 41 41 { 42 LuaBind* LuaBind::singletonRef = NULL;42 LuaBind* LuaBind::singletonRef_s = NULL; 43 43 44 44 LuaBind::LuaBind() 45 45 { 46 assert(LuaBind::singletonRef_s == 0); 47 LuaBind::singletonRef_s = this; 48 46 49 luaState_ = lua_open(); 47 50 luaSource_ = ""; -
code/branches/objecthierarchy2/src/core/LuaBind.h
r2087 r2344 42 42 } 43 43 44 #include <cassert> 44 45 #include <list> 45 46 #include <string> … … 58 59 59 60 public: 60 inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export 61 inline ~LuaBind() { LuaBind::singletonRef = NULL; }; 61 LuaBind(); 62 inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; }; 63 64 inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export 62 65 63 66 void loadFile(std::string filename, bool luaTags); … … 83 86 84 87 private: 85 LuaBind(); 86 static LuaBind* singletonRef; 88 static LuaBind* singletonRef_s; 87 89 88 90 std::string luaSource_; -
code/branches/objecthierarchy2/src/core/RootGameState.cc
r2103 r2344 31 31 #include "util/Debug.h" 32 32 #include "util/Exception.h" 33 #include "Core.h"34 33 #include "Clock.h" 35 34 #include "CommandLine.h" … … 137 136 Clock clock; 138 137 139 // create the Core settings to configure the output level140 Core::getInstance();141 142 138 this->activate(); 143 139 -
code/branches/objecthierarchy2/src/core/RootGameState.h
r2103 r2344 48 48 void gotoState(const std::string& name); 49 49 50 std::string 50 std::string stateRequest_; 51 51 }; 52 52 } -
code/branches/objecthierarchy2/src/core/XMLPort.h
r2173 r2344 43 43 #include "CorePrereqs.h" 44 44 45 #include <cassert> 45 46 #include "util/Debug.h" 46 47 #include "util/Exception.h" … … 327 328 this->loadexecutor_ = loadexecutor; 328 329 this->saveexecutor_ = saveexecutor; 330 } 331 332 ~XMLPortClassParamContainer() 333 { 334 assert(this->loadexecutor_); 335 delete this->loadexecutor_; 336 if (this->saveexecutor_) 337 delete this->saveexecutor_; 329 338 } 330 339 … … 471 480 this->bApplyLoaderMask_ = bApplyLoaderMask; 472 481 this->bLoadBefore_ = bLoadBefore; 482 } 483 484 ~XMLPortClassObjectContainer() 485 { 486 assert(this->loadexecutor_); 487 delete this->loadexecutor_; 488 if (this->saveexecutor_) 489 delete this->saveexecutor_; 473 490 } 474 491 -
code/branches/objecthierarchy2/src/core/input/Button.cc
r2103 r2344 59 59 nCommands_[1]=0; 60 60 nCommands_[2]=0; 61 this->configContainer_ = 0; 61 62 clear(); 62 63 } … … 80 81 } 81 82 } 83 84 if (this->configContainer_) 85 delete this->configContainer_; 86 this->configContainer_ = 0; 82 87 } 83 88 -
code/branches/objecthierarchy2/src/core/input/InputBuffer.cc
r1755 r2344 73 73 } 74 74 75 InputBuffer::~InputBuffer() 76 { 77 for (std::list<BaseInputBufferListenerTuple*>::const_iterator it = this->listeners_.begin(); 78 it != this->listeners_.end(); ++it) 79 delete *it; 80 } 81 75 82 void InputBuffer::setConfigValues() 76 83 { -
code/branches/objecthierarchy2/src/core/input/InputBuffer.h
r1887 r2344 79 79 public: 80 80 InputBuffer(); 81 ~InputBuffer(); 81 82 InputBuffer(const std::string allowedChars); 82 83
Note: See TracChangeset
for help on using the changeset viewer.