Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (9 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/config/ConfigFile.cc

    r10624 r11071  
    3535
    3636#include <boost/filesystem.hpp>
     37
     38#include <iterator>
     39#include <algorithm>
     40#include <fstream>
    3741
    3842#include "util/Convert.h"
     
    9397                        try
    9498                        {
    95                             boost::filesystem::copy_file(defaultFilepath, filepath);
     99                            std::ifstream input(defaultFilepath.string().c_str(), std::ifstream::in | std::ifstream::binary);
     100                            std::ofstream output(filepath.string().c_str(), std::ofstream::out | std::ofstream::binary);
     101                            copy(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>(), std::ostream_iterator<char>(output));
    96102                            orxout(internal_info, context::config) << "Copied " << this->filename_ << " from the default config folder." << endl;
    97103                        }
     
    108114        if (file.is_open())
    109115        {
    110             ConfigFileSection* newsection = 0;
     116            ConfigFileSection* newsection = nullptr;
    111117
    112118            while (file.good() && !file.eof())
     
    135141                }
    136142
    137                 if (newsection != 0)
     143                if (newsection != nullptr)
    138144                {
    139145                    if (isComment(line))
     
    228234        }
    229235
    230         for (std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
    231         {
    232             file << (*it)->getFileEntry() << endl;
    233 
    234             for (std::list<ConfigFileEntry*>::const_iterator it_entries = (*it)->getEntriesBegin(); it_entries != (*it)->getEntriesEnd(); ++it_entries)
    235                 file << (*it_entries)->getFileEntry() << endl;
     236        for (ConfigFileSection* section : this->sections_)
     237        {
     238            file << section->getFileEntry() << endl;
     239
     240            for (ConfigFileEntry* entry : section->getEntries())
     241                file << entry->getFileEntry() << endl;
    236242
    237243            file << endl;
     
    270276
    271277    /**
    272         @brief Returns a pointer to the section with given name (or NULL if the section doesn't exist).
    273     */
    274     ConfigFileSection* ConfigFile::getSection(const std::string& section) const
    275     {
    276         for (std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
    277             if ((*it)->getName() == section)
    278                 return (*it);
    279         return NULL;
     278        @brief Returns a pointer to the section with given name (or nullptr if the section doesn't exist).
     279    */
     280    ConfigFileSection* ConfigFile::getSection(const std::string& sectionName) const
     281    {
     282        for (ConfigFileSection* section : this->sections_)
     283            if (section->getName() == sectionName)
     284                return section;
     285        return nullptr;
    280286    }
    281287
     
    283289        @brief Returns a pointer to the section with given name. If it doesn't exist, the section is created.
    284290    */
    285     ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& section)
    286     {
    287         for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
    288             if ((*it)->getName() == section)
    289                 return (*it);
     291    ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& sectionName)
     292    {
     293        for (ConfigFileSection* section : this->sections_)
     294            if (section->getName() == sectionName)
     295                return section;
    290296
    291297        this->bUpdated_ = true;
    292298
    293         return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(section)));
     299        return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(sectionName)));
    294300    }
    295301
     
    301307        bool sectionsUpdated = false;
    302308
    303         for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
    304         {
    305             if ((*it)->bUpdated_)
     309        for (ConfigFileSection* section : this->sections_)
     310        {
     311            if (section->bUpdated_)
    306312            {
    307313                sectionsUpdated = true;
    308                 (*it)->bUpdated_ = false;
     314                section->bUpdated_ = false;
    309315            }
    310316        }
  • code/trunk/src/libraries/core/config/ConfigFileEntry.h

    r9559 r11071  
    5151        public:
    5252            /// Destructor
    53             virtual ~ConfigFileEntry() {};
     53            virtual ~ConfigFileEntry() = default;
    5454
    5555            /// Changes the value of the entry.
  • code/trunk/src/libraries/core/config/ConfigFileEntryComment.h

    r9559 r11071  
    5454
    5555            /// Destructor
    56             inline virtual ~ConfigFileEntryComment() {}
     56            virtual inline ~ConfigFileEntryComment() = default;
    5757
    58             inline virtual const std::string& getName() const
     58            virtual inline const std::string& getName() const override
    5959                { return this->comment_; }
    6060
    61             inline virtual void setComment(const std::string& comment)
     61            virtual inline void setComment(const std::string& comment) override
    6262                { this->comment_ = comment; }
    6363
    64             inline virtual void setValue(const std::string& value)
     64            virtual inline void setValue(const std::string& value) override
    6565                {}
    66             inline virtual const std::string& getValue() const
     66            virtual inline const std::string& getValue() const override
    6767                { return BLANKSTRING; }
    6868
    69             inline void setString(bool bString)
     69            virtual inline void setString(bool bString) override
    7070                {}
    7171
    72             inline virtual const std::string& getFileEntry() const
     72            virtual inline const std::string& getFileEntry() const override
    7373                { return this->comment_; }
    7474
  • code/trunk/src/libraries/core/config/ConfigFileEntryValue.h

    r9684 r11071  
    6767
    6868            /// Destructor
    69             inline virtual ~ConfigFileEntryValue() {}
     69            virtual inline ~ConfigFileEntryValue() = default;
    7070
    71             inline virtual const std::string& getName() const
     71            virtual inline const std::string& getName() const override
    7272                { return this->name_; }
    7373
    74             inline virtual void setComment(const std::string& comment)
     74            virtual inline void setComment(const std::string& comment) override
    7575                { this->additionalComment_ = comment; this->update(); }
    7676
    77             inline virtual void setValue(const std::string& value)
     77            virtual inline void setValue(const std::string& value) override
    7878                { this->value_ = value; this->update(); }
    79             inline virtual const std::string& getValue() const
     79            virtual inline const std::string& getValue() const override
    8080                { return this->value_; }
    8181
    82             inline void virtual setString(bool bString)
     82            virtual inline void setString(bool bString) override
    8383                { this->bString_ = bString; this->update(); }
    8484
    85             inline virtual const std::string& getFileEntry() const
     85            virtual inline const std::string& getFileEntry() const override
    8686                { return this->fileEntry_; }
    8787
    8888            /// Returns the "key" of the value (in this case it's just the name of the entry, but for vectors it's different)
    89             inline virtual const std::string& getKeyString() const
     89            virtual inline const std::string& getKeyString() const
    9090                { return this->name_; }
    9191
  • code/trunk/src/libraries/core/config/ConfigFileEntryVectorValue.h

    r9559 r11071  
    6565
    6666            /// Destructor
    67             inline ~ConfigFileEntryVectorValue() {}
     67            inline ~ConfigFileEntryVectorValue() = default;
    6868
    69             inline unsigned int getIndex() const
     69            virtual inline unsigned int getIndex() const override
    7070                { return this->index_; }
    7171
    7272            /// Returns the "key" of the value (the name of the vector plus the index of the element)
    73             inline const std::string& getKeyString() const
     73            virtual inline const std::string& getKeyString() const override
    7474                { return this->keyString_; }
    7575
    7676        private:
    77             void update();
     77            virtual void update() override;
    7878
    7979            unsigned int index_;        ///< The index of the element in the vector
  • code/trunk/src/libraries/core/config/ConfigFileManager.cc

    r9559 r11071  
    4242    ///////////////////////
    4343
    44     ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
     44    ConfigFileManager* ConfigFileManager::singletonPtr_s = nullptr;
    4545
    46     /// Constructor: Initializes the array of config files with NULL.
     46    /// Constructor: Initializes the array of config files with nullptr.
    4747    ConfigFileManager::ConfigFileManager()
    4848    {
    49         this->configFiles_.assign(NULL);
     49        this->configFiles_.fill(nullptr);
    5050    }
    5151
     
    5353    ConfigFileManager::~ConfigFileManager()
    5454    {
    55         for (boost::array<ConfigFile*, 3>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
    56             if (*it)
    57                 delete (*it);
     55        for (ConfigFile* configFile : this->configFiles_)
     56            if (configFile)
     57                delete configFile;
    5858    }
    5959
  • code/trunk/src/libraries/core/config/ConfigFileManager.h

    r9559 r11071  
    3838#include "core/CorePrereqs.h"
    3939
    40 #include <boost/array.hpp>
     40#include <array>
    4141
    4242#include "util/Singleton.h"
     
    6767
    6868        private:
    69             ConfigFileManager(const ConfigFileManager&);    ///< Copy-constructor: not implemented
     69            // non-copyable:
     70            ConfigFileManager(const ConfigFileManager&) = delete;
     71            ConfigFileManager& operator=(const ConfigFileManager&) = delete;
    7072
    71             boost::array<ConfigFile*, 3> configFiles_;      ///< Stores the config files for each type in an array (must have the same size like ConfigFileType::Value)
     73            std::array<ConfigFile*, 3> configFiles_;        ///< Stores the config files for each type in an array (must have the same size like ConfigFileType::Value)
    7274            static ConfigFileManager* singletonPtr_s;       ///< Stores the singleton-pointer
    7375    };
  • code/trunk/src/libraries/core/config/ConfigFileSection.cc

    r9559 r11071  
    8080    {
    8181        unsigned int size = 0;
    82         for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
    83             if ((*it)->getName() == name)
    84                 if ((*it)->getIndex() >= size)
    85                     size = (*it)->getIndex() + 1;
     82        for (ConfigFileEntry* entry : this->entries_)
     83            if (entry->getName() == name)
     84                if (entry->getIndex() >= size)
     85                    size = entry->getIndex() + 1;
    8686        return size;
    8787    }
     
    9999
    100100    /**
    101         @brief Returns the entry with given name (or NULL if it doesn't exist).
     101        @brief Returns the entry with given name (or nullptr if it doesn't exist).
    102102
    103103        @param name     The name of the entry
     
    105105    ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name) const
    106106    {
    107         for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
     107        for (ConfigFileEntry* entry : this->entries_)
    108108        {
    109             if ((*it)->getName() == name)
    110                 return *it;
     109            if (entry->getName() == name)
     110                return entry;
    111111        }
    112         return NULL;
     112        return nullptr;
    113113    }
    114114
    115115    /**
    116         @brief Returns the entry of a vector element with given name and index (or NULL if it doesn't exist).
     116        @brief Returns the entry of a vector element with given name and index (or nullptr if it doesn't exist).
    117117
    118118        @param name     The name of the vector
     
    121121    ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name, unsigned int index) const
    122122    {
    123         for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
     123        for (ConfigFileEntry* entry : this->entries_)
    124124        {
    125             if (((*it)->getName() == name) && ((*it)->getIndex() == index))
    126                 return *it;
     125            if ((entry->getName() == name) && (entry->getIndex() == index))
     126                return entry;
    127127        }
    128         return NULL;
     128        return nullptr;
    129129    }
    130130
  • code/trunk/src/libraries/core/config/ConfigFileSection.h

    r9684 r11071  
    3939#include <string>
    4040#include <list>
     41#include "util/StringUtils.h"
    4142#include "ConfigFileEntry.h"
    4243
     
    160161            std::list<ConfigFileEntry*>& getEntries()
    161162                { return this->entries_; }
    162             /// Returns the begin-iterator of the list of entries in this section.
    163             std::list<ConfigFileEntry*>::const_iterator getEntriesBegin() const
    164                 { return this->entries_.begin(); }
    165             /// Returns the end-iterator of the list of entries in this section.
    166             std::list<ConfigFileEntry*>::const_iterator getEntriesEnd() const
    167                 { return this->entries_.end(); }
     163            const std::list<ConfigFileEntry*>& getEntries() const
     164                { return this->entries_; }
    168165
    169166            std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString);
  • code/trunk/src/libraries/core/config/ConfigValueContainer.cc

    r9559 r11071  
    5353        this->sectionname_ = sectionname;
    5454        this->varname_ = varname;
    55         this->callback_ = 0;
     55        this->callback_ = nullptr;
    5656        this->bContainerIsNew_ = true;
    5757        this->bDoInitialCallback_ = false;
     
    191191                for (unsigned int i = this->valueVector_.size(); i <= index; i++)
    192192                {
    193                     this->valueVector_.push_back(MultiType());
     193                    this->valueVector_.emplace_back();
    194194                }
    195195            }
  • code/trunk/src/libraries/core/config/ConfigValueContainer.h

    r9667 r11071  
    5959        public:
    6060            virtual void call(void* object) = 0;
    61             inline virtual ~ConfigValueCallbackBase() {}
     61            virtual inline ~ConfigValueCallbackBase() {}
    6262    };
    6363
     
    6767        public:
    6868            inline ConfigValueCallback(void (T::*function) (void)) : function_(function) {}
    69             inline virtual ~ConfigValueCallback() {}
    70             inline virtual void call(void* object)
     69            virtual inline ~ConfigValueCallback() = default;
     70            virtual inline void call(void* object) override
    7171            {
    7272                if (!IdentifierManager::getInstance().isCreatingHierarchy())
     
    130130
    131131                this->value_ = V();
    132                 for (unsigned int i = 0; i < defvalue.size(); i++)
    133                     this->valueVector_.push_back(MultiType(defvalue[i]));
     132                for (const D& defvalueElement : defvalue)
     133                    this->valueVector_.emplace_back(defvalueElement);
    134134
    135135                this->initVector();
     
    183183                    std::vector<T> temp = *value;
    184184                    value->clear();
    185                     for (unsigned int i = 0; i < this->valueVector_.size(); ++i)
    186                         value->push_back(this->valueVector_[i]);
     185                    for (const MultiType& vectorEntry : this->valueVector_)
     186                        value->push_back(vectorEntry);
    187187
    188188                    if (value->size() != temp.size())
     
    211211                {
    212212                    value->clear();
    213                     for (unsigned int i = 0; i < this->valueVector_.size(); ++i)
    214                         value->push_back(this->valueVector_[i]);
     213                    for (const MultiType& vectorEntry : this->valueVector_)
     214                        value->push_back(vectorEntry);
    215215                }
    216216                return *this;
     
    223223            inline const std::string& getSectionName() const
    224224                { return this->sectionname_; }
    225             /// Returns the associated identifier (can be NULL).
     225            /// Returns the associated identifier (can be nullptr).
    226226            inline Identifier* getIdentifier() const
    227227                { return this->identifier_; }
  • code/trunk/src/libraries/core/config/SettingsConfigFile.cc

    r10624 r11071  
    5757    SetConsoleCommand(__CC_getConfig_name,       &SettingsConfigFile::getConfig).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries());
    5858
    59     SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0;
     59    SettingsConfigFile* SettingsConfigFile::singletonPtr_s = nullptr;
    6060
    6161    /**
     
    7777    SettingsConfigFile::~SettingsConfigFile()
    7878    {
    79         ModifyConsoleCommand(__CC_load_name).setObject(0);
    80         ModifyConsoleCommand(__CC_setFilename_name).setObject(0);
    81         ModifyConsoleCommand(__CC_config_name).setObject(0);
    82         ModifyConsoleCommand(__CC_tconfig_name).setObject(0);
    83         ModifyConsoleCommand(__CC_getConfig_name).setObject(0);
     79        ModifyConsoleCommand(__CC_load_name).setObject(nullptr);
     80        ModifyConsoleCommand(__CC_setFilename_name).setObject(nullptr);
     81        ModifyConsoleCommand(__CC_config_name).setObject(nullptr);
     82        ModifyConsoleCommand(__CC_tconfig_name).setObject(nullptr);
     83        ModifyConsoleCommand(__CC_getConfig_name).setObject(nullptr);
    8484    }
    8585
     
    106106    void SettingsConfigFile::addConfigValueContainer(ConfigValueContainer* container)
    107107    {
    108         if (container == NULL)
     108        if (container == nullptr)
    109109            return;
    110110        std::pair<std::string, ConfigValueContainer*> second(getLowercase(container->getName()), container);
     
    118118    void SettingsConfigFile::removeConfigValueContainer(ConfigValueContainer* container)
    119119    {
    120         if (container == NULL)
     120        if (container == nullptr)
    121121            return;
    122122        const std::string& sectionLC = getLowercase(container->getSectionName());
     
    142142        // todo: can this be done more efficiently? looks like some identifiers will be updated multiple times.
    143143
    144         for (ContainerMap::const_iterator it = this->containers_.begin(); it != this->containers_.end(); ++it)
    145         {
    146             it->second.second->update();
    147             it->second.second->getIdentifier()->updateConfigValues();
     144        for (const auto& mapEntry : this->containers_)
     145        {
     146            mapEntry.second.second->update();
     147            mapEntry.second.second->getIdentifier()->updateConfigValues();
    148148        }
    149149    }
     
    269269            {
    270270                std::string value;
    271                 it->second.second->getValue<std::string, void>(&value, NULL);
     271                it->second.second->getValue<std::string, void>(&value, nullptr);
    272272                return value;
    273273            }
  • code/trunk/src/libraries/core/config/SettingsConfigFile.h

    r9684 r11071  
    6363
    6464        public:
    65             typedef std::multimap<std::string, std::pair<std::string, ConfigValueContainer*> > ContainerMap;
     65            typedef std::multimap<std::string, std::pair<std::string, ConfigValueContainer*>> ContainerMap;
    6666
    6767            SettingsConfigFile(const std::string& filename);
    6868            ~SettingsConfigFile();
    6969
    70             void load(); // tolua_export
     70            virtual void load() override; // tolua_export
    7171            void setFilename(const std::string& filename); // tolua_export
    7272            void clean(bool bCleanComments = false); // tolua_export
Note: See TracChangeset for help on using the changeset viewer.