OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Serializer.h
Go to the documentation of this file.
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 typedef std::vector<std::string> StringList;
32 extern OSGDB_EXPORT void split( const std::string& src, StringList& list, char separator=' ' );
33 
34 
35 #ifndef OBJECT_CAST
36  #define OBJECT_CAST static_cast
37 #endif
38 
39 class IntLookup
40 {
41 public:
42  typedef int Value;
43  typedef std::map<std::string, Value> StringToValue;
44  typedef std::map<Value, std::string> ValueToString;
45 
46  IntLookup() {}
47  unsigned int size() const { return static_cast<unsigned int>(_stringToValue.size()); }
48 
49  void add( const char* str, Value value )
50  {
51  if ( _valueToString.find(value)!=_valueToString.end() )
52  {
53  osg::notify(osg::INFO) << "Duplicate enum value " << value
54  << " with old string: " << _valueToString[value]
55  << " and new string: " << str << std::endl;
56  }
57  _valueToString[value] = str;
58  _stringToValue[str] = value;
59  }
60 
61  Value getValue( const char* str )
62  {
63  StringToValue::iterator itr = _stringToValue.find(str);
64  if ( itr==_stringToValue.end() )
65  {
66  Value value;
67  std::stringstream stream;
68  stream << str; stream >> value;
69  _stringToValue[str] = value;
70  return value;
71  }
72  return itr->second;
73  }
74 
75  const std::string& getString( Value value )
76  {
77  ValueToString::iterator itr = _valueToString.find(value);
78  if ( itr==_valueToString.end() )
79  {
80  std::string str;
81  std::stringstream stream;
82  stream << value; stream >> str;
83  _valueToString[value] = str;
84  return _valueToString[value];
85  }
86  return itr->second;
87  }
88 
89  StringToValue& getStringToValue() { return _stringToValue; }
90  const StringToValue& getStringToValue() const { return _stringToValue; }
91 
92  ValueToString& getValueToString() { return _valueToString; }
93  const ValueToString& getValueToString() const { return _valueToString; }
94 
95 protected:
96  StringToValue _stringToValue;
97  ValueToString _valueToString;
98 };
99 
101 {
102 public:
103  typedef void (*AddValueFunc)( IntLookup* lookup );
104  UserLookupTableProxy( AddValueFunc func ) { if ( func ) (*func)(&_lookup); }
105 
107 };
108 
109 #define BEGIN_USER_TABLE(NAME, CLASS) \
110  static void add_user_value_func_##NAME(osgDB::IntLookup*); \
111  static osgDB::UserLookupTableProxy s_user_lookup_table_##NAME(&add_user_value_func_##NAME); \
112  static void add_user_value_func_##NAME(osgDB::IntLookup* lookup) { typedef CLASS MyClass
113 #define ADD_USER_VALUE(VALUE) lookup->add(#VALUE, MyClass::VALUE)
114 #define END_USER_TABLE() }
115 
116 #define USER_READ_FUNC(NAME, FUNCNAME) \
117  static int FUNCNAME(osgDB::InputStream& is) { \
118  int value; if (is.isBinary()) is >> value; \
119  else { std::string str; is >> str; \
120  value = (s_user_lookup_table_##NAME)._lookup.getValue(str.c_str()); } \
121  return value; }
122 
123 #define USER_WRITE_FUNC(NAME, FUNCNAME) \
124  static void FUNCNAME(osgDB::OutputStream& os, int value) { \
125  if (os.isBinary()) os << value; \
126  else os << (s_user_lookup_table_##NAME)._lookup.getString(value); } \
127 
129 {
130  friend class ObjectWrapper;
131 public:
132  enum Type
133  {
144  };
145 
146  enum Usage
147  {
152  };
153 
154 
155  BaseSerializer(int usage) : _firstVersion(0), _lastVersion(INT_MAX), _usage(usage) {}
156 
157  virtual bool set(osg::Object& /*object*/, void* /*value*/) { return false; }
158  virtual bool get(const osg::Object& /*object*/, void* /*value*/) { return false; }
159 
160  virtual bool read( InputStream&, osg::Object& ) = 0;
161  virtual bool write( OutputStream&, const osg::Object& ) = 0;
162  virtual const std::string& getName() const = 0;
163 
164  virtual IntLookup* getIntLookup() { return 0; }
165 
166  void setUsage(int usage) { _usage = usage; }
167  int getUsage() const { return _usage; }
168 
169  void setUsage(bool hasGetter, bool hasSetter)
170  {
171  setUsage( ((hasGetter && hasSetter) ? BaseSerializer::READ_WRITE_PROPERTY : 0) |
172  ((hasGetter) ? BaseSerializer::GET_PROPERTY : 0) |
173  ((hasSetter) ? BaseSerializer::SET_PROPERTY : 0) );
174  }
175 
176  bool supportsReadWrite() const { return (_usage & READ_WRITE_PROPERTY)!=0; }
177  bool supportsGetSet() const { return (_usage & GET_SET_PROPERTY)!=0; }
178  bool supportsGet() const { return (_usage & GET_PROPERTY)!=0; }
179  bool supportsSet() const { return (_usage & SET_PROPERTY)!=0; }
180 
181 protected:
182  int _firstVersion; // Library version when the serializer is first introduced
183  int _lastVersion; // Library version when the serializer is last required.
184  int _usage; // How the Serializer can be used.
185 };
186 
187 template<typename C>
189 {
190 public:
191  typedef bool (*Checker)( const C& );
192  typedef bool (*Reader)( InputStream&, C& );
193  typedef bool (*Writer)( OutputStream&, const C& );
194 
195  UserSerializer( const char* name, Checker cf, Reader rf, Writer wf )
196  : BaseSerializer(READ_WRITE_PROPERTY), _name(name), _checker(cf), _reader(rf), _writer(wf) {}
197 
198  virtual bool read( InputStream& is, osg::Object& obj )
199  {
200  C& object = OBJECT_CAST<C&>(obj);
201  if ( is.isBinary() )
202  {
203  bool ok = false; is >> ok;
204  if ( !ok ) return true;
205  }
206  else
207  {
208  if ( !is.matchString(_name) )
209  return true;
210  }
211  return (*_reader)(is, object);
212  }
213 
214  virtual bool write( OutputStream& os, const osg::Object& obj )
215  {
216  const C& object = OBJECT_CAST<const C&>(obj);
217  bool ok = (*_checker)(object);
218  if ( os.isBinary() )
219  {
220  os << ok;
221  if ( !ok ) return true;
222  }
223  else
224  {
225  if ( !ok ) return true;
226  os << os.PROPERTY(_name.c_str());
227  }
228  return (*_writer)(os, object);
229  }
230 
231  virtual const std::string& getName() const { return _name; }
232 
233 protected:
234  std::string _name;
236 
237 public:
240 };
241 
242 template<typename P>
244 {
245 public:
246 
247  TemplateSerializer( const char* name, P def)
249 
250  virtual bool read( InputStream& is, osg::Object& obj ) = 0;
251  virtual bool write( OutputStream& os, const osg::Object& obj ) = 0;
252  virtual const std::string& getName() const { return _name; }
253 
254 protected:
255  std::string _name;
257 };
258 
259 template<typename C, typename P>
261 {
262 public:
264  typedef P (C::*Getter)() const;
265  typedef void (C::*Setter)( P );
266 
267  PropByValSerializer( const char* name, P def, Getter gf, Setter sf, bool useHex=false ) : ParentType(name, def), _getter(gf), _setter(sf), _useHex(useHex)
268  {
270  }
271 
272  virtual bool read( InputStream& is, osg::Object& obj )
273  {
274  C& object = OBJECT_CAST<C&>(obj);
275  P value;
276  if ( is.isBinary() )
277  {
278  is >> value;
279  (object.*_setter)( value );
280  }
281  else if ( is.matchString(ParentType::_name) )
282  {
283  if ( _useHex ) is >> std::hex;
284  is >> value;
285  if ( _useHex ) is >> std::dec;
286  (object.*_setter)( value );
287  }
288  return true;
289  }
290 
291  virtual bool write( OutputStream& os, const osg::Object& obj )
292  {
293  const C& object = OBJECT_CAST<const C&>(obj);
294  P value = (object.*_getter)();
295  if ( os.isBinary() )
296  {
297  os << value;
298  }
299  else if ( ParentType::_defaultValue!=value )
300  {
301  os << os.PROPERTY((ParentType::_name).c_str());
302  if ( _useHex ) { os << std::hex << std::showbase; }
303  os << value;
304  if ( _useHex ) os << std::dec << std::noshowbase;
305  os << std::endl;
306  }
307  return true;
308  }
309 
310 public:
313 
314 protected:
315  bool _useHex;
316 };
317 
318 template<typename C, typename P>
320 {
321 public:
323  typedef const P& CP;
324  typedef CP (C::*Getter)() const;
325  typedef void (C::*Setter)( CP );
326 
327  PropByRefSerializer( const char* name, CP def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
328  {
330  }
331 
332  virtual bool read( InputStream& is, osg::Object& obj )
333  {
334  C& object = OBJECT_CAST<C&>(obj);
335  P value;
336  if ( is.isBinary() )
337  {
338  is >> value;
339  (object.*_setter)( value );
340  }
341  else if ( is.matchString(ParentType::_name) )
342  {
343  is >> value;
344  (object.*_setter)( value );
345  }
346  return true;
347  }
348 
349  virtual bool write( OutputStream& os, const osg::Object& obj )
350  {
351  const C& object = OBJECT_CAST<const C&>(obj);
352  CP value = (object.*_getter)();
353  if ( os.isBinary() )
354  {
355  os << value;
356  }
357  else if ( ParentType::_defaultValue!=value )
358  {
359  os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
360  }
361  return true;
362  }
363 
364 public:
367 };
368 
369 template<typename C>
370 class MatrixSerializer : public TemplateSerializer<osg::Matrix>
371 {
372 public:
374  typedef const osg::Matrix& (C::*Getter)() const;
375  typedef void (C::*Setter)( const osg::Matrix& );
376 
377  MatrixSerializer( const char* name, const osg::Matrix& def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
378  {
380  }
381 
382  virtual bool read( InputStream& is, osg::Object& obj )
383  {
384  C& object = OBJECT_CAST<C&>(obj);
385  osg::Matrix value;
386  if ( is.isBinary() )
387  {
388  readMatrixImplementation( is, value );
389  (object.*_setter)( value );
390  }
391  else if ( is.matchString(ParentType::_name) )
392  {
393  readMatrixImplementation( is, value );
394  (object.*_setter)( value );
395  }
396  return true;
397  }
398 
399  virtual bool write( OutputStream& os, const osg::Object& obj )
400  {
401 
402  const C& object = OBJECT_CAST<const C&>(obj);
403  const osg::Matrix& value = (object.*_getter)();
404  if ( os.isBinary() )
405  {
406  os << value;
407  }
408  else if ( ParentType::_defaultValue!=value )
409  {
410  os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
411  }
412  return true;
413  }
414 
415 protected:
417  {
418 #if 1
419  is >> matrix;
420 #else
421  if ( is.getUseFloatMatrix() )
422  {
423  osg::Matrixf realValue; is >> realValue;
424  matrix = realValue;
425  }
426  else
427  {
428  osg::Matrixd realValue; is >> realValue;
429  matrix = realValue;
430  }
431 #endif
432  }
433 
434 public:
437 };
438 
439 template<typename C, typename P>
441 {
442 public:
444  typedef P (C::*Getter)() const;
445  typedef void (C::*Setter)( P );
446 
447  GLenumSerializer( const char* name, P def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
448  {
450  }
451 
452  virtual bool read( InputStream& is, osg::Object& obj )
453  {
454  C& object = OBJECT_CAST<C&>(obj);
455  if ( is.isBinary() )
456  {
457  GLenum value; is >> value;
458  (object.*_setter)( static_cast<P>(value) );
459  }
460  else if ( is.matchString(ParentType::_name) )
461  {
462  DEF_GLENUM(value); is >> value;
463  (object.*_setter)( static_cast<P>(value.get()) );
464  }
465  return true;
466  }
467 
468  virtual bool write( OutputStream& os, const osg::Object& obj )
469  {
470  const C& object = OBJECT_CAST<const C&>(obj);
471  const P value = (object.*_getter)();
472  if ( os.isBinary() )
473  {
474  os << static_cast<GLenum>(value);
475  }
476  else if ( ParentType::_defaultValue!=value )
477  {
478  os << os.PROPERTY((ParentType::_name).c_str()) << GLENUM(value) << std::endl;
479  }
480  return true;
481  }
482 
483 public:
486 };
487 
488 template<typename C>
489 class StringSerializer : public TemplateSerializer<std::string>
490 {
491 public:
493  typedef const std::string& (C::*Getter)() const;
494  typedef void (C::*Setter)( const std::string& );
495 
496  StringSerializer( const char* name, const std::string& def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
497  {
499  }
500 
501  virtual bool read( InputStream& is, osg::Object& obj )
502  {
503  C& object = OBJECT_CAST<C&>(obj);
504  std::string value;
505  if ( is.isBinary() )
506  {
507  is >> value;
508  (object.*_setter)( value );
509  }
510  else if ( is.matchString(ParentType::_name) )
511  {
512  is.readWrappedString( value );
513  if ( !value.empty() && (_setter!=0) )
514  (object.*_setter)( value );
515  }
516  return true;
517  }
518 
519  virtual bool write( OutputStream& os, const osg::Object& obj )
520  {
521  const C& object = OBJECT_CAST<const C&>(obj);
522  const std::string& value = (object.*_getter)();
523  if ( os.isBinary() )
524  {
525  os << value;
526  }
527  else if ( ParentType::_defaultValue!=value )
528  {
529  os << os.PROPERTY((ParentType::_name).c_str());
530  os.writeWrappedString( value );
531  os << std::endl;
532  }
533  return true;
534  }
535 
536 public:
539 };
540 
541 template<typename C, typename P>
543 {
544 public:
546  typedef const P* (C::*Getter)() const;
547  typedef void (C::*Setter)( P* );
548 
549  ObjectSerializer( const char* name, P* def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
550  {
552  }
553 
554  virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST<C&>(obj); (object.*_setter)( *(reinterpret_cast<P**>(value)) ); return true; }
555  virtual bool get(const osg::Object& obj, void* value) { const C& object = OBJECT_CAST<const C&>(obj);*(reinterpret_cast<const P**>(value )) = (object.*_getter)(); return true; }
556 
557  virtual bool read( InputStream& is, osg::Object& obj )
558  {
559  C& object = OBJECT_CAST<C&>(obj);
560  bool hasObject = false;
561  if ( is.isBinary() )
562  {
563  is >> hasObject;
564  if ( hasObject )
565  {
566  P* value = dynamic_cast<P*>( is.readObject() );
567  (object.*_setter)( value );
568  }
569  }
570  else if ( is.matchString(ParentType::_name) )
571  {
572  is >> hasObject;
573  if ( hasObject )
574  {
575  is >> is.BEGIN_BRACKET;
576  P* value = dynamic_cast<P*>( is.readObject() );
577  (object.*_setter)( value );
578  is >> is.END_BRACKET;
579  }
580  }
581  return true;
582  }
583 
584  virtual bool write( OutputStream& os, const osg::Object& obj )
585  {
586  const C& object = OBJECT_CAST<const C&>(obj);
587  const P* value = (object.*_getter)();
588  bool hasObject = (value!=NULL);
589  if ( os.isBinary() )
590  {
591  os << hasObject;
592  if (hasObject)
593  {
594  os.writeObject( value );
595  }
596  }
597  else if ( ParentType::_defaultValue!=value )
598  {
599  os << os.PROPERTY((ParentType::_name).c_str()) << hasObject;
600  if ( hasObject )
601  {
602  os << os.BEGIN_BRACKET << std::endl;
603  os.writeObject( value );
604  os << os.END_BRACKET;
605  }
606  os << std::endl;
607  }
608  return true;
609  }
610 
611 public:
614 };
615 
616 template<typename C, typename P>
618 {
619 public:
621  typedef const P* (C::*Getter)() const;
622  typedef void (C::*Setter)( P* );
623 
624  ImageSerializer( const char* name, P* def, Getter gf, Setter sf ):
625  ParentType(name, def), _getter(gf), _setter(sf)
626  {
628  }
629 
630  virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST<C&>(obj); (object.*_setter)( *(reinterpret_cast<P**>(value)) ); return true; }
631  virtual bool get(const osg::Object& obj, void* value) { const C& object = OBJECT_CAST<const C&>(obj);*(reinterpret_cast<const P**>(value )) = (object.*_getter)(); return true; }
632 
633  virtual bool read( InputStream& is, osg::Object& obj )
634  {
635  C& object = OBJECT_CAST<C&>(obj);
636  bool hasObject = false;
637  if ( is.isBinary() )
638  {
639  is >> hasObject;
640  if ( hasObject )
641  {
642  P* value = dynamic_cast<P*>( is.readImage() );
643  (object.*_setter)( value );
644  }
645  }
646  else if ( is.matchString(ParentType::_name) )
647  {
648  is >> hasObject;
649  if ( hasObject )
650  {
651  is >> is.BEGIN_BRACKET;
652  P* value = dynamic_cast<P*>( is.readImage() );
653  (object.*_setter)( value );
654  is >> is.END_BRACKET;
655  }
656  }
657  return true;
658  }
659 
660  virtual bool write( OutputStream& os, const osg::Object& obj )
661  {
662  const C& object = OBJECT_CAST<const C&>(obj);
663  const P* value = (object.*_getter)();
664  bool hasObject = (value!=NULL);
665  if ( os.isBinary() )
666  {
667  os << hasObject;
668  os.writeImage( value );
669  }
670  else if ( ParentType::_defaultValue!=value )
671  {
672  os << os.PROPERTY((ParentType::_name).c_str()) << hasObject;
673  if ( hasObject )
674  {
675  os << os.BEGIN_BRACKET << std::endl;
676  os.writeImage( value );
677  os << os.END_BRACKET;
678  }
679  os << std::endl;
680  }
681  return true;
682  }
683 
684 public:
687 };
688 
689 template<typename C, typename P, typename B>
691 {
692 public:
694  typedef P (C::*Getter)() const;
695  typedef B (C::*Setter)( P );
696 
697  EnumSerializer( const char* name, P def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
698  {
700  }
701 
702  virtual IntLookup* getIntLookup() { return &_lookup; }
703 
704  void add( const char* str, P value )
705  { _lookup.add(str, static_cast<IntLookup::Value>(value)); }
706 
707  P getValue( const char* str )
708  { return static_cast<P>(_lookup.getValue(str)); }
709 
710  const std::string& getString( P value )
711  { return _lookup.getString(static_cast<IntLookup::Value>(value)); }
712 
713  virtual bool read( InputStream& is, osg::Object& obj )
714  {
715  C& object = OBJECT_CAST<C&>(obj);
716  IntLookup::Value value;
717  if ( is.isBinary() )
718  {
719  is >> value;
720  (object.*_setter)( static_cast<P>(value) );
721  }
722  else if ( is.matchString(ParentType::_name) )
723  {
724  std::string str; is >> str;
725  (object.*_setter)( getValue(str.c_str()) );
726  }
727  return true;
728  }
729 
730  virtual bool write( osgDB::OutputStream& os, const osg::Object& obj )
731  {
732  const C& object = OBJECT_CAST<const C&>(obj);
733  const P value = (object.*_getter)();
734  if ( os.isBinary() )
735  {
736  os << (IntLookup::Value)value;
737  }
738  else if ( ParentType::_defaultValue!=value )
739  {
740  os << os.PROPERTY((ParentType::_name).c_str()) << getString(value) << std::endl;
741  }
742  return true;
743  }
744 
745 public:
748 
749 protected:
751 };
752 
753 
754 template<typename C, typename P>
756 {
757 public:
758  typedef typename P::value_type ValueType;
759  typedef typename P::const_iterator ConstIterator;
760  typedef const P& (C::*Getter)() const;
761  typedef void (C::*Setter)( const P& );
762 
763  ListSerializer( const char* name, Getter gf, Setter sf ):
765  _name(name), _getter(gf), _setter(sf) {}
766 
767  virtual const std::string& getName() const { return _name; }
768 
769  virtual bool read( InputStream& is, osg::Object& obj )
770  {
771  C& object = OBJECT_CAST<C&>(obj);
772  unsigned int size = 0;
773  P list;
774  if ( is.isBinary() )
775  {
776  is >> size;
777  for ( unsigned int i=0; i<size; ++i )
778  {
779  ValueType value;
780  is >> value;
781  list.push_back( value );
782  }
783  if ( size>0 ) (object.*_setter)( list );
784  }
785  else if ( is.matchString(_name) )
786  {
787  is >> size;
788  if ( size>0 ) is >> is.BEGIN_BRACKET;
789  for ( unsigned int i=0; i<size; ++i )
790  {
791  ValueType value;
792  is >> value;
793  list.push_back( value );
794  }
795  if ( size>0 )
796  {
797  is >> is.END_BRACKET;
798  (object.*_setter)( list );
799  }
800  }
801  return true;
802  }
803 
804  virtual bool write( OutputStream& os, const osg::Object& obj )
805  {
806  const C& object = OBJECT_CAST<const C&>(obj);
807  const P& list = (object.*_getter)();
808  unsigned int size = (unsigned int)list.size();
809  if ( os.isBinary() )
810  {
811  os << size;
812  for ( ConstIterator itr=list.begin();
813  itr!=list.end(); ++itr )
814  {
815  os << (*itr);
816  }
817  }
818  else if ( size>0 )
819  {
820  os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
821  for ( ConstIterator itr=list.begin();
822  itr!=list.end(); ++itr )
823  {
824  os << (*itr);
825  }
826  os << std::endl;
827  os << os.END_BRACKET << std::endl;
828  }
829  return true;
830  }
831 
832 public:
833  std::string _name;
836 };
837 
839 {
840 public:
841 
842  VectorBaseSerializer(BaseSerializer::Type elementType, unsigned int elementSize):
844  _elementType(elementType),_elementSize(elementSize) {}
845 
846  Type getElementType() const { return _elementType; }
847  unsigned int getElementSize() const { return _elementSize; }
848 
849  virtual unsigned int size(const osg::Object& /*obj*/) const { return 0; }
850  virtual void resize(osg::Object& /*obj*/, unsigned int /*numElements*/) const {}
851  virtual void reserve(osg::Object& /*obj*/, unsigned int /*numElements*/) const {}
852  virtual void clear(osg::Object& /*obj*/) const {}
853  virtual void addElement(osg::Object& /*obj*/, void* /*ptr*/) const {}
854  virtual void insertElement(osg::Object& /*obj*/, unsigned int /*index*/, void* /*ptr*/) const {}
855  virtual void setElement(osg::Object& /*obj*/, unsigned int /*index*/, void* /*ptr*/) const {}
856  virtual void* getElement(osg::Object& /*obj*/, unsigned int /*index*/) const { return 0; }
857  virtual const void* getElement(const osg::Object& /*obj*/, unsigned int /*index*/) const { return 0; }
858 
859 protected:
861  unsigned int _elementSize;
862 };
863 
864 
865 template<typename C, typename P>
867 {
868 public:
869  typedef typename P::value_type ValueType;
870  typedef typename P::const_iterator ConstIterator;
871  typedef P& (C::*Getter)();
872  typedef const P& (C::*ConstGetter)() const;
873  typedef void (C::*Setter)( const P& );
874 
875  VectorSerializer( const char* name, ConstGetter cgf, Getter gf, Setter sf, BaseSerializer::Type elementType, unsigned int numElementsOnRow):
876  VectorBaseSerializer(elementType, sizeof(ValueType)),
877  _name(name),
878  _constgetter(cgf), _getter(gf), _setter(sf),
879  _numElementsOnRow(numElementsOnRow) {}
880 
881  virtual const std::string& getName() const { return _name; }
882 
883  virtual unsigned int size(const osg::Object& obj) const
884  {
885  const C& object = OBJECT_CAST<const C&>(obj);
886  const P& list = (object.*_constgetter)();
887  return static_cast<unsigned int>(list.size());
888  }
889  virtual void resize(osg::Object& obj, unsigned int numElements) const
890  {
891  C& object = OBJECT_CAST<C&>(obj);
892  P& list = (object.*_getter)();
893  list.resize(numElements);
894  }
895  virtual void reserve(osg::Object& obj, unsigned int numElements) const
896  {
897  C& object = OBJECT_CAST<C&>(obj);
898  P& list = (object.*_getter)();
899  list.reserve(numElements);
900  }
901  virtual void clear(osg::Object& obj) const
902  {
903  C& object = OBJECT_CAST<C&>(obj);
904  P& list = (object.*_getter)();
905  list.clear();
906  }
907  virtual void addElement(osg::Object& obj, void* ptr) const
908  {
909  C& object = OBJECT_CAST<C&>(obj);
910  P& list = (object.*_getter)();
911  list.push_back(*reinterpret_cast<ValueType*>(ptr));
912  }
913  virtual void insertElement(osg::Object& obj, unsigned int index, void* ptr) const
914  {
915  C& object = OBJECT_CAST<C&>(obj);
916  P& list = (object.*_getter)();
917  if (index>=list.size()) list.resize(index+1);
918  list.insert(list.begin()+index, *reinterpret_cast<ValueType*>(ptr));
919  }
920  virtual void setElement(osg::Object& obj, unsigned int index, void* ptr) const
921  {
922  C& object = OBJECT_CAST<C&>(obj);
923  P& list = (object.*_getter)();
924  if (index>=list.size()) list.resize(index+1);
925  list[index] = *reinterpret_cast<ValueType*>(ptr);
926  }
927  virtual void* getElement(osg::Object& obj, unsigned int index) const
928  {
929  C& object = OBJECT_CAST<C&>(obj);
930  P& list = (object.*_getter)();
931  if (index>=list.size()) return 0;
932  else return &list[index];
933  }
934  virtual const void* getElement(const osg::Object& obj, unsigned int index) const
935  {
936  const C& object = OBJECT_CAST<const C&>(obj);
937  const P& list = (object.*_constgetter)();
938  if (index>=list.size()) return 0;
939  else return &list[index];
940  }
941 
942  virtual bool read( InputStream& is, osg::Object& obj )
943  {
944  C& object = OBJECT_CAST<C&>(obj);
945  unsigned int size = 0;
946  P list;
947  if ( is.isBinary() )
948  {
949  is >> size;
950  for ( unsigned int i=0; i<size; ++i )
951  {
952  ValueType value;
953  is >> value;
954  list.push_back( value );
955  }
956  if ( size>0 ) (object.*_setter)( list );
957  }
958  else if ( is.matchString(_name) )
959  {
960  is >> size;
961  if ( size>0 ) is >> is.BEGIN_BRACKET;
962  for ( unsigned int i=0; i<size; ++i )
963  {
964  ValueType value;
965  is >> value;
966  list.push_back( value );
967  }
968  if ( size>0 )
969  {
970  is >> is.END_BRACKET;
971  (object.*_setter)( list );
972  }
973  }
974  return true;
975  }
976 
977  virtual bool write( OutputStream& os, const osg::Object& obj )
978  {
979  const C& object = OBJECT_CAST<const C&>(obj);
980  const P& list = (object.*_constgetter)();
981  unsigned int size = (unsigned int)list.size();
982  if ( os.isBinary() )
983  {
984  os << size;
985  for ( ConstIterator itr=list.begin();
986  itr!=list.end(); ++itr )
987  {
988  os << (*itr);
989  }
990  }
991  else if ( size>0 )
992  {
993  os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
994  if (_numElementsOnRow==0)
995  {
996  for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
997  {
998  os << (*itr);
999  }
1000  }
1001  else if (_numElementsOnRow==1)
1002  {
1003  for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
1004  {
1005  os << (*itr); os << std::endl;
1006  }
1007  }
1008  else
1009  {
1010  unsigned int i = _numElementsOnRow-1;
1011  for (ConstIterator itr=list.begin(); itr!=list.end(); ++itr)
1012  {
1013  os << (*itr);
1014  if (i==0) { os << std::endl; i = _numElementsOnRow-1; }
1015  else --i;
1016  }
1017  if (i!=_numElementsOnRow) os << std::endl;
1018  }
1019  os << os.END_BRACKET << std::endl;
1020  }
1021  return true;
1022  }
1023 
1024 public:
1025  std::string _name;
1029  unsigned int _numElementsOnRow;
1030 };
1031 
1032 
1033 template<typename C>
1035 {
1036 public:
1037  typedef typename C::value_type ValueType;
1038  typedef typename C::const_iterator ConstIterator;
1039 
1040  IsAVectorSerializer( const char* name, BaseSerializer::Type elementType, unsigned int numElementsOnRow) :
1041  VectorBaseSerializer(elementType, sizeof(ValueType)),
1042  _name(name),
1043  _numElementsOnRow(numElementsOnRow) {}
1044 
1045  virtual const std::string& getName() const { return _name; }
1046 
1047  virtual unsigned int size(const osg::Object& obj) const
1048  {
1049  const C& list = OBJECT_CAST<const C&>(obj);
1050  return static_cast<unsigned int>(list.size());
1051  }
1052  virtual void resize(osg::Object& obj, unsigned int numElements) const
1053  {
1054  C& list = OBJECT_CAST<C&>(obj);
1055  list.resize(numElements);
1056  }
1057  virtual void reserve(osg::Object& obj, unsigned int numElements) const
1058  {
1059  C& list = OBJECT_CAST<C&>(obj);
1060  list.reserve(numElements);
1061  }
1062  virtual void clear(osg::Object& obj) const
1063  {
1064  C& list = OBJECT_CAST<C&>(obj);
1065  list.clear();
1066  }
1067  virtual void addElement(osg::Object& obj, void* ptr) const
1068  {
1069  C& list = OBJECT_CAST<C&>(obj);
1070  list.push_back(*reinterpret_cast<ValueType*>(ptr));
1071  }
1072  virtual void insertElement(osg::Object& obj, unsigned int index, void* ptr) const
1073  {
1074  C& list = OBJECT_CAST<C&>(obj);
1075  if (index>=list.size()) list.resize(index+1);
1076  list.insert(list.begin()+index, *reinterpret_cast<ValueType*>(ptr));
1077  }
1078  virtual void setElement(osg::Object& obj, unsigned int index, void* ptr) const
1079  {
1080  C& list = OBJECT_CAST<C&>(obj);
1081  if (index>=list.size()) list.resize(index+1);
1082  list[index] = *reinterpret_cast<ValueType*>(ptr);
1083  }
1084  virtual void* getElement(osg::Object& obj, unsigned int index) const
1085  {
1086  C& list = OBJECT_CAST<C&>(obj);
1087  if (index>=list.size()) return 0;
1088  else return &list[index];
1089  }
1090 
1091  virtual const void* getElement(const osg::Object& obj, unsigned int index) const
1092  {
1093  const C& list = OBJECT_CAST<const C&>(obj);
1094  if (index>=list.size()) return 0;
1095  else return &list[index];
1096  }
1097 
1098  virtual bool read( InputStream& is, osg::Object& obj )
1099  {
1100  C& list = OBJECT_CAST<C&>(obj);
1101  unsigned int size = 0;
1102  if ( is.isBinary() )
1103  {
1104  is >> size;
1105  for ( unsigned int i=0; i<size; ++i )
1106  {
1107  ValueType value;
1108  is >> value;
1109  list.push_back( value );
1110  }
1111  }
1112  else if ( is.matchString(_name) )
1113  {
1114  is >> size;
1115  if ( size>0 ) is >> is.BEGIN_BRACKET;
1116  for ( unsigned int i=0; i<size; ++i )
1117  {
1118  ValueType value;
1119  is >> value;
1120  list.push_back( value );
1121  }
1122  if ( size>0 )
1123  {
1124  is >> is.END_BRACKET;
1125  }
1126  }
1127  return true;
1128  }
1129 
1130  virtual bool write( OutputStream& os, const osg::Object& obj )
1131  {
1132  const C& list = OBJECT_CAST<const C&>(obj);
1133  unsigned int size = (unsigned int)list.size();
1134  if ( os.isBinary() )
1135  {
1136  os << size;
1137  for ( ConstIterator itr=list.begin();
1138  itr!=list.end(); ++itr )
1139  {
1140  os << (*itr);
1141  }
1142  }
1143  else if ( size>0 )
1144  {
1145  os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
1146  if (_numElementsOnRow==0)
1147  {
1148  for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
1149  {
1150  os << (*itr);
1151  }
1152  }
1153  else if (_numElementsOnRow==1)
1154  {
1155  for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
1156  {
1157  os << (*itr); os << std::endl;
1158  }
1159  }
1160  else
1161  {
1162  unsigned int i = _numElementsOnRow-1;
1163  for (ConstIterator itr=list.begin(); itr!=list.end(); ++itr)
1164  {
1165  os << (*itr);
1166  if (i==0) { os << std::endl; i = _numElementsOnRow-1; }
1167  else --i;
1168  }
1169  if (i!=_numElementsOnRow) os << std::endl;
1170  }
1171  os << os.END_BRACKET << std::endl;
1172  }
1173  return true;
1174  }
1175 
1176 public:
1177  std::string _name;
1178  unsigned int _numElementsOnRow;
1179 };
1180 
1182 {
1183 public:
1185  _keyType(BaseSerializer::RW_UNDEFINED), _keySize(0),
1186  _elementType(BaseSerializer::RW_UNDEFINED),_elementSize(0) {}
1187 
1188  MapIteratorObject(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize):
1189  _keyType(keyType), _keySize(keySize),
1190  _elementType(elementType),_elementSize(elementSize) {}
1191 
1193  osg::Object(rhs, copyop),
1194  _keyType(rhs._keyType), _keySize(rhs._keySize),
1196 
1198 
1200  unsigned int getKeySize() const { return _keySize; }
1201 
1203  unsigned int getElementSize() const { return _elementSize; }
1204 
1205  virtual bool advance() { return false; }
1206  virtual bool valid() const { return false; }
1207  virtual const void* getKey() const { return 0; }
1208  virtual void* getElement() const { return 0; }
1209  virtual void setElement(void* /*ptr*/) const {}
1210 
1211 protected:
1213  unsigned int _keySize;
1214 
1216  unsigned int _elementSize;
1217 };
1218 
1220 {
1221 public:
1222 
1223  MapBaseSerializer(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize):
1225  _keyType(keyType), _keySize(keySize),
1226  _elementType(elementType),_elementSize(elementSize) {}
1227 
1228  Type getKeyType() const { return _keyType; }
1229  unsigned int getKeySize() const { return _keySize; }
1230 
1231  Type getElementType() const { return _elementType; }
1232  unsigned int getElementSize() const { return _elementSize; }
1233 
1234  virtual void clear(osg::Object& /*obj*/) const {}
1235  virtual void setElement(osg::Object& /*obj*/, void* /*ptrKey*/, void* /*ptrValue*/) const {}
1236  virtual void* getElement(osg::Object& /*obj*/, void* /*ptrKey*/) const { return 0; }
1237  virtual const void* getElement(const osg::Object& /*obj*/, void* /*ptrKey*/) const { return 0; }
1238  virtual unsigned int size(const osg::Object& /*obj*/) const { return 0; }
1239 
1240  virtual MapIteratorObject* createIterator(osg::Object& /*obj*/) const { return 0; }
1241  virtual MapIteratorObject* createReverseIterator(osg::Object& /*obj*/) const { return 0; }
1242 
1243 protected:
1245  unsigned int _keySize;
1246 
1248  unsigned int _elementSize;
1249 };
1250 
1251 
1252 template<typename C, typename P>
1254 {
1255 public:
1256  typedef typename P::value_type ValueType;
1257  typedef typename P::key_type KeyType;
1258  typedef typename P::mapped_type ElementType;
1259  typedef typename P::iterator Iterator;
1260  typedef typename P::reverse_iterator ReverseIterator;
1261  typedef typename P::const_iterator ConstIterator;
1262  typedef P& (C::*Getter)();
1263  typedef const P& (C::*ConstGetter)() const;
1264  typedef void (C::*Setter)( const P& );
1265 
1266  MapSerializer( const char* name, ConstGetter cgf, Getter gf, Setter sf, BaseSerializer::Type keyType, BaseSerializer::Type elementType):
1267  MapBaseSerializer(keyType, sizeof(KeyType), elementType, sizeof(ElementType)),
1268  _name(name),
1269  _constgetter(cgf), _getter(gf), _setter(sf) {}
1270 
1271  virtual const std::string& getName() const { return _name; }
1272 
1273  virtual void clear(osg::Object& obj) const
1274  {
1275  C& object = OBJECT_CAST<C&>(obj);
1276  P& map = (object.*_getter)();
1277  map.clear();
1278  }
1279 
1280  virtual void setElement(osg::Object& obj, void* ptrKey, void* ptrValue) const
1281  {
1282  C& object = OBJECT_CAST<C&>(obj);
1283  P& map = (object.*_getter)();
1284  map[*reinterpret_cast<KeyType*>(ptrKey)] = *reinterpret_cast<ElementType*>(ptrValue);
1285  }
1286 
1287  virtual void* getElement(osg::Object& obj, void* ptrKey) const
1288  {
1289  C& object = OBJECT_CAST<C&>(obj);
1290  P& map = (object.*_getter)();
1291  return &(map[*reinterpret_cast<KeyType*>(ptrKey)]);
1292  }
1293 
1294  virtual const void* getElement(const osg::Object& obj, void* ptrKey) const
1295  {
1296  const C& object = OBJECT_CAST<const C&>(obj);
1297  const P& map = (object.*_constgetter)();
1298  ConstIterator itr = map.find(*reinterpret_cast<KeyType*>(ptrKey));
1299  if (itr==map.end()) return 0;
1300  else return &(itr->second);
1301  }
1302 
1303  virtual unsigned int size(const osg::Object& obj) const
1304  {
1305  const C& object = OBJECT_CAST<const C&>(obj);
1306  const P& map = (object.*_constgetter)();
1307  return map.size();
1308  }
1309 
1311  {
1312  MapIterator(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize,
1313  Iterator itr, Iterator endItr):
1314  MapIteratorObject(keyType, keySize, elementType, elementSize),
1315  _itr(itr),_endItr(endItr) {}
1316 
1317  Iterator _itr;
1318  Iterator _endItr;
1319 
1320  virtual bool advance() { if (valid()) ++_itr; return valid(); }
1321  virtual bool valid() const { return _itr!=_endItr; }
1322  virtual const void* getKey() const { return valid() ? &(_itr->first) : 0; }
1323  virtual void* getElement() const { return valid() ? &(_itr->second) : 0; }
1324  virtual void setElement(void* ptr) const { if (valid()) _itr->second = *reinterpret_cast<ElementType*>(ptr); }
1325  };
1326 
1328  {
1329  ReverseMapIterator(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize,
1330  ReverseIterator itr, ReverseIterator endItr):
1331  MapIteratorObject(keyType, keySize, elementType, elementSize),
1332  _itr(itr),_endItr(endItr) {}
1333 
1334  ReverseIterator _itr;
1335  ReverseIterator _endItr;
1336 
1337  virtual bool advance() { if (valid()) ++_itr; return valid(); }
1338  virtual bool valid() const { return _itr!=_endItr; }
1339  virtual const void* getKey() const { return valid() ? &(_itr->first) : 0; }
1340  virtual void* getElement() const { return valid() ? &(_itr->second) : 0; }
1341  virtual void setElement(void* ptr) const { if (valid()) _itr->second = *reinterpret_cast<ElementType*>(ptr); }
1342  };
1343 
1345  {
1346  C& object = OBJECT_CAST<C&>(obj);
1347  P& map = (object.*_getter)();
1348  return new MapIterator(_keyType, _keySize, _elementType, _elementSize, map.begin(), map.end());
1349  }
1350 
1352  {
1353  C& object = OBJECT_CAST<C&>(obj);
1354  P& map = (object.*_getter)();
1355  return new ReverseMapIterator(_keyType, _keySize, _elementType, _elementSize, map.rbegin(), map.rend());
1356  }
1357 
1358  virtual bool read( InputStream& is, osg::Object& obj )
1359  {
1360  C& object = OBJECT_CAST<C&>(obj);
1361  unsigned int size = 0;
1362  P map;
1363  if ( is.isBinary() )
1364  {
1365  is >> size;
1366  for ( unsigned int i=0; i<size; ++i )
1367  {
1368  KeyType key;
1369  ElementType value;
1370  is >> key >> value;
1371  map[key] = value;
1372  }
1373  (object.*_setter)( map );
1374  }
1375  else if ( is.matchString(_name) )
1376  {
1377  is >> size;
1378  if ( size>0 )
1379  {
1380  is >> is.BEGIN_BRACKET;
1381  for ( unsigned int i=0; i<size; ++i )
1382  {
1383  KeyType key;
1384  ElementType value;
1385  is >> key >> value;
1386  map[key] = value;
1387  }
1388  is >> is.END_BRACKET;
1389  }
1390  (object.*_setter)( map );
1391  }
1392  return true;
1393  }
1394 
1395  virtual bool write( OutputStream& os, const osg::Object& obj )
1396  {
1397  const C& object = OBJECT_CAST<const C&>(obj);
1398  const P& map = (object.*_constgetter)();
1399  unsigned int size = (unsigned int)map.size();
1400  if ( os.isBinary() )
1401  {
1402  os << size;
1403  for ( ConstIterator itr=map.begin();
1404  itr!=map.end(); ++itr )
1405  {
1406  os << itr->first << itr->second;
1407  }
1408  }
1409  else if ( size>0 )
1410  {
1411  os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
1412  for ( ConstIterator itr=map.begin(); itr!=map.end(); ++itr )
1413  {
1414  os << itr->first << itr->second; os << std::endl;
1415  }
1416  os << os.END_BRACKET << std::endl;
1417  }
1418  return true;
1419  }
1420 
1421 public:
1422  std::string _name;
1426 };
1427 
1428 template<typename C, typename P=unsigned int>
1430 {
1431 public:
1433  typedef P (C::*Getter)() const;
1434  typedef void (C::*Setter)( P );
1435 
1436  BitFlagsSerializer( const char* name, P def, Getter gf, Setter sf )
1437  : ParentType(name, def), _getter(gf), _setter(sf) {}
1438 
1439  void add( const char* str, P value )
1440  {
1441  _lookup.add(str, static_cast<osgDB::IntLookup::Value>(value));
1442  }
1443 
1444  P getValue( const char* str )
1445  { return static_cast<P>(_lookup.getValue(str)); }
1446 
1447  const std::string& getString( P value )
1448  { return _lookup.getString(static_cast<osgDB::IntLookup::Value>(value)); }
1449 
1450  virtual bool read( osgDB::InputStream& is, osg::Object& obj )
1451  {
1452  C& object = OBJECT_CAST<C&>(obj);
1453  if ( is.isBinary() )
1454  {
1455  if (is.getFileVersion()<123)
1456  {
1457  bool ok = false; is >> ok; //code from user serialized ensuring backwards-compatibility
1458  if ( !ok ) return true;
1459  }
1460 
1461  P mask;
1462  is >> mask;
1463  (object.*_setter)( mask );
1464  }
1465  else
1466  {
1467  if ( !is.matchString(ParentType::_name) ) //code from user serialized ensuring backwards-compatibility
1468  return true;
1469  P mask=P();
1470  std::string maskSetString;
1471  is >> maskSetString;
1472  osgDB::StringList maskList;
1473  osgDB::split( maskSetString, maskList, '|' );
1474  for ( unsigned int i=0; i<maskList.size(); ++i )
1475  mask |= _lookup.getValue( maskList[i].c_str());
1476  (object.*_setter)( mask );
1477  }
1478  return true;
1479  }
1480 
1481  virtual bool write( osgDB::OutputStream& os, const osg::Object& obj )
1482  {
1483  const C& object = OBJECT_CAST<const C&>(obj);
1484  const P mask = (object.*_getter)();
1485  bool ok = ParentType::_defaultValue!=static_cast<P>(mask);
1486  if ( os.isBinary() )
1487  {
1488  if (os.getFileVersion()<123)
1489  {
1490  os << ok;
1491  if ( !ok )
1492  return true;
1493  }
1494  os << (int)mask; //just write int value in binary case
1495  }
1496  else
1497  {
1498  if ( !ok )
1499  return true;
1500  os << os.PROPERTY(ParentType::_name.c_str());
1501 
1502  std::string maskString;
1504  for( osgDB::IntLookup::ValueToString::const_iterator itr = v2sm.begin() ; itr != v2sm.end() ; itr++)
1505  if( (mask & itr->first) != 0 )
1506  maskString += std::string(itr->second + "|");
1507 
1508  if ( !maskString.size() )
1509  maskString = std::string("NONE|");
1510  maskString.erase(maskString.size()-1,1);
1511  os << maskString << std::endl; //remove last "|"
1512  }
1513  return true;
1514  }
1515 
1516 public:
1519 
1520 protected:
1522 };
1523 
1524 // ADDING MANIPULATORS
1525 #define ADD_SERIALIZER(S) \
1526  wrapper->addSerializer( (S) )
1527 
1528 #define ADD_USER_SERIALIZER(PROP) \
1529  wrapper->addSerializer( new osgDB::UserSerializer<MyClass>( \
1530  #PROP, &check##PROP, &read##PROP, &write##PROP), osgDB::BaseSerializer::RW_USER )
1531 
1532 #define ADD_BOOL_SERIALIZER(PROP, DEF) \
1533  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, bool >( \
1534  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOOL )
1535 
1536 #define ADD_CHAR_SERIALIZER(PROP, DEF) \
1537  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, char >( \
1538  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_CHAR )
1539 
1540 #define ADD_UCHAR_SERIALIZER(PROP, DEF) \
1541  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned char >( \
1542  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UCHAR )
1543 
1544 #define ADD_SHORT_SERIALIZER(PROP, DEF) \
1545  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, short >( \
1546  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_SHORT )
1547 
1548 #define ADD_USHORT_SERIALIZER(PROP, DEF) \
1549  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \
1550  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_USHORT )
1551 
1552 #define ADD_HEXSHORT_SERIALIZER(PROP, DEF) \
1553  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \
1554  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_USHORT )
1555 
1556 #define ADD_INT_SERIALIZER(PROP, DEF) \
1557  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, int >( \
1558  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
1559 
1560 #define ADD_INT_SERIALIZER_NO_SET(PROP, DEF) \
1561  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, int >( \
1562  #PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_INT )
1563 
1564 #define ADD_UINT_SERIALIZER(PROP, DEF) \
1565  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \
1566  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT )
1567 
1568 #define ADD_UINT_SERIALIZER_NO_SET(PROP, DEF) \
1569  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \
1570  #PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_UINT )
1571 
1572 #define ADD_GLINT_SERIALIZER(PROP, DEF) \
1573  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLint >( \
1574  #PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
1575 
1576 #define ADD_HEXINT_SERIALIZER(PROP, DEF) \
1577  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \
1578  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_UINT )
1579 
1580 #define ADD_FLOAT_SERIALIZER(PROP, DEF) \
1581  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, float >( \
1582  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_FLOAT )
1583 
1584 #define ADD_DOUBLE_SERIALIZER(PROP, DEF) \
1585  wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, double >( \
1586  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_DOUBLE )
1587 
1588 #define ADD_REF_BOOL_SERIALIZER(PROP, DEF) \
1589  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, bool >( \
1590  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOOL )
1591 
1592 #define ADD_REF_CHAR_SERIALIZER(PROP, DEF) \
1593  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, char >( \
1594  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_CHAR )
1595 
1596 #define ADD_REF_UCHAR_SERIALIZER(PROP, DEF) \
1597  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned char >( \
1598  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UCHAR )
1599 
1600 #define ADD_REF_SHORT_SERIALIZER(PROP, DEF) \
1601  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, short >( \
1602  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_SHORT )
1603 
1604 #define ADD_REF_USHORT_SERIALIZER(PROP, DEF) \
1605  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned short >( \
1606  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_USHORT )
1607 
1608 #define ADD_REF_HEXSHORT_SERIALIZER(PROP, DEF) \
1609  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned short >( \
1610  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_USHORT )
1611 
1612 #define ADD_REF_INT_SERIALIZER(PROP, DEF) \
1613  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, int >( \
1614  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
1615 
1616 #define ADD_REF_UINT_SERIALIZER(PROP, DEF) \
1617  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned int >( \
1618  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT )
1619 
1620 #define ADD_REF_GLINT_SERIALIZER(PROP, DEF) \
1621  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, GLint >( \
1622  #PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
1623 
1624 #define ADD_REF_HEXINT_SERIALIZER(PROP, DEF) \
1625  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned int >( \
1626  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_UINT )
1627 
1628 #define ADD_REF_FLOAT_SERIALIZER(PROP, DEF) \
1629  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, float >( \
1630  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_FLOAT )
1631 
1632 #define ADD_REF_DOUBLE_SERIALIZER(PROP, DEF) \
1633  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, double >( \
1634  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_DOUBLE )
1635 
1636 
1637 #define ADD_VEC2B_SERIALIZER(PROP, DEF) \
1638  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2b >( \
1639  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2B )
1640 
1641 #define ADD_VEC2UB_SERIALIZER(PROP, DEF) \
1642  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2ub >( \
1643  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2UB )
1644 
1645 #define ADD_VEC2S_SERIALIZER(PROP, DEF) \
1646  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2s >( \
1647  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2S )
1648 
1649 #define ADD_VEC2US_SERIALIZER(PROP, DEF) \
1650  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2us >( \
1651  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2US )
1652 
1653 #define ADD_VEC2I_SERIALIZER(PROP, DEF) \
1654  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2i >( \
1655  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2I )
1656 
1657 #define ADD_VEC2UI_SERIALIZER(PROP, DEF) \
1658  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2ui >( \
1659  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2UI )
1660 
1661 #define ADD_VEC2F_SERIALIZER(PROP, DEF) \
1662  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2f >( \
1663  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2F )
1664 
1665 #define ADD_VEC2D_SERIALIZER(PROP, DEF) \
1666  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2d >( \
1667  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2D )
1668 
1669 #define ADD_VEC2_SERIALIZER(PROP, DEF) ADD_VEC2F_SERIALIZER(PROP, DEF)
1670 
1671 
1672 #define ADD_VEC3B_SERIALIZER(PROP, DEF) \
1673  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3b >( \
1674  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3B )
1675 
1676 #define ADD_VEC3UB_SERIALIZER(PROP, DEF) \
1677  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3ub >( \
1678  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3UB )
1679 
1680 #define ADD_VEC3S_SERIALIZER(PROP, DEF) \
1681  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3s >( \
1682  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3S )
1683 
1684 #define ADD_VEC3US_SERIALIZER(PROP, DEF) \
1685  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3us >( \
1686  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3US )
1687 
1688 #define ADD_VEC3I_SERIALIZER(PROP, DEF) \
1689  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3i >( \
1690  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3I )
1691 
1692 #define ADD_VEC3UI_SERIALIZER(PROP, DEF) \
1693  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3ui >( \
1694  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3UI )
1695 
1696 #define ADD_VEC3F_SERIALIZER(PROP, DEF) \
1697  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3f >( \
1698  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3F )
1699 
1700 #define ADD_VEC3D_SERIALIZER(PROP, DEF) \
1701  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3d >( \
1702  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3D )
1703 
1704 #define ADD_VEC3_SERIALIZER(PROP, DEF) ADD_VEC3F_SERIALIZER(PROP, DEF)
1705 
1706 #define ADD_VEC4B_SERIALIZER(PROP, DEF) \
1707  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4b >( \
1708  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4B )
1709 
1710 #define ADD_VEC4UB_SERIALIZER(PROP, DEF) \
1711  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4ub >( \
1712  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4UB )
1713 
1714 #define ADD_VEC4S_SERIALIZER(PROP, DEF) \
1715  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4s >( \
1716  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4S )
1717 
1718 #define ADD_VEC4US_SERIALIZER(PROP, DEF) \
1719  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4us >( \
1720  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4US )
1721 
1722 #define ADD_VEC4I_SERIALIZER(PROP, DEF) \
1723  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4i >( \
1724  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4I )
1725 
1726 #define ADD_VEC4UI_SERIALIZER(PROP, DEF) \
1727  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4ui >( \
1728  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4UI )
1729 
1730 #define ADD_VEC4F_SERIALIZER(PROP, DEF) \
1731  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4f >( \
1732  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4F )
1733 
1734 #define ADD_VEC4D_SERIALIZER(PROP, DEF) \
1735  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4d >( \
1736  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4D )
1737 
1738 #define ADD_VEC4_SERIALIZER(PROP, DEF) ADD_VEC4F_SERIALIZER(PROP, DEF)
1739 
1740 #define ADD_QUAT_SERIALIZER(PROP, DEF) \
1741  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Quat >( \
1742  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_QUAT )
1743 
1744 #define ADD_PLANE_SERIALIZER(PROP, DEF) \
1745  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Plane >( \
1746  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_PLANE )
1747 
1748 #define ADD_MATRIXF_SERIALIZER(PROP, DEF) \
1749  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixf >( \
1750  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXF )
1751 
1752 #define ADD_MATRIXD_SERIALIZER(PROP, DEF) \
1753  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixd >( \
1754  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXD )
1755 
1756 #define ADD_MATRIX_SERIALIZER(PROP, DEF) \
1757  wrapper->addSerializer( new osgDB::MatrixSerializer< MyClass >( \
1758  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIX )
1759 
1760 
1761 #define ADD_BOUNDINGBOXF_SERIALIZER(PROP, DEF) \
1762  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingBoxf >( \
1763  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGBOXF )
1764 
1765 #define ADD_BOUNDINGBOXD_SERIALIZER(PROP, DEF) \
1766  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingBoxd >( \
1767  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGBOXD )
1768 
1769 #define ADD_BOUNDINGSPHEREF_SERIALIZER(PROP, DEF) \
1770  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingSpheref >( \
1771  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGSPHEREF )
1772 
1773 #define ADD_BOUNDINGSPHERED_SERIALIZER(PROP, DEF) \
1774  wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingSphered >( \
1775  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGSPHERED )
1776 
1777 
1778 #define ADD_GLENUM_SERIALIZER(PROP, TYPE, DEF) \
1779  wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \
1780  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_GLENUM )
1781 
1782 #define ADD_GLENUM_SERIALIZER_NO_SET(PROP, TYPE, DEF) \
1783  wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \
1784  #PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_GLENUM )
1785 
1786 #define ADD_STRING_SERIALIZER(PROP, DEF) \
1787  wrapper->addSerializer( new osgDB::StringSerializer< MyClass >( \
1788  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_STRING )
1789 
1790 #define ADD_OBJECT_SERIALIZER(PROP, TYPE, DEF) \
1791  wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \
1792  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_OBJECT )
1793 
1794 #define ADD_OBJECT_SERIALIZER_NO_SET(PROP, TYPE, DEF) \
1795  wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \
1796  #PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_OBJECT )
1797 
1798 #define ADD_IMAGE_SERIALIZER(PROP, TYPE, DEF) \
1799  wrapper->addSerializer( new osgDB::ImageSerializer< MyClass, TYPE >( \
1800  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_IMAGE )
1801 
1802 #define ADD_LIST_SERIALIZER(PROP, TYPE) \
1803  wrapper->addSerializer( new osgDB::ListSerializer< MyClass, TYPE >( \
1804  #PROP, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_LIST )
1805 
1806 
1807 #define ADD_VECTOR_SERIALIZER(PROP, TYPE, ELEMENTTYPE, NUMELEMENTSONROW) \
1808  wrapper->addSerializer( new osgDB::VectorSerializer< MyClass, TYPE >( \
1809  #PROP, &MyClass::get##PROP, &MyClass::get##PROP, &MyClass::set##PROP, ELEMENTTYPE, NUMELEMENTSONROW), osgDB::BaseSerializer::RW_VECTOR )
1810 
1811 #define ADD_ISAVECTOR_SERIALIZER(PROP, ELEMENTTYPE, NUMELEMENTSONROW) \
1812  wrapper->addSerializer( new osgDB::IsAVectorSerializer< MyClass >( #PROP, ELEMENTTYPE, NUMELEMENTSONROW), osgDB::BaseSerializer::RW_VECTOR )
1813 
1814 #define BEGIN_ENUM_SERIALIZER(PROP, DEF) \
1815  { typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, void> MySerializer; \
1816  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1817  #PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
1818 
1819 #define BEGIN_ENUM_SERIALIZER2(PROP, TYPE, DEF) \
1820  { typedef osgDB::EnumSerializer<MyClass, TYPE, void> MySerializer; \
1821  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1822  #PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
1823 
1824 #define BEGIN_ENUM_SERIALIZER3(PROP, DEF) \
1825  { typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, bool> MySerializer; \
1826  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1827  #PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
1828 
1829 #define BEGIN_ENUM_SERIALIZER4(PROPERTIES_CLASS, PROP, DEF) \
1830  { typedef osgDB::EnumSerializer<MyClass, PROPERTIES_CLASS::PROP, void> MySerializer; \
1831  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1832  #PROP, PROPERTIES_CLASS::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
1833 
1834 #define BEGIN_ENUM_SERIALIZER_NO_SET(PROP, DEF) \
1835  { typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, void> MySerializer; \
1836  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1837  #PROP, MyClass::DEF, &MyClass::get##PROP, 0)
1838 
1839 #define ADD_ENUM_VALUE(VALUE) \
1840  serializer->add(#VALUE, MyClass::VALUE)
1841 
1842 #define ADD_ENUM_CLASS_VALUE(CLASS, VALUE) \
1843  serializer->add(#VALUE, CLASS::VALUE)
1844 
1845 #define END_ENUM_SERIALIZER() \
1846  wrapper->addSerializer(serializer.get(), osgDB::BaseSerializer::RW_ENUM); }
1847 
1849 #define BEGIN_BITFLAGS_SERIALIZER(PROP, DEF) \
1850  { typedef osgDB::BitFlagsSerializer<MyClass> MySerializer; \
1851  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1852  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP)
1853 
1854 #define BEGIN_UINT_BITFLAGS_SERIALIZER(PROP, DEF) \
1855  { typedef osgDB::BitFlagsSerializer<MyClass, unsigned int> MySerializer; \
1856  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1857  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP)
1858 
1859 #define BEGIN_INT_BITFLAGS_SERIALIZER(PROP, DEF) \
1860  { typedef osgDB::BitFlagsSerializer<MyClass, int> MySerializer; \
1861  osg::ref_ptr<MySerializer> serializer = new MySerializer( \
1862  #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP)
1863 
1864 #define ADD_BITFLAG_VALUE(VALUE_NAME, VALUE) \
1865  serializer->add(#VALUE_NAME, VALUE)
1866 
1867 #define END_BITFLAGS_SERIALIZER() \
1868  wrapper->addSerializer(serializer.get(), osgDB::BaseSerializer::RW_INT); }
1869 
1870 // VERSION CONTROL OPERATORS
1871 #define UPDATE_TO_VERSION(VER) \
1872  wrapper->setUpdatedVersion( (VER) );
1873 
1874 #define UPDATE_TO_VERSION_SCOPED(VER) \
1875  osgDB::UpdateWrapperVersionProxy uwvp(wrapper, (VER));
1876 
1877 #define REMOVE_SERIALIZER(PROP) \
1878  wrapper->markSerializerAsRemoved( #PROP );
1879 
1880 #define ADD_MAP_SERIALIZER(PROP, TYPE, KEYTYPE, ELEMENTTYPE) \
1881  wrapper->addSerializer( new osgDB::MapSerializer< MyClass, TYPE >( \
1882  #PROP, &MyClass::get##PROP, &MyClass::get##PROP, &MyClass::set##PROP, KEYTYPE, ELEMENTTYPE), osgDB::BaseSerializer::RW_MAP )
1883 
1884 #define ADD_METHOD_OBJECT( METHODNAME, METHODOBJECTCLASS ) wrapper->addMethodObject(METHODNAME, new METHODOBJECTCLASS());
1885 
1886 #define ADD_METHOD(METHODNAME) \
1887  { \
1888  struct MethodCaller : public osgDB::MethodObject \
1889  { \
1890  virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const \
1891  { \
1892  MyClass* obj = reinterpret_cast<MyClass*>(objectPtr); \
1893  obj->METHODNAME(); \
1894  return true; \
1895  } \
1896  }; \
1897  wrapper->addMethodObject(#METHODNAME, new MethodCaller()); \
1898  }
1899 
1900 
1901 #define SET_USAGE(VALUE) wrapper->getLastSerializer()->setUsage(VALUE)
1902 
1903 }
1904 
1905 #endif
void writeWrappedString(const std::string &str)
Definition: OutputStream.h:159
virtual unsigned int size(const osg::Object &) const
Definition: Serializer.h:1238
P::value_type ValueType
Definition: Serializer.h:758
bool supportsReadWrite() const
Definition: Serializer.h:176
const std::string & getString(Value value)
Definition: Serializer.h:75
const P *(C::* Getter)() const
Definition: Serializer.h:546
bool(* Writer)(OutputStream &, const C &)
Definition: Serializer.h:193
const P &(C::* ConstGetter)() const
Definition: Serializer.h:1263
const osg::Matrix &(C::* Getter)() const
Definition: Serializer.h:374
BaseSerializer::Type getElementType() const
Definition: Serializer.h:1202
virtual void clear(osg::Object &obj) const
Definition: Serializer.h:901
virtual unsigned int size(const osg::Object &) const
Definition: Serializer.h:849
virtual const std::string & getName() const
Definition: Serializer.h:231
bool supportsSet() const
Definition: Serializer.h:179
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:349
TemplateSerializer< P > ParentType
Definition: Serializer.h:1432
unsigned int _elementSize
Definition: Serializer.h:1248
void(C::* Setter)(const P &)
Definition: Serializer.h:873
#define NULL
Definition: Export.h:59
Type getKeyType() const
Definition: Serializer.h:1228
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:977
virtual void resize(osg::Object &obj, unsigned int numElements) const
Definition: Serializer.h:889
ValueToString & getValueToString()
Definition: Serializer.h:92
ConstGetter _constgetter
Definition: Serializer.h:1423
P::const_iterator ConstIterator
Definition: Serializer.h:759
P::iterator Iterator
Definition: Serializer.h:1259
ObjectProperty PROPERTY
Definition: OutputStream.h:190
MapBaseSerializer(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize)
Definition: Serializer.h:1223
virtual MapIteratorObject * createIterator(osg::Object &) const
Definition: Serializer.h:1240
MapSerializer(const char *name, ConstGetter cgf, Getter gf, Setter sf, BaseSerializer::Type keyType, BaseSerializer::Type elementType)
Definition: Serializer.h:1266
virtual void reserve(osg::Object &obj, unsigned int numElements) const
Definition: Serializer.h:1057
virtual const std::string & getName() const =0
void readMatrixImplementation(InputStream &is, osg::Matrix &matrix)
Definition: Serializer.h:416
P::value_type ValueType
Definition: Serializer.h:869
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:452
virtual void resize(osg::Object &obj, unsigned int numElements) const
Definition: Serializer.h:1052
virtual void clear(osg::Object &obj) const
Definition: Serializer.h:1273
virtual void setElement(osg::Object &, void *, void *) const
Definition: Serializer.h:1235
P::value_type ValueType
Definition: Serializer.h:1256
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:382
unsigned int _numElementsOnRow
Definition: Serializer.h:1029
void writeImage(const osg::Image *img)
virtual void setElement(void *ptr) const
Definition: Serializer.h:1341
virtual const std::string & getName() const
Definition: Serializer.h:252
ValueToString _valueToString
Definition: Serializer.h:97
virtual const std::string & getName() const
Definition: Serializer.h:1271
CP(C::* Getter)() const
Definition: Serializer.h:324
virtual IntLookup * getIntLookup()
Definition: Serializer.h:702
virtual unsigned int size(const osg::Object &obj) const
Definition: Serializer.h:1303
std::vector< std::string > StringList
Definition: Serializer.h:31
osg::Image * readImage(bool readFromExternal=true)
BaseSerializer::Type _elementType
Definition: Serializer.h:1215
std::map< Value, std::string > ValueToString
Definition: Serializer.h:44
int getUsage() const
Definition: Serializer.h:167
bool(* Checker)(const C &)
Definition: Serializer.h:191
virtual void clear(osg::Object &) const
Definition: Serializer.h:852
P getValue(const char *str)
Definition: Serializer.h:707
osg::Object * readObject(osg::Object *existingObj=0)
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:713
virtual void * getElement() const
Definition: Serializer.h:1323
virtual MapIteratorObject * createReverseIterator(osg::Object &obj) const
Definition: Serializer.h:1351
MapIteratorObject(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize)
Definition: Serializer.h:1188
P::key_type KeyType
Definition: Serializer.h:1257
VectorBaseSerializer(BaseSerializer::Type elementType, unsigned int elementSize)
Definition: Serializer.h:842
unsigned int getElementSize() const
Definition: Serializer.h:1232
TemplateSerializer< P * > ParentType
Definition: Serializer.h:620
virtual void setElement(osg::Object &obj, unsigned int index, void *ptr) const
Definition: Serializer.h:920
const P &(C::* Getter)() const
Definition: Serializer.h:760
virtual bool set(osg::Object &, void *)
Definition: Serializer.h:157
BaseSerializer(int usage)
Definition: Serializer.h:155
TemplateSerializer< osg::Matrix > ParentType
Definition: Serializer.h:373
void add(const char *str, P value)
Definition: Serializer.h:1439
const std::string & getString(P value)
Definition: Serializer.h:710
TemplateSerializer< P > ParentType
Definition: Serializer.h:443
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:1358
virtual bool write(osgDB::OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:730
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:1395
TemplateSerializer< P > ParentType
Definition: Serializer.h:263
const P &(C::* ConstGetter)() const
Definition: Serializer.h:872
const std::string &(C::* Getter)() const
Definition: Serializer.h:493
StringToValue & getStringToValue()
Definition: Serializer.h:89
virtual const void * getKey() const
Definition: Serializer.h:1207
TemplateSerializer< P > ParentType
Definition: Serializer.h:693
Type getElementType() const
Definition: Serializer.h:1231
const std::string & getString(P value)
Definition: Serializer.h:1447
void writeObject(const osg::Object *obj)
virtual bool write(osgDB::OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:1481
P &(C::* Getter)()
Definition: Serializer.h:1262
virtual const void * getKey() const
Definition: Serializer.h:1339
ObjectMark END_BRACKET
Definition: InputStream.h:200
virtual void addElement(osg::Object &obj, void *ptr) const
Definition: Serializer.h:1067
P getValue(const char *str)
Definition: Serializer.h:1444
Type getElementType() const
Definition: Serializer.h:846
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:291
PropByValSerializer(const char *name, P def, Getter gf, Setter sf, bool useHex=false)
Definition: Serializer.h:267
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:399
osgDB::IntLookup _lookup
Definition: Serializer.h:1521
unsigned int getKeySize() const
Definition: Serializer.h:1229
virtual const std::string & getName() const
Definition: Serializer.h:1045
P(C::* Getter)() const
Definition: Serializer.h:444
TemplateSerializer< P * > ParentType
Definition: Serializer.h:545
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:519
virtual void insertElement(osg::Object &obj, unsigned int index, void *ptr) const
Definition: Serializer.h:913
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:584
virtual bool write(OutputStream &, const osg::Object &)=0
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:660
ObjectSerializer(const char *name, P *def, Getter gf, Setter sf)
Definition: Serializer.h:549
const ValueToString & getValueToString() const
Definition: Serializer.h:93
typedef void(GL_APIENTRY *GLTexImage3DProc)(GLenum target
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:332
virtual void * getElement() const
Definition: Serializer.h:1340
Object()
Definition: Object.h:65
P::reverse_iterator ReverseIterator
Definition: Serializer.h:1260
P(C::* Getter)() const
Definition: Serializer.h:264
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:272
void readWrappedString(std::string &str)
Definition: InputStream.h:155
EnumSerializer(const char *name, P def, Getter gf, Setter sf)
Definition: Serializer.h:697
virtual void setElement(osg::Object &obj, unsigned int index, void *ptr) const
Definition: Serializer.h:1078
BaseSerializer::Type _keyType
Definition: Serializer.h:1212
void add(const char *str, P value)
Definition: Serializer.h:704
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:1130
GLenumSerializer(const char *name, P def, Getter gf, Setter sf)
Definition: Serializer.h:447
unsigned int _numElementsOnRow
Definition: Serializer.h:1178
ObjectMark BEGIN_BRACKET
Definition: OutputStream.h:191
C::const_iterator ConstIterator
Definition: Serializer.h:1038
int getFileVersion(const std::string &d=std::string()) const
virtual bool set(osg::Object &obj, void *value)
Definition: Serializer.h:554
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:557
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:198
virtual unsigned int size(const osg::Object &obj) const
Definition: Serializer.h:1047
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:769
IsAVectorSerializer(const char *name, BaseSerializer::Type elementType, unsigned int numElementsOnRow)
Definition: Serializer.h:1040
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:1098
StringToValue _stringToValue
Definition: Serializer.h:96
bool isBinary() const
Definition: InputStream.h:83
const StringToValue & getStringToValue() const
Definition: Serializer.h:90
unsigned int size() const
Definition: Serializer.h:47
unsigned int getKeySize() const
Definition: Serializer.h:1200
Definition: Archive.h:24
virtual const void * getKey() const
Definition: Serializer.h:1322
Value getValue(const char *str)
Definition: Serializer.h:61
UserLookupTableProxy(AddValueFunc func)
Definition: Serializer.h:104
void(C::* Setter)(P *)
Definition: Serializer.h:547
virtual unsigned int size(const osg::Object &obj) const
Definition: Serializer.h:883
ReverseMapIterator(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize, ReverseIterator itr, ReverseIterator endItr)
Definition: Serializer.h:1329
virtual bool set(osg::Object &obj, void *value)
Definition: Serializer.h:630
virtual const void * getElement(const osg::Object &obj, unsigned int index) const
Definition: Serializer.h:934
bool isBinary() const
Definition: OutputStream.h:85
virtual const void * getElement(const osg::Object &obj, unsigned int index) const
Definition: Serializer.h:1091
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:804
virtual bool read(InputStream &is, osg::Object &obj)=0
TemplateSerializer< P > ParentType
Definition: Serializer.h:322
unsigned int getElementSize() const
Definition: Serializer.h:847
P::mapped_type ElementType
Definition: Serializer.h:1258
#define OSGDB_EXPORT
Definition: Export.h:39
ImageSerializer(const char *name, P *def, Getter gf, Setter sf)
Definition: Serializer.h:624
virtual IntLookup * getIntLookup()
Definition: Serializer.h:164
virtual const std::string & getName() const
Definition: Serializer.h:881
void setUsage(bool hasGetter, bool hasSetter)
Definition: Serializer.h:169
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:214
virtual const std::string & getName() const
Definition: Serializer.h:767
void(C::* Setter)(P)
Definition: Serializer.h:445
virtual void setElement(osg::Object &obj, void *ptrKey, void *ptrValue) const
Definition: Serializer.h:1280
virtual void reserve(osg::Object &obj, unsigned int numElements) const
Definition: Serializer.h:895
virtual bool write(OutputStream &os, const osg::Object &obj)
Definition: Serializer.h:468
virtual void addElement(osg::Object &obj, void *ptr) const
Definition: Serializer.h:907
VectorSerializer(const char *name, ConstGetter cgf, Getter gf, Setter sf, BaseSerializer::Type elementType, unsigned int numElementsOnRow)
Definition: Serializer.h:875
virtual void * getElement(osg::Object &obj, unsigned int index) const
Definition: Serializer.h:1084
MatrixSerializer(const char *name, const osg::Matrix &def, Getter gf, Setter sf)
Definition: Serializer.h:377
virtual const void * getElement(const osg::Object &, unsigned int) const
Definition: Serializer.h:857
void(C::* Setter)(P *)
Definition: Serializer.h:622
TemplateSerializer< std::string > ParentType
Definition: Serializer.h:492
unsigned int _elementSize
Definition: Serializer.h:1216
virtual void setElement(osg::Object &, unsigned int, void *) const
Definition: Serializer.h:855
virtual bool advance()
Definition: Serializer.h:1205
virtual void reserve(osg::Object &, unsigned int) const
Definition: Serializer.h:851
virtual MapIteratorObject * createReverseIterator(osg::Object &) const
Definition: Serializer.h:1241
P::const_iterator ConstIterator
Definition: Serializer.h:870
Definition: AlphaFunc.h:19
virtual bool write(OutputStream &os, const osg::Object &obj)=0
virtual const void * getElement(const osg::Object &, void *) const
Definition: Serializer.h:1237
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:501
BitFlagsSerializer(const char *name, P def, Getter gf, Setter sf)
Definition: Serializer.h:1436
virtual void * getElement() const
Definition: Serializer.h:1208
OSG_EXPORT std::ostream & notify(const NotifySeverity severity)
virtual const void * getElement(const osg::Object &obj, void *ptrKey) const
Definition: Serializer.h:1294
virtual bool valid() const
Definition: Serializer.h:1321
const P *(C::* Getter)() const
Definition: Serializer.h:621
void(C::* Setter)(const P &)
Definition: Serializer.h:1264
ListSerializer(const char *name, Getter gf, Setter sf)
Definition: Serializer.h:763
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:942
virtual void * getElement(osg::Object &, void *) const
Definition: Serializer.h:1236
virtual void clear(osg::Object &obj) const
Definition: Serializer.h:1062
virtual void resize(osg::Object &, unsigned int) const
Definition: Serializer.h:850
virtual void * getElement(osg::Object &, unsigned int) const
Definition: Serializer.h:856
virtual void setElement(void *ptr) const
Definition: Serializer.h:1324
MapIteratorObject(const MapIteratorObject &rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Serializer.h:1192
int getFileVersion(const std::string &d=std::string()) const
virtual void addElement(osg::Object &, void *) const
Definition: Serializer.h:853
UserSerializer(const char *name, Checker cf, Reader rf, Writer wf)
Definition: Serializer.h:195
PropByRefSerializer(const char *name, CP def, Getter gf, Setter sf)
Definition: Serializer.h:327
P::const_iterator ConstIterator
Definition: Serializer.h:1261
virtual bool read(InputStream &is, osg::Object &obj)
Definition: Serializer.h:633
virtual void * getElement(osg::Object &obj, unsigned int index) const
Definition: Serializer.h:927
virtual bool read(InputStream &, osg::Object &)=0
virtual MapIteratorObject * createIterator(osg::Object &obj) const
Definition: Serializer.h:1344
ConstGetter _constgetter
Definition: Serializer.h:1026
#define GLENUM(value)
Definition: DataTypes.h:97
OSGDB_EXPORT void split(const std::string &src, StringList &list, char separator=' ')
std::map< std::string, Value > StringToValue
Definition: Serializer.h:43
TemplateSerializer(const char *name, P def)
Definition: Serializer.h:247
unsigned int getElementSize() const
Definition: Serializer.h:1203
bool supportsGetSet() const
Definition: Serializer.h:177
void(* AddValueFunc)(IntLookup *lookup)
Definition: Serializer.h:103
void add(const char *str, Value value)
Definition: Serializer.h:49
void(C::* Setter)(const osg::Matrix &)
Definition: Serializer.h:375
MapIterator(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize, Iterator itr, Iterator endItr)
Definition: Serializer.h:1312
StringSerializer(const char *name, const std::string &def, Getter gf, Setter sf)
Definition: Serializer.h:496
virtual void clear(osg::Object &) const
Definition: Serializer.h:1234
ObjectMark BEGIN_BRACKET
Definition: InputStream.h:199
bool(* Reader)(InputStream &, C &)
Definition: Serializer.h:192
virtual void insertElement(osg::Object &obj, unsigned int index, void *ptr) const
Definition: Serializer.h:1072
P(C::* Getter)() const
Definition: Serializer.h:694
virtual void setElement(void *) const
Definition: Serializer.h:1209
void(C::* Setter)(const std::string &)
Definition: Serializer.h:494
void(C::* Setter)(const P &)
Definition: Serializer.h:761
virtual bool valid() const
Definition: Serializer.h:1206
void setUsage(int usage)
Definition: Serializer.h:166
META_Object(osgDB, MapIteratorObject)
bool matchString(const std::string &str)
Definition: InputStream.h:153
ObjectMark END_BRACKET
Definition: OutputStream.h:192
BaseSerializer::Type getKeyType() const
Definition: Serializer.h:1199
virtual bool read(osgDB::InputStream &is, osg::Object &obj)
Definition: Serializer.h:1450
virtual void insertElement(osg::Object &, unsigned int, void *) const
Definition: Serializer.h:854
P(C::* Getter)() const
Definition: Serializer.h:1433
#define DEF_GLENUM(var)
Definition: DataTypes.h:98
bool supportsGet() const
Definition: Serializer.h:178
virtual void * getElement(osg::Object &obj, void *ptrKey) const
Definition: Serializer.h:1287