Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 5, 2009, 9:22:22 PM (15 years ago)
Author:
rgrieder
Message:

Synchronised sandbox with current code trunk. There should be a few bug fixes.

Location:
sandbox
Files:
6 deleted
20 edited
4 copied

Legend:

Unmodified
Added
Removed
  • sandbox

  • sandbox/src/libraries/core/CMakeLists.txt

    r5782 r6038  
    1919
    2020SET_SOURCE_FILES(CORE_SRC_FILES
    21   Clock.cc
    22   ConfigFileManager.cc
    2321  ConfigValueContainer.cc
    2422  Core.cc
     
    3331
    3432  # command
    35   CommandLine.cc
     33  CommandLineParser.cc
    3634  Executor.cc
    3735
    3836  # hierarchy
    39   Factory.cc
    4037  Identifier.cc
    4138  MetaObjectList.cc
     
    4340  # level
    4441  BaseObject.cc
     42
     43COMPILATION_BEGIN FilesystemCompilation.cc
     44  ConfigFileManager.cc
     45  PathConfig.cc
     46COMPILATION_END
    4547
    4648  # multithreading
  • sandbox/src/libraries/core/ClassFactory.h

    r5782 r6038  
    4242
    4343#include "util/Debug.h"
    44 #include "Factory.h"
    4544#include "Identifier.h"
    4645
    4746namespace orxonox
    4847{
     48    // ###########################
     49    // ###       Factory       ###
     50    // ###########################
     51    //! Base-class of ClassFactory.
     52    class _CoreExport Factory
     53    {
     54        public:
     55            virtual ~Factory() {};
     56            virtual BaseObject* fabricate(BaseObject* creator) = 0;
     57    };
     58
    4959    // ###############################
    5060    // ###      ClassFactory       ###
     
    5262    //! The ClassFactory is able to create new objects of a specific class.
    5363    template <class T>
    54     class ClassFactory : public BaseFactory
     64    class ClassFactory : public Factory
    5565    {
    5666        public:
    57             static bool create(const std::string& name);
    58             BaseObject* fabricate(BaseObject* creator);
     67            /**
     68                @brief Constructor: Adds the ClassFactory to the Identifier of the same type.
     69                @param name The name of the class
     70                @param bLoadable True if the class can be loaded through XML
     71            */
     72            ClassFactory(const std::string& name, bool bLoadable = true)
     73            {
     74                COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
     75                ClassIdentifier<T>::getIdentifier(name)->addFactory(this);
     76            }
    5977
    60         private:
    61             ClassFactory() {}                               // Don't create
    62             ClassFactory(const ClassFactory& factory) {}    // Don't copy
    63             virtual ~ClassFactory() {}                      // Don't delete
    64 
    65             static T* createNewObject(BaseObject* creator);
     78            /**
     79                @brief Creates and returns a new object of class T.
     80                @return The new object
     81            */
     82            inline BaseObject* fabricate(BaseObject* creator)
     83            {
     84                return static_cast<BaseObject*>(new T(creator));
     85            }
    6686    };
    67 
    68     /**
    69         @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.
    70         @param name The name of the class
    71         @param bLoadable True if the class can be loaded through XML
    72         @return Always true (this is needed because the compiler only allows assignments before main())
    73     */
    74     template <class T>
    75     bool ClassFactory<T>::create(const std::string& name)
    76     {
    77         COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
    78         ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
    79         Factory::add(name, ClassIdentifier<T>::getIdentifier());
    80 
    81         return true;
    82     }
    83 
    84     /**
    85         @brief Creates and returns a new object of class T.
    86         @return The new object
    87     */
    88     template <class T>
    89     inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)
    90     {
    91         return ClassFactory<T>::createNewObject(creator);
    92     }
    93 
    94     /**
    95         @brief Creates and returns a new object of class T; this is a wrapper for the new operator.
    96         @return The new object
    97     */
    98     template <class T>
    99     inline T* ClassFactory<T>::createNewObject(BaseObject* creator)
    100     {
    101         return new T(creator);
    102     }
    10387}
    10488
  • sandbox/src/libraries/core/ConfigFileManager.cc

    r5782 r6038  
    3535#include "util/StringUtils.h"
    3636#include "ConfigValueContainer.h"
    37 #include "Core.h"
     37#include "PathConfig.h"
    3838
    3939namespace orxonox
     
    4141    bool config(const std::string& classname, const std::string& varname, const std::string& value)
    4242    {
    43         std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
    44         if (identifier != Identifier::getLowercaseIdentifierMapEnd())
     43        std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
     44        if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
    4545        {
    4646            std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
     
    5353    bool tconfig(const std::string& classname, const std::string& varname, const std::string& value)
    5454    {
    55         std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
    56         if (identifier != Identifier::getLowercaseIdentifierMapEnd())
     55        std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
     56        if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
    5757        {
    5858            std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
     
    215215
    216216        // Get default file if necessary and available
    217         boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
     217        boost::filesystem::path filepath(PathConfig::getConfigPath() / this->filename_);
    218218        if (!boost::filesystem::exists(filepath))
    219219        {
    220220            // Try to get default one from the data folder
    221             boost::filesystem::path defaultFilepath(Core::getDataPath() / "defaultConfig" / this->filename_);
     221            boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / "defaultConfig" / this->filename_);
    222222            if (boost::filesystem::exists(defaultFilepath))
    223223            {
     
    329329    {
    330330        std::ofstream file;
    331         file.open((Core::getConfigPathString() + filename_).c_str(), std::fstream::out);
     331        file.open((PathConfig::getConfigPathString() + filename_).c_str(), std::fstream::out);
    332332        file.setf(std::ios::fixed, std::ios::floatfield);
    333333        file.precision(6);
     
    369369        for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); )
    370370        {
    371             std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName());
    372             if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues())
     371            std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getStringIdentifierMap().find((*it1)->getName());
     372            if (it2 != Identifier::getStringIdentifierMapEnd() && (*it2).second->hasConfigValues())
    373373            {
    374374                // The section exists, delete comment
     
    448448        if (this->type_ == ConfigFileType::Settings)
    449449        {
    450             for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)
     450            for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)
    451451            {
    452452                if (it->second->hasConfigValues())
  • sandbox/src/libraries/core/Core.cc

    r5782 r6038  
    3737
    3838#include <cassert>
    39 #include <fstream>
    40 #include <cstdlib>
    41 #include <cstdio>
    42 #include <boost/version.hpp>
    43 #include <boost/filesystem.hpp>
     39#include <vector>
    4440
    4541#ifdef ORXONOX_PLATFORM_WINDOWS
     
    5046#  undef min
    5147#  undef max
    52 #elif defined(ORXONOX_PLATFORM_APPLE)
    53 #  include <sys/param.h>
    54 #  include <mach-o/dyld.h>
    55 #else /* Linux */
    56 #  include <sys/types.h>
    57 #  include <unistd.h>
    58 #endif
    59 
    60 #include "SpecialConfig.h"
     48#endif
     49
     50#include "util/Clock.h"
    6151#include "util/Debug.h"
    6252#include "util/Exception.h"
    6353#include "util/SignalHandler.h"
    64 #include "Clock.h"
    65 #include "CommandLine.h"
     54#include "PathConfig.h"
     55#include "CommandLineParser.h"
    6656#include "ConfigFileManager.h"
    6757#include "ConfigValueIncludes.h"
    6858#include "CoreIncludes.h"
    6959#include "DynLibManager.h"
    70 #include "Factory.h"
    7160#include "Identifier.h"
    7261#include "Language.h"
    7362#include "LuaState.h"
    74 
    75 // Boost 1.36 has some issues with deprecated functions that have been omitted
    76 #if (BOOST_VERSION == 103600)
    77 #  define BOOST_LEAF_FUNCTION filename
    78 #else
    79 #  define BOOST_LEAF_FUNCTION leaf
    80 #endif
    8163
    8264namespace orxonox
     
    8567    Core* Core::singletonPtr_s  = 0;
    8668
    87     SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
    88     SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
    8969    SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
    9070#ifdef ORXONOX_PLATFORM_WINDOWS
     
    195175        std::string language_;                          //!< The language
    196176        bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
    197 
    198         //! Path to the parent directory of the ones above if program was installed with relativ pahts
    199         boost::filesystem::path rootPath_;
    200         boost::filesystem::path executablePath_;        //!< Path to the executable
    201         boost::filesystem::path modulePath_;            //!< Path to the modules
    202         boost::filesystem::path dataPath_;              //!< Path to the data file folder
    203         boost::filesystem::path configPath_;            //!< Path to the config file folder
    204         boost::filesystem::path logPath_;               //!< Path to the log file folder
    205177    };
    206178
     
    210182        : identifierDestroyer_(Identifier::destroyAllIdentifiers)
    211183        , configuration_(new CoreConfiguration()) // Don't yet create config values!
    212         , bDevRun_(false)
    213184    {
    214185        // Set the hard coded fixed paths
    215         this->setFixedPaths();
     186        this->pathConfig_.reset(new PathConfig());
    216187
    217188        // Create a new dynamic library manager
     
    219190
    220191        // Load modules
    221         try
    222         {
    223             // We search for helper files with the following extension
    224             std::string moduleextension = specialConfig::moduleExtension;
    225             size_t moduleextensionlength = moduleextension.size();
    226 
    227             // Search in the directory of our executable
    228             boost::filesystem::path searchpath = this->configuration_->modulePath_;
    229 
    230             // Add that path to the PATH variable in case a module depends on another one
    231             std::string pathVariable = getenv("PATH");
    232             putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str()));
    233 
    234             boost::filesystem::directory_iterator file(searchpath);
    235             boost::filesystem::directory_iterator end;
    236 
    237             // Iterate through all files
    238             while (file != end)
     192        const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths();
     193        for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
     194        {
     195            try
    239196            {
    240                 std::string filename = file->BOOST_LEAF_FUNCTION();
    241 
    242                 // Check if the file ends with the exension in question
    243                 if (filename.size() > moduleextensionlength)
    244                 {
    245                     if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
    246                     {
    247                         // We've found a helper file - now load the library with the same name
    248                         std::string library = filename.substr(0, filename.size() - moduleextensionlength);
    249                         boost::filesystem::path librarypath = searchpath / library;
    250 
    251                         try
    252                         {
    253                             DynLibManager::getInstance().load(librarypath.string());
    254                         }
    255                         catch (...)
    256                         {
    257                             COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << Exception::handleMessage() << std::endl;
    258                         }
    259                     }
    260                 }
    261 
    262                 ++file;
     197                this->dynLibManager_->load(*it);
    263198            }
    264         }
    265         catch (...)
    266         {
    267             COUT(1) << "An error occurred while loading modules: " << Exception::handleMessage() << std::endl;
     199            catch (...)
     200            {
     201                COUT(1) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << std::endl;
     202            }
    268203        }
    269204
    270205        // Parse command line arguments AFTER the modules have been loaded (static code!)
    271         CommandLine::parseCommandLine(cmdLine);
     206        CommandLineParser::parseCommandLine(cmdLine);
    272207
    273208        // Set configurable paths like log, config and media
    274         this->setConfigurablePaths();
     209        this->pathConfig_->setConfigurablePaths();
    275210
    276211        // create a signal handler (only active for linux)
    277212        // This call is placed as soon as possible, but after the directories are set
    278213        this->signalHandler_.reset(new SignalHandler());
    279         this->signalHandler_->doCatch(configuration_->executablePath_.string(), Core::getLogPathString() + "orxonox_crash.log");
     214        this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");
    280215
    281216        // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used
    282         OutputHandler::getOutStream().setLogPath(Core::getLogPathString());
     217        OutputHandler::getOutStream().setLogPath(PathConfig::getLogPathString());
    283218
    284219        // Parse additional options file now that we know its path
    285         CommandLine::parseFile();
     220        CommandLineParser::parseFile();
    286221
    287222#ifdef ORXONOX_PLATFORM_WINDOWS
     
    289224        // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
    290225        // the timer though).
    291         int limitToCPU = CommandLine::getValue("limitToCPU");
     226        int limitToCPU = CommandLineParser::getValue("limitToCPU");
    292227        if (limitToCPU > 0)
    293228            setThreadAffinity(static_cast<unsigned int>(limitToCPU));
     
    297232        this->configFileManager_.reset(new ConfigFileManager());
    298233        this->configFileManager_->setFilename(ConfigFileType::Settings,
    299             CommandLine::getValue("settingsFile").getString());
     234            CommandLineParser::getValue("settingsFile").getString());
    300235
    301236        // Required as well for the config values
     
    303238
    304239        // creates the class hierarchy for all classes with factories
    305         Factory::createClassHierarchy();
     240        Identifier::createClassHierarchy();
    306241
    307242        // Do this soon after the ConfigFileManager has been created to open up the
     
    376311    }
    377312
    378     /*static*/ const boost::filesystem::path& Core::getDataPath()
    379     {
    380         return getInstance().configuration_->dataPath_;
    381     }
    382     /*static*/ std::string Core::getDataPathString()
    383     {
    384         return getInstance().configuration_->dataPath_.string() + '/';
    385     }
    386 
    387     /*static*/ const boost::filesystem::path& Core::getConfigPath()
    388     {
    389         return getInstance().configuration_->configPath_;
    390     }
    391     /*static*/ std::string Core::getConfigPathString()
    392     {
    393         return getInstance().configuration_->configPath_.string() + '/';
    394     }
    395 
    396     /*static*/ const boost::filesystem::path& Core::getLogPath()
    397     {
    398         return getInstance().configuration_->logPath_;
    399     }
    400     /*static*/ std::string Core::getLogPathString()
    401     {
    402         return getInstance().configuration_->logPath_.string() + '/';
    403     }
    404 
    405     /*static*/ const boost::filesystem::path& Core::getRootPath()
    406     {
    407         return getInstance().configuration_->rootPath_;
    408     }
    409     /*static*/ std::string Core::getRootPathString()
    410     {
    411         return getInstance().configuration_->rootPath_.string() + '/';
    412     }
    413 
    414313    /**
    415314    @note
     
    458357    }
    459358
    460     /**
    461     @brief
    462         Retrievs the executable path and sets all hard coded fixed path (currently only the module path)
    463         Also checks for "orxonox_dev_build.keep_me" in the executable diretory.
    464         If found it means that this is not an installed run, hence we
    465         don't write the logs and config files to ~/.orxonox
    466     @throw
    467         GeneralException
    468     */
    469     void Core::setFixedPaths()
    470     {
    471         //////////////////////////
    472         // FIND EXECUTABLE PATH //
    473         //////////////////////////
    474 
    475 #ifdef ORXONOX_PLATFORM_WINDOWS
    476         // get executable module
    477         TCHAR buffer[1024];
    478         if (GetModuleFileName(NULL, buffer, 1024) == 0)
    479             ThrowException(General, "Could not retrieve executable path.");
    480 
    481 #elif defined(ORXONOX_PLATFORM_APPLE)
    482         char buffer[1024];
    483         unsigned long path_len = 1023;
    484         if (_NSGetExecutablePath(buffer, &path_len))
    485             ThrowException(General, "Could not retrieve executable path.");
    486 
    487 #else /* Linux */
    488         /* written by Nicolai Haehnle <prefect_@gmx.net> */
    489 
    490         /* Get our PID and build the name of the link in /proc */
    491         char linkname[64]; /* /proc/<pid>/exe */
    492         if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)
    493         {
    494             /* This should only happen on large word systems. I'm not sure
    495                what the proper response is here.
    496                Since it really is an assert-like condition, aborting the
    497                program seems to be in order. */
    498             assert(false);
    499         }
    500 
    501         /* Now read the symbolic link */
    502         char buffer[1024];
    503         int ret;
    504         ret = readlink(linkname, buffer, 1024);
    505         /* In case of an error, leave the handling up to the caller */
    506         if (ret == -1)
    507             ThrowException(General, "Could not retrieve executable path.");
    508 
    509         /* Ensure proper NUL termination */
    510         buffer[ret] = 0;
    511 #endif
    512 
    513         configuration_->executablePath_ = boost::filesystem::path(buffer);
    514 #ifndef ORXONOX_PLATFORM_APPLE
    515         configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name
    516 #endif
    517 
    518         /////////////////////
    519         // SET MODULE PATH //
    520         /////////////////////
    521 
    522         if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me"))
    523         {
    524             COUT(1) << "Running from the build tree." << std::endl;
    525             Core::bDevRun_ = true;
    526             configuration_->modulePath_ = specialConfig::moduleDevDirectory;
    527         }
    528         else
    529         {
    530 
    531 #ifdef INSTALL_COPYABLE // --> relative paths
    532 
    533             // Also set the root path
    534             boost::filesystem::path relativeExecutablePath(specialConfig::defaultRuntimePath);
    535             configuration_->rootPath_ = configuration_->executablePath_;
    536             while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_)
    537                    && !configuration_->rootPath_.empty())
    538                 configuration_->rootPath_ = configuration_->rootPath_.branch_path();
    539             if (configuration_->rootPath_.empty())
    540                 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
    541 
    542             // Module path is fixed as well
    543             configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;
    544 
    545 #else
    546 
    547             // There is no root path, so don't set it at all
    548             // Module path is fixed as well
    549             configuration_->modulePath_ = specialConfig::moduleInstallDirectory;
    550 
    551 #endif
    552         }
    553     }
    554 
    555     /**
    556     @brief
    557         Sets config, log and media path and creates folders if necessary.
    558     @throws
    559         GeneralException
    560     */
    561     void Core::setConfigurablePaths()
    562     {
    563         if (Core::isDevelopmentRun())
    564         {
    565             configuration_->dataPath_  = specialConfig::dataDevDirectory;
    566             configuration_->configPath_ = specialConfig::configDevDirectory;
    567             configuration_->logPath_    = specialConfig::logDevDirectory;
    568         }
    569         else
    570         {
    571 
    572 #ifdef INSTALL_COPYABLE // --> relative paths
    573 
    574             // Using paths relative to the install prefix, complete them
    575             configuration_->dataPath_   = configuration_->rootPath_ / specialConfig::defaultDataPath;
    576             configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath;
    577             configuration_->logPath_    = configuration_->rootPath_ / specialConfig::defaultLogPath;
    578 
    579 #else
    580 
    581             configuration_->dataPath_  = specialConfig::dataInstallDirectory;
    582 
    583             // Get user directory
    584 #  ifdef ORXONOX_PLATFORM_UNIX /* Apple? */
    585             char* userDataPathPtr(getenv("HOME"));
    586 #  else
    587             char* userDataPathPtr(getenv("APPDATA"));
    588 #  endif
    589             if (userDataPathPtr == NULL)
    590                 ThrowException(General, "Could not retrieve user data path.");
    591             boost::filesystem::path userDataPath(userDataPathPtr);
    592             userDataPath /= ".orxonox";
    593 
    594             configuration_->configPath_ = userDataPath / specialConfig::defaultConfigPath;
    595             configuration_->logPath_    = userDataPath / specialConfig::defaultLogPath;
    596 
    597 #endif
    598 
    599         }
    600 
    601         // Option to put all the config and log files in a separate folder
    602         if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue())
    603         {
    604             std::string directory(CommandLine::getValue("writingPathSuffix").getString());
    605             configuration_->configPath_ = configuration_->configPath_ / directory;
    606             configuration_->logPath_    = configuration_->logPath_    / directory;
    607         }
    608 
    609         // Create directories to avoid problems when opening files in non existent folders.
    610         std::vector<std::pair<boost::filesystem::path, std::string> > directories;
    611         directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config"));
    612         directories.push_back(std::make_pair(boost::filesystem::path(configuration_->logPath_), "log"));
    613 
    614         for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin();
    615             it != directories.end(); ++it)
    616         {
    617             if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first))
    618             {
    619                 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
    620                                          Please remove " + it->first.string());
    621             }
    622             if (boost::filesystem::create_directories(it->first)) // function may not return true at all (bug?)
    623             {
    624                 COUT(4) << "Created " << it->second << " directory" << std::endl;
    625             }
    626         }
    627     }
    628 
    629359    void Core::preUpdate(const Clock& time)
    630360    {
  • sandbox/src/libraries/core/Core.h

    r5782 r6038  
    2828 */
    2929
    30 /**
    31 @file
    32 @brief
    33     Declaration of the Core class.
    34 @details
    35     The Core class is a singleton, only used to configure some variables
    36     in the core through the config-file.
    37 */
    38 
    3930#ifndef _Core_H__
    4031#define _Core_H__
     
    5546    @brief
    5647        The Core class is a singleton used to configure the program basics.
    57     @details
    58         The class provides information about the data, config and log path.
    59         It determines those by the use of platform specific functions.
    6048    @remark
    6149        You should only create this singleton once because it destroys the identifiers!
     
    8573            static void  resetLanguage();
    8674
    87             //! Returns the path to the data files as boost::filesystem::path
    88             static const boost::filesystem::path& getDataPath();
    89             //! Returns the path to the config files as boost::filesystem::path
    90             static const boost::filesystem::path& getConfigPath();
    91             //! Returns the path to the log files as boost::filesystem::path
    92             static const boost::filesystem::path& getLogPath();
    93             //! Returns the path to the root folder as boost::filesystem::path
    94             static const boost::filesystem::path& getRootPath();
    95             //! Returns the path to the data files as std::string
    96             static std::string getDataPathString();
    97             //! Returns the path to the config files as std::string
    98             static std::string getConfigPathString();
    99             //! Returns the path to the log files as std::string
    100             static std::string getLogPathString();
    101             //! Returns the path to the root folder as std::string
    102             static std::string getRootPathString();
    103 
    104             static bool isDevelopmentRun() { return getInstance().bDevRun_; }
    105 
    10675        private:
    10776            Core(const Core&); //!< Don't use (undefined symbol)
     
    11079            void postUpdate(const Clock& time);
    11180
    112             void setFixedPaths();
    113             void setConfigurablePaths();
    11481            void setThreadAffinity(int limitToCPU);
    11582
    11683            // Mind the order for the destruction!
     84            scoped_ptr<PathConfig>        pathConfig_;
    11785            scoped_ptr<DynLibManager>     dynLibManager_;
    11886            scoped_ptr<SignalHandler>     signalHandler_;
     
    12290            scoped_ptr<CoreConfiguration> configuration_;
    12391
    124             bool                          bDevRun_;             //!< True for runs in the build directory (not installed)
    125 
    12692            static Core* singletonPtr_s;
    12793    };
  • sandbox/src/libraries/core/CoreIncludes.h

    r5782 r6038  
    2929/**
    3030    @file
    31     @brief Definition of macros for Identifier and Factory.
     31    @brief Definition of macros for Identifiers
    3232
    3333    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
     
    4545#include "util/Debug.h"
    4646#include "Identifier.h"
    47 #include "Factory.h"
    4847#include "ClassFactory.h"
    4948#include "ObjectList.h"
     
    7675
    7776/**
    78     @brief Creates the entry in the Factory.
     77    @brief Creates the Factory.
    7978    @param ClassName The name of the class
    8079*/
    8180#define CreateFactory(ClassName) \
    82     bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
     81    Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName)
    8382
    8483/**
     
    9392{
    9493    /**
    95         @brief Returns the Identifier with a given name through the factory.
     94        @brief Returns the Identifier with a given name.
    9695        @param String The name of the class
    9796    */
    9897    inline Identifier* ClassByString(const std::string& name)
    9998    {
    100         return Factory::getIdentifier(name);
     99        return Identifier::getIdentifierByString(name);
    101100    }
    102101
    103102    /**
    104         @brief Returns the Identifier with a given network ID through the factory.
    105         @param networkID The network ID of the class
     103        @brief Returns the Identifier with a given lowercase name.
     104        @param String The lowercase name of the class
    106105    */
    107     inline Identifier* ClassByID(uint32_t id)
     106    inline Identifier* ClassByLowercaseString(const std::string& name)
    108107    {
    109         return Factory::getIdentifier(id);
     108        return Identifier::getIdentifierByLowercaseString(name);
    110109    }
    111110}
  • sandbox/src/libraries/core/CorePrereqs.h

    r5738 r6038  
    2828
    2929/**
    30   @file
    31   @brief Contains all the necessary forward declarations for all classes and structs.
     30@file
     31@brief
     32    Shared library macros, enums, constants and forward declarations for the core library
    3233*/
    3334
     
    4041// Shared library settings
    4142//-----------------------------------------------------------------------
     43
    4244#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD )
    4345#  ifdef CORE_SHARED_BUILD
     
    5658#endif
    5759
    58 
    59 //-----------------------------------------------------------------------
    60 // Forward declarations
    61 //-----------------------------------------------------------------------
     60//-----------------------------------------------------------------------
     61// Constants
     62//-----------------------------------------------------------------------
     63
     64namespace orxonox
     65{
     66    static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);
     67}
     68
     69//-----------------------------------------------------------------------
     70// Enums
     71//-----------------------------------------------------------------------
     72
    6273namespace orxonox
    6374{
     
    6677        enum Mode
    6778        {
     79            NOP,
    6880            LoadObject,
    6981            SaveObject,
    7082            ExpandObject
    7183        };
    72     }
     84}
    7385
    7486    namespace KeybindMode
     
    8294        };
    8395    };
    84 
     96}
     97
     98//-----------------------------------------------------------------------
     99// Forward declarations
     100//-----------------------------------------------------------------------
     101
     102namespace orxonox
     103{
    85104    typedef std::string LanguageEntryLabel;
    86105
    87106    class ArgumentCompleter;
    88107    class ArgumentCompletionListElement;
    89     class BaseFactory;
    90     class BaseMetaObjectListElement;
    91108    class BaseObject;
    92109    template <class T>
     
    98115    class ClassTreeMaskNode;
    99116    class ClassTreeMaskObjectIterator;
    100     class Clock;
    101117    class CommandEvaluation;
    102     class CommandExecutor;
    103     class CommandLine;
     118    class CommandLineParser;
    104119    class CommandLineArgument;
    105120    class ConfigFile;
     
    109124    class ConfigFileManager;
    110125    class ConfigFileSection;
     126    struct ConfigFileType;
    111127    class ConfigValueContainer;
    112128    class ConsoleCommand;
     
    115131    class DynLibManager;
    116132    struct Event;
    117     class EventContainer;
     133    class EventState;
    118134    class Executor;
    119135    template <class T>
     
    125141    class FunctorMember;
    126142    class FunctorStatic;
     143    class Game;
     144    class GameState;
     145    struct GameStateInfo;
     146    struct GameStateTreeNode;
    127147    class GraphicsManager;
    128148    class GUIManager;
     
    131151    template <class T>
    132152    class Iterator;
    133     class IteratorBase;
    134153    class Language;
    135     class LanguageEntry;
    136     class Loader;
    137154    class LuaState;
    138155    class MemoryArchive;
     
    152169    class OgreWindowEventListener;
    153170    class OrxonoxClass;
     171    class PathConfig;
    154172    struct ResourceInfo;
    155173    class Shell;
    156174    class ShellListener;
    157175    template <class T>
     176    class SmartPtr;
     177    template <class T>
    158178    class SubclassIdentifier;
    159179    class TclBind;
     
    163183    class TclThreadManager;
    164184    class Template;
     185    class Thread;
     186    class ThreadPool;
     187    template <class T>
     188    class WeakPtr;
    165189    class WindowEventListener;
    166190    class XMLFile;
     
    173197    class XMLPortParamContainer;
    174198
    175     // game states
    176     class Game;
    177     class GameState;
    178     struct GameStateInfo;
    179     struct GameStateTreeNode;
    180 
    181     // input
     199    // Input
    182200    class BaseCommand;
    183201    class BufferedParamCommand;
    184202    class Button;
    185     class CalibratorCallback;
    186203    class HalfAxis;
    187204    class InputBuffer;
     
    192209    class InputManager;
    193210    class InputState;
     211    struct InputStatePriority;
     212    class JoyStickQuantityListener;
    194213    class JoyStick;
     214    class KeyBinder;
     215    class KeyBinderManager;
     216    class Keyboard;
     217    class KeyDetector;
     218    class KeyEvent;
    195219    class Mouse;
    196     class Keyboard;
    197     class KeyBinder;
    198     class KeyDetector;
    199220    class ParamCommand;
    200221    class SimpleCommand;
    201 
    202 
    203     // multithreading
    204     class Thread;
    205     class ThreadPool;
    206222}
    207223
     
    282298namespace orxonox
    283299{
    284     using ticpp::Document;
    285300    using ticpp::Element;
    286     using ticpp::Declaration;
    287     using ticpp::StylesheetReference;
    288     using ticpp::Text;
    289     using ticpp::Comment;
    290     using ticpp::Attribute;
    291 }
    292 
     301}
    293302
    294303#endif /* _CorePrereqs_H__ */
  • sandbox/src/libraries/core/Functor.h

    r5738 r6038  
    191191
    192192
    193 #define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams
    194 #define FUNCTOR_TEMPLATE000
    195 #define FUNCTOR_TEMPLATE001 template <class P1>
    196 #define FUNCTOR_TEMPLATE002 template <class P1, class P2>
    197 #define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3>
    198 #define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4>
    199 #define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5>
    200 #define FUNCTOR_TEMPLATE010 template <class R>
    201 #define FUNCTOR_TEMPLATE011 template <class R, class P1>
    202 #define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2>
    203 #define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3>
    204 #define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4>
    205 #define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5>
    206 #define FUNCTOR_TEMPLATE100 template <class T>
    207 #define FUNCTOR_TEMPLATE101 template <class T, class P1>
    208 #define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2>
    209 #define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3>
    210 #define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4>
    211 #define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5>
    212 #define FUNCTOR_TEMPLATE110 template <class T, class R>
    213 #define FUNCTOR_TEMPLATE111 template <class T, class R, class P1>
    214 #define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2>
    215 #define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3>
    216 #define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4>
    217 #define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5>
     193#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams, additionalobject) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams(additionalobject)
     194#define FUNCTOR_TEMPLATE000(additionalobject)
     195#define FUNCTOR_TEMPLATE001(additionalobject) template <class P1>
     196#define FUNCTOR_TEMPLATE002(additionalobject) template <class P1, class P2>
     197#define FUNCTOR_TEMPLATE003(additionalobject) template <class P1, class P2, class P3>
     198#define FUNCTOR_TEMPLATE004(additionalobject) template <class P1, class P2, class P3, class P4>
     199#define FUNCTOR_TEMPLATE005(additionalobject) template <class P1, class P2, class P3, class P4, class P5>
     200#define FUNCTOR_TEMPLATE010(additionalobject) template <class R>
     201#define FUNCTOR_TEMPLATE011(additionalobject) template <class R, class P1>
     202#define FUNCTOR_TEMPLATE012(additionalobject) template <class R, class P1, class P2>
     203#define FUNCTOR_TEMPLATE013(additionalobject) template <class R, class P1, class P2, class P3>
     204#define FUNCTOR_TEMPLATE014(additionalobject) template <class R, class P1, class P2, class P3, class P4>
     205#define FUNCTOR_TEMPLATE015(additionalobject) template <class R, class P1, class P2, class P3, class P4, class P5>
     206#define FUNCTOR_TEMPLATE100(additionalobject) template <class T FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     207#define FUNCTOR_TEMPLATE101(additionalobject) template <class T, class P1 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     208#define FUNCTOR_TEMPLATE102(additionalobject) template <class T, class P1, class P2 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     209#define FUNCTOR_TEMPLATE103(additionalobject) template <class T, class P1, class P2, class P3 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     210#define FUNCTOR_TEMPLATE104(additionalobject) template <class T, class P1, class P2, class P3, class P4 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     211#define FUNCTOR_TEMPLATE105(additionalobject) template <class T, class P1, class P2, class P3, class P4, class P5 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     212#define FUNCTOR_TEMPLATE110(additionalobject) template <class T, class R FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     213#define FUNCTOR_TEMPLATE111(additionalobject) template <class T, class R, class P1 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     214#define FUNCTOR_TEMPLATE112(additionalobject) template <class T, class R, class P1, class P2 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     215#define FUNCTOR_TEMPLATE113(additionalobject) template <class T, class R, class P1, class P2, class P3 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     216#define FUNCTOR_TEMPLATE114(additionalobject) template <class T, class R, class P1, class P2, class P3, class P4 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     217#define FUNCTOR_TEMPLATE115(additionalobject) template <class T, class R, class P1, class P2, class P3, class P4, class P5 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) >
     218
     219
     220
     221#define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT##additionalobject
     222#define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT0
     223#define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT1 , class O
    218224
    219225
     
    317323
    318324#define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \
    319     FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
     325    FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \
    320326    class FunctorStatic##returnvalue##numparams : public FunctorStatic \
    321327    { \
     
    347353    \
    348354    \
    349     FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
     355    FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \
    350356    inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
    351357    { \
     
    358364
    359365#define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \
    360     FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     366    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
    361367    class FunctorMember##returnvalue##numparams : public FunctorMember<T> \
    362368    { \
     
    391397    \
    392398    \
    393     FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     399    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
    394400    class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \
    395401    { \
     
    423429    \
    424430    \
    425     FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     431    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
    426432    inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
    427433    { \
     
    430436    \
    431437    \
    432     FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     438    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \
    433439    inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
    434440    { \
    435441        return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     442    } \
     443    \
     444    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
     445    inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)), O* object) \
     446    { \
     447        FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     448        functor->setObject(object); \
     449        return functor; \
     450    } \
     451    \
     452    \
     453    FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \
     454    inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const, O* object) \
     455    { \
     456        FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     457        functor->setObject(object); \
     458        return functor; \
    436459    }
    437460
  • sandbox/src/libraries/core/Game.cc

    r5782 r6038  
    3838#include <boost/weak_ptr.hpp>
    3939
     40#include "util/Clock.h"
    4041#include "util/Debug.h"
    4142#include "util/Exception.h"
     
    4344#include "util/Sleep.h"
    4445#include "util/SubString.h"
    45 #include "Clock.h"
    46 #include "CommandLine.h"
     46#include "CommandLineParser.h"
    4747#include "Core.h"
    4848#include "CoreIncludes.h"
     
    105105    Game::Game(const std::string& cmdLine)
    106106        // Destroy factories before the Core!
    107         : gsFactoryDestroyer_(Game::GameStateFactory::factories_s, &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
     107        : gsFactoryDestroyer_(Game::GameStateFactory::getFactories(), &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
    108108    {
    109109        this->bAbort_ = false;
     
    404404                requestedNodes.push_back(currentNode);
    405405            }
     406            if (currentNode == NULL)
     407                requestedNodes.clear();
    406408        }
    407409
     
    451453    {
    452454        // Split string into pieces of the form whitespacesText
    453         std::vector<std::pair<std::string, unsigned> > stateStrings;
     455        std::vector<std::pair<std::string, int> > stateStrings;
    454456        size_t pos = 0;
    455457        size_t startPos = 0;
    456458        while (pos < str.size())
    457459        {
    458             unsigned indentation = 0;
     460            int indentation = 0;
    459461            while(pos < str.size() && str[pos] == ' ')
    460462                ++indentation, ++pos;
     
    464466            stateStrings.push_back(std::make_pair(str.substr(startPos, pos - startPos), indentation));
    465467        }
    466         unsigned int currentLevel = 0;
    467         shared_ptr<GameStateTreeNode> currentNode = this->rootStateNode_;
    468         for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
    469         {
    470             std::string newStateName = it->first;
    471             unsigned newLevel = it->second + 1; // empty root is 0
    472             if (!this->checkState(newStateName))
    473                 ThrowException(GameState, "GameState with name '" << newStateName << "' not found!");
    474             if (newStateName == this->rootStateNode_->name_)
     468        if (stateStrings.empty())
     469            ThrowException(GameState, "Emtpy GameState hierarchy provided, terminating.");
     470        // Add element with large identation to detect the last with just an iterator
     471        stateStrings.push_back(std::make_pair("", -1));
     472
     473        // Parse elements recursively
     474        std::vector<std::pair<std::string, int> >::const_iterator begin = stateStrings.begin();
     475        parseStates(begin, this->rootStateNode_);
     476    }
     477
     478    /*** Internal ***/
     479
     480    void Game::parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode)
     481        {
     482        SubString tokens(it->first, ",");
     483        std::vector<std::pair<std::string, int> >::const_iterator startIt = it;
     484
     485        for (unsigned int i = 0; i < tokens.size(); ++i)
     486        {
     487            it = startIt; // Reset iterator to the beginning of the sub tree
     488            if (!this->checkState(tokens[i]))
     489                ThrowException(GameState, "GameState with name '" << tokens[i] << "' not found!");
     490            if (tokens[i] == this->rootStateNode_->name_)
    475491                ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy...");
    476             shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
    477             newNode->name_ = newStateName;
    478 
    479             if (newLevel <= currentLevel)
    480             {
    481                 do
    482                     currentNode = currentNode->parent_.lock();
    483                 while (newLevel <= --currentLevel);
    484             }
    485             if (newLevel == currentLevel + 1)
    486             {
    487                 // Add the child
    488                 newNode->parent_ = currentNode;
    489                 currentNode->children_.push_back(newNode);
    490             }
     492            shared_ptr<GameStateTreeNode> node(new GameStateTreeNode());
     493            node->name_ = tokens[i];
     494            node->parent_ = currentNode;
     495            currentNode->children_.push_back(node);
     496
     497            int currentLevel = it->second;
     498            ++it;
     499            while (it->second != -1)
     500            {
     501                if (it->second <= currentLevel)
     502                    break;
     503                else if (it->second == currentLevel + 1)
     504                    parseStates(it, node);
    491505            else
    492506                ThrowException(GameState, "Indentation error while parsing the hierarchy.");
    493             currentNode = newNode;
    494             currentLevel = newLevel;
    495         }
    496     }
    497 
    498     /*** Internal ***/
     507        }
     508    }
     509    }
    499510
    500511    void Game::loadGraphics()
     
    566577    }
    567578
    568     std::map<std::string, shared_ptr<Game::GameStateFactory> > Game::GameStateFactory::factories_s;
     579    /*static*/ std::map<std::string, shared_ptr<Game::GameStateFactory> >& Game::GameStateFactory::getFactories()
     580    {
     581        static std::map<std::string, shared_ptr<GameStateFactory> > factories;
     582        return factories;
     583    }
    569584
    570585    /*static*/ shared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info)
    571586    {
    572         std::map<std::string, shared_ptr<Game::GameStateFactory> >::const_iterator it = factories_s.find(info.className);
    573         assert(it != factories_s.end());
     587        std::map<std::string, shared_ptr<Game::GameStateFactory> >::const_iterator it = getFactories().find(info.className);
     588        assert(it != getFactories().end());
    574589        return it->second->fabricateInternal(info);
    575590    }
  • sandbox/src/libraries/core/Game.h

    r5747 r6038  
    117117            template <class T>
    118118            static void createFactory(const std::string& className)
    119                 { factories_s[className].reset(new TemplateGameStateFactory<T>()); }
     119                { getFactories()[className].reset(new TemplateGameStateFactory<T>()); }
    120120
    121121            virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0;
    122             static std::map<std::string, shared_ptr<GameStateFactory> > factories_s;
     122            static std::map<std::string, shared_ptr<GameStateFactory> >& getFactories();
    123123        };
    124124        template <class T>
     
    143143        void unloadGraphics();
    144144
     145        void parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode);
    145146        bool checkState(const std::string& name) const;
    146147        void loadState(const std::string& name);
  • sandbox/src/libraries/core/GameState.h

    r5738 r6038  
    4040#include <map>
    4141#include <string>
     42#include "util/UtilPrereqs.h"
    4243
    4344namespace orxonox
  • sandbox/src/libraries/core/Identifier.cc

    r5782 r6038  
    3737
    3838#include "util/StringUtils.h"
     39#include "BaseObject.h"
    3940#include "ConfigValueContainer.h"
    40 #include "Factory.h"
     41#include "ClassFactory.h"
    4142
    4243namespace orxonox
     
    6263        this->bHasConfigValues_ = false;
    6364
    64         this->children_ = new std::set<const Identifier*>();
    65         this->directChildren_ = new std::set<const Identifier*>();
    6665    }
    6766
     
    7170    Identifier::~Identifier()
    7271    {
    73         delete this->children_;
    74         delete this->directChildren_;
    7572        delete this->objects_;
    7673
     
    105102            // There is already an entry: return it and delete the proposal
    106103            delete proposal;
    107             return (*it).second;
     104            return it->second;
    108105        }
    109106        else
     
    152149            {
    153150                // Tell the parent we're one of it's children
    154                 (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
     151                (*it)->children_.insert((*it)->children_.end(), this);
    155152
    156153                // Erase all parents of our parent from our direct-parent-list
     
    174171            {
    175172                // Tell the parent we're one of it's direct children
    176                 (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
     173                (*it)->directChildren_.insert((*it)->directChildren_.end(), this);
    177174            }
    178175        }
     176    }
     177
     178    /**
     179        @brief Creates the class-hierarchy by creating and destroying one object of each type.
     180    */
     181    void Identifier::createClassHierarchy()
     182    {
     183        COUT(3) << "*** Identifier: Create class-hierarchy" << std::endl;
     184        Identifier::startCreatingHierarchy();
     185        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
     186        {
     187            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     188            if (it->second->hasFactory())
     189            {
     190                BaseObject* temp = it->second->fabricate(0);
     191                delete temp;
     192            }
     193        }
     194        Identifier::stopCreatingHierarchy();
     195        COUT(3) << "*** Identifier: Finished class-hierarchy creation" << std::endl;
    179196    }
    180197
     
    198215            this->name_ = name;
    199216            this->bSetName_ = true;
    200             Identifier::getIdentifierMapIntern()[name] = this;
    201             Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
     217            Identifier::getStringIdentifierMapIntern()[name] = this;
     218            Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
    202219        }
    203220    }
     
    219236            COUT(1) << "Aborting..." << std::endl;
    220237            abort();
    221             return NULL;
     238            return 0;
    222239        }
    223240    }
     
    265282    bool Identifier::isParentOf(const Identifier* identifier) const
    266283    {
    267         return (this->children_->find(identifier) != this->children_->end());
     284        return (this->children_.find(identifier) != this->children_.end());
    268285    }
    269286
     
    274291    bool Identifier::isDirectParentOf(const Identifier* identifier) const
    275292    {
    276         return (this->directChildren_->find(identifier) != this->directChildren_->end());
    277     }
    278 
    279     /**
    280         @brief Returns the map that stores all Identifiers.
     293        return (this->directChildren_.find(identifier) != this->directChildren_.end());
     294    }
     295
     296    /**
     297        @brief Returns the map that stores all Identifiers with their names.
    281298        @return The map
    282299    */
    283     std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
     300    std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
    284301    {
    285302        static std::map<std::string, Identifier*> identifierMap;
     
    288305
    289306    /**
    290         @brief Returns the map that stores all Identifiers.
     307        @brief Returns the map that stores all Identifiers with their names in lowercase.
    291308        @return The map
    292309    */
    293     std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
     310    std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
    294311    {
    295312        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
    296313        return lowercaseIdentifierMap;
     314    }
     315
     316    /**
     317        @brief Returns the map that stores all Identifiers with their network IDs.
     318        @return The map
     319    */
     320    std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
     321    {
     322        static std::map<uint32_t, Identifier*> identifierMap;
     323        return identifierMap;
     324    }
     325
     326    /**
     327        @brief Returns the Identifier with a given name.
     328        @param name The name of the wanted Identifier
     329        @return The Identifier
     330    */
     331    Identifier* Identifier::getIdentifierByString(const std::string& name)
     332    {
     333        std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
     334        if (it != Identifier::getStringIdentifierMapIntern().end())
     335            return it->second;
     336        else
     337            return 0;
     338    }
     339
     340    /**
     341        @brief Returns the Identifier with a given name in lowercase.
     342        @param name The name of the wanted Identifier
     343        @return The Identifier
     344    */
     345    Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name)
     346    {
     347        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name);
     348        if (it != Identifier::getLowercaseStringIdentifierMapIntern().end())
     349            return it->second;
     350        else
     351            return 0;
    297352    }
    298353
     
    325380        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);
    326381        if (it != configValues_.end())
    327             return ((*it).second);
     382            return it->second;
    328383        else
    329384            return 0;
     
    339394        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
    340395        if (it != configValues_LC_.end())
    341             return ((*it).second);
     396            return it->second;
    342397        else
    343398            return 0;
     
    353408    {
    354409        for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
    355             out << (*it)->getName() << " ";
     410        {
     411            if (it != list.begin())
     412                out << " ";
     413            out << (*it)->getName();
     414        }
    356415
    357416        return out;
  • sandbox/src/libraries/core/Identifier.h

    r5782 r6038  
    2929/**
    3030    @file
    31     @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
     31    @brief Definition of the Identifier class, definition and implementation of the ClassIdentifier class.
    3232
    3333    The Identifier contains all needed information about the class it belongs to:
     
    4545
    4646    Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier.
    47 
    48     SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
    49     You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
    5047*/
    5148
     
    8986    class _CoreExport Identifier
    9087    {
    91         template <class T>
    92         friend class SubclassIdentifier;
    93 
    94         friend class Factory;
    95 
    9688        public:
     89            /** @brief Returns the name of the class the Identifier belongs to. @return The name */
     90            inline const std::string& getName() const { return this->name_; }
     91            void setName(const std::string& name);
     92
     93            /** @brief Returns the unique ID of the class */
     94            FORCEINLINE unsigned int getClassID() const { return this->classID_; }
     95
     96            /** @brief Returns the list of all existing objects of this class. @return The list */
     97            inline ObjectListBase* getObjects() const { return this->objects_; }
     98
    9799            /** @brief Sets the Factory. @param factory The factory to assign */
    98             inline void addFactory(BaseFactory* factory) { this->factory_ = factory; }
     100            inline void addFactory(Factory* factory) { this->factory_ = factory; }
     101            /** @brief Returns true if the Identifier has a Factory. */
     102            inline bool hasFactory() const { return (this->factory_ != 0); }
    99103
    100104            BaseObject* fabricate(BaseObject* creator);
     105
    101106            bool isA(const Identifier* identifier) const;
    102107            bool isExactlyA(const Identifier* identifier) const;
     
    106111            bool isDirectParentOf(const Identifier* identifier) const;
    107112
    108             /** @brief Returns the list of all existing objects of this class. @return The list */
    109             inline ObjectListBase* getObjects() const
    110                 { return this->objects_; }
    111 
    112             /** @brief Returns the name of the class the Identifier belongs to. @return The name */
    113             inline const std::string& getName() const { return this->name_; }
    114             void setName(const std::string& name);
    115 
    116             virtual void updateConfigValues(bool updateChildren = true) const = 0;
     113
     114            /////////////////////////////
     115            ////// Class Hierarchy //////
     116            /////////////////////////////
     117            static void createClassHierarchy();
     118
     119            /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
     120            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    117121
    118122            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
     
    124128
    125129            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    126             inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); }
     130            inline const std::set<const Identifier*>& getChildren() const { return this->children_; }
    127131            /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
    128             inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
     132            inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_.begin(); }
    129133            /** @brief Returns the end-iterator of the children-list. @return The end-iterator */
    130             inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
     134            inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_.end(); }
    131135
    132136            /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
     
    138142
    139143            /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
    140             inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
     144            inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; }
    141145            /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
    142             inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
     146            inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_.begin(); }
    143147            /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
    144             inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
    145 
    146 
    147             /** @brief Returns the map that stores all Identifiers. @return The map */
    148             static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); }
    149             /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */
    150             static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); }
    151             /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */
    152             static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); }
     148            inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); }
     149
     150
     151            //////////////////////////
     152            ///// Identifier Map /////
     153            //////////////////////////
     154            static void destroyAllIdentifiers();
     155
     156            static Identifier* getIdentifierByString(const std::string& name);
     157            static Identifier* getIdentifierByLowercaseString(const std::string& name);
     158            static Identifier* getIdentifierByID(uint32_t id);
     159
     160            static void clearNetworkIDs();
     161
     162            /** @brief Returns the map that stores all Identifiers with their names. @return The map */
     163            static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); }
     164            /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. @return The const_iterator */
     165            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); }
     166            /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names. @return The const_iterator */
     167            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); }
    153168
    154169            /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
    155             static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); }
     170            static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); }
    156171            /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
    157             static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); }
     172            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); }
    158173            /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
    159             static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); }
    160 
     174            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); }
     175
     176            /** @brief Returns the map that stores all Identifiers with their IDs. @return The map */
     177            static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); }
     178            /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. @return The const_iterator */
     179            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); }
     180            /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. @return The const_iterator */
     181            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); }
     182
     183
     184            /////////////////////////
     185            ///// Config Values /////
     186            /////////////////////////
     187            virtual void updateConfigValues(bool updateChildren = true) const = 0;
     188
     189            /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
     190            inline bool hasConfigValues() const { return this->bHasConfigValues_; }
    161191
    162192            /** @brief Returns the map that stores all config values. @return The const_iterator */
     
    174204            inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }
    175205
    176 
    177             /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
    178             inline bool hasConfigValues() const { return this->bHasConfigValues_; }
    179 
    180             /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
    181             inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    182 
    183             /** @brief Returns the unique ID of the class */
    184             FORCEINLINE unsigned int getClassID() const { return this->classID_; }
    185 
    186206            void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
    187207            ConfigValueContainer* getConfigValueContainer(const std::string& varname);
    188208            ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
    189209
    190             void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    191 
    192             static void destroyAllIdentifiers();
    193210
    194211        protected:
     
    199216            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
    200217
    201             /** @brief Returns the map that stores all Identifiers. @return The map */
    202             static std::map<std::string, Identifier*>& getIdentifierMapIntern();
     218            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     219
     220            /** @brief Returns the map that stores all Identifiers with their names. @return The map */
     221            static std::map<std::string, Identifier*>& getStringIdentifierMapIntern();
    203222            /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
    204             static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
     223            static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern();
     224            /** @brief Returns the map that stores all Identifiers with their network IDs. @return The map */
     225            static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
    205226
    206227            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    207             inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     228            inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; }
    208229            /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
    209             inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
     230            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }
    210231
    211232            ObjectListBase* objects_;                                      //!< The list of all objects of this class
    212233
    213234        private:
    214             /**
    215                 @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
    216             */
    217             inline static void startCreatingHierarchy()
    218             {
    219                 hierarchyCreatingCounter_s++;
    220                 COUT(4) << "*** Identifier: Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
    221             }
    222 
    223             /**
    224                 @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
    225             */
    226             inline static void stopCreatingHierarchy()
    227             {
    228                 hierarchyCreatingCounter_s--;
    229                 COUT(4) << "*** Identifier: Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
    230             }
     235            /** @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. */
     236            inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; }
     237            /** @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. */
     238            inline static void stopCreatingHierarchy()  { hierarchyCreatingCounter_s--; }
    231239
    232240            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
     
    235243
    236244            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
    237             std::set<const Identifier*>* children_;                        //!< The children of the class the Identifier belongs to
     245            mutable std::set<const Identifier*> children_;                 //!< The children of the class the Identifier belongs to
    238246
    239247            std::set<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to
    240             std::set<const Identifier*>* directChildren_;                  //!< The direct children of the class the Identifier belongs to
     248            mutable std::set<const Identifier*> directChildren_;           //!< The direct children of the class the Identifier belongs to
    241249
    242250            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    243251            bool bSetName_;                                                //!< True if the name is set
    244252            std::string name_;                                             //!< The name of the class the Identifier belongs to
    245             BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
     253            Factory* factory_;                                             //!< The Factory, able to create new objects of the given class (if available)
    246254            static int hierarchyCreatingCounter_s;                         //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
    247255            const unsigned int classID_;                                   //!< Uniquely identifies a class (might not be the same as the networkID_)
     
    302310    inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    303311    {
    304         // check if the static field has already been filled
    305         if (ClassIdentifier<T>::classIdentifier_s == 0)
     312        // check if the Identifier already exists
     313        if (!ClassIdentifier<T>::classIdentifier_s)
    306314            ClassIdentifier<T>::initialiseIdentifier();
    307315
     
    430438#endif
    431439    }
    432 
    433 
    434     // ###############################
    435     // ###   SubclassIdentifier    ###
    436     // ###############################
    437     //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
    438     /**
    439         You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
    440         If you assign something else, the program aborts.
    441         Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object.
    442     */
    443     template <class T>
    444     class SubclassIdentifier
    445     {
    446         public:
    447             /**
    448                 @brief Constructor: Automaticaly assigns the Identifier of the given class.
    449             */
    450             SubclassIdentifier()
    451             {
    452                 this->identifier_ = ClassIdentifier<T>::getIdentifier();
    453             }
    454 
    455             /**
    456                 @brief Copyconstructor: Assigns the given Identifier.
    457                 @param identifier The Identifier
    458             */
    459             SubclassIdentifier(Identifier* identifier)
    460             {
    461                 this->operator=(identifier);
    462             }
    463 
    464             /**
    465                 @brief Overloading of the = operator: assigns the identifier and checks its type.
    466                 @param identifier The Identifier to assign
    467                 @return The SubclassIdentifier itself
    468             */
    469             SubclassIdentifier<T>& operator=(Identifier* identifier)
    470             {
    471                 if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))
    472                 {
    473                     COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
    474                     if (identifier)
    475                     {
    476                         COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
    477                         COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
    478                     }
    479                     else
    480                     {
    481                         COUT(1) << "Error: Can't assign NULL identifier" << std::endl;
    482                     }
    483                 }
    484                 else
    485                 {
    486                     this->identifier_ = identifier;
    487                 }
    488                 return *this;
    489             }
    490 
    491             /**
    492                 @brief Overloading of the * operator: returns the assigned identifier.
    493             */
    494             inline Identifier* operator*() const
    495             {
    496                 return this->identifier_;
    497             }
    498 
    499             /**
    500                 @brief Overloading of the -> operator: returns the assigned identifier.
    501             */
    502             inline Identifier* operator->() const
    503             {
    504                 return this->identifier_;
    505             }
    506 
    507             /**
    508                 @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.
    509             */
    510             inline operator Identifier*() const
    511             {
    512                 return this->identifier_;
    513             }
    514 
    515             /**
    516                 @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
    517                 @return The new object
    518             */
    519             T* fabricate(BaseObject* creator) const
    520             {
    521                 BaseObject* newObject = this->identifier_->fabricate(creator);
    522 
    523                 // Check if the creation was successful
    524                 if (newObject)
    525                 {
    526                     return orxonox_cast<T*>(newObject);
    527                 }
    528                 else
    529                 {
    530                     // Something went terribly wrong
    531                     if (this->identifier_)
    532                     {
    533                         COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
    534                         COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
    535                         COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
    536                         COUT(1) << "Aborting..." << std::endl;
    537                     }
    538                     else
    539                     {
    540                         COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
    541                         COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
    542                         COUT(1) << "Aborting..." << std::endl;
    543                     }
    544 
    545                     assert(false);
    546                     return 0;
    547                 }
    548             }
    549 
    550             /** @brief Returns the assigned identifier. @return The identifier */
    551             inline Identifier* getIdentifier() const
    552                 { return this->identifier_; }
    553 
    554         private:
    555             Identifier* identifier_;            //!< The assigned identifier
    556     };
    557440}
    558441
  • sandbox/src/libraries/core/Iterator.h

    r5738 r6038  
    167167
    168168                return (*this);
    169                 return *this;
    170169            }
    171170
     
    193192            inline const Iterator<T>& operator++()
    194193            {
    195                 if (this->element_)
    196                     this->element_ = this->element_->next_;
     194                this->element_ = this->element_->next_;
    197195                return *this;
    198196            }
     
    205203            {
    206204                Iterator<T> copy = *this;
    207                 if (this->element_)
    208                     this->element_ = this->element_->next_;
     205                this->element_ = this->element_->next_;
    209206                return copy;
    210207            }
     
    216213            inline const Iterator<T>& operator--()
    217214            {
    218                 if (this->element_)
    219                     this->element_ = this->element_->prev_;
     215                this->element_ = this->element_->prev_;
    220216                return *this;
    221217            }
     
    228224            {
    229225                Iterator<T> copy = *this;
    230                 if (this->element_)
    231                     this->element_ = this->element_->prev_;
     226                this->element_ = this->element_->prev_;
    232227                return copy;
    233228            }
     
    239234            inline T* operator*() const
    240235            {
    241                 if (this->element_)
    242                     return orxonox_cast<T*>(this->element_->objectBase_);
    243                 else
    244                     return 0;
     236                return orxonox_cast<T*>(this->element_->objectBase_);
    245237            }
    246238
     
    251243            inline T* operator->() const
    252244            {
    253                 if (this->element_)
    254                     return orxonox_cast<T*>(this->element_->objectBase_);
    255                 else
    256                     return 0;
     245                return orxonox_cast<T*>(this->element_->objectBase_);
    257246            }
    258247
  • sandbox/src/libraries/core/Language.cc

    r5738 r6038  
    3535
    3636#include <fstream>
    37 #include <boost/filesystem.hpp>
    38 
    3937#include "util/Debug.h"
    4038#include "Core.h"
     39#include "PathConfig.h"
    4140
    4241namespace orxonox
     
    200199        COUT(4) << "Read default language file." << std::endl;
    201200
    202         boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
     201        std::string filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_);
    203202
    204203        // This creates the file if it's not existing
    205204        std::ofstream createFile;
    206         createFile.open(filepath.string().c_str(), std::fstream::app);
     205        createFile.open(filepath.c_str(), std::fstream::app);
    207206        createFile.close();
    208207
    209208        // Open the file
    210209        std::ifstream file;
    211         file.open(filepath.string().c_str(), std::fstream::in);
     210        file.open(filepath.c_str(), std::fstream::in);
    212211
    213212        if (!file.is_open())
     
    249248        COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl;
    250249
    251         boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage()));
     250        std::string filepath = PathConfig::getConfigPathString() + getFilename(Core::getLanguage());
    252251
    253252        // Open the file
    254253        std::ifstream file;
    255         file.open(filepath.string().c_str(), std::fstream::in);
     254        file.open(filepath.c_str(), std::fstream::in);
    256255
    257256        if (!file.is_open())
     
    303302        COUT(4) << "Language: Write default language file." << std::endl;
    304303
    305         boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
     304        std::string filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_);
    306305
    307306        // Open the file
    308307        std::ofstream file;
    309         file.open(filepath.string().c_str(), std::fstream::out);
     308        file.open(filepath.c_str(), std::fstream::out);
    310309
    311310        if (!file.is_open())
  • sandbox/src/libraries/core/LuaState.cc

    r5782 r6038  
    3838
    3939#include "util/Debug.h"
    40 #include "Core.h"
     40#include "PathConfig.h"
    4141#include "ToluaBindCore.h"
    4242
     
    106106    shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename)
    107107    {
    108         boost::filesystem::path filepath = Core::getDataPath() / "lua" / filename;
     108        boost::filesystem::path filepath = PathConfig::getDataPath() / "lua" / filename;
    109109        if (boost::filesystem::exists(filepath))
    110110        {
  • sandbox/src/libraries/core/ObjectListIterator.h

    r5738 r6038  
    123123            inline const ObjectListIterator<T>& operator++()
    124124            {
    125                 if (this->element_)
    126                     this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
     125                this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
    127126                return *this;
    128127            }
     
    135134            {
    136135                ObjectListIterator<T> copy = *this;
    137                 if (this->element_)
    138                     this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
     136                this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
    139137                return copy;
    140138            }
     
    146144            inline const ObjectListIterator<T>& operator--()
    147145            {
    148                 if (this->element_)
    149                     this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
     146                this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
    150147                return *this;
    151148            }
     
    158155            {
    159156                ObjectListIterator<T> copy = *this;
    160                 if (this->element_)
    161                     this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
     157                this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
    162158                return copy;
    163159            }
     
    169165            inline T* operator*() const
    170166            {
    171                 if (this->element_)
    172                     return this->element_->object_;
    173                 else
    174                     return 0;
     167                return this->element_->object_;
    175168            }
    176169
     
    181174            inline T* operator->() const
    182175            {
    183                 if (this->element_)
    184                     return this->element_->object_;
    185                 else
    186                     return 0;
     176                return this->element_->object_;
    187177            }
    188178
  • sandbox/src/libraries/core/OrxonoxClass.cc

    r5738 r6038  
    7878
    7979    /** @brief Returns true if the objects class is of the given type or a derivative. */
    80     template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B>* identifier)
    81         { return this->getIdentifier()->isA(identifier->getIdentifier()); }
    82     /** @brief Returns true if the objects class is exactly of the given type. */
    83     template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B>* identifier)
    84         { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }
    85     /** @brief Returns true if the objects class is a child of the given type. */
    86     template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B>* identifier)
    87         { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
    88     /** @brief Returns true if the objects class is a direct child of the given type. */
    89     template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B>* identifier)
    90         { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }
    91     /** @brief Returns true if the objects class is a parent of the given type. */
    92     template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B>* identifier)
    93         { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
    94     /** @brief Returns true if the objects class is a direct parent of the given type. */
    95     template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B>* identifier)
    96         { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }
    97 
    98 
    99     /** @brief Returns true if the objects class is of the given type or a derivative. */
    100     template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B> identifier)
    101         { return this->getIdentifier()->isA(identifier.getIdentifier()); }
    102     /** @brief Returns true if the objects class is exactly of the given type. */
    103     template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B> identifier)
    104         { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }
    105     /** @brief Returns true if the objects class is a child of the given type. */
    106     template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B> identifier)
    107         { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
    108     /** @brief Returns true if the objects class is a direct child of the given type. */
    109     template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B> identifier)
    110         { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }
    111     /** @brief Returns true if the objects class is a parent of the given type. */
    112     template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B> identifier)
    113         { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
    114     /** @brief Returns true if the objects class is a direct parent of the given type. */
    115     template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B> identifier)
    116         { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }
    117 
    118 
    119     /** @brief Returns true if the objects class is of the given type or a derivative. */
    12080    bool OrxonoxClass::isA(const OrxonoxClass* object)
    12181        { return this->getIdentifier()->isA(object->getIdentifier()); }
  • sandbox/src/libraries/core/OrxonoxClass.h

    r5738 r6038  
    7272            bool isDirectParentOf(const Identifier* identifier);
    7373
    74             template <class B> bool isA(const SubclassIdentifier<B>* identifier);
    75             template <class B> bool isExactlyA(const SubclassIdentifier<B>* identifier);
    76             template <class B> bool isChildOf(const SubclassIdentifier<B>* identifier);
    77             template <class B> bool isDirectChildOf(const SubclassIdentifier<B>* identifier);
    78             template <class B> bool isParentOf(const SubclassIdentifier<B>* identifier);
    79             template <class B> bool isDirectParentOf(const SubclassIdentifier<B>* identifier);
    80 
    81             template <class B> bool isA(const SubclassIdentifier<B> identifier);
    82             template <class B> bool isExactlyA(const SubclassIdentifier<B> identifier);
    83             template <class B> bool isChildOf(const SubclassIdentifier<B> identifier);
    84             template <class B> bool isDirectChildOf(const SubclassIdentifier<B> identifier);
    85             template <class B> bool isParentOf(const SubclassIdentifier<B> identifier);
    86             template <class B> bool isDirectParentOf(const SubclassIdentifier<B> identifier);
     74            template <class B> inline bool isA(const SubclassIdentifier<B>* identifier)
     75                { return this->isA(*identifier); }
     76            template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier)
     77                { return this->isExactlyA(*identifier); }
     78            template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier)
     79                { return this->isChildOf(*identifier); }
     80            template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier)
     81                { return this->isDirectChildOf(*identifier); }
     82            template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier)
     83                { return this->isParentOf(*identifier); }
     84            template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier)
     85                { return this->isDirectParentOf(*identifier); }
    8786
    8887            bool isA(const OrxonoxClass* object);
     
    10099                Returns NULL if the no pointer was found.
    101100            */
    102             template <class T>
    103             FORCEINLINE T* getDerivedPointer(unsigned int classID)
     101            FORCEINLINE void* getDerivedPointer(unsigned int classID)
    104102            {
    105103                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
    106104                {
    107105                    if (this->objectPointers_[i].first == classID)
    108                         return static_cast<T*>(this->objectPointers_[i].second);
     106                        return this->objectPointers_[i].second;
    109107                }
    110108                return NULL;
    111109            }
    112             //! Const version of getDerivedPointer
    113             template <class T>
    114             FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
    115             {
    116                 return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);
    117             }
     110
     111            //! Version of getDerivedPointer with template
     112            template <class T> FORCEINLINE T* getDerivedPointer(unsigned int classID)
     113            {   return static_cast<T*>(this->getDerivedPointer(classID));   }
     114            //! Const version of getDerivedPointer with template
     115            template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
     116            {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
    118117
    119118        private:
  • sandbox/src/libraries/core/PathConfig.cc

    r6035 r6038  
    7070    PathConfig* PathConfig::singletonPtr_s  = 0;
    7171
    72     SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
    7372    SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
    7473
     
    7877        , modulePath_(*(new bf::path()))
    7978        , dataPath_(*(new bf::path()))
    80         , externalDataPath_(*(new bf::path()))
    8179        , configPath_(*(new bf::path()))
    8280        , logPath_(*(new bf::path()))
     
    172170        delete &modulePath_;
    173171        delete &dataPath_;
    174         delete &externalDataPath_;
    175172        delete &configPath_;
    176173        delete &logPath_;
     
    184181            configPath_       = specialConfig::configDevDirectory;
    185182            logPath_          = specialConfig::logDevDirectory;
    186 
    187             // Check for data path override by the command line
    188             if (!CommandLineParser::getArgument("externalDataPath")->hasDefaultValue())
    189                 externalDataPath_ = CommandLineParser::getValue("externalDataPath").getString();
    190             else
    191                 externalDataPath_ = specialConfig::externalDataDevDirectory;
    192183        }
    193184        else
     
    302293    }
    303294
    304     /*static*/ std::string PathConfig::getExternalDataPathString()
    305     {
    306         return getInstance().externalDataPath_.string() + '/';
    307     }
    308 
    309295    /*static*/ std::string PathConfig::getConfigPathString()
    310296    {
  • sandbox/src/libraries/core/PathConfig.h

    r6035 r6038  
    7777            static const boost::filesystem::path& getDataPath()
    7878                { return getInstance().dataPath_; }
    79             //! Returns the path to the external data files as boost::filesystem::path
    80             static const boost::filesystem::path& getExternalDataPath()
    81                 { return getInstance().externalDataPath_; }
    8279            //! Returns the path to the config files as boost::filesystem::path
    8380            static const boost::filesystem::path& getConfigPath()
     
    9693            //! Returns the path to the data files as std::string
    9794            static std::string getDataPathString();
    98             //! Returns the path to the external data files as std::string
    99             static std::string getExternalDataPathString();
    10095            //! Returns the path to the config files as std::string
    10196            static std::string getConfigPathString();
     
    126121            boost::filesystem::path& modulePath_;            //!< Path to the modules
    127122            boost::filesystem::path& dataPath_;              //!< Path to the data files folder
    128             boost::filesystem::path& externalDataPath_;      //!< Path to the external data files folder
    129123            boost::filesystem::path& configPath_;            //!< Path to the config files folder
    130124            boost::filesystem::path& logPath_;               //!< Path to the log files folder
Note: See TracChangeset for help on using the changeset viewer.