Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 451 for code


Ignore:
Timestamp:
Dec 10, 2007, 3:55:33 AM (17 years ago)
Author:
landauf
Message:

used a union to save some memory

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

Legend:

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

    r450 r451  
    1212
    1313    /**
    14         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_int_.
     14        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_.value_int_.
    1515        @param classname The name of the class the variable belongs to
    1616        @param varname The name of the variable
     
    3232        // Try to convert the value-string to int
    3333        std::istringstream istream(valueString);
    34         if (!(istream >> this->value_int_))
     34        if (!(istream >> this->value_.value_int_))
    3535        {
    3636            // The conversion failed - use the default value and restore the entry in the config-file
    37             this->value_int_ = defvalue;
     37            this->value_.value_int_ = defvalue;
    3838            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
    3939            ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     
    4242
    4343    /**
    44         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_double_.
     44        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_.value_double_.
    4545        @param classname The name of the class the variable belongs to
    4646        @param varname The name of the variable
     
    6262        // Try to convert the value-string to double
    6363        std::istringstream istream(valueString);
    64         if (!(istream >> this->value_double_))
     64        if (!(istream >> this->value_.value_double_))
    6565        {
    6666            // The conversion failed - use the default value and restore the entry in the config-file
    67             this->value_double_ = defvalue;
     67            this->value_.value_double_ = defvalue;
    6868            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
    6969            ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     
    7272
    7373    /**
    74         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_bool_.
     74        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_.value_bool_.
    7575        @param classname The name of the class the variable belongs to
    7676        @param varname The name of the variable
     
    9191        // Try to parse the value-string - is it a word?
    9292        if (valueString.find("true") < valueString.size() || valueString.find("yes") < valueString.size())
    93             this->value_bool_ = true;
     93            this->value_.value_bool_ = true;
    9494        else if (valueString.find("false") < valueString.size() || valueString.find("no") < valueString.size())
    95             this->value_bool_ = false;
     95            this->value_.value_bool_ = false;
    9696        else
    9797        {
    9898            // Its not a known word - is it a number?
    9999            std::istringstream istream(valueString);
    100             if (!(istream >> this->value_bool_))
    101             {
    102                 // The conversion failed - use the default value and restore the entry in the config-file
    103                 this->value_bool_ = defvalue;
     100            if (!(istream >> this->value_.value_bool_))
     101            {
     102                // The conversion failed - use the default value and restore the entry in the config-file
     103                this->value_.value_bool_ = defvalue;
    104104                (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
    105105                ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     
    404404
    405405        // Set the values of all types to zero
    406         this->value_int_ = 0;
    407         this->value_double_ = 0.000000;
    408         this->value_bool_ = false;
     406        this->value_.value_int_ = 0;
     407        this->value_.value_double_ = 0.000000;
     408        this->value_.value_bool_ = false;
    409409        this->value_string_ = "";
    410410        this->value_vector2_ = Ogre::Vector2(0, 0);
  • code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.h

    r450 r451  
    6363
    6464            /** @returns the value of the type int. @param value This is only needed to determine the right type. */
    65             inline int getValue(int value)                                      { return this->value_int_; }
     65            inline int getValue(int value)                                      { return this->value_.value_int_; }
    6666            /** @returns the value of the type double. @param value This is only needed to determine the right type. */
    67             inline double getValue(double value)                                { return this->value_double_; }
     67            inline double getValue(double value)                                { return this->value_.value_double_; }
    6868            /** @returns the value of the type bool. @param value This is only needed to determine the right type. */
    69             inline bool getValue(bool value)                                    { return this->value_bool_; }
     69            inline bool getValue(bool value)                                    { return this->value_.value_bool_; }
    7070            /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */
    7171            inline std::string getValue(const std::string& value)               { return this->value_string_; }
     
    8282            std::string         defvalue_;                      //!< The string of the default-variable
    8383
    84             int                 value_int_;                     //!< The value, if the variable is of the type int
    85             double              value_double_;                  //!< The value, if the variable is of the type double
    86             bool                value_bool_;                    //!< The value, if the variable is of the type bool
     84            union MultiType
     85            {
     86                int                 value_int_;                 //!< The value, if the variable is of the type int
     87                double              value_double_;              //!< The value, if the variable is of the type double
     88                bool                value_bool_;                //!< The value, if the variable is of the type bool
     89            } value_;
     90
    8791            std::string         value_string_;                  //!< The value, if the variable is of the type string
    8892            Ogre::Vector2       value_vector2_;                 //!< The value, if the variable is of the type Vector2
Note: See TracChangeset for help on using the changeset viewer.