Changeset 925
- Timestamp:
- Mar 26, 2008, 1:36:35 AM (17 years ago)
- Location:
- code/branches/core2/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/Functor.h
r871 r925 161 161 bool bConstObject_; 162 162 }; 163 164 165 166 #define MAKE_COMMA(x) MAKE_COMMA##x167 #define MAKE_COMMA0168 #define MAKE_COMMA1 ,169 #define MAKE_COMMA2 ,170 #define MAKE_COMMA3 ,171 #define MAKE_COMMA4 ,172 #define MAKE_COMMA5 ,173 163 174 164 -
code/branches/core2/src/util/Convert.h
r871 r925 41 41 #include "MultiTypeMath.h" 42 42 43 44 43 // DEFAULT CLASS 45 44 template <typename FromType, typename ToType> … … 151 150 bool operator()(ToType* output, const MultiTypePrimitive& input) const 152 151 { 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) 154 155 return ConvertValue(output, input.getInt()); 155 156 else if (input.getType() == MT_uint) … … 185 186 bool operator()(std::string* output, const MultiTypePrimitive& input) const 186 187 { 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) 188 191 return ConvertValue(output, input.getInt()); 189 192 else if (input.getType() == MT_uint) … … 225 228 else if (input.getType() == MT_string) 226 229 return ConvertValue(output, input.getString()); 230 else if (input.getType() == MT_xmlelement) 231 return ConvertValue(output, input.getXMLElement()); 227 232 else 228 233 return ConvertValue(output, (MultiTypePrimitive)input); … … 239 244 else if (input.getType() == MT_string) 240 245 return ConvertValue(output, input.getString()); 246 else if (input.getType() == MT_xmlelement) 247 return ConvertValue(output, input.getXMLElement()); 241 248 else 242 249 return ConvertValue(output, (MultiTypePrimitive)input); … … 534 541 }; 535 542 543 544 //////////////// 545 // XMLElement // 546 //////////////// 547 548 // orxonox::Element to std::string 549 template <> 550 class 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 567 template <> 568 class 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 536 582 #endif /* _Convert_H__ */ -
code/branches/core2/src/util/MultiType.h
r871 r925 35 35 { 36 36 MT_null, 37 MT_void, 37 38 MT_int, 38 39 MT_uint, … … 49 50 MT_constchar, 50 51 MT_string, 52 MT_xmlelement, 51 53 MT_vector2, 52 54 MT_vector3, … … 59 61 union _UtilExport MultiTypeValue 60 62 { 63 void* void_; 61 64 int int_; 62 65 unsigned int uint_; -
code/branches/core2/src/util/MultiTypeMath.cc
r871 r925 88 88 } 89 89 90 MultiTypeMath::operator orxonox::BaseObject*() const 91 { return (this->type_ == MT_void) ? (orxonox::BaseObject*)this->value_.void_ : (orxonox::BaseObject*)ConvertValueAndReturn<MultiTypeMath, void*>(*this); } 92 MultiTypeMath::operator void*() const 93 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeMath, void*>(*this); } 90 94 MultiTypeMath::operator int() const 91 95 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeMath, int>(*this); } … … 118 122 MultiTypeMath::operator orxonox::Vector2() const 119 123 { return (this->type_ == MT_vector2) ? this->vector2_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector2>(*this); } 124 MultiTypeMath::operator orxonox::Element() const 125 { return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Element>(*this); } 120 126 MultiTypeMath::operator orxonox::Vector3() const 121 127 { return (this->type_ == MT_vector3) ? this->vector3_ : ConvertValueAndReturn<MultiTypeMath, orxonox::Vector3>(*this); } -
code/branches/core2/src/util/MultiTypeMath.h
r871 r925 38 38 { 39 39 public: 40 MultiTypeMath(MultiType type = MT_null); 40 MultiTypeMath(MultiType type = MT_null); 41 inline MultiTypeMath(void* value) : MultiTypeString(value) {} 41 42 inline MultiTypeMath(int value) : MultiTypeString(value) {} 42 43 inline MultiTypeMath(unsigned int value) : MultiTypeString(value) {} … … 51 52 inline MultiTypeMath(long double value) : MultiTypeString(value) {} 52 53 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) {} 55 57 inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } 56 58 inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } … … 89 91 bool operator!=(const MultiTypeMath& mtm) const; 90 92 93 virtual operator orxonox::BaseObject*() const; 94 virtual operator void*() const; 91 95 virtual operator int() const; 92 96 virtual operator unsigned int() const; … … 103 107 virtual operator std::string() const; 104 108 virtual operator const char*() const; 109 virtual operator orxonox::Element() const; 105 110 virtual operator orxonox::Vector2() const; 106 111 virtual operator orxonox::Vector3() const; -
code/branches/core2/src/util/MultiTypePrimitive.cc
r871 r925 34 34 this->type_ = type; 35 35 36 if (type == MT_int) 36 if (type == MT_void) 37 this->value_.void_ = 0; 38 else if (type == MT_int) 37 39 this->value_.int_ = 0; 38 40 else if (type == MT_uint) … … 59 61 this->value_.bool_ = false; 60 62 else 61 this->value_. int_ = 0;63 this->value_.void_ = 0; 62 64 } 63 65 … … 66 68 if (this->type_ == mtp.type_) 67 69 { 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) 69 73 return (this->value_.int_ == mtp.value_.int_); 70 74 else if (this->type_ == MT_uint) … … 99 103 if (this->type_ == mtp.type_) 100 104 { 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) 102 108 return (this->value_.int_ != mtp.value_.int_); 103 109 else if (this->type_ == MT_uint) … … 128 134 } 129 135 136 MultiTypePrimitive::operator orxonox::BaseObject*() const 137 { return (this->type_ == MT_void) ? (orxonox::BaseObject*)this->value_.void_ : (orxonox::BaseObject*)ConvertValueAndReturn<MultiTypePrimitive, void*>(*this); } 138 MultiTypePrimitive::operator void*() const 139 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypePrimitive, void*>(*this); } 130 140 MultiTypePrimitive::operator int() const 131 141 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypePrimitive, int>(*this); } … … 163 173 std::string output; 164 174 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) 166 178 ConvertValue(&output, this->value_.int_); 167 179 else if (this->type_ == MT_uint) … … 193 205 bool MultiTypePrimitive::fromString(const std::string value) 194 206 { 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) 196 210 return ConvertValue(&this->value_.int_, value, (int)0); 197 211 else if (this->type_ == MT_uint) -
code/branches/core2/src/util/MultiTypePrimitive.h
r871 r925 36 36 #include "MultiType.h" 37 37 38 namespace orxonox 39 { 40 class BaseObject; 41 } 38 42 class _UtilExport MultiTypePrimitive 39 43 { 40 44 public: 41 MultiTypePrimitive(MultiType type = MT_null); 45 MultiTypePrimitive(MultiType type = MT_null); 46 inline MultiTypePrimitive(void* value) { this->setValue(value); } 42 47 inline MultiTypePrimitive(int value) { this->setValue(value); } 43 48 inline MultiTypePrimitive(unsigned int value) { this->setValue(value); } … … 56 61 57 62 inline MultiTypePrimitive& operator=(MultiType value) { this->type_ = MT_null; return *this; } 63 inline MultiTypePrimitive& operator=(void* value) { this->setValue(value); return *this; } 58 64 inline MultiTypePrimitive& operator=(int value) { this->setValue(value); return *this; } 59 65 inline MultiTypePrimitive& operator=(unsigned int value) { this->setValue(value); return *this; } … … 70 76 inline MultiTypePrimitive& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; } 71 77 78 inline bool operator==(void* value) const { return (this->value_.void_ == value); } 72 79 inline bool operator==(int value) const { return (this->value_.int_ == value); } 73 80 inline bool operator==(unsigned int value) const { return (this->value_.uint_ == value); } … … 84 91 bool operator==(const MultiTypePrimitive& mtp) const; 85 92 86 inline bool operator!=( int value) const { return (this->value_.int_!= value); }93 inline bool operator!=(void* value) const { return (this->value_.void_ != value); } 87 94 inline bool operator!=(unsigned int value) const { return (this->value_.uint_ != value); } 88 95 inline bool operator!=(char value) const { return (this->value_.char_ != value); } … … 98 105 bool operator!=(const MultiTypePrimitive& mtp) const; 99 106 107 virtual operator orxonox::BaseObject*() const; 108 virtual operator void*() const; 100 109 virtual operator int() const; 101 110 virtual operator unsigned int() const; … … 111 120 virtual operator bool() const; 112 121 122 inline void setValue(void* value) { this->type_ = MT_void; this->value_.void_ = value; } 113 123 inline void setValue(int value) { this->type_ = MT_int; this->value_.int_ = value; } 114 124 inline void setValue(unsigned int value) { this->type_ = MT_uint; this->value_.uint_ = value; } … … 125 135 void setValue(const MultiTypePrimitive& mtp); 126 136 137 inline void* getVoid() const { return this->value_.void_; } 127 138 inline int getInt() const { return this->value_.int_; } 128 139 inline unsigned int getUnsignedInt() const { return this->value_.uint_; } … … 151 162 inline bool& getBool() { return this->value_.bool_; } 152 163 164 inline void getValue(void* variable) const { variable = this->value_.void_; } 153 165 inline void getValue(int* variable) const { (*variable) = this->value_.int_; } 154 166 inline void getValue(unsigned int* variable) const { (*variable) = this->value_.uint_; } -
code/branches/core2/src/util/MultiTypeString.cc
r871 r925 46 46 else if (this->type_ == MT_string) 47 47 return (this->string_ == mts.string_); 48 else if (this->type_ == MT_xmlelement) 49 return (&this->xmlelement_ == &mts.xmlelement_); 48 50 } 49 51 … … 59 61 else if (this->type_ == MT_string) 60 62 return (this->string_ != mts.string_); 63 else if (this->type_ == MT_xmlelement) 64 return (&this->xmlelement_ != &mts.xmlelement_); 61 65 } 62 66 … … 64 68 } 65 69 70 MultiTypeString::operator orxonox::BaseObject*() const 71 { return (this->type_ == MT_void) ? (orxonox::BaseObject*)this->value_.void_ : (orxonox::BaseObject*)ConvertValueAndReturn<MultiTypeString, void*>(*this); } 72 MultiTypeString::operator void*() const 73 { return (this->type_ == MT_void) ? this->value_.void_ : ConvertValueAndReturn<MultiTypeString, void*>(*this); } 66 74 MultiTypeString::operator int() const 67 75 { return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this); } … … 92 100 MultiTypeString::operator const char*() const 93 101 { return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this)).c_str(); } 102 MultiTypeString::operator orxonox::Element() const 103 { return (this->type_ == MT_xmlelement) ? this->xmlelement_ : ConvertValueAndReturn<MultiTypeString, orxonox::Element>(*this); } 94 104 95 105 void MultiTypeString::setValue(const MultiTypeString& mts) … … 101 111 std::string MultiTypeString::toString() const 102 112 { 113 std::string output; 114 103 115 if (this->type_ == MT_constchar) 104 116 return this->string_; 105 117 else if (this->type_ == MT_string) 106 118 return this->string_; 119 else if (this->type_ == MT_xmlelement) 120 ConvertValue(&output, this->xmlelement_); 107 121 else 108 122 return MultiTypePrimitive::toString(); 123 124 return output; 109 125 } 110 126 … … 115 131 else if (this->type_ == MT_string) 116 132 this->string_ = value; 133 else if (this->type_ == MT_xmlelement) 134 return ConvertValue(&this->xmlelement_, value, orxonox::Element()); 117 135 else 118 136 return MultiTypePrimitive::fromString(value); -
code/branches/core2/src/util/MultiTypeString.h
r871 r925 33 33 #include <iostream> 34 34 #include "UtilPrereqs.h" 35 #include "XMLIncludes.h" 36 #include "tinyxml/ticpp.h" 35 37 36 38 #include "MultiTypePrimitive.h" … … 39 41 { 40 42 public: 41 MultiTypeString(MultiType type = MT_null); 43 MultiTypeString(MultiType type = MT_null); 44 inline MultiTypeString(void* value) : MultiTypePrimitive(value) {} 42 45 inline MultiTypeString(int value) : MultiTypePrimitive(value) {} 43 46 inline MultiTypeString(unsigned int value) : MultiTypePrimitive(value) {} … … 52 55 inline MultiTypeString(long double value) : MultiTypePrimitive(value) {} 53 56 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); } 57 61 virtual inline ~MultiTypeString() {} 58 62 59 63 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; } 63 68 64 69 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); } 67 73 bool operator==(const MultiTypeString& mts) const; 68 74 69 75 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); } 72 79 bool operator!=(const MultiTypeString& mts) const; 73 80 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; 88 98 89 99 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; } 92 103 void setValue(const MultiTypeString& mts); 93 104 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_; } 96 108 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_; } 99 112 100 113 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_; } 103 117 104 118 virtual std::string toString() const; … … 106 120 107 121 protected: 108 std::string string_; 122 std::string string_; 123 orxonox::Element xmlelement_; 109 124 }; 110 125 -
code/branches/core2/src/util/tinyxml/ticpp.h
r871 r925 973 973 Stream output operator. 974 974 */ 975 friend std::ostream& operator <<( std::ostream& out, Node& base )975 friend std::ostream& operator <<( std::ostream& out, const Node& base ) 976 976 { 977 977 out << *base.GetTiXmlPointer();
Note: See TracChangeset
for help on using the changeset viewer.