Changeset 827 for code/branches/core/src
- Timestamp:
- Feb 18, 2008, 12:54:30 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/util/Convert.h
r792 r827 37 37 38 38 #include "UtilPrereqs.h" 39 #include "Math.h" 39 40 40 41 // DEFAULT CLASS … … 42 43 class _UtilExport Converter 43 44 { 44 public:45 bool operator()(ToType* output, const FromType& input) const46 {47 return false;48 }45 public: 46 bool operator()(ToType* output, const FromType& input) const 47 { 48 return false; 49 } 49 50 }; 50 51 … … 53 54 class _UtilExport Converter<FromType, std::string> 54 55 { 55 public: 56 bool operator()(std::string* output, const FromType& input) const 57 { 58 std::ostringstream oss; 59 if (oss << input) 56 public: 57 bool operator()(std::string* output, const FromType& input) const 60 58 { 61 (*output) = oss.str(); 62 return true; 59 std::ostringstream oss; 60 if (oss << input) 61 { 62 (*output) = oss.str(); 63 return true; 64 } 65 else 66 return false; 63 67 } 64 else65 return false;66 }67 68 }; 68 69 … … 71 72 class _UtilExport Converter<std::string, ToType> 72 73 { 73 public:74 bool operator()(ToType* output, const std::string& input) const75 {76 std::istringstream iss(input);77 if (iss >> (*output))78 return true;79 else80 return false;81 }74 public: 75 bool operator()(ToType* output, const std::string& input) const 76 { 77 std::istringstream iss(input); 78 if (iss >> (*output)) 79 return true; 80 else 81 return false; 82 } 82 83 }; 83 84 … … 102 103 } 103 104 105 106 107 // MORE SPECIALISATIONS 108 // Vector2 to std::string 109 template <> 110 class _UtilExport Converter<orxonox::Vector2, std::string> 111 { 112 public: 113 bool operator()(std::string* output, const orxonox::Vector2& input) const 114 { 115 std::ostringstream ostream; 116 if (ostream << input.x << "," << input.y) 117 { 118 (*output) = ostream.str(); 119 return true; 120 } 121 122 return false; 123 } 124 }; 125 126 // Vector3 to std::string 127 template <> 128 class _UtilExport Converter<orxonox::Vector3, std::string> 129 { 130 public: 131 bool operator()(std::string* output, const orxonox::Vector3& input) const 132 { 133 std::ostringstream ostream; 134 if (ostream << input.x << "," << input.y << "," << input.z) 135 { 136 (*output) = ostream.str(); 137 return true; 138 } 139 140 return false; 141 } 142 }; 143 144 // Vector4 to std::string 145 template <> 146 class _UtilExport Converter<orxonox::Vector4, std::string> 147 { 148 public: 149 bool operator()(std::string* output, const orxonox::Vector4& input) const 150 { 151 std::ostringstream ostream; 152 if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w) 153 { 154 (*output) = ostream.str(); 155 return true; 156 } 157 158 return false; 159 } 160 }; 161 162 // Quaternion to std::string 163 template <> 164 class _UtilExport Converter<orxonox::Quaternion, std::string> 165 { 166 public: 167 bool operator()(std::string* output, const orxonox::Quaternion& input) const 168 { 169 std::ostringstream ostream; 170 if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z) 171 { 172 (*output) = ostream.str(); 173 return true; 174 } 175 176 return false; 177 } 178 }; 179 180 // ColourValue to std::string 181 template <> 182 class _UtilExport Converter<orxonox::ColourValue, std::string> 183 { 184 public: 185 bool operator()(std::string* output, const orxonox::ColourValue& input) const 186 { 187 std::ostringstream ostream; 188 if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a) 189 { 190 (*output) = ostream.str(); 191 return true; 192 } 193 194 return false; 195 } 196 }; 197 104 198 #endif /* _Convert_H__ */
Note: See TracChangeset
for help on using the changeset viewer.