Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 9, 2008, 4:25:52 AM (16 years ago)
Author:
landauf
Message:

merged core3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/ConfigValueContainer.cc

    r1505 r1747  
    4747{
    4848    /**
    49         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    50         @param type The type of the corresponding config-file
    51         @param identifier The identifier of the class the variable belongs to
    52         @param varname The name of the variable
    53         @param defvalue The default-value
    54     */
    55     ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue)
     49        @brief Initializes the ConfigValueContainer with defaultvalues.
     50    */
     51    void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& varname)
    5652    {
    5753        this->type_ = type;
     
    5955        this->sectionname_ = identifier->getName();
    6056        this->varname_ = varname;
    61 
     57        this->callback_ = 0;
     58        this->bContainerIsNew_ = true;
     59        this->bDoInitialCallback_ = false;
     60        this->bAddedDescription_ = false;
     61    }
     62
     63    /**
     64        @brief Does some special initialization for single config-values.
     65    */
     66    void ConfigValueContainer::initValue(const MultiType& defvalue)
     67    {
    6268        this->value_ = defvalue;
    63         this->bAddedDescription_ = false;
    6469        this->bIsVector_ = false;
    6570
    66         this->defvalueString_ = defvalue.toString();
     71        this->defvalueString_ = this->value_.getString();
    6772        this->update();
    6873    }
    6974
    7075    /**
    71         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
    72         @param type The type of the corresponding config-file
    73         @param identifier The identifier of the class the variable belongs to
    74         @param varname The name of the variable
    75         @param defvalue The default-value
    76     */
    77     ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue)
    78     {
    79         this->type_ = type;
    80         this->identifier_ = identifier;
    81         this->sectionname_ = identifier->getName();
    82         this->varname_ = varname;
    83 
    84         this->valueVector_ = defvalue;
    85         this->bAddedDescription_ = false;
     76        @brief Does some special initialization for vector config-values.
     77    */
     78    void ConfigValueContainer::initVector()
     79    {
    8680        this->bIsVector_ = true;
    8781
    88         if (defvalue.size() > 0)
    89         {
    90                 this->value_ = defvalue[0];
    91 
    92             for (unsigned int i = 0; i < defvalue.size(); i++)
    93             {
    94                 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string));
    95                 this->defvalueStringVector_.push_back(defvalue[i].toString());
    96             }
    97 
    98             this->update();
    99         }
     82        for (unsigned int i = 0; i < this->valueVector_.size(); i++)
     83        {
     84            ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_string));
     85            this->defvalueStringVector_.push_back(this->valueVector_[i]);
     86        }
     87
     88        this->update();
     89    }
     90
     91    /**
     92        @brief Destructor: Deletes the callback object if necessary.
     93    */
     94    ConfigValueContainer::~ConfigValueContainer()
     95    {
     96        if (this->callback_)
     97            delete this->callback_;
    10098    }
    10199
     
    105103        @return True if the new value was successfully assigned
    106104    */
    107     bool ConfigValueContainer::set(const MultiTypeMath& input)
    108     {
    109         if (this->bIsVector_)
    110         {
    111             return this->callFunctionWithIndex(&ConfigValueContainer::set, input.toString());
     105    bool ConfigValueContainer::set(const MultiType& input)
     106    {
     107        if (this->bIsVector_)
     108        {
     109            return this->callFunctionWithIndex(&ConfigValueContainer::set, input);
    112110        }
    113111        else
     
    115113            if (this->tset(input))
    116114            {
    117                 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input.toString(), this->value_.isA(MT_string));
     115                ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isType(MT_string));
    118116                return true;
    119117            }
     
    128126        @return True if the new value was successfully assigned
    129127    */
    130     bool ConfigValueContainer::set(unsigned int index, const MultiTypeMath& input)
     128    bool ConfigValueContainer::set(unsigned int index, const MultiType& input)
    131129    {
    132130        if (this->bIsVector_)
     
    134132            if (this->tset(index, input))
    135133            {
    136                 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.toString(), this->value_.isA(MT_string));
     134                ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isType(MT_string));
    137135                return true;
    138136            }
     
    150148        @return True if the new value was successfully assigned
    151149    */
    152     bool ConfigValueContainer::tset(const MultiTypeMath& input)
    153     {
    154         if (this->bIsVector_)
    155         {
    156             return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.toString());
    157         }
    158         else
    159         {
    160             MultiTypeMath temp = this->value_;
    161             if (temp.assimilate(input))
    162             {
    163                 this->value_ = temp;
    164                 if (this->identifier_)
    165                     this->identifier_->updateConfigValues();
    166 
    167                 return true;
    168             }
    169         }
    170         return false;
     150    bool ConfigValueContainer::tset(const MultiType& input)
     151    {
     152        if (this->bIsVector_)
     153        {
     154            return this->callFunctionWithIndex(&ConfigValueContainer::tset, input);
     155            return false;
     156        }
     157        else
     158        {
     159            this->value_ = input;
     160
     161            if (this->identifier_)
     162                this->identifier_->updateConfigValues();
     163
     164            return true;
     165        }
    171166    }
    172167
     
    177172        @return True if the new value was successfully assigned
    178173    */
    179     bool ConfigValueContainer::tset(unsigned int index, const MultiTypeMath& input)
     174    bool ConfigValueContainer::tset(unsigned int index, const MultiType& input)
    180175    {
    181176        if (this->bIsVector_)
     
    191186                for (unsigned int i = this->valueVector_.size(); i <= index; i++)
    192187                {
    193                     this->valueVector_.push_back(MultiTypeMath());
     188                    this->valueVector_.push_back(MultiType());
    194189                }
    195190            }
    196191
    197             MultiTypeMath temp = this->value_;
    198             if (temp.assimilate(input))
    199             {
    200                 this->valueVector_[index] = temp;
    201 
    202                 if (this->identifier_)
    203                     this->identifier_->updateConfigValues();
    204 
    205                 return true;
    206             }
     192            this->valueVector_[index] = input;
     193
     194            if (this->identifier_)
     195                this->identifier_->updateConfigValues();
     196
     197            return true;
    207198        }
    208199        else
    209200        {
    210201            COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
    211         }
    212         return false;
     202            return false;
     203        }
    213204    }
    214205
     
    218209        @return True if the new entry was successfully added
    219210    */
    220     bool ConfigValueContainer::add(const MultiTypeMath& input)
     211    bool ConfigValueContainer::add(const MultiType& input)
    221212    {
    222213        if (this->bIsVector_)
     
    241232                this->valueVector_.erase(this->valueVector_.begin() + index);
    242233                for (unsigned int i = index; i < this->valueVector_.size(); i++)
    243                     ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string));
    244                 ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
     234                    ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_string));
     235                ConfigFileManager::getInstance()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
    245236
    246237                return true;
     
    266257                if (!this->set(i, this->defvalueStringVector_[i]))
    267258                    success = false;
    268             ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size());
     259            ConfigFileManager::getInstance()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size());
    269260            return success;
    270261        }
     
    277268    {
    278269        if (!this->bIsVector_)
    279             this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isA(MT_string)));
     270            this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_string));
    280271        else
    281272        {
    282273            this->valueVector_.clear();
    283             for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++)
     274            for (unsigned int i = 0; i < ConfigFileManager::getInstance()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++)
    284275            {
    285276                if (i < this->defvalueStringVector_.size())
    286277                {
    287                     this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string)));
     278                    this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_string));
    288279                }
    289280                else
    290281                {
    291                     this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiTypeMath(), this->value_.isA(MT_string)));
     282                    this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_string));
    292283                }
    293284
     
    303294        @return The returnvalue of the functioncall
    304295    */
    305     bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input)
     296    bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiType&), const std::string& input)
    306297    {
    307298        SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0');
     
    335326        @param description The description
    336327    */
    337     void ConfigValueContainer::description(const std::string& description)
     328    ConfigValueContainer& ConfigValueContainer::description(const std::string& description)
    338329    {
    339330        if (!this->bAddedDescription_)
     
    343334            this->bAddedDescription_ = true;
    344335        }
     336        return (*this);
    345337    }
    346338
Note: See TracChangeset for help on using the changeset viewer.