/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include namespace osgSim { ShapeAttribute::ShapeAttribute() : _type(UNKNOW), _integer(0) {} ShapeAttribute::ShapeAttribute(const char * name) : _name(name), _type(UNKNOW), _integer(0) {} ShapeAttribute::ShapeAttribute(const char * name, int value) : _name(name), _type(INTEGER), _integer(value) {} ShapeAttribute::ShapeAttribute(const char * name, double value) : _name(name), _type(DOUBLE), _double(value) {} ShapeAttribute::ShapeAttribute(const char * name, const char * value) : _name(name), _type(STRING) { std::string str(value); _string = new char[str.size() + 1]; memcpy(_string, str.c_str(), str.size()); _string[str.size()] = 0; } ShapeAttribute::ShapeAttribute(const ShapeAttribute & sa) { copy(sa); } ShapeAttribute::~ShapeAttribute() { free(); } void ShapeAttribute::free() { if ((_type == STRING) && (_string)) { delete [] _string; _string = 0; } } void ShapeAttribute::copy(const ShapeAttribute& sa) { _name = sa._name; _type = sa._type; switch (_type) { case INTEGER: { _integer = sa._integer; break; } case STRING: { std::string str(sa._string); _string = new char[str.size() + 1]; memcpy(_string, str.c_str(), str.size()); _string[str.size()] = 0; break; } case DOUBLE: { _double = sa._double; break; } case UNKNOW: default: { _integer = 0; break; } } } ShapeAttribute& ShapeAttribute::operator = (const ShapeAttribute& sa) { if (&sa == this) return *this; free(); copy(sa); return *this; } int ShapeAttribute::compare(const osgSim::ShapeAttribute& sa) const { if (_name*rhs.*/ int ShapeAttributeList::compare(const osgSim::ShapeAttributeList& sal) const { const_iterator salIt, thisIt, thisEnd = end(); int ret; for (thisIt = begin(), salIt = sal.begin(); thisIt!= thisEnd; ++thisIt, ++salIt) if ((ret = thisIt->compare(*salIt)) != 0) return ret; return 0; } }