| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | // Written by Wang Rui, (C) 2010 |
|---|
| 14 | |
|---|
| 15 | #ifndef OSGDB__SERIALIZER |
|---|
| 16 | #define OSGDB__SERIALIZER |
|---|
| 17 | |
|---|
| 18 | #include <osg/ref_ptr> |
|---|
| 19 | #include <osg/Notify> |
|---|
| 20 | #include <osg/Object> |
|---|
| 21 | #include <osgDB/InputStream> |
|---|
| 22 | #include <osgDB/OutputStream> |
|---|
| 23 | |
|---|
| 24 | #include <string> |
|---|
| 25 | #include <sstream> |
|---|
| 26 | #include <limits.h> |
|---|
| 27 | |
|---|
| 28 | namespace osgDB |
|---|
| 29 | { |
|---|
| 30 | |
|---|
| 31 | #ifndef OBJECT_CAST |
|---|
| 32 | #define OBJECT_CAST static_cast |
|---|
| 33 | #endif |
|---|
| 34 | |
|---|
| 35 | class IntLookup |
|---|
| 36 | { |
|---|
| 37 | public: |
|---|
| 38 | typedef int Value; |
|---|
| 39 | typedef std::map<std::string, Value> StringToValue; |
|---|
| 40 | typedef std::map<Value, std::string> ValueToString; |
|---|
| 41 | |
|---|
| 42 | IntLookup() {} |
|---|
| 43 | unsigned int size() const { return _stringToValue.size(); } |
|---|
| 44 | |
|---|
| 45 | void add( const char* str, Value value ) |
|---|
| 46 | { |
|---|
| 47 | if ( _valueToString.find(value)!=_valueToString.end() ) |
|---|
| 48 | { |
|---|
| 49 | osg::notify(osg::WARN) << "Duplicate enum value " << value |
|---|
| 50 | << " with old string: " << _valueToString[value] |
|---|
| 51 | << " and new string: " << str << std::endl; |
|---|
| 52 | } |
|---|
| 53 | _valueToString[value] = str; |
|---|
| 54 | _stringToValue[str] = value; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | Value getValue( const char* str ) |
|---|
| 58 | { |
|---|
| 59 | StringToValue::iterator itr = _stringToValue.find(str); |
|---|
| 60 | if ( itr==_stringToValue.end() ) |
|---|
| 61 | { |
|---|
| 62 | Value value; |
|---|
| 63 | std::stringstream stream; |
|---|
| 64 | stream << str; stream >> value; |
|---|
| 65 | _stringToValue[str] = value; |
|---|
| 66 | return value; |
|---|
| 67 | } |
|---|
| 68 | return itr->second; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | const std::string& getString( Value value ) |
|---|
| 72 | { |
|---|
| 73 | ValueToString::iterator itr = _valueToString.find(value); |
|---|
| 74 | if ( itr==_valueToString.end() ) |
|---|
| 75 | { |
|---|
| 76 | std::string str; |
|---|
| 77 | std::stringstream stream; |
|---|
| 78 | stream << value; stream >> str; |
|---|
| 79 | _valueToString[value] = str; |
|---|
| 80 | return _valueToString[value]; |
|---|
| 81 | } |
|---|
| 82 | return itr->second; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | protected: |
|---|
| 86 | StringToValue _stringToValue; |
|---|
| 87 | ValueToString _valueToString; |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | class UserLookupTableProxy |
|---|
| 91 | { |
|---|
| 92 | public: |
|---|
| 93 | typedef void (*AddValueFunc)( IntLookup* lookup ); |
|---|
| 94 | UserLookupTableProxy( AddValueFunc func ) { if ( func ) (*func)(&_lookup); } |
|---|
| 95 | |
|---|
| 96 | IntLookup _lookup; |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | #define BEGIN_USER_TABLE(NAME, CLASS) \ |
|---|
| 100 | static void add_user_value_func_##NAME(osgDB::IntLookup*); \ |
|---|
| 101 | static osgDB::UserLookupTableProxy s_user_lookup_table_##NAME(&add_user_value_func_##NAME); \ |
|---|
| 102 | static void add_user_value_func_##NAME(osgDB::IntLookup* lookup) { typedef CLASS MyClass |
|---|
| 103 | #define ADD_USER_VALUE(VALUE) lookup->add(#VALUE, MyClass::VALUE) |
|---|
| 104 | #define END_USER_TABLE() } |
|---|
| 105 | |
|---|
| 106 | #define USER_READ_FUNC(NAME, FUNCNAME) \ |
|---|
| 107 | static int FUNCNAME(osgDB::InputStream& is) { \ |
|---|
| 108 | int value; if (is.isBinary()) is >> value; \ |
|---|
| 109 | else { std::string str; is >> str; \ |
|---|
| 110 | value = (s_user_lookup_table_##NAME)._lookup.getValue(str.c_str()); } \ |
|---|
| 111 | return value; } |
|---|
| 112 | |
|---|
| 113 | #define USER_WRITE_FUNC(NAME, FUNCNAME) \ |
|---|
| 114 | static void FUNCNAME(osgDB::OutputStream& os, int value) { \ |
|---|
| 115 | if (os.isBinary()) os << value; \ |
|---|
| 116 | else os << (s_user_lookup_table_##NAME)._lookup.getString(value); } \ |
|---|
| 117 | |
|---|
| 118 | class BaseSerializer : public osg::Referenced |
|---|
| 119 | { |
|---|
| 120 | friend class ObjectWrapper; |
|---|
| 121 | public: |
|---|
| 122 | enum Type |
|---|
| 123 | { |
|---|
| 124 | RW_UNDEFINED = 0, RW_USER, RW_OBJECT, RW_IMAGE, RW_LIST, |
|---|
| 125 | RW_BOOL, RW_SHORT, RW_USHORT, RW_INT, RW_UINT, RW_FLOAT, RW_DOUBLE, |
|---|
| 126 | RW_VEC2F, RW_VEC2D, RW_VEC3F, RW_VEC3D, RW_VEC4F, RW_VEC4D, RW_QUAT, RW_PLANE, |
|---|
| 127 | RW_MATRIXF, RW_MATRIXD, RW_MATRIX, RW_GLENUM, RW_STRING, RW_ENUM |
|---|
| 128 | }; |
|---|
| 129 | |
|---|
| 130 | BaseSerializer() : _firstVersion(0), _lastVersion(INT_MAX) {} |
|---|
| 131 | |
|---|
| 132 | virtual bool read( InputStream&, osg::Object& ) = 0; |
|---|
| 133 | virtual bool write( OutputStream&, const osg::Object& ) = 0; |
|---|
| 134 | virtual const std::string& getName() const = 0; |
|---|
| 135 | |
|---|
| 136 | protected: |
|---|
| 137 | int _firstVersion; // Library version when the serializer is first introduced |
|---|
| 138 | int _lastVersion; // Library version when the serializer is last required. |
|---|
| 139 | }; |
|---|
| 140 | |
|---|
| 141 | template<typename C> |
|---|
| 142 | class UserSerializer : public BaseSerializer |
|---|
| 143 | { |
|---|
| 144 | public: |
|---|
| 145 | typedef bool (*Checker)( const C& ); |
|---|
| 146 | typedef bool (*Reader)( InputStream&, C& ); |
|---|
| 147 | typedef bool (*Writer)( OutputStream&, const C& ); |
|---|
| 148 | |
|---|
| 149 | UserSerializer( const char* name, Checker cf, Reader rf, Writer wf ) |
|---|
| 150 | : _name(name), _checker(cf), _reader(rf), _writer(wf) {} |
|---|
| 151 | |
|---|
| 152 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 153 | { |
|---|
| 154 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 155 | if ( is.isBinary() ) |
|---|
| 156 | { |
|---|
| 157 | bool ok = false; is >> ok; |
|---|
| 158 | if ( !ok ) return true; |
|---|
| 159 | } |
|---|
| 160 | else |
|---|
| 161 | { |
|---|
| 162 | if ( !is.matchString(_name) ) |
|---|
| 163 | return true; |
|---|
| 164 | } |
|---|
| 165 | return (*_reader)(is, object); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 169 | { |
|---|
| 170 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 171 | bool ok = (*_checker)(object); |
|---|
| 172 | if ( os.isBinary() ) |
|---|
| 173 | { |
|---|
| 174 | os << ok; |
|---|
| 175 | if ( !ok ) return true; |
|---|
| 176 | } |
|---|
| 177 | else |
|---|
| 178 | { |
|---|
| 179 | if ( !ok ) return true; |
|---|
| 180 | os << PROPERTY(_name.c_str()); |
|---|
| 181 | } |
|---|
| 182 | return (*_writer)(os, object); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | virtual const std::string& getName() const { return _name; } |
|---|
| 186 | |
|---|
| 187 | protected: |
|---|
| 188 | std::string _name; |
|---|
| 189 | Checker _checker; |
|---|
| 190 | |
|---|
| 191 | public: |
|---|
| 192 | Reader _reader; |
|---|
| 193 | Writer _writer; |
|---|
| 194 | }; |
|---|
| 195 | |
|---|
| 196 | template<typename P> |
|---|
| 197 | class TemplateSerializer : public BaseSerializer |
|---|
| 198 | { |
|---|
| 199 | public: |
|---|
| 200 | TemplateSerializer( const char* name ) |
|---|
| 201 | : _name(name) {} |
|---|
| 202 | |
|---|
| 203 | virtual bool read( InputStream& is, osg::Object& obj ) = 0; |
|---|
| 204 | virtual bool write( OutputStream& os, const osg::Object& obj ) = 0; |
|---|
| 205 | virtual const std::string& getName() const { return _name; } |
|---|
| 206 | |
|---|
| 207 | protected: |
|---|
| 208 | std::string _name; |
|---|
| 209 | P _defaultValue; |
|---|
| 210 | }; |
|---|
| 211 | |
|---|
| 212 | template<typename C, typename P> |
|---|
| 213 | class PropByValSerializer : public TemplateSerializer<P> |
|---|
| 214 | { |
|---|
| 215 | public: |
|---|
| 216 | typedef TemplateSerializer<P> ParentType; |
|---|
| 217 | typedef P (C::*Getter)() const; |
|---|
| 218 | typedef void (C::*Setter)( P ); |
|---|
| 219 | |
|---|
| 220 | PropByValSerializer( const char* name, P def, Getter gf, Setter sf, bool useHex=false ) |
|---|
| 221 | : ParentType(name), _getter(gf), _setter(sf), _useHex(useHex) |
|---|
| 222 | { ParentType::_defaultValue = def; } |
|---|
| 223 | |
|---|
| 224 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 225 | { |
|---|
| 226 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 227 | P value; |
|---|
| 228 | if ( is.isBinary() ) |
|---|
| 229 | { |
|---|
| 230 | is >> value; |
|---|
| 231 | if ( ParentType::_defaultValue!=value ) |
|---|
| 232 | (object.*_setter)( value ); |
|---|
| 233 | } |
|---|
| 234 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 235 | { |
|---|
| 236 | if ( _useHex ) is >> std::hex; |
|---|
| 237 | is >> value; |
|---|
| 238 | if ( _useHex ) is >> std::dec; |
|---|
| 239 | (object.*_setter)( value ); |
|---|
| 240 | } |
|---|
| 241 | return true; |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 245 | { |
|---|
| 246 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 247 | P value = (object.*_getter)(); |
|---|
| 248 | if ( os.isBinary() ) |
|---|
| 249 | { |
|---|
| 250 | os << value; |
|---|
| 251 | } |
|---|
| 252 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 253 | { |
|---|
| 254 | os << PROPERTY((ParentType::_name).c_str()); |
|---|
| 255 | if ( _useHex ) os << std::hex; |
|---|
| 256 | os << value; |
|---|
| 257 | if ( _useHex ) os << std::dec; |
|---|
| 258 | os << std::endl; |
|---|
| 259 | } |
|---|
| 260 | return true; |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | public: |
|---|
| 264 | Getter _getter; |
|---|
| 265 | Setter _setter; |
|---|
| 266 | |
|---|
| 267 | protected: |
|---|
| 268 | bool _useHex; |
|---|
| 269 | }; |
|---|
| 270 | |
|---|
| 271 | template<typename C, typename P> |
|---|
| 272 | class PropByRefSerializer : public TemplateSerializer<P> |
|---|
| 273 | { |
|---|
| 274 | public: |
|---|
| 275 | typedef TemplateSerializer<P> ParentType; |
|---|
| 276 | typedef const P& CP; |
|---|
| 277 | typedef CP (C::*Getter)() const; |
|---|
| 278 | typedef void (C::*Setter)( CP ); |
|---|
| 279 | |
|---|
| 280 | PropByRefSerializer( const char* name, CP def, Getter gf, Setter sf ) |
|---|
| 281 | : ParentType(name), _getter(gf), _setter(sf) |
|---|
| 282 | { ParentType::_defaultValue = def; } |
|---|
| 283 | |
|---|
| 284 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 285 | { |
|---|
| 286 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 287 | P value; |
|---|
| 288 | if ( is.isBinary() ) |
|---|
| 289 | { |
|---|
| 290 | is >> value; |
|---|
| 291 | if ( ParentType::_defaultValue!=value ) |
|---|
| 292 | (object.*_setter)( value ); |
|---|
| 293 | } |
|---|
| 294 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 295 | { |
|---|
| 296 | is >> value; |
|---|
| 297 | (object.*_setter)( value ); |
|---|
| 298 | } |
|---|
| 299 | return true; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 303 | { |
|---|
| 304 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 305 | CP value = (object.*_getter)(); |
|---|
| 306 | if ( os.isBinary() ) |
|---|
| 307 | { |
|---|
| 308 | os << value; |
|---|
| 309 | } |
|---|
| 310 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 311 | { |
|---|
| 312 | os << PROPERTY((ParentType::_name).c_str()) << value << std::endl; |
|---|
| 313 | } |
|---|
| 314 | return true; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | public: |
|---|
| 318 | Getter _getter; |
|---|
| 319 | Setter _setter; |
|---|
| 320 | }; |
|---|
| 321 | |
|---|
| 322 | template<typename C> |
|---|
| 323 | class MatrixSerializer : public TemplateSerializer<osg::Matrix> |
|---|
| 324 | { |
|---|
| 325 | public: |
|---|
| 326 | typedef TemplateSerializer<osg::Matrix> ParentType; |
|---|
| 327 | typedef const osg::Matrix& (C::*Getter)() const; |
|---|
| 328 | typedef void (C::*Setter)( const osg::Matrix& ); |
|---|
| 329 | |
|---|
| 330 | MatrixSerializer( const char* name, const osg::Matrix& def, Getter gf, Setter sf ) |
|---|
| 331 | : ParentType(name), _getter(gf), _setter(sf) |
|---|
| 332 | { ParentType::_defaultValue = def; } |
|---|
| 333 | |
|---|
| 334 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 335 | { |
|---|
| 336 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 337 | osg::Matrix value; |
|---|
| 338 | if ( is.isBinary() ) |
|---|
| 339 | { |
|---|
| 340 | readMatrixImplementation( is, value ); |
|---|
| 341 | if ( ParentType::_defaultValue!=value ) |
|---|
| 342 | (object.*_setter)( value ); |
|---|
| 343 | } |
|---|
| 344 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 345 | { |
|---|
| 346 | readMatrixImplementation( is, value ); |
|---|
| 347 | (object.*_setter)( value ); |
|---|
| 348 | } |
|---|
| 349 | return true; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 353 | { |
|---|
| 354 | |
|---|
| 355 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 356 | const osg::Matrix& value = (object.*_getter)(); |
|---|
| 357 | if ( os.isBinary() ) |
|---|
| 358 | { |
|---|
| 359 | OSG_NOTICE<<"MatrixSerializer::write() binary"<<std::endl; |
|---|
| 360 | os << value; |
|---|
| 361 | } |
|---|
| 362 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 363 | { |
|---|
| 364 | OSG_NOTICE<<"MatrixSerializer::write() ascii, ParentType::_name="<<ParentType::_name<<std::endl; |
|---|
| 365 | os << PROPERTY((ParentType::_name).c_str()) << value << std::endl; |
|---|
| 366 | } |
|---|
| 367 | return true; |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | protected: |
|---|
| 371 | void readMatrixImplementation( InputStream& is, osg::Matrix& matrix ) |
|---|
| 372 | { |
|---|
| 373 | #if 1 |
|---|
| 374 | is >> matrix; |
|---|
| 375 | #else |
|---|
| 376 | if ( is.getUseFloatMatrix() ) |
|---|
| 377 | { |
|---|
| 378 | osg::Matrixf realValue; is >> realValue; |
|---|
| 379 | matrix = realValue; |
|---|
| 380 | } |
|---|
| 381 | else |
|---|
| 382 | { |
|---|
| 383 | osg::Matrixd realValue; is >> realValue; |
|---|
| 384 | matrix = realValue; |
|---|
| 385 | } |
|---|
| 386 | #endif |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | public: |
|---|
| 390 | Getter _getter; |
|---|
| 391 | Setter _setter; |
|---|
| 392 | }; |
|---|
| 393 | |
|---|
| 394 | template<typename C, typename P> |
|---|
| 395 | class GLenumSerializer : public TemplateSerializer<P> |
|---|
| 396 | { |
|---|
| 397 | public: |
|---|
| 398 | typedef TemplateSerializer<P> ParentType; |
|---|
| 399 | typedef P (C::*Getter)() const; |
|---|
| 400 | typedef void (C::*Setter)( P ); |
|---|
| 401 | |
|---|
| 402 | GLenumSerializer( const char* name, P def, Getter gf, Setter sf ) |
|---|
| 403 | : ParentType(name), _getter(gf), _setter(sf) |
|---|
| 404 | { ParentType::_defaultValue = def; } |
|---|
| 405 | |
|---|
| 406 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 407 | { |
|---|
| 408 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 409 | if ( is.isBinary() ) |
|---|
| 410 | { |
|---|
| 411 | GLenum value; is >> value; |
|---|
| 412 | if ( ParentType::_defaultValue!=static_cast<P>(value) ) |
|---|
| 413 | (object.*_setter)( static_cast<P>(value) ); |
|---|
| 414 | } |
|---|
| 415 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 416 | { |
|---|
| 417 | DEF_GLENUM(value); is >> value; |
|---|
| 418 | (object.*_setter)( static_cast<P>(value.get()) ); |
|---|
| 419 | } |
|---|
| 420 | return true; |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 424 | { |
|---|
| 425 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 426 | const P value = (object.*_getter)(); |
|---|
| 427 | if ( os.isBinary() ) |
|---|
| 428 | { |
|---|
| 429 | os << static_cast<GLenum>(value); |
|---|
| 430 | } |
|---|
| 431 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 432 | { |
|---|
| 433 | os << PROPERTY((ParentType::_name).c_str()) << GLENUM(value) << std::endl; |
|---|
| 434 | } |
|---|
| 435 | return true; |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | public: |
|---|
| 439 | Getter _getter; |
|---|
| 440 | Setter _setter; |
|---|
| 441 | }; |
|---|
| 442 | |
|---|
| 443 | template<typename C> |
|---|
| 444 | class StringSerializer : public TemplateSerializer<std::string> |
|---|
| 445 | { |
|---|
| 446 | public: |
|---|
| 447 | typedef TemplateSerializer<std::string> ParentType; |
|---|
| 448 | typedef const std::string& (C::*Getter)() const; |
|---|
| 449 | typedef void (C::*Setter)( const std::string& ); |
|---|
| 450 | |
|---|
| 451 | StringSerializer( const char* name, const std::string& def, Getter gf, Setter sf ) |
|---|
| 452 | : ParentType(name), _getter(gf), _setter(sf) |
|---|
| 453 | { ParentType::_defaultValue = def; } |
|---|
| 454 | |
|---|
| 455 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 456 | { |
|---|
| 457 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 458 | std::string value; |
|---|
| 459 | if ( is.isBinary() ) |
|---|
| 460 | { |
|---|
| 461 | is >> value; |
|---|
| 462 | if ( ParentType::_defaultValue!=value ) |
|---|
| 463 | (object.*_setter)( value ); |
|---|
| 464 | } |
|---|
| 465 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 466 | { |
|---|
| 467 | is.readWrappedString( value ); |
|---|
| 468 | if ( !value.empty() ) |
|---|
| 469 | (object.*_setter)( value ); |
|---|
| 470 | } |
|---|
| 471 | return true; |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 475 | { |
|---|
| 476 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 477 | const std::string& value = (object.*_getter)(); |
|---|
| 478 | if ( os.isBinary() ) |
|---|
| 479 | { |
|---|
| 480 | os << value; |
|---|
| 481 | } |
|---|
| 482 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 483 | { |
|---|
| 484 | os << PROPERTY((ParentType::_name).c_str()); |
|---|
| 485 | os.writeWrappedString( value ); |
|---|
| 486 | os << std::endl; |
|---|
| 487 | } |
|---|
| 488 | return true; |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | public: |
|---|
| 492 | Getter _getter; |
|---|
| 493 | Setter _setter; |
|---|
| 494 | }; |
|---|
| 495 | |
|---|
| 496 | template<typename C, typename P> |
|---|
| 497 | class ObjectSerializer : public TemplateSerializer<P*> |
|---|
| 498 | { |
|---|
| 499 | public: |
|---|
| 500 | typedef TemplateSerializer<P*> ParentType; |
|---|
| 501 | typedef const P* (C::*Getter)() const; |
|---|
| 502 | typedef void (C::*Setter)( P* ); |
|---|
| 503 | |
|---|
| 504 | ObjectSerializer( const char* name, P* def, Getter gf, Setter sf ) |
|---|
| 505 | : ParentType(name), _getter(gf), _setter(sf) |
|---|
| 506 | { ParentType::_defaultValue = def; } |
|---|
| 507 | |
|---|
| 508 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 509 | { |
|---|
| 510 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 511 | bool hasObject = false; |
|---|
| 512 | if ( is.isBinary() ) |
|---|
| 513 | { |
|---|
| 514 | is >> hasObject; |
|---|
| 515 | if ( hasObject ) |
|---|
| 516 | { |
|---|
| 517 | P* value = dynamic_cast<P*>( is.readObject() ); |
|---|
| 518 | if ( ParentType::_defaultValue!=value ) |
|---|
| 519 | (object.*_setter)( value ); |
|---|
| 520 | } |
|---|
| 521 | } |
|---|
| 522 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 523 | { |
|---|
| 524 | is >> hasObject; |
|---|
| 525 | if ( hasObject ) |
|---|
| 526 | { |
|---|
| 527 | is >> BEGIN_BRACKET; |
|---|
| 528 | P* value = dynamic_cast<P*>( is.readObject() ); |
|---|
| 529 | if ( ParentType::_defaultValue!=value ) |
|---|
| 530 | (object.*_setter)( value ); |
|---|
| 531 | is >> END_BRACKET; |
|---|
| 532 | } |
|---|
| 533 | } |
|---|
| 534 | return true; |
|---|
| 535 | } |
|---|
| 536 | |
|---|
| 537 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 538 | { |
|---|
| 539 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 540 | const P* value = (object.*_getter)(); |
|---|
| 541 | bool hasObject = (value!=NULL); |
|---|
| 542 | if ( os.isBinary() ) |
|---|
| 543 | { |
|---|
| 544 | os << hasObject; |
|---|
| 545 | os.writeObject( value ); |
|---|
| 546 | } |
|---|
| 547 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 548 | { |
|---|
| 549 | os << PROPERTY((ParentType::_name).c_str()) << hasObject; |
|---|
| 550 | if ( hasObject ) |
|---|
| 551 | { |
|---|
| 552 | os << BEGIN_BRACKET << std::endl; |
|---|
| 553 | os.writeObject( value ); |
|---|
| 554 | os << END_BRACKET; |
|---|
| 555 | } |
|---|
| 556 | os << std::endl; |
|---|
| 557 | } |
|---|
| 558 | return true; |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | public: |
|---|
| 562 | Getter _getter; |
|---|
| 563 | Setter _setter; |
|---|
| 564 | }; |
|---|
| 565 | |
|---|
| 566 | template<typename C, typename P> |
|---|
| 567 | class ImageSerializer : public TemplateSerializer<P*> |
|---|
| 568 | { |
|---|
| 569 | public: |
|---|
| 570 | typedef TemplateSerializer<P*> ParentType; |
|---|
| 571 | typedef const P* (C::*Getter)() const; |
|---|
| 572 | typedef void (C::*Setter)( P* ); |
|---|
| 573 | |
|---|
| 574 | ImageSerializer( const char* name, P* def, Getter gf, Setter sf ) |
|---|
| 575 | : ParentType(name), _getter(gf), _setter(sf) |
|---|
| 576 | { ParentType::_defaultValue = def; } |
|---|
| 577 | |
|---|
| 578 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 579 | { |
|---|
| 580 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 581 | bool hasObject = false; |
|---|
| 582 | if ( is.isBinary() ) |
|---|
| 583 | { |
|---|
| 584 | is >> hasObject; |
|---|
| 585 | if ( hasObject ) |
|---|
| 586 | { |
|---|
| 587 | P* value = dynamic_cast<P*>( is.readImage() ); |
|---|
| 588 | if ( ParentType::_defaultValue!=value ) |
|---|
| 589 | (object.*_setter)( value ); |
|---|
| 590 | } |
|---|
| 591 | } |
|---|
| 592 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 593 | { |
|---|
| 594 | is >> hasObject; |
|---|
| 595 | if ( hasObject ) |
|---|
| 596 | { |
|---|
| 597 | is >> BEGIN_BRACKET; |
|---|
| 598 | P* value = dynamic_cast<P*>( is.readImage() ); |
|---|
| 599 | if ( ParentType::_defaultValue!=value ) |
|---|
| 600 | (object.*_setter)( value ); |
|---|
| 601 | is >> END_BRACKET; |
|---|
| 602 | } |
|---|
| 603 | } |
|---|
| 604 | return true; |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 608 | { |
|---|
| 609 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 610 | const P* value = (object.*_getter)(); |
|---|
| 611 | bool hasObject = (value!=NULL); |
|---|
| 612 | if ( os.isBinary() ) |
|---|
| 613 | { |
|---|
| 614 | os << hasObject; |
|---|
| 615 | os.writeImage( value ); |
|---|
| 616 | } |
|---|
| 617 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 618 | { |
|---|
| 619 | os << PROPERTY((ParentType::_name).c_str()) << hasObject; |
|---|
| 620 | if ( hasObject ) |
|---|
| 621 | { |
|---|
| 622 | os << BEGIN_BRACKET << std::endl; |
|---|
| 623 | os.writeImage( value ); |
|---|
| 624 | os << END_BRACKET; |
|---|
| 625 | } |
|---|
| 626 | os << std::endl; |
|---|
| 627 | } |
|---|
| 628 | return true; |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | public: |
|---|
| 632 | Getter _getter; |
|---|
| 633 | Setter _setter; |
|---|
| 634 | }; |
|---|
| 635 | |
|---|
| 636 | template<typename C, typename P, typename B> |
|---|
| 637 | class EnumSerializer : public TemplateSerializer<P> |
|---|
| 638 | { |
|---|
| 639 | public: |
|---|
| 640 | typedef TemplateSerializer<P> ParentType; |
|---|
| 641 | typedef P (C::*Getter)() const; |
|---|
| 642 | typedef B (C::*Setter)( P ); |
|---|
| 643 | |
|---|
| 644 | EnumSerializer( const char* name, P def, Getter gf, Setter sf ) |
|---|
| 645 | : ParentType(name), _getter(gf), _setter(sf) |
|---|
| 646 | { ParentType::_defaultValue = def; } |
|---|
| 647 | |
|---|
| 648 | void add( const char* str, P value ) |
|---|
| 649 | { _lookup.add(str, static_cast<IntLookup::Value>(value)); } |
|---|
| 650 | |
|---|
| 651 | P getValue( const char* str ) |
|---|
| 652 | { return static_cast<P>(_lookup.getValue(str)); } |
|---|
| 653 | |
|---|
| 654 | const std::string& getString( P value ) |
|---|
| 655 | { return _lookup.getString(static_cast<IntLookup::Value>(value)); } |
|---|
| 656 | |
|---|
| 657 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 658 | { |
|---|
| 659 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 660 | IntLookup::Value value; |
|---|
| 661 | if ( is.isBinary() ) |
|---|
| 662 | { |
|---|
| 663 | is >> value; |
|---|
| 664 | if ( ParentType::_defaultValue!=static_cast<P>(value) ) |
|---|
| 665 | (object.*_setter)( static_cast<P>(value) ); |
|---|
| 666 | } |
|---|
| 667 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 668 | { |
|---|
| 669 | std::string str; is >> str; |
|---|
| 670 | (object.*_setter)( getValue(str.c_str()) ); |
|---|
| 671 | } |
|---|
| 672 | return true; |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | virtual bool write( osgDB::OutputStream& os, const osg::Object& obj ) |
|---|
| 676 | { |
|---|
| 677 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 678 | const P value = (object.*_getter)(); |
|---|
| 679 | if ( os.isBinary() ) |
|---|
| 680 | { |
|---|
| 681 | os << (IntLookup::Value)value; |
|---|
| 682 | } |
|---|
| 683 | else if ( ParentType::_defaultValue!=value ) |
|---|
| 684 | { |
|---|
| 685 | os << PROPERTY((ParentType::_name).c_str()) << getString(value) << std::endl; |
|---|
| 686 | } |
|---|
| 687 | return true; |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | public: |
|---|
| 691 | Getter _getter; |
|---|
| 692 | Setter _setter; |
|---|
| 693 | |
|---|
| 694 | protected: |
|---|
| 695 | IntLookup _lookup; |
|---|
| 696 | }; |
|---|
| 697 | |
|---|
| 698 | template<typename C, typename P> |
|---|
| 699 | class ListSerializer : public TemplateSerializer<P> |
|---|
| 700 | { |
|---|
| 701 | public: |
|---|
| 702 | typedef TemplateSerializer<P> ParentType; |
|---|
| 703 | typedef typename P::value_type ValueType; |
|---|
| 704 | typedef typename P::const_iterator ConstIterator; |
|---|
| 705 | typedef const P& (C::*Getter)() const; |
|---|
| 706 | typedef void (C::*Setter)( const P& ); |
|---|
| 707 | |
|---|
| 708 | ListSerializer( const char* name, Getter gf, Setter sf ) |
|---|
| 709 | : ParentType(name), _getter(gf), _setter(sf) {} |
|---|
| 710 | |
|---|
| 711 | virtual bool read( InputStream& is, osg::Object& obj ) |
|---|
| 712 | { |
|---|
| 713 | C& object = OBJECT_CAST<C&>(obj); |
|---|
| 714 | unsigned int size = 0; |
|---|
| 715 | P list; |
|---|
| 716 | if ( is.isBinary() ) |
|---|
| 717 | { |
|---|
| 718 | is >> size; |
|---|
| 719 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 720 | { |
|---|
| 721 | ValueType value; |
|---|
| 722 | is >> value; |
|---|
| 723 | list.push_back( value ); |
|---|
| 724 | } |
|---|
| 725 | if ( size>0 ) (object.*_setter)( list ); |
|---|
| 726 | } |
|---|
| 727 | else if ( is.matchString(ParentType::_name) ) |
|---|
| 728 | { |
|---|
| 729 | is >> size; |
|---|
| 730 | if ( size>0 ) is >> BEGIN_BRACKET; |
|---|
| 731 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 732 | { |
|---|
| 733 | ValueType value; |
|---|
| 734 | is >> value; |
|---|
| 735 | list.push_back( value ); |
|---|
| 736 | } |
|---|
| 737 | if ( size>0 ) |
|---|
| 738 | { |
|---|
| 739 | is >> END_BRACKET; |
|---|
| 740 | (object.*_setter)( list ); |
|---|
| 741 | } |
|---|
| 742 | } |
|---|
| 743 | return true; |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | virtual bool write( OutputStream& os, const osg::Object& obj ) |
|---|
| 747 | { |
|---|
| 748 | const C& object = OBJECT_CAST<const C&>(obj); |
|---|
| 749 | const P& list = (object.*_getter)(); |
|---|
| 750 | unsigned int size = (unsigned int)list.size(); |
|---|
| 751 | if ( os.isBinary() ) |
|---|
| 752 | { |
|---|
| 753 | os << size; |
|---|
| 754 | for ( ConstIterator itr=list.begin(); |
|---|
| 755 | itr!=list.end(); ++itr ) |
|---|
| 756 | { |
|---|
| 757 | os << (*itr); |
|---|
| 758 | } |
|---|
| 759 | } |
|---|
| 760 | else if ( size>0 ) |
|---|
| 761 | { |
|---|
| 762 | os << PROPERTY((ParentType::_name).c_str()) << size << BEGIN_BRACKET << std::endl; |
|---|
| 763 | for ( ConstIterator itr=list.begin(); |
|---|
| 764 | itr!=list.end(); ++itr ) |
|---|
| 765 | { |
|---|
| 766 | os << (*itr); |
|---|
| 767 | } |
|---|
| 768 | os << std::endl; |
|---|
| 769 | os << END_BRACKET << std::endl; |
|---|
| 770 | } |
|---|
| 771 | return true; |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | public: |
|---|
| 775 | Getter _getter; |
|---|
| 776 | Setter _setter; |
|---|
| 777 | }; |
|---|
| 778 | |
|---|
| 779 | // ADDING MANIPULATORS |
|---|
| 780 | #define ADD_SERIALIZER(S) \ |
|---|
| 781 | wrapper->addSerializer( (S) ) |
|---|
| 782 | |
|---|
| 783 | #define ADD_USER_SERIALIZER(PROP) \ |
|---|
| 784 | wrapper->addSerializer( new osgDB::UserSerializer<MyClass>( \ |
|---|
| 785 | #PROP, &check##PROP, &read##PROP, &write##PROP), osgDB::BaseSerializer::RW_USER ) |
|---|
| 786 | |
|---|
| 787 | #define ADD_BOOL_SERIALIZER(PROP, DEF) \ |
|---|
| 788 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, bool >( \ |
|---|
| 789 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOOL ) |
|---|
| 790 | |
|---|
| 791 | #define ADD_SHORT_SERIALIZER(PROP, DEF) \ |
|---|
| 792 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, short >( \ |
|---|
| 793 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_SHORT ) |
|---|
| 794 | |
|---|
| 795 | #define ADD_USHORT_SERIALIZER(PROP, DEF) \ |
|---|
| 796 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \ |
|---|
| 797 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_USHORT ) |
|---|
| 798 | |
|---|
| 799 | #define ADD_HEXSHORT_SERIALIZER(PROP, DEF) \ |
|---|
| 800 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \ |
|---|
| 801 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_USHORT ) |
|---|
| 802 | |
|---|
| 803 | #define ADD_INT_SERIALIZER(PROP, DEF) \ |
|---|
| 804 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, int >( \ |
|---|
| 805 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT ) |
|---|
| 806 | |
|---|
| 807 | #define ADD_UINT_SERIALIZER(PROP, DEF) \ |
|---|
| 808 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \ |
|---|
| 809 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT ) |
|---|
| 810 | |
|---|
| 811 | #define ADD_GLINT_SERIALIZER(PROP, DEF) \ |
|---|
| 812 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLint >( \ |
|---|
| 813 | #PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT ) |
|---|
| 814 | |
|---|
| 815 | #define ADD_HEXINT_SERIALIZER(PROP, DEF) \ |
|---|
| 816 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \ |
|---|
| 817 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_UINT ) |
|---|
| 818 | |
|---|
| 819 | #define ADD_FLOAT_SERIALIZER(PROP, DEF) \ |
|---|
| 820 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, float >( \ |
|---|
| 821 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_FLOAT ) |
|---|
| 822 | |
|---|
| 823 | #define ADD_DOUBLE_SERIALIZER(PROP, DEF) \ |
|---|
| 824 | wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, double >( \ |
|---|
| 825 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_DOUBLE ) |
|---|
| 826 | |
|---|
| 827 | #define ADD_VEC2F_SERIALIZER(PROP, DEF) \ |
|---|
| 828 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2f >( \ |
|---|
| 829 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2F ) |
|---|
| 830 | |
|---|
| 831 | #define ADD_VEC2D_SERIALIZER(PROP, DEF) \ |
|---|
| 832 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2d >( \ |
|---|
| 833 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2D ) |
|---|
| 834 | |
|---|
| 835 | #define ADD_VEC2_SERIALIZER(PROP, DEF) ADD_VEC2F_SERIALIZER(PROP, DEF) |
|---|
| 836 | |
|---|
| 837 | #define ADD_VEC3F_SERIALIZER(PROP, DEF) \ |
|---|
| 838 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3f >( \ |
|---|
| 839 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3F ) |
|---|
| 840 | |
|---|
| 841 | #define ADD_VEC3D_SERIALIZER(PROP, DEF) \ |
|---|
| 842 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3d >( \ |
|---|
| 843 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3D ) |
|---|
| 844 | |
|---|
| 845 | #define ADD_VEC3_SERIALIZER(PROP, DEF) ADD_VEC3F_SERIALIZER(PROP, DEF) |
|---|
| 846 | |
|---|
| 847 | #define ADD_VEC4F_SERIALIZER(PROP, DEF) \ |
|---|
| 848 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4f >( \ |
|---|
| 849 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4F ) |
|---|
| 850 | |
|---|
| 851 | #define ADD_VEC4D_SERIALIZER(PROP, DEF) \ |
|---|
| 852 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4d >( \ |
|---|
| 853 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4D ) |
|---|
| 854 | |
|---|
| 855 | #define ADD_VEC4_SERIALIZER(PROP, DEF) ADD_VEC4F_SERIALIZER(PROP, DEF) |
|---|
| 856 | |
|---|
| 857 | #define ADD_QUAT_SERIALIZER(PROP, DEF) \ |
|---|
| 858 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Quat >( \ |
|---|
| 859 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_QUAT ) |
|---|
| 860 | |
|---|
| 861 | #define ADD_PLANE_SERIALIZER(PROP, DEF) \ |
|---|
| 862 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Plane >( \ |
|---|
| 863 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_PLANE ) |
|---|
| 864 | |
|---|
| 865 | #define ADD_MATRIXF_SERIALIZER(PROP, DEF) \ |
|---|
| 866 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixf >( \ |
|---|
| 867 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXF ) |
|---|
| 868 | |
|---|
| 869 | #define ADD_MATRIXD_SERIALIZER(PROP, DEF) \ |
|---|
| 870 | wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixd >( \ |
|---|
| 871 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXD ) |
|---|
| 872 | |
|---|
| 873 | #define ADD_MATRIX_SERIALIZER(PROP, DEF) \ |
|---|
| 874 | wrapper->addSerializer( new osgDB::MatrixSerializer< MyClass >( \ |
|---|
| 875 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIX ) |
|---|
| 876 | |
|---|
| 877 | #define ADD_GLENUM_SERIALIZER(PROP, TYPE, DEF) \ |
|---|
| 878 | wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \ |
|---|
| 879 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_GLENUM ) |
|---|
| 880 | |
|---|
| 881 | #define ADD_STRING_SERIALIZER(PROP, DEF) \ |
|---|
| 882 | wrapper->addSerializer( new osgDB::StringSerializer< MyClass >( \ |
|---|
| 883 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_STRING ) |
|---|
| 884 | |
|---|
| 885 | #define ADD_OBJECT_SERIALIZER(PROP, TYPE, DEF) \ |
|---|
| 886 | wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \ |
|---|
| 887 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_OBJECT ) |
|---|
| 888 | |
|---|
| 889 | #define ADD_IMAGE_SERIALIZER(PROP, TYPE, DEF) \ |
|---|
| 890 | wrapper->addSerializer( new osgDB::ImageSerializer< MyClass, TYPE >( \ |
|---|
| 891 | #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_IMAGE ) |
|---|
| 892 | |
|---|
| 893 | #define ADD_LIST_SERIALIZER(PROP, TYPE) \ |
|---|
| 894 | wrapper->addSerializer( new osgDB::ListSerializer< MyClass, TYPE >( \ |
|---|
| 895 | #PROP, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_LIST ) |
|---|
| 896 | |
|---|
| 897 | #define BEGIN_ENUM_SERIALIZER(PROP, DEF) \ |
|---|
| 898 | { typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, void> MySerializer; \ |
|---|
| 899 | osg::ref_ptr<MySerializer> serializer = new MySerializer( \ |
|---|
| 900 | #PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP) |
|---|
| 901 | |
|---|
| 902 | #define BEGIN_ENUM_SERIALIZER2(PROP, TYPE, DEF) \ |
|---|
| 903 | { typedef osgDB::EnumSerializer<MyClass, TYPE, void> MySerializer; \ |
|---|
| 904 | osg::ref_ptr<MySerializer> serializer = new MySerializer( \ |
|---|
| 905 | #PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP) |
|---|
| 906 | |
|---|
| 907 | #define BEGIN_ENUM_SERIALIZER3(PROP, DEF) \ |
|---|
| 908 | { typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, bool> MySerializer; \ |
|---|
| 909 | osg::ref_ptr<MySerializer> serializer = new MySerializer( \ |
|---|
| 910 | #PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP) |
|---|
| 911 | |
|---|
| 912 | #define BEGIN_ENUM_SERIALIZER4(PROPERTIES_CLASS, PROP, DEF) \ |
|---|
| 913 | { typedef osgDB::EnumSerializer<MyClass, PROPERTIES_CLASS::PROP, void> MySerializer; \ |
|---|
| 914 | osg::ref_ptr<MySerializer> serializer = new MySerializer( \ |
|---|
| 915 | #PROP, PROPERTIES_CLASS::DEF, &MyClass::get##PROP, &MyClass::set##PROP) |
|---|
| 916 | |
|---|
| 917 | #define ADD_ENUM_VALUE(VALUE) \ |
|---|
| 918 | serializer->add(#VALUE, MyClass::VALUE) |
|---|
| 919 | |
|---|
| 920 | #define ADD_ENUM_CLASS_VALUE(CLASS, VALUE) \ |
|---|
| 921 | serializer->add(#VALUE, CLASS::VALUE) |
|---|
| 922 | |
|---|
| 923 | #define END_ENUM_SERIALIZER() \ |
|---|
| 924 | wrapper->addSerializer(serializer.get(), osgDB::BaseSerializer::RW_ENUM); } |
|---|
| 925 | |
|---|
| 926 | // VERSION CONTROL OPERATORS |
|---|
| 927 | #define UPDATE_TO_VERSION(VER) \ |
|---|
| 928 | wrapper->setUpdatedVersion( (VER) ); |
|---|
| 929 | |
|---|
| 930 | #define REMOVE_SERIALIZER(PROP) \ |
|---|
| 931 | wrapper->markSerializerAsRemoved( #PROP ); |
|---|
| 932 | |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | #endif |
|---|