Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 6, 2008, 4:21:56 PM (16 years ago)
Author:
landauf
Message:

Added new 'MultiType', replacing MultiTypePrimitive, MultiTypeString and MultiTypeMath. MultiType can hold all types MultiTypeMath was able to hold, namely all primitives, pointers, string and several math objects (vector2, 3 and 4, quaternion, colourvalue, radian, degree).

The new MultiType has a completely changed behaviour, I'll explain this on a wiki page somewhen.
But to say the most important things in a few words:
The MultiType has a fixed type. This type is determined by the first assigned value (by using setValue(value), operator=(value) or MultiType(value)). Every other value getting assigned later, will be converted to the first type. But you can change the type (setType<T>()), convert the value (convert<T>()) or force the type of a newly assigned value manually (setValue<T>(value)) by using template functions.

In contrast, the old MultiTypeMath changed it's internal type whenever a new type was assigned. So be aware of this important change.

At the moment I can't see any issues, but there might very well be several problems yet to discover, so further tests will be done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/ConfigValueContainer.cc

    r1658 r1716  
    6464        @brief Does some special initialization for single config-values.
    6565    */
    66     void ConfigValueContainer::initValue(const MultiTypeMath& defvalue)
     66    void ConfigValueContainer::initValue(const MultiType& defvalue)
    6767    {
    6868        this->value_ = defvalue;
     
    8282        for (unsigned int i = 0; i < this->valueVector_.size(); i++)
    8383        {
    84             ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i].toString(), this->value_.isA(MT_string));
    85             this->defvalueStringVector_.push_back(this->valueVector_[i].toString());
     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]);
    8686        }
    8787
     
    103103        @return True if the new value was successfully assigned
    104104    */
    105     bool ConfigValueContainer::set(const MultiTypeMath& input)
    106     {
    107         if (this->bIsVector_)
    108         {
    109             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);
    110110        }
    111111        else
     
    113113            if (this->tset(input))
    114114            {
    115                 ConfigFileManager::getInstance()->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));
    116116                return true;
    117117            }
     
    126126        @return True if the new value was successfully assigned
    127127    */
    128     bool ConfigValueContainer::set(unsigned int index, const MultiTypeMath& input)
     128    bool ConfigValueContainer::set(unsigned int index, const MultiType& input)
    129129    {
    130130        if (this->bIsVector_)
     
    132132            if (this->tset(index, input))
    133133            {
    134                 ConfigFileManager::getInstance()->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));
    135135                return true;
    136136            }
     
    148148        @return True if the new value was successfully assigned
    149149    */
    150     bool ConfigValueContainer::tset(const MultiTypeMath& input)
    151     {
    152         if (this->bIsVector_)
    153         {
    154             return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.toString());
    155         }
    156         else
    157         {
    158             MultiTypeMath temp = this->value_;
    159             if (temp.assimilate(input))
    160             {
    161                 this->value_ = temp;
     150    bool ConfigValueContainer::tset(const MultiType& input)
     151    {
     152        if (this->bIsVector_)
     153        {
     154            return this->callFunctionWithIndex(&ConfigValueContainer::tset, input);
     155        }
     156        else
     157        {
     158//            MultiType temp = this->value_;
     159//            if (temp.assimilate(input))
     160//            {
     161//                this->value_ = temp;
     162                this->value_ = input;
    162163                if (this->identifier_)
    163164                    this->identifier_->updateConfigValues();
    164165
    165166                return true;
    166             }
     167//            }
    167168        }
    168169        return false;
     
    175176        @return True if the new value was successfully assigned
    176177    */
    177     bool ConfigValueContainer::tset(unsigned int index, const MultiTypeMath& input)
     178    bool ConfigValueContainer::tset(unsigned int index, const MultiType& input)
    178179    {
    179180        if (this->bIsVector_)
     
    189190                for (unsigned int i = this->valueVector_.size(); i <= index; i++)
    190191                {
    191                     this->valueVector_.push_back(MultiTypeMath());
     192                    this->valueVector_.push_back(MultiType());
    192193                }
    193194            }
    194195
    195             MultiTypeMath temp = this->value_;
    196             if (temp.assimilate(input))
    197             {
    198                 this->valueVector_[index] = temp;
     196//            MultiType temp = this->value_;
     197//            if (temp.assimilate(input))
     198//            {
     199//                this->valueVector_[index] = temp;
     200                this->valueVector_[index] = input;
    199201
    200202                if (this->identifier_)
     
    202204
    203205                return true;
    204             }
     206//            }
    205207        }
    206208        else
     
    216218        @return True if the new entry was successfully added
    217219    */
    218     bool ConfigValueContainer::add(const MultiTypeMath& input)
     220    bool ConfigValueContainer::add(const MultiType& input)
    219221    {
    220222        if (this->bIsVector_)
     
    239241                this->valueVector_.erase(this->valueVector_.begin() + index);
    240242                for (unsigned int i = index; i < this->valueVector_.size(); i++)
    241                     ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string));
     243                    ConfigFileManager::getInstance()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_string));
    242244                ConfigFileManager::getInstance()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
    243245
     
    275277    {
    276278        if (!this->bIsVector_)
    277             this->value_.fromString(ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isA(MT_string)));
     279            this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_string));
    278280        else
    279281        {
     
    283285                if (i < this->defvalueStringVector_.size())
    284286                {
    285                     this->value_.fromString(ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string)));
     287                    this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_string));
    286288                }
    287289                else
    288290                {
    289                     this->value_.fromString(ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiTypeMath(), this->value_.isA(MT_string)));
     291                    this->value_ = ConfigFileManager::getInstance()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_string));
    290292                }
    291293
     
    301303        @return The returnvalue of the functioncall
    302304    */
    303     bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input)
     305    bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiType&), const std::string& input)
    304306    {
    305307        SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0');
Note: See TracChangeset for help on using the changeset viewer.