Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 2, 2008, 12:22:42 AM (16 years ago)
Author:
rgrieder
Message:

Merged r2101 (objecthierarchy) to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/trunk/src/core/ConfigFileManager.h

    r1887 r2103  
    4141namespace orxonox
    4242{
    43     enum _CoreExport ConfigFileType
    44     {
    45         CFT_Settings,
    46         CFT_Keybindings,
    47         CFT_JoyStickCalibration
    48     };
    49 
     43    // Use unsigned int as config file type to have an arbitrary number of files
     44    class ConfigFileType
     45    {
     46    public:
     47        ConfigFileType() { }
     48        ConfigFileType(unsigned int type)              { type_ = type; }
     49        ConfigFileType(const ConfigFileType& instance) { type_ = instance.type_; }
     50
     51        operator unsigned int() { return type_; }
     52        ConfigFileType& operator =(unsigned int type) { type_ = type; return *this; }
     53        bool operator <(const ConfigFileType& right) const   { return (type_ < right.type_); }
     54
     55        /* *** Put the different config file types here *** */
     56        static const unsigned int NoType              = 0;
     57        static const unsigned int Settings            = 1;
     58        static const unsigned int JoyStickCalibration = 2;
     59
     60        static const unsigned int numberOfReservedTypes = 1024;
     61
     62    private:
     63        unsigned int type_;
     64    };
    5065
    5166    bool config(const std::string& classname, const std::string& varname, const std::string& value);
     
    5570    void cleanConfig();
    5671    void loadSettings(const std::string& filename);
    57     void loadKeybindings(const std::string& filename);
    5872
    5973
     
    218232    {
    219233        public:
    220             inline ConfigFile(const std::string& filename) : filename_(filename), bUpdated_(false) {}
     234            inline ConfigFile(const std::string& filename, ConfigFileType type)
     235                : filename_(filename)
     236                , type_(type)
     237                , bUpdated_(false)
     238            { }
    221239            ~ConfigFile();
    222240
    223241            void load(bool bCreateIfNotExisting = true);
    224242            void save() const;
    225             void save(const std::string& filename);
     243            void saveAs(const std::string& filename);
    226244            void clean(bool bCleanComments = false);
     245            void clear();
     246
     247            const std::string& getFilename() { return this->filename_; }
    227248
    228249            inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString)
     
    241262                { return this->getSection(section)->getVectorSize(name); }
    242263
     264            void updateConfigValues();
     265
    243266        private:
    244267            ConfigFileSection* getSection(const std::string& section);
     
    246269
    247270            std::string filename_;
     271            ConfigFileType type_;
    248272            std::list<ConfigFileSection*> sections_;
    249273            bool bUpdated_;
     
    257281    {
    258282        public:
    259             static ConfigFileManager& getInstance();
    260 
    261             void setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting = true);
    262 
    263             void load(bool bCreateIfNotExisting = true);
     283            ConfigFileManager();
     284            ~ConfigFileManager();
     285
     286            void load();
    264287            void save();
    265288            void clean(bool bCleanComments = false);
    266289
    267             void load(ConfigFileType type, bool bCreateIfNotExisting = true);
     290            void setFilename(ConfigFileType type, const std::string& filename);
     291            const std::string& getFilename(ConfigFileType type);
     292
     293            ConfigFileType getNewConfigFileType() { return mininmalFreeType_++; }
     294
     295            void load(ConfigFileType type);
    268296            void save(ConfigFileType type);
    269             void save(ConfigFileType type, const std::string& filename);
     297            void saveAs(ConfigFileType type, const std::string& saveFilename);
    270298            void clean(ConfigFileType type, bool bCleanComments = false);
    271299
     
    285313                { return this->getFile(type)->getVectorSize(section, name); }
    286314
    287             void updateConfigValues() const;
    288             void updateConfigValues(ConfigFileType type) const;
    289 
    290         private:
    291             ConfigFileManager();
    292             ConfigFileManager(const ConfigFileManager& other);
    293             ~ConfigFileManager();
     315            void updateConfigValues();
     316            void updateConfigValues(ConfigFileType type);
     317
     318            static ConfigFileManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
     319
     320        private:
     321            ConfigFileManager(const ConfigFileManager&);
    294322
    295323            ConfigFile* getFile(ConfigFileType type);
    296324
    297             std::string getFilePath(const std::string& name) const;
    298 
    299325            std::map<ConfigFileType, ConfigFile*> configFiles_;
     326            unsigned int mininmalFreeType_;
     327
     328            static ConfigFileManager* singletonRef_s;
    300329    };
    301330}
Note: See TracChangeset for help on using the changeset viewer.