Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 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        }
Note: See TracChangeset for help on using the changeset viewer.