Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 925


Ignore:
Timestamp:
Mar 26, 2008, 1:36:35 AM (16 years ago)
Author:
landauf
Message:
  • the MultiTypes can now handle pointers and xml-elements
  • added a const keyword in the ticpp.h file (TinyXML++)
Location:
code/branches/core2/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/Functor.h

    r871 r925  
    161161        bool bConstObject_;
    162162};
    163 
    164 
    165 
    166 #define MAKE_COMMA(x) MAKE_COMMA##x
    167 #define MAKE_COMMA0
    168 #define MAKE_COMMA1 ,
    169 #define MAKE_COMMA2 ,
    170 #define MAKE_COMMA3 ,
    171 #define MAKE_COMMA4 ,
    172 #define MAKE_COMMA5 ,
    173163
    174164
  • code/branches/core2/src/util/Convert.h

    r871 r925  
    4141#include "MultiTypeMath.h"
    4242
    43 
    4443// DEFAULT CLASS
    4544template <typename FromType, typename ToType>
     
    151150    bool operator()(ToType* output, const MultiTypePrimitive& input) const
    152151    {
    153       if (input.getType() == MT_int)
     152      if (input.getType() == MT_void)
     153        return ConvertValue(output, input.getVoid());
     154      else if (input.getType() == MT_int)
    154155        return ConvertValue(output, input.getInt());
    155156      else if (input.getType() == MT_uint)
     
    185186    bool operator()(std::string* output, const MultiTypePrimitive& input) const
    186187    {
    187       if (input.getType() == MT_int)
     188      if (input.getType() == MT_void)
     189        return ConvertValue(output, input.getVoid());
     190      else if (input.getType() == MT_int)
    188191        return ConvertValue(output, input.getInt());
    189192      else if (input.getType() == MT_uint)
     
    225228      else if (input.getType() == MT_string)
    226229        return ConvertValue(output, input.getString());
     230      else if (input.getType() == MT_xmlelement)
     231        return ConvertValue(output, input.getXMLElement());
    227232      else
    228233        return ConvertValue(output, (MultiTypePrimitive)input);
     
    239244      else if (input.getType() == MT_string)
    240245        return ConvertValue(output, input.getString());
     246      else if (input.getType() == MT_xmlelement)
     247        return ConvertValue(output, input.getXMLElement());
    241248      else
    242249        return ConvertValue(output, (MultiTypePrimitive)input);
     
    534541};
    535542
     543
     544////////////////
     545// XMLElement //
     546////////////////
     547
     548// orxonox::Element to std::string
     549template <>
     550class Converter<orxonox::Element, std::string>
     551{
     552  public:
     553    bool operator()(std::string* output, const orxonox::Element& input) const
     554    {
     555      std::ostringstream ostream;
     556      if (ostream << input)
     557      {
     558        (*output) = ostream.str();
     559        return true;
     560      }
     561
     562      return false;
     563    }
     564};
     565
     566// std::string to orxonox::Element
     567template <>
     568class Converter<std::string, orxonox::Element>
     569{
     570  public:
     571    bool operator()(orxonox::Element* output, const std::string& input) const
     572    {
     573      std::istringstream istream(input);
     574      if (istream >> (*output))
     575        return true;
     576
     577      return false;
     578    }
     579};
     580
     581
    536582#endif /* _Convert_H__ */
  • code/branches/core2/src/util/MultiType.h

    r871 r925  
    3535{
    3636    MT_null,
     37    MT_void,
    3738    MT_int,
    3839    MT_uint,
     
    4950    MT_constchar,
    5051    MT_string,
     52    MT_xmlelement,
    5153    MT_vector2,
    5254    MT_vector3,
     
    5961union _UtilExport MultiTypeValue
    6062{
     63    void*           void_;
    6164    int             int_;
    6265    unsigned int    uint_;
  • code/branches/core2/src/util/MultiTypeMath.cc

    r871 r925  
    8888}
    8989
     90MultiTypeMath::operator orxonox::BaseObject*() const
     91{ return (this->type_ == MT_void) ? (orxonox::BaseObject*)this->value_.void_ : (orxonox::BaseObject*)ConvertValueAndReturn<MultiTypeMath, void*>(*this); }
     92MultiTypeMath::operator void*() const
     93{ return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeMath, void*>(*this); }
    9094MultiTypeMath::operator int() const
    9195{ return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this); }
     
    118122MultiTypeMath::operator orxonox::Vector2() const
    119123{ return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector2>(*this); }
     124MultiTypeMath::operator orxonox::Element() const
     125{ return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Element>(*this); }
    120126MultiTypeMath::operator orxonox::Vector3() const
    121127{ return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector3>(*this); }
  • code/branches/core2/src/util/MultiTypeMath.h

    r871 r925  
    3838{
    3939    public:
    40         MultiTypeMath(MultiType      type = MT_null);
     40        MultiTypeMath(MultiType type = MT_null);
     41        inline MultiTypeMath(void*          value) : MultiTypeString(value) {}
    4142        inline MultiTypeMath(int            value) : MultiTypeString(value) {}
    4243        inline MultiTypeMath(unsigned int   value) : MultiTypeString(value) {}
     
    5152        inline MultiTypeMath(long double    value) : MultiTypeString(value) {}
    5253        inline MultiTypeMath(bool           value) : MultiTypeString(value) {}
    53         inline MultiTypeMath(const char*        value) : MultiTypeString(value) {}
    54         inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {}
     54        inline MultiTypeMath(const char*             value) : MultiTypeString(value) {}
     55        inline MultiTypeMath(const std::string&      value) : MultiTypeString(value) {}
     56        inline MultiTypeMath(const orxonox::Element& value) : MultiTypeString(value) {}
    5557        inline MultiTypeMath(const orxonox::Vector2&     value) { this->setValue(value); }
    5658        inline MultiTypeMath(const orxonox::Vector3&     value) { this->setValue(value); }
     
    8991        bool operator!=(const MultiTypeMath& mtm) const;
    9092
     93        virtual operator orxonox::BaseObject*()          const;
     94        virtual operator void*()                const;
    9195        virtual operator int()                  const;
    9296        virtual operator unsigned int()         const;
     
    103107        virtual operator std::string()          const;
    104108        virtual operator const char*()          const;
     109        virtual operator orxonox::Element()     const;
    105110        virtual operator orxonox::Vector2()     const;
    106111        virtual operator orxonox::Vector3()     const;
  • code/branches/core2/src/util/MultiTypePrimitive.cc

    r871 r925  
    3434    this->type_ = type;
    3535
    36     if (type == MT_int)
     36    if (type == MT_void)
     37        this->value_.void_ = 0;
     38    else if (type == MT_int)
    3739        this->value_.int_ = 0;
    3840    else if (type == MT_uint)
     
    5961        this->value_.bool_ = false;
    6062    else
    61         this->value_.int_ = 0;
     63        this->value_.void_ = 0;
    6264}
    6365
     
    6668    if (this->type_ == mtp.type_)
    6769    {
    68         if (this->type_ == MT_int)
     70        if (this->type_ == MT_void)
     71            return (this->value_.void_ == mtp.value_.void_);
     72        else if (this->type_ == MT_int)
    6973            return (this->value_.int_ == mtp.value_.int_);
    7074        else if (this->type_ == MT_uint)
     
    99103    if (this->type_ == mtp.type_)
    100104    {
    101         if (this->type_ == MT_int)
     105        if (this->type_ == MT_void)
     106            return (this->value_.void_ != mtp.value_.void_);
     107        else if (this->type_ == MT_int)
    102108            return (this->value_.int_ != mtp.value_.int_);
    103109        else if (this->type_ == MT_uint)
     
    128134}
    129135
     136MultiTypePrimitive::operator orxonox::BaseObject*() const
     137{ return (this->type_ == MT_void) ? (orxonox::BaseObject*)this->value_.void_ : (orxonox::BaseObject*)ConvertValueAndReturn<MultiTypePrimitive, void*>(*this); }
     138MultiTypePrimitive::operator void*() const
     139{ return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypePrimitive, void*>(*this); }
    130140MultiTypePrimitive::operator int() const
    131141{ return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this); }
     
    163173    std::string output;
    164174
    165     if (this->type_ == MT_int)
     175    if (this->type_ == MT_void)
     176        ConvertValue(&output, this->value_.void_);
     177    else if (this->type_ == MT_int)
    166178        ConvertValue(&output, this->value_.int_);
    167179    else if (this->type_ == MT_uint)
     
    193205bool MultiTypePrimitive::fromString(const std::string value)
    194206{
    195     if (this->type_ == MT_int)
     207    if (this->type_ == MT_void)
     208        return ConvertValue(&this->value_.void_, value, (void*)0);
     209    else if (this->type_ == MT_int)
    196210        return ConvertValue(&this->value_.int_, value, (int)0);
    197211    else if (this->type_ == MT_uint)
  • code/branches/core2/src/util/MultiTypePrimitive.h

    r871 r925  
    3636#include "MultiType.h"
    3737
     38namespace orxonox
     39{
     40    class BaseObject;
     41}
    3842class _UtilExport MultiTypePrimitive
    3943{
    4044    public:
    41         MultiTypePrimitive(MultiType      type = MT_null);
     45        MultiTypePrimitive(MultiType type = MT_null);
     46        inline MultiTypePrimitive(void*          value) { this->setValue(value); }
    4247        inline MultiTypePrimitive(int            value) { this->setValue(value); }
    4348        inline MultiTypePrimitive(unsigned int   value) { this->setValue(value); }
     
    5661
    5762        inline MultiTypePrimitive& operator=(MultiType      value) { this->type_ = MT_null; return *this; }
     63        inline MultiTypePrimitive& operator=(void*          value) { this->setValue(value); return *this; }
    5864        inline MultiTypePrimitive& operator=(int            value) { this->setValue(value); return *this; }
    5965        inline MultiTypePrimitive& operator=(unsigned int   value) { this->setValue(value); return *this; }
     
    7076        inline MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; }
    7177
     78        inline bool operator==(void*          value) const { return (this->value_.void_       == value); }
    7279        inline bool operator==(int            value) const { return (this->value_.int_        == value); }
    7380        inline bool operator==(unsigned int   value) const { return (this->value_.uint_       == value); }
     
    8491        bool operator==(const MultiTypePrimitive& mtp) const;
    8592
    86         inline bool operator!=(int            value) const { return (this->value_.int_        != value); }
     93        inline bool operator!=(void*          value) const { return (this->value_.void_       != value); }
    8794        inline bool operator!=(unsigned int   value) const { return (this->value_.uint_       != value); }
    8895        inline bool operator!=(char           value) const { return (this->value_.char_       != value); }
     
    98105        bool operator!=(const MultiTypePrimitive& mtp) const;
    99106
     107        virtual operator orxonox::BaseObject*()    const;
     108        virtual operator void*()          const;
    100109        virtual operator int()            const;
    101110        virtual operator unsigned int()   const;
     
    111120        virtual operator bool()           const;
    112121
     122        inline void setValue(void*          value) { this->type_ = MT_void;       this->value_.void_       = value; }
    113123        inline void setValue(int            value) { this->type_ = MT_int;        this->value_.int_        = value; }
    114124        inline void setValue(unsigned int   value) { this->type_ = MT_uint;       this->value_.uint_       = value; }
     
    125135        void setValue(const MultiTypePrimitive& mtp);
    126136
     137        inline void*          getVoid()          const { return this->value_.void_;        }
    127138        inline int            getInt()           const { return this->value_.int_;        }
    128139        inline unsigned int   getUnsignedInt()   const { return this->value_.uint_;       }
     
    151162        inline bool&           getBool()          { return this->value_.bool_;       }
    152163
     164        inline void getValue(void*           variable) const { variable    = this->value_.void_;       }
    153165        inline void getValue(int*            variable) const { (*variable) = this->value_.int_;        }
    154166        inline void getValue(unsigned int*   variable) const { (*variable) = this->value_.uint_;       }
  • code/branches/core2/src/util/MultiTypeString.cc

    r871 r925  
    4646        else if (this->type_ == MT_string)
    4747            return (this->string_ == mts.string_);
     48        else if (this->type_ == MT_xmlelement)
     49            return (&this->xmlelement_ == &mts.xmlelement_);
    4850    }
    4951
     
    5961        else if (this->type_ == MT_string)
    6062            return (this->string_ != mts.string_);
     63        else if (this->type_ == MT_xmlelement)
     64            return (&this->xmlelement_ != &mts.xmlelement_);
    6165    }
    6266
     
    6468}
    6569
     70MultiTypeString::operator orxonox::BaseObject*() const
     71{ return (this->type_ == MT_void) ? (orxonox::BaseObject*)this->value_.void_ : (orxonox::BaseObject*)ConvertValueAndReturn<MultiTypeString, void*>(*this); }
     72MultiTypeString::operator void*() const
     73{ return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeString, void*>(*this); }
    6674MultiTypeString::operator int() const
    6775{ return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this); }
     
    92100MultiTypeString::operator const char*() const
    93101{ return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this)).c_str(); }
     102MultiTypeString::operator orxonox::Element() const
     103{ return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeString, orxonox::Element>(*this); }
    94104
    95105void MultiTypeString::setValue(const MultiTypeString& mts)
     
    101111std::string MultiTypeString::toString() const
    102112{
     113    std::string output;
     114
    103115    if (this->type_ == MT_constchar)
    104116        return this->string_;
    105117    else if (this->type_ == MT_string)
    106118        return this->string_;
     119    else if (this->type_ == MT_xmlelement)
     120        ConvertValue(&output, this->xmlelement_);
    107121    else
    108122        return MultiTypePrimitive::toString();
     123
     124    return output;
    109125}
    110126
     
    115131    else if (this->type_ == MT_string)
    116132        this->string_ = value;
     133    else if (this->type_ == MT_xmlelement)
     134        return ConvertValue(&this->xmlelement_, value, orxonox::Element());
    117135    else
    118136        return MultiTypePrimitive::fromString(value);
  • code/branches/core2/src/util/MultiTypeString.h

    r871 r925  
    3333#include <iostream>
    3434#include "UtilPrereqs.h"
     35#include "XMLIncludes.h"
     36#include "tinyxml/ticpp.h"
    3537
    3638#include "MultiTypePrimitive.h"
     
    3941{
    4042    public:
    41         MultiTypeString(MultiType      type = MT_null);
     43        MultiTypeString(MultiType type = MT_null);
     44        inline MultiTypeString(void*          value) : MultiTypePrimitive(value) {}
    4245        inline MultiTypeString(int            value) : MultiTypePrimitive(value) {}
    4346        inline MultiTypeString(unsigned int   value) : MultiTypePrimitive(value) {}
     
    5255        inline MultiTypeString(long double    value) : MultiTypePrimitive(value) {}
    5356        inline MultiTypeString(bool           value) : MultiTypePrimitive(value) {}
    54         inline MultiTypeString(const char*        value)   { this->setValue(value); }
    55         inline MultiTypeString(const std::string& value)   { this->setValue(value); }
    56         inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts);   }
     57        inline MultiTypeString(const char*           value)   { this->setValue(value); }
     58        inline MultiTypeString(const std::string&    value)   { this->setValue(value); }
     59        inline MultiTypeString(const orxonox::Element& value) { this->setValue(value); }
     60        inline MultiTypeString(const MultiTypeString& mts)    { this->setValue(mts);   }
    5761        virtual inline ~MultiTypeString() {}
    5862
    5963        using MultiTypePrimitive::operator=;
    60         inline MultiTypeString& operator=(const char*        value)   { this->setValue(value); return *this; }
    61         inline MultiTypeString& operator=(const std::string& value)   { this->setValue(value); return *this; }
    62         inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts);   return *this; }
     64        inline MultiTypeString& operator=(const char*             value)   { this->setValue(value); return *this; }
     65        inline MultiTypeString& operator=(const std::string&      value)   { this->setValue(value); return *this; }
     66        inline MultiTypeString& operator=(const orxonox::Element& value)   { this->setValue(value); return *this; }
     67        inline MultiTypeString& operator=(const MultiTypeString& mts)      { this->setValue(mts);   return *this; }
    6368
    6469        using MultiTypePrimitive::operator==;
    65         inline bool operator==(const char*        value) const { return (this->string_ == std::string(value)); }
    66         inline bool operator==(const std::string& value) const { return (this->string_ == value);              }
     70        inline bool operator==(const char*             value) const { return (this->string_      == std::string(value)); }
     71        inline bool operator==(const std::string&      value) const { return (this->string_      == value);              }
     72        inline bool operator==(const orxonox::Element& value) const { return (&this->xmlelement_ == &value);             }
    6773        bool operator==(const MultiTypeString& mts) const;
    6874
    6975        using MultiTypePrimitive::operator!=;
    70         inline bool operator!=(const char*        value) const { return (this->string_ != std::string(value)); }
    71         inline bool operator!=(const std::string& value) const { return (this->string_ != value);              }
     76        inline bool operator!=(const char*             value) const { return (this->string_      != std::string(value)); }
     77        inline bool operator!=(const std::string&      value) const { return (this->string_      != value);              }
     78        inline bool operator!=(const orxonox::Element& value) const { return (&this->xmlelement_ != &value);             }
    7279        bool operator!=(const MultiTypeString& mts) const;
    7380
    74         virtual operator int()            const;
    75         virtual operator unsigned int()   const;
    76         virtual operator char()           const;
    77         virtual operator unsigned char()  const;
    78         virtual operator short()          const;
    79         virtual operator unsigned short() const;
    80         virtual operator long()           const;
    81         virtual operator unsigned long()  const;
    82         virtual operator float ()         const;
    83         virtual operator double ()        const;
    84         virtual operator long double()    const;
    85         virtual operator bool()           const;
    86         virtual operator std::string()    const;
    87         virtual operator const char*()    const;
     81        virtual operator orxonox::BaseObject*() const;
     82        virtual operator void*()                const;
     83        virtual operator int()                  const;
     84        virtual operator unsigned int()         const;
     85        virtual operator char()                 const;
     86        virtual operator unsigned char()        const;
     87        virtual operator short()                const;
     88        virtual operator unsigned short()       const;
     89        virtual operator long()                 const;
     90        virtual operator unsigned long()        const;
     91        virtual operator float ()               const;
     92        virtual operator double ()              const;
     93        virtual operator long double()          const;
     94        virtual operator bool()                 const;
     95        virtual operator std::string()          const;
     96        virtual operator const char*()          const;
     97        virtual operator orxonox::Element()     const;
    8898
    8999        using MultiTypePrimitive::setValue;
    90         inline void setValue(const char*        value) { this->type_ = MT_string; this->string_ = std::string(value); }
    91         inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value;              }
     100        inline void setValue(const char*             value) { this->type_ = MT_string;     this->string_     = std::string(value); }
     101        inline void setValue(const std::string&      value) { this->type_ = MT_string;     this->string_     = value;              }
     102        inline void setValue(const orxonox::Element& value) { this->type_ = MT_xmlelement; this->xmlelement_ = value;              }
    92103        void setValue(const MultiTypeString& mts);
    93104
    94         inline const std::string getString() const { return this->string_;         }
    95         inline const char*  getConstChar()   const { return this->string_.c_str(); }
     105        inline std::string getString()          const { return this->string_;         }
     106        inline const char*  getConstChar()      const { return this->string_.c_str(); }
     107        inline orxonox::Element getXMLElement() const { return this->xmlelement_;     }
    96108
    97         inline const std::string& getString() { return this->string_;         }
    98         inline const char*  getConstChar()    { return this->string_.c_str(); }
     109        inline std::string& getString()          { return this->string_;         }
     110        inline const char*  getConstChar()       { return this->string_.c_str(); }
     111        inline orxonox::Element& getXMLElement() { return this->xmlelement_;     }
    99112
    100113        using MultiTypePrimitive::getValue;
    101         inline void getValue(std::string* variable) const { (*variable) = this->string_;         }
    102         inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); }
     114        inline void getValue(std::string*      variable) const { (*variable) = this->string_;         }
     115        inline void getValue(const char**      variable) const { (*variable) = this->string_.c_str(); }
     116        inline void getValue(orxonox::Element* variable) const { (*variable) = this->xmlelement_;     }
    103117
    104118        virtual std::string toString() const;
     
    106120
    107121    protected:
    108         std::string string_;
     122        std::string      string_;
     123        orxonox::Element xmlelement_;
    109124};
    110125
  • code/branches/core2/src/util/tinyxml/ticpp.h

    r871 r925  
    973973                Stream output operator.
    974974                */
    975                 friend std::ostream& operator <<( std::ostream& out, Node& base )
     975                friend std::ostream& operator <<( std::ostream& out, const Node& base )
    976976                {
    977977                        out << *base.GetTiXmlPointer();
Note: See TracChangeset for help on using the changeset viewer.