00001 #include "X3DTypes.h" 00002 00003 #include <sstream> 00004 00005 using namespace X3DTK; 00006 using namespace std; 00007 00008 MFString::MFString(const SFString &s) 00009 { 00010 string token; 00011 string::const_iterator itChar = s.begin(); 00012 size_t counter = 0; 00013 size_t begin = 0; 00014 size_t size = 0; 00015 00016 while (itChar != s.end()) 00017 { 00018 if (*itChar == '\"') 00019 { 00020 ++itChar; 00021 ++counter; 00022 begin = counter; 00023 size = 0; 00024 00025 while ((*itChar != '\"') && (itChar != s.end())) 00026 { 00027 ++itChar; 00028 ++counter; 00029 ++size; 00030 } 00031 token = s.substr(begin, size); 00032 this->push_back(token); 00033 } 00034 ++itChar; 00035 ++counter; 00036 } 00037 } 00038 00039 MFBool::MFBool(const SFString &s) 00040 { 00041 istringstream iss(s, istringstream::in); 00042 bool b; 00043 while (!iss.eof()) 00044 { 00045 iss >> b; 00046 this->push_back(b); 00047 } 00048 } 00049 00050 MFInt32::MFInt32(size_type n, const SFInt32 &V) 00051 : vector<SFInt32>(n, V) 00052 { 00053 } 00054 00055 MFInt32::MFInt32(const SFString &s) 00056 { 00057 istringstream iss(s, istringstream::in); 00058 SFInt32 i; 00059 while (!iss.eof()) 00060 { 00061 iss >> i; 00062 this->push_back(i); 00063 } 00064 } 00065 00066 MFFloat::MFFloat(size_type n, const SFFloat &V) 00067 : vector<SFFloat>(n, V) 00068 { 00069 } 00070 00071 MFFloat::MFFloat(const SFString &s) 00072 { 00073 istringstream iss(s, istringstream::in); 00074 SFFloat f; 00075 while (!iss.eof()) 00076 { 00077 iss >> f; 00078 this->push_back(f); 00079 } 00080 } 00081 00082 MFDouble::MFDouble(const SFString &s) 00083 { 00084 istringstream iss(s, istringstream::in); 00085 SFDouble d; 00086 while (!iss.eof()) 00087 { 00088 iss >> d; 00089 this->push_back(d); 00090 } 00091 } 00092 00093 SFColorRGBA::SFColorRGBA(SFFloat r, SFFloat g, SFFloat b, SFFloat a) 00094 { 00095 this->r = r; 00096 this->g = g; 00097 this->b = b; 00098 this->a = a; 00099 } 00100 00101 bool X3DTK::operator== (const SFColorRGBA &r1, const SFColorRGBA &r2) 00102 { 00103 return ((r1.r == r2.r) && (r1.g == r2.g) && (r1.b == r2.b) && (r1.a == r2.a)); 00104 } 00105 00106 bool X3DTK::operator!= (const SFColorRGBA &r1, const SFColorRGBA &r2) 00107 { 00108 return ((r1.r != r2.r) || (r1.g != r2.g) || (r1.b != r2.b) || (r1.a != r2.a)); 00109 } 00110 00111 00112 SFColorRGBA::SFColorRGBA(const SFString &s) 00113 { 00114 istringstream iss(s, istringstream::in); 00115 iss >> r >> g >> b >> a; 00116 } 00117 00118 SFString toSFString(const SFColorRGBA c) 00119 { 00120 return SFString::number(c.r) + SFString(" ") 00121 + SFString::number(c.g) + SFString(" ") 00122 + SFString::number(c.b) + SFString(" ") 00123 + SFString::number(c.a); 00124 } 00125 00126 MFColorRGBA::MFColorRGBA(size_type n, const SFColorRGBA &C) 00127 : vector<SFColorRGBA>(n, C) 00128 { 00129 } 00130 00131 MFColorRGBA::MFColorRGBA(const SFString &s) 00132 { 00133 SFString copy(s); 00134 replace(copy.begin(), copy.end(), ',', ' '); 00135 istringstream iss(copy, istringstream::in); 00136 while (!iss.eof()) 00137 { 00138 SFColorRGBA c; 00139 iss >> c.r >> c.g >> c.b >> c.a; 00140 this->push_back(c); 00141 } 00142 } 00143 00144 SFColor::SFColor(SFFloat r, SFFloat g, SFFloat b) 00145 { 00146 this->r = r; 00147 this->g = g; 00148 this->b = b; 00149 }; 00150 00151 bool X3DTK::operator== (const SFColor &r1, const SFColor &r2) 00152 { 00153 return ((r1.r == r2.r) && (r1.g == r2.g) && (r1.b == r2.b)); 00154 } 00155 00156 bool X3DTK::operator!= (const SFColor &r1, const SFColor &r2) 00157 { 00158 return ((r1.r != r2.r) || (r1.g != r2.g) || (r1.b != r2.b)); 00159 } 00160 00161 SFColor::SFColor(const SFString &s) 00162 { 00163 istringstream iss(s, istringstream::in); 00164 iss >> r >> g >> b; 00165 } 00166 00167 SFColor::operator const SFColorRGBA() const 00168 { 00169 return SFColorRGBA(r, g, b, 1.0f); 00170 } 00171 00172 MFColor::MFColor(const SFString &s) 00173 { 00174 SFString copy(s); 00175 replace(copy.begin(), copy.end(), ',', ' '); 00176 istringstream iss(copy, istringstream::in); 00177 while (!iss.eof()) 00178 { 00179 SFColor c; 00180 iss >> c.r >> c.g >> c.b; 00181 this->push_back(c); 00182 } 00183 } 00184 00185 MFColor::operator const MFColorRGBA() const 00186 { 00187 MFColorRGBA color = MFColorRGBA(this->size()); 00188 MFColorRGBA::iterator itColor = color.begin(); 00189 for (const_iterator it = this->begin(); it != this->end(); ++it) 00190 { 00191 *itColor = *it; 00192 ++itColor; 00193 } 00194 00195 return color; 00196 } 00197 00198 SFVec2d::SFVec2d() 00199 { 00200 } 00201 00202 SFVec2d::SFVec2d(SFDouble x, SFDouble y) 00203 { 00204 this->x = x; 00205 this->y = y; 00206 } 00207 00208 SFVec2d::SFVec2d(const SFString &s) 00209 { 00210 istringstream iss(s, istringstream::in); 00211 iss >> x >> y; 00212 } 00213 00214 MFVec2d::MFVec2d(const SFString &s) 00215 { 00216 SFString copy(s); 00217 replace(copy.begin(), copy.end(), ',', ' '); 00218 istringstream iss(copy, istringstream::in); 00219 while (!iss.eof()) 00220 { 00221 SFVec2d v; 00222 iss >> v.x >> v.y; 00223 this->push_back(v); 00224 } 00225 } 00226 00227 SFVec2f::SFVec2f() 00228 { 00229 } 00230 00231 SFVec2f::SFVec2f(SFFloat x, SFFloat y) 00232 { 00233 this->x = x; 00234 this->y = y; 00235 } 00236 00237 SFVec2f::SFVec2f(const SFString &s) 00238 { 00239 istringstream iss(s, istringstream::in); 00240 iss >> x >> y; 00241 } 00242 00243 MFVec2f::MFVec2f(const SFString &s) 00244 { 00245 SFString copy(s); 00246 replace(copy.begin(), copy.end(), ',', ' '); 00247 istringstream iss(copy, istringstream::in); 00248 while (!iss.eof()) 00249 { 00250 SFVec2f v; 00251 iss >> v.x >> v.y; 00252 this->push_back(v); 00253 } 00254 } 00255 00256 SFVec3d::SFVec3d() 00257 { 00258 } 00259 00260 00261 SFVec3d::SFVec3d(SFDouble x, SFDouble y, SFDouble z) 00262 { 00263 this->x = x; 00264 this->y = y; 00265 this->z = z; 00266 } 00267 00268 SFVec3d::SFVec3d(const SFString &s) 00269 { 00270 istringstream iss(s, istringstream::in); 00271 iss >> x >> y >> z; 00272 } 00273 00274 MFVec3d::MFVec3d(const SFString &s) 00275 { 00276 SFString copy(s); 00277 replace(copy.begin(), copy.end(), ',', ' '); 00278 istringstream iss(copy, istringstream::in); 00279 while (!iss.eof()) 00280 { 00281 SFVec3d v; 00282 iss >> v.x >> v.y >> v.z; 00283 this->push_back(v); 00284 } 00285 } 00286 00287 MFVec3f::MFVec3f(size_type n, const SFVec3f &V) 00288 : vector<SFVec3f>(n, V) 00289 { 00290 } 00291 00292 MFVec3f::MFVec3f(const SFString &s) 00293 : vector<SFVec3f>() 00294 { 00295 SFString copy(s); 00296 replace(copy.begin(), copy.end(), ',', ' '); 00297 istringstream iss(copy, istringstream::in); 00298 while (!iss.eof()) 00299 { 00300 SFVec3f v; 00301 iss >> v.x >> v.y >> v.z; 00302 this->push_back(v); 00303 } 00304 } 00305 00306 SFRotation::SFRotation(SFFloat x, SFFloat y, SFFloat z, SFFloat angle) 00307 { 00308 this->x = x; 00309 this->y = y; 00310 this->z = z; 00311 this->angle = angle; 00312 } 00313 00314 SFRotation::SFRotation(const SFString &s) 00315 { 00316 istringstream iss(s, istringstream::in); 00317 iss >> x >> y >> z >> angle; 00318 } 00319 00320 bool X3DTK::operator== (const SFRotation &r1, const SFRotation &r2) 00321 { 00322 return ((r1.x == r2.x) && (r1.y == r2.y) && (r1.z == r2.z)); 00323 } 00324 00325 bool X3DTK::operator!= (const SFRotation &r1, const SFRotation &r2) 00326 { 00327 return ((r1.x != r2.x) || (r1.y != r2.y) || (r1.z != r2.z)); 00328 } 00329 00330 MFRotation::MFRotation(const SFString &s) 00331 { 00332 SFString copy(s); 00333 replace(copy.begin(), copy.end(), ',', ' '); 00334 istringstream iss(copy, istringstream::in); 00335 while (!iss.eof()) 00336 { 00337 SFRotation r; 00338 iss >> r.x >> r.y >> r.z >> r.angle; 00339 this->push_back(r); 00340 } 00341 } 00342 00343 std::ostream& X3DTK::operator<<(std::ostream& o, const MFString &ms) 00344 { 00345 if (!ms.empty()) 00346 { 00347 for (unsigned int i = 0; i < ms.size() - 1; ++i) 00348 o << ms[i] << " "; 00349 00350 o << ms.back(); 00351 } 00352 return o; 00353 } 00354 00355 std::ostream& X3DTK::operator<<(std::ostream& o, const MFBool &mb) 00356 { 00357 for (unsigned int i = 0; i < mb.size() - 1; ++i) 00358 { 00359 if (mb[i]) 00360 o << "TRUE, "; 00361 else 00362 o << "FALSE, "; 00363 } 00364 00365 if (!mb.empty()) 00366 { 00367 if (mb.back()) 00368 o << "TRUE"; 00369 else 00370 o << "FALSE"; 00371 } 00372 return o; 00373 } 00374 00375 std::ostream& X3DTK::operator<<(std::ostream& o, const MFInt32 &mi) 00376 { 00377 if (!mi.empty()) 00378 { 00379 for (unsigned int i = 0; i < mi.size() - 1; ++i) 00380 o << mi[i] << " "; 00381 00382 o << mi.back(); 00383 } 00384 return o; 00385 } 00386 00387 std::ostream& X3DTK::operator<<(std::ostream& o, const MFFloat &mf) 00388 { 00389 if (!mf.empty()) 00390 { 00391 for (unsigned int i = 0; i < mf.size() - 1; ++i) 00392 o << mf[i] << " "; 00393 00394 o << mf.back(); 00395 } 00396 return o; 00397 } 00398 00399 std::ostream& X3DTK::operator<<(std::ostream& o, const MFDouble &md) 00400 { 00401 if (!md.empty()) 00402 { 00403 for (unsigned int i = 0; i < md.size() - 1; ++i) 00404 o << md[i] << " "; 00405 00406 o << md.back(); 00407 } 00408 return o; 00409 } 00410 00411 std::ostream& X3DTK::operator<<(std::ostream& o, const SFColor &c) 00412 { 00413 return o << c.r << " " << c.g << " " << c.b; 00414 } 00415 00416 std::ostream& X3DTK::operator<<(std::ostream& o, const MFColor &mc) 00417 { 00418 if (!mc.empty()) 00419 { 00420 for (unsigned int i = 0; i < mc.size() - 1; ++i) 00421 o << mc[i] << ", "; 00422 00423 o << mc.back(); 00424 } 00425 return o; 00426 } 00427 00428 std::ostream& X3DTK::operator<<(std::ostream& o, const SFColorRGBA &c) 00429 { 00430 return o << c.r << " " << c.g << " " << c.b << " " << c.a; 00431 } 00432 00433 std::ostream& X3DTK::operator<<(std::ostream& o, const MFColorRGBA &mc) 00434 { 00435 if (!mc.empty()) 00436 { 00437 for (unsigned int i = 0; i < mc.size() - 1; ++i) 00438 o << mc[i] << ", "; 00439 00440 o << mc.back(); 00441 } 00442 return o; 00443 } 00444 00445 std::ostream& X3DTK::operator<<(std::ostream& o, const SFVec2d &v) 00446 { 00447 return o << v.x << " " << v.y ; 00448 } 00449 00450 std::ostream& X3DTK::operator<<(std::ostream& o, const MFVec2d &mv) 00451 { 00452 if (!mv.empty()) 00453 { 00454 for (unsigned int i = 0; i < mv.size() - 1; ++i) 00455 o << mv[i] << ", "; 00456 00457 o << mv.back(); 00458 } 00459 return o; 00460 } 00461 00462 std::ostream& X3DTK::operator<<(std::ostream& o, const SFVec2f &v) 00463 { 00464 return o << v.x << " " << v.y; 00465 } 00466 00467 std::ostream& X3DTK::operator<<(std::ostream& o, const MFVec2f &mv) 00468 { 00469 if (!mv.empty()) 00470 { 00471 for (unsigned int i = 0; i < mv.size() - 1; ++i) 00472 o << mv[i] << ", "; 00473 00474 o << mv.back(); 00475 } 00476 return o; 00477 } 00478 00479 std::ostream& X3DTK::operator<<(std::ostream& o, const SFVec3d &v) 00480 { 00481 return o << v.x << " " << v.y << " " << v.z; 00482 } 00483 00484 std::ostream& X3DTK::operator<<(std::ostream& o, const MFVec3d &mv) 00485 { 00486 if (!mv.empty()) 00487 { 00488 for (unsigned int i = 0; i < mv.size() - 1; ++i) 00489 o << mv[i] << ", "; 00490 00491 o << mv.back(); 00492 } 00493 return o; 00494 } 00495 00496 std::ostream& X3DTK::operator<<(std::ostream& o, const SFVec3f &v) 00497 { 00498 return o << v.x << " " << v.y << " " << v.z; 00499 } 00500 00501 std::ostream& X3DTK::operator<<(std::ostream& o, const MFVec3f &mv) 00502 { 00503 if (!mv.empty()) 00504 { 00505 for (unsigned int i = 0; i < mv.size() - 1; ++i) 00506 o << mv[i] << ", "; 00507 00508 o << mv.back(); 00509 } 00510 return o; 00511 } 00512 00513 std::ostream& X3DTK::operator<<(std::ostream& o, const SFPoint3f &v) 00514 { 00515 return o << v.x << " " << v.y << " " << v.z; 00516 } 00517 00518 std::ostream& X3DTK::operator<<(std::ostream& o, const SFRotation &r) 00519 { 00520 return o << r.x << " " << r.y << " " << r.z << " " << r.angle; 00521 } 00522 00523 std::ostream& X3DTK::operator<<(std::ostream& o, const MFRotation &mr) 00524 { 00525 if (!mr.empty()) 00526 { 00527 for (unsigned int i = 0; i < mr.size() - 1; ++i) 00528 o << mr[i] << ", "; 00529 00530 o << mr.back(); 00531 } 00532 return o; 00533 }