Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1027


Ignore:
Timestamp:
Apr 10, 2008, 6:44:38 PM (16 years ago)
Author:
landauf
Message:

console command 'cleanConfig' is now implemented: it drops all not-existing classes and variables and all comments from the config file

Location:
code/branches/core2/src/orxonox/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/ConfigFileManager.cc

    r1026 r1027  
    3838{
    3939    ConsoleCommandShortcutExtern(reloadConfig, AccessLevel::None);
    40     ConsoleCommandShortcutExtern(saveConfig, AccessLevel::None);
    4140    ConsoleCommandShortcutExtern(cleanConfig, AccessLevel::None);
    4241    ConsoleCommandShortcutExtern(loadSettings, AccessLevel::None);
     
    4847    }
    4948
    50     void saveConfig()
    51     {
    52         ConfigFileManager::getSingleton()->save();
    53     }
    54 
    5549    void cleanConfig()
    5650    {
     
    6054    void loadSettings(const std::string& filename)
    6155    {
    62         ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename);
     56        ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename, false);
    6357    }
    6458
     
    145139    }
    146140
    147     void ConfigFile::load()
    148     {
    149         // This creates the file if it's not existing
    150         std::ofstream createFile;
    151         createFile.open(this->filename_.c_str(), std::fstream::app);
    152         createFile.close();
     141    void ConfigFile::load(bool bCreateIfNotExisting)
     142    {
     143        if (bCreateIfNotExisting)
     144        {
     145            // This creates the default config file if it's not existing
     146            std::ofstream createFile;
     147            createFile.open(this->filename_.c_str(), std::fstream::app);
     148            createFile.close();
     149        }
    153150
    154151        // Open the file
     
    289286    void ConfigFile::clean()
    290287    {
     288        for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); )
     289        {
     290            std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName());
     291            if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues())
     292            {
     293                // The section exists, delete comment
     294                (*it1)->setComment("");
     295                for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); )
     296                {
     297                    std::map<std::string, ConfigValueContainer*>::const_iterator it4 = (*it2).second->getConfigValueMap().find((*it3)->getName());
     298                    if (it4 != (*it2).second->getConfigValueMapEnd())
     299                    {
     300                        // The config-value exists, delete comment
     301                        (*it3)->setComment("");
     302                        ++it3;
     303                    }
     304                    else
     305                    {
     306                        // The config-value doesn't exist
     307                        delete (*it3);
     308                        (*it1)->entries_.erase(it3++);
     309                    }
     310                }
     311                ++it1;
     312            }
     313            else
     314            {
     315                // The section doesn't exist
     316                delete (*it1);
     317                this->sections_.erase(it1++);
     318            }
     319        }
     320
     321        // Save the file
     322        this->save();
    291323    }
    292324
     
    343375    }
    344376
    345     void ConfigFileManager::setFile(ConfigFileType type, const std::string& filename)
     377    void ConfigFileManager::setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting)
    346378    {
    347379        std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type);
     
    351383
    352384        this->configFiles_[type] = new ConfigFile(this->getFilePath(filename));
    353         this->load(type);
    354     }
    355 
    356     void ConfigFileManager::load()
     385        this->load(type, bCreateIfNotExisting);
     386    }
     387
     388    void ConfigFileManager::load(bool bCreateIfNotExisting)
    357389    {
    358390        for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
    359             (*it).second->load();
     391            (*it).second->load(bCreateIfNotExisting);
    360392
    361393        this->updateConfigValues();
     
    374406    }
    375407
    376     void ConfigFileManager::load(ConfigFileType type)
    377     {
    378         this->getFile(type)->load();
     408    void ConfigFileManager::load(ConfigFileType type, bool bCreateIfNotExisting)
     409    {
     410        this->getFile(type)->load(bCreateIfNotExisting);
    379411        this->updateConfigValues(type);
    380412    }
  • code/branches/core2/src/orxonox/core/ConfigFileManager.h

    r1025 r1027  
    6565            virtual const std::string& getValue() const = 0;
    6666            virtual const std::string& getName() const = 0;
     67            virtual void setComment(const std::string& comment) = 0;
    6768            virtual unsigned int getIndex() const { return 0; }
    6869            virtual std::string getFileEntry() const = 0;
     
    8182            inline virtual const std::string& getName() const
    8283                { return this->name_; }
     84
     85            inline virtual void setComment(const std::string& comment)
     86                { this->additionalComment_ = comment; }
    8387
    8488            inline virtual void setValue(const std::string& value)
     
    133137                { return this->comment_; }
    134138
     139            inline virtual void setComment(const std::string& comment)
     140                { this->comment_ = comment; }
     141
    135142            inline virtual void setValue(const std::string& value)
    136143                {}
     
    159166            inline const std::string& getName() const
    160167                { return this->name_; }
     168
     169            inline void setComment(const std::string& comment)
     170                { this->additionalComment_ = comment; }
    161171
    162172            inline void setValue(const std::string& name, const std::string& value)
     
    204214            ~ConfigFile();
    205215
    206             void load();
     216            void load(bool bCreateIfNotExisting = true);
    207217            void save() const;
    208218            void clean();
     
    236246            static ConfigFileManager* getSingleton();
    237247
    238             void setFile(ConfigFileType type, const std::string& filename);
    239 
    240             void load();
     248            void setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting = true);
     249
     250            void load(bool bCreateIfNotExisting = true);
    241251            void save();
    242252            void clean();
    243253
    244             void load(ConfigFileType type);
     254            void load(ConfigFileType type, bool bCreateIfNotExisting = true);
    245255            void save(ConfigFileType type);
    246256            void clean(ConfigFileType type);
Note: See TracChangeset for help on using the changeset viewer.