2010-01-21 04:13:33 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
// Written by Wang Rui, (C) 2010
|
|
|
|
|
2010-01-25 19:03:21 +08:00
|
|
|
#ifndef OSGDB__SERIALIZER
|
|
|
|
#define OSGDB__SERIALIZER
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Notify>
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osgDB/InputStream>
|
|
|
|
#include <osgDB/OutputStream>
|
2010-11-09 21:23:43 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2010-11-09 21:23:43 +08:00
|
|
|
#include <limits.h>
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
namespace osgDB
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifndef OBJECT_CAST
|
|
|
|
#define OBJECT_CAST static_cast
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class IntLookup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef int Value;
|
|
|
|
typedef std::map<std::string, Value> StringToValue;
|
|
|
|
typedef std::map<Value, std::string> ValueToString;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
IntLookup() {}
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int size() const { return static_cast<unsigned int>(_stringToValue.size()); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
void add( const char* str, Value value )
|
|
|
|
{
|
|
|
|
if ( _valueToString.find(value)!=_valueToString.end() )
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN) << "Duplicate enum value " << value
|
|
|
|
<< " with old string: " << _valueToString[value]
|
|
|
|
<< " and new string: " << str << std::endl;
|
|
|
|
}
|
|
|
|
_valueToString[value] = str;
|
|
|
|
_stringToValue[str] = value;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
Value getValue( const char* str )
|
|
|
|
{
|
|
|
|
StringToValue::iterator itr = _stringToValue.find(str);
|
|
|
|
if ( itr==_stringToValue.end() )
|
|
|
|
{
|
|
|
|
Value value;
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << str; stream >> value;
|
|
|
|
_stringToValue[str] = value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return itr->second;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
const std::string& getString( Value value )
|
|
|
|
{
|
|
|
|
ValueToString::iterator itr = _valueToString.find(value);
|
|
|
|
if ( itr==_valueToString.end() )
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << value; stream >> str;
|
|
|
|
_valueToString[value] = str;
|
|
|
|
return _valueToString[value];
|
|
|
|
}
|
|
|
|
return itr->second;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2013-09-11 23:44:08 +08:00
|
|
|
StringToValue& getStringToValue() { return _stringToValue; }
|
|
|
|
const StringToValue& getStringToValue() const { return _stringToValue; }
|
|
|
|
|
|
|
|
ValueToString& getValueToString() { return _valueToString; }
|
|
|
|
const ValueToString& getValueToString() const { return _valueToString; }
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
protected:
|
|
|
|
StringToValue _stringToValue;
|
|
|
|
ValueToString _valueToString;
|
|
|
|
};
|
|
|
|
|
|
|
|
class UserLookupTableProxy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef void (*AddValueFunc)( IntLookup* lookup );
|
|
|
|
UserLookupTableProxy( AddValueFunc func ) { if ( func ) (*func)(&_lookup); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
IntLookup _lookup;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BEGIN_USER_TABLE(NAME, CLASS) \
|
|
|
|
static void add_user_value_func_##NAME(osgDB::IntLookup*); \
|
|
|
|
static osgDB::UserLookupTableProxy s_user_lookup_table_##NAME(&add_user_value_func_##NAME); \
|
|
|
|
static void add_user_value_func_##NAME(osgDB::IntLookup* lookup) { typedef CLASS MyClass
|
|
|
|
#define ADD_USER_VALUE(VALUE) lookup->add(#VALUE, MyClass::VALUE)
|
|
|
|
#define END_USER_TABLE() }
|
|
|
|
|
|
|
|
#define USER_READ_FUNC(NAME, FUNCNAME) \
|
|
|
|
static int FUNCNAME(osgDB::InputStream& is) { \
|
|
|
|
int value; if (is.isBinary()) is >> value; \
|
|
|
|
else { std::string str; is >> str; \
|
|
|
|
value = (s_user_lookup_table_##NAME)._lookup.getValue(str.c_str()); } \
|
|
|
|
return value; }
|
|
|
|
|
|
|
|
#define USER_WRITE_FUNC(NAME, FUNCNAME) \
|
|
|
|
static void FUNCNAME(osgDB::OutputStream& os, int value) { \
|
|
|
|
if (os.isBinary()) os << value; \
|
|
|
|
else os << (s_user_lookup_table_##NAME)._lookup.getString(value); } \
|
|
|
|
|
|
|
|
class BaseSerializer : public osg::Referenced
|
|
|
|
{
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
friend class ObjectWrapper;
|
2010-01-21 04:13:33 +08:00
|
|
|
public:
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
RW_UNDEFINED = 0, RW_USER, RW_OBJECT, RW_IMAGE, RW_LIST,
|
2011-06-03 06:07:16 +08:00
|
|
|
RW_BOOL, RW_CHAR, RW_UCHAR, RW_SHORT, RW_USHORT, RW_INT, RW_UINT, RW_FLOAT, RW_DOUBLE,
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
RW_VEC2F, RW_VEC2D, RW_VEC3F, RW_VEC3D, RW_VEC4F, RW_VEC4D, RW_QUAT, RW_PLANE,
|
2013-06-03 21:13:18 +08:00
|
|
|
RW_MATRIXF, RW_MATRIXD, RW_MATRIX, RW_GLENUM, RW_STRING, RW_ENUM,
|
2013-06-28 16:57:42 +08:00
|
|
|
RW_VEC2B, RW_VEC2UB, RW_VEC2S, RW_VEC2US, RW_VEC2I, RW_VEC2UI,
|
|
|
|
RW_VEC3B, RW_VEC3UB, RW_VEC3S, RW_VEC3US, RW_VEC3I, RW_VEC3UI,
|
2014-02-11 00:44:13 +08:00
|
|
|
RW_VEC4B, RW_VEC4UB, RW_VEC4S, RW_VEC4US, RW_VEC4I, RW_VEC4UI,
|
|
|
|
RW_BOUNDINGBOXF, RW_BOUNDINGBOXD,
|
2014-02-24 18:19:48 +08:00
|
|
|
RW_BOUNDINGSPHEREF, RW_BOUNDINGSPHERED,
|
2014-02-26 16:26:51 +08:00
|
|
|
RW_VECTOR, RW_MAP
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
};
|
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
enum Usage
|
|
|
|
{
|
|
|
|
READ_WRITE_PROPERTY = 1,
|
|
|
|
GET_PROPERTY = 2,
|
|
|
|
SET_PROPERTY = 4,
|
|
|
|
GET_SET_PROPERTY = GET_PROPERTY | SET_PROPERTY
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
BaseSerializer(int usage) : _firstVersion(0), _lastVersion(INT_MAX), _usage(usage) {}
|
2010-11-09 21:23:43 +08:00
|
|
|
|
2013-10-10 17:28:26 +08:00
|
|
|
virtual bool set(osg::Object& /*object*/, void* /*value*/) { return false; }
|
|
|
|
virtual bool get(const osg::Object& /*object*/, void* /*value*/) { return false; }
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream&, osg::Object& ) = 0;
|
|
|
|
virtual bool write( OutputStream&, const osg::Object& ) = 0;
|
|
|
|
virtual const std::string& getName() const = 0;
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
|
2014-02-08 18:39:20 +08:00
|
|
|
virtual IntLookup* getIntLookup() { return 0; }
|
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
void setUsage(int usage) { _usage = usage; }
|
|
|
|
int getUsage() const { return _usage; }
|
|
|
|
|
|
|
|
void setUsage(bool hasGetter, bool hasSetter)
|
|
|
|
{
|
|
|
|
setUsage( ((hasGetter && hasSetter) ? BaseSerializer::READ_WRITE_PROPERTY : 0) |
|
|
|
|
((hasGetter) ? BaseSerializer::GET_PROPERTY : 0) |
|
|
|
|
((hasSetter) ? BaseSerializer::SET_PROPERTY : 0) );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool supportsReadWrite() const { return (_usage & READ_WRITE_PROPERTY)!=0; }
|
|
|
|
bool supportsGetSet() const { return (_usage & GET_SET_PROPERTY)!=0; }
|
|
|
|
bool supportsGet() const { return (_usage & GET_PROPERTY)!=0; }
|
|
|
|
bool supportsSet() const { return (_usage & SET_PROPERTY)!=0; }
|
|
|
|
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
protected:
|
2010-11-09 21:23:43 +08:00
|
|
|
int _firstVersion; // Library version when the serializer is first introduced
|
2014-09-05 19:05:43 +08:00
|
|
|
int _lastVersion; // Library version when the serializer is last required.
|
|
|
|
int _usage; // How the Serializer can be used.
|
2010-01-21 04:13:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C>
|
|
|
|
class UserSerializer : public BaseSerializer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef bool (*Checker)( const C& );
|
|
|
|
typedef bool (*Reader)( InputStream&, C& );
|
|
|
|
typedef bool (*Writer)( OutputStream&, const C& );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
UserSerializer( const char* name, Checker cf, Reader rf, Writer wf )
|
2014-09-05 19:05:43 +08:00
|
|
|
: BaseSerializer(READ_WRITE_PROPERTY), _name(name), _checker(cf), _reader(rf), _writer(wf) {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
2010-01-28 01:09:05 +08:00
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
bool ok = false; is >> ok;
|
|
|
|
if ( !ok ) return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !is.matchString(_name) )
|
|
|
|
return true;
|
|
|
|
}
|
2010-01-21 04:13:33 +08:00
|
|
|
return (*_reader)(is, object);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-01-28 01:09:05 +08:00
|
|
|
bool ok = (*_checker)(object);
|
|
|
|
if ( os.isBinary() )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2010-01-28 01:09:05 +08:00
|
|
|
os << ok;
|
|
|
|
if ( !ok ) return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !ok ) return true;
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY(_name.c_str());
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return (*_writer)(os, object);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual const std::string& getName() const { return _name; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
protected:
|
|
|
|
std::string _name;
|
|
|
|
Checker _checker;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Reader _reader;
|
|
|
|
Writer _writer;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename P>
|
|
|
|
class TemplateSerializer : public BaseSerializer
|
|
|
|
{
|
|
|
|
public:
|
2011-05-05 20:37:00 +08:00
|
|
|
|
|
|
|
TemplateSerializer( const char* name, P def)
|
2014-09-05 19:05:43 +08:00
|
|
|
: BaseSerializer(READ_WRITE_PROPERTY), _name(name), _defaultValue(def) {}
|
2011-05-05 20:37:00 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj ) = 0;
|
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj ) = 0;
|
|
|
|
virtual const std::string& getName() const { return _name; }
|
2011-05-06 17:00:46 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
protected:
|
|
|
|
std::string _name;
|
|
|
|
P _defaultValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C, typename P>
|
|
|
|
class PropByValSerializer : public TemplateSerializer<P>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<P> ParentType;
|
|
|
|
typedef P (C::*Getter)() const;
|
|
|
|
typedef void (C::*Setter)( P );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
PropByValSerializer( const char* name, P def, Getter gf, Setter sf, bool useHex=false ) : ParentType(name, def), _getter(gf), _setter(sf), _useHex(useHex)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P value;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> value;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
if ( _useHex ) is >> std::hex;
|
|
|
|
is >> value;
|
|
|
|
if ( _useHex ) is >> std::dec;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-02 01:07:27 +08:00
|
|
|
P value = (object.*_getter)();
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
2010-10-01 00:03:04 +08:00
|
|
|
os << value;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str());
|
2012-08-24 23:05:03 +08:00
|
|
|
if ( _useHex ) { os << std::hex << std::showbase; }
|
2010-10-01 00:03:04 +08:00
|
|
|
os << value;
|
2012-08-24 23:05:03 +08:00
|
|
|
if ( _useHex ) os << std::dec << std::noshowbase;
|
2010-01-21 04:13:33 +08:00
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
protected:
|
2010-01-21 04:13:33 +08:00
|
|
|
bool _useHex;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C, typename P>
|
|
|
|
class PropByRefSerializer : public TemplateSerializer<P>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<P> ParentType;
|
|
|
|
typedef const P& CP;
|
|
|
|
typedef CP (C::*Getter)() const;
|
|
|
|
typedef void (C::*Setter)( CP );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
PropByRefSerializer( const char* name, CP def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P value;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> value;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
is >> value;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-02 01:07:27 +08:00
|
|
|
CP value = (object.*_getter)();
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
2010-10-01 00:03:04 +08:00
|
|
|
os << value;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C>
|
|
|
|
class MatrixSerializer : public TemplateSerializer<osg::Matrix>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<osg::Matrix> ParentType;
|
|
|
|
typedef const osg::Matrix& (C::*Getter)() const;
|
|
|
|
typedef void (C::*Setter)( const osg::Matrix& );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
MatrixSerializer( const char* name, const osg::Matrix& def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
osg::Matrix value;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
readMatrixImplementation( is, value );
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
readMatrixImplementation( is, value );
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
2010-10-04 23:23:19 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-01 00:03:04 +08:00
|
|
|
const osg::Matrix& value = (object.*_getter)();
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
2010-10-01 00:03:04 +08:00
|
|
|
os << value;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
protected:
|
|
|
|
void readMatrixImplementation( InputStream& is, osg::Matrix& matrix )
|
|
|
|
{
|
2010-10-04 23:23:19 +08:00
|
|
|
#if 1
|
|
|
|
is >> matrix;
|
|
|
|
#else
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( is.getUseFloatMatrix() )
|
|
|
|
{
|
|
|
|
osg::Matrixf realValue; is >> realValue;
|
|
|
|
matrix = realValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::Matrixd realValue; is >> realValue;
|
|
|
|
matrix = realValue;
|
|
|
|
}
|
2010-10-04 23:23:19 +08:00
|
|
|
#endif
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C, typename P>
|
|
|
|
class GLenumSerializer : public TemplateSerializer<P>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<P> ParentType;
|
|
|
|
typedef P (C::*Getter)() const;
|
|
|
|
typedef void (C::*Setter)( P );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
GLenumSerializer( const char* name, P def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
GLenum value; is >> value;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( static_cast<P>(value) );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
DEF_GLENUM(value); is >> value;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( static_cast<P>(value.get()) );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-01 00:03:04 +08:00
|
|
|
const P value = (object.*_getter)();
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
2010-10-01 00:03:04 +08:00
|
|
|
os << static_cast<GLenum>(value);
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str()) << GLENUM(value) << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C>
|
|
|
|
class StringSerializer : public TemplateSerializer<std::string>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<std::string> ParentType;
|
|
|
|
typedef const std::string& (C::*Getter)() const;
|
|
|
|
typedef void (C::*Setter)( const std::string& );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
StringSerializer( const char* name, const std::string& def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
std::string value;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> value;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
is.readWrappedString( value );
|
2014-02-13 02:03:53 +08:00
|
|
|
if ( !value.empty() && (_setter!=0) )
|
2010-01-21 04:13:33 +08:00
|
|
|
(object.*_setter)( value );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-01 00:03:04 +08:00
|
|
|
const std::string& value = (object.*_getter)();
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
2010-10-01 00:03:04 +08:00
|
|
|
os << value;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str());
|
2010-10-01 00:03:04 +08:00
|
|
|
os.writeWrappedString( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C, typename P>
|
|
|
|
class ObjectSerializer : public TemplateSerializer<P*>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<P*> ParentType;
|
|
|
|
typedef const P* (C::*Getter)() const;
|
|
|
|
typedef void (C::*Setter)( P* );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
ObjectSerializer( const char* name, P* def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST<C&>(obj); (object.*_setter)( *(reinterpret_cast<P**>(value)) ); return true; }
|
|
|
|
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; }
|
2013-10-10 17:28:26 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
bool hasObject = false;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> hasObject;
|
|
|
|
if ( hasObject )
|
|
|
|
{
|
|
|
|
P* value = dynamic_cast<P*>( is.readObject() );
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
is >> hasObject;
|
|
|
|
if ( hasObject )
|
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
is >> is.BEGIN_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
P* value = dynamic_cast<P*>( is.readObject() );
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2012-04-05 21:53:47 +08:00
|
|
|
is >> is.END_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-01 00:03:04 +08:00
|
|
|
const P* value = (object.*_getter)();
|
|
|
|
bool hasObject = (value!=NULL);
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
|
|
|
os << hasObject;
|
2010-10-01 00:03:04 +08:00
|
|
|
os.writeObject( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str()) << hasObject;
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( hasObject )
|
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.BEGIN_BRACKET << std::endl;
|
2010-10-01 00:03:04 +08:00
|
|
|
os.writeObject( value );
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.END_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C, typename P>
|
|
|
|
class ImageSerializer : public TemplateSerializer<P*>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<P*> ParentType;
|
|
|
|
typedef const P* (C::*Getter)() const;
|
|
|
|
typedef void (C::*Setter)( P* );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
ImageSerializer( const char* name, P* def, Getter gf, Setter sf ):
|
|
|
|
ParentType(name, def), _getter(gf), _setter(sf)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2013-10-11 04:43:03 +08:00
|
|
|
virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST<C&>(obj); (object.*_setter)( *(reinterpret_cast<P**>(value)) ); return true; }
|
|
|
|
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; }
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
bool hasObject = false;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> hasObject;
|
|
|
|
if ( hasObject )
|
|
|
|
{
|
|
|
|
P* value = dynamic_cast<P*>( is.readImage() );
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
is >> hasObject;
|
|
|
|
if ( hasObject )
|
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
is >> is.BEGIN_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
P* value = dynamic_cast<P*>( is.readImage() );
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( value );
|
2012-04-05 21:53:47 +08:00
|
|
|
is >> is.END_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-01 00:03:04 +08:00
|
|
|
const P* value = (object.*_getter)();
|
|
|
|
bool hasObject = (value!=NULL);
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
|
|
|
os << hasObject;
|
2010-10-01 00:03:04 +08:00
|
|
|
os.writeImage( value );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str()) << hasObject;
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( hasObject )
|
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.BEGIN_BRACKET << std::endl;
|
2010-10-01 00:03:04 +08:00
|
|
|
os.writeImage( value );
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.END_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
os << std::endl;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename C, typename P, typename B>
|
|
|
|
class EnumSerializer : public TemplateSerializer<P>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef TemplateSerializer<P> ParentType;
|
|
|
|
typedef P (C::*Getter)() const;
|
|
|
|
typedef B (C::*Setter)( P );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
EnumSerializer( const char* name, P def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf)
|
|
|
|
{
|
|
|
|
ParentType::setUsage( _getter!=0, _setter!=0);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-02-08 18:39:20 +08:00
|
|
|
virtual IntLookup* getIntLookup() { return &_lookup; }
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
void add( const char* str, P value )
|
2010-10-01 00:03:04 +08:00
|
|
|
{ _lookup.add(str, static_cast<IntLookup::Value>(value)); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
P getValue( const char* str )
|
|
|
|
{ return static_cast<P>(_lookup.getValue(str)); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
const std::string& getString( P value )
|
2010-10-01 00:03:04 +08:00
|
|
|
{ return _lookup.getString(static_cast<IntLookup::Value>(value)); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
IntLookup::Value value;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> value;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( static_cast<P>(value) );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
else if ( is.matchString(ParentType::_name) )
|
|
|
|
{
|
|
|
|
std::string str; is >> str;
|
2014-09-05 19:05:43 +08:00
|
|
|
(object.*_setter)( getValue(str.c_str()) );
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( osgDB::OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
2010-10-01 00:03:04 +08:00
|
|
|
const P value = (object.*_getter)();
|
2010-01-21 04:13:33 +08:00
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
2010-10-01 00:03:04 +08:00
|
|
|
os << (IntLookup::Value)value;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
2010-10-01 00:03:04 +08:00
|
|
|
else if ( ParentType::_defaultValue!=value )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((ParentType::_name).c_str()) << getString(value) << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
protected:
|
2010-01-21 04:13:33 +08:00
|
|
|
IntLookup _lookup;
|
|
|
|
};
|
|
|
|
|
2011-05-06 17:00:46 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
template<typename C, typename P>
|
2011-05-06 17:00:46 +08:00
|
|
|
class ListSerializer : public BaseSerializer
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename P::value_type ValueType;
|
|
|
|
typedef typename P::const_iterator ConstIterator;
|
2010-10-01 00:03:04 +08:00
|
|
|
typedef const P& (C::*Getter)() const;
|
2010-01-21 04:13:33 +08:00
|
|
|
typedef void (C::*Setter)( const P& );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
ListSerializer( const char* name, Getter gf, Setter sf ):
|
|
|
|
BaseSerializer(READ_WRITE_PROPERTY),
|
|
|
|
_name(name), _getter(gf), _setter(sf) {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2011-05-06 17:00:46 +08:00
|
|
|
virtual const std::string& getName() const { return _name; }
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
unsigned int size = 0;
|
|
|
|
P list;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> size;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
ValueType value;
|
|
|
|
is >> value;
|
|
|
|
list.push_back( value );
|
|
|
|
}
|
|
|
|
if ( size>0 ) (object.*_setter)( list );
|
|
|
|
}
|
2011-05-06 17:00:46 +08:00
|
|
|
else if ( is.matchString(_name) )
|
2010-01-21 04:13:33 +08:00
|
|
|
{
|
|
|
|
is >> size;
|
2012-04-05 21:53:47 +08:00
|
|
|
if ( size>0 ) is >> is.BEGIN_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
ValueType value;
|
|
|
|
is >> value;
|
|
|
|
list.push_back( value );
|
|
|
|
}
|
|
|
|
if ( size>0 )
|
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
is >> is.END_BRACKET;
|
2010-01-21 04:13:33 +08:00
|
|
|
(object.*_setter)( list );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
|
|
|
const P& list = (object.*_getter)();
|
|
|
|
unsigned int size = (unsigned int)list.size();
|
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
|
|
|
os << size;
|
|
|
|
for ( ConstIterator itr=list.begin();
|
|
|
|
itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( size>0 )
|
|
|
|
{
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
for ( ConstIterator itr=list.begin();
|
|
|
|
itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
}
|
2010-06-09 18:01:25 +08:00
|
|
|
os << std::endl;
|
2012-04-05 21:53:47 +08:00
|
|
|
os << os.END_BRACKET << std::endl;
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-01-28 01:09:05 +08:00
|
|
|
public:
|
2011-05-06 17:00:46 +08:00
|
|
|
std::string _name;
|
2010-01-21 04:13:33 +08:00
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
2014-02-24 18:19:48 +08:00
|
|
|
class VectorBaseSerializer : public BaseSerializer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-02-26 16:26:51 +08:00
|
|
|
VectorBaseSerializer(BaseSerializer::Type elementType, unsigned int elementSize):
|
2014-09-05 19:05:43 +08:00
|
|
|
BaseSerializer(READ_WRITE_PROPERTY|GET_SET_PROPERTY),
|
2014-02-26 16:26:51 +08:00
|
|
|
_elementType(elementType),_elementSize(elementSize) {}
|
2014-02-24 18:19:48 +08:00
|
|
|
|
|
|
|
Type getElementType() const { return _elementType; }
|
2014-02-26 16:26:51 +08:00
|
|
|
unsigned int getElementSize() const { return _elementSize; }
|
2014-02-24 18:19:48 +08:00
|
|
|
|
|
|
|
virtual unsigned int size(const osg::Object& obj) const { return 0; }
|
|
|
|
virtual void resize(osg::Object& obj, unsigned int numElements) const {}
|
|
|
|
virtual void reserve(osg::Object& obj, unsigned int numElements) const {}
|
|
|
|
virtual void clear(osg::Object& obj) const {}
|
|
|
|
virtual void addElement(osg::Object& obj, void* ptr) const {}
|
|
|
|
virtual void insertElement(osg::Object& obj, unsigned int index, void* ptr) const {}
|
|
|
|
virtual void setElement(osg::Object& obj, unsigned int index, void* ptr) const {}
|
|
|
|
virtual void* getElement(osg::Object& obj, unsigned int index) const { return 0; }
|
|
|
|
virtual const void* getElement(const osg::Object& obj, unsigned int index) const { return 0; }
|
|
|
|
|
|
|
|
protected:
|
2014-02-26 16:26:51 +08:00
|
|
|
Type _elementType;
|
|
|
|
unsigned int _elementSize;
|
2014-02-24 18:19:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename C, typename P>
|
|
|
|
class VectorSerializer : public VectorBaseSerializer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename P::value_type ValueType;
|
|
|
|
typedef typename P::const_iterator ConstIterator;
|
|
|
|
typedef P& (C::*Getter)();
|
|
|
|
typedef const P& (C::*ConstGetter)() const;
|
|
|
|
typedef void (C::*Setter)( const P& );
|
|
|
|
|
|
|
|
VectorSerializer( const char* name, ConstGetter cgf, Getter gf, Setter sf, BaseSerializer::Type elementType, unsigned int numElementsOnRow):
|
2014-02-26 16:26:51 +08:00
|
|
|
VectorBaseSerializer(elementType, sizeof(ValueType)),
|
2014-02-24 18:19:48 +08:00
|
|
|
_name(name),
|
|
|
|
_constgetter(cgf), _getter(gf), _setter(sf),
|
|
|
|
_numElementsOnRow(numElementsOnRow) {}
|
|
|
|
|
|
|
|
virtual const std::string& getName() const { return _name; }
|
|
|
|
|
|
|
|
virtual unsigned int size(const osg::Object& obj) const
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
|
|
|
const P& list = (object.*_constgetter)();
|
|
|
|
return static_cast<unsigned int>(list.size());
|
|
|
|
}
|
|
|
|
virtual void resize(osg::Object& obj, unsigned int numElements) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& list = (object.*_getter)();
|
|
|
|
list.resize(numElements);
|
|
|
|
}
|
|
|
|
virtual void reserve(osg::Object& obj, unsigned int numElements) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& list = (object.*_getter)();
|
|
|
|
list.reserve(numElements);
|
|
|
|
}
|
|
|
|
virtual void clear(osg::Object& obj) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& list = (object.*_getter)();
|
|
|
|
list.clear();
|
|
|
|
}
|
|
|
|
virtual void addElement(osg::Object& obj, void* ptr) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& list = (object.*_getter)();
|
|
|
|
list.push_back(*reinterpret_cast<ValueType*>(ptr));
|
|
|
|
}
|
|
|
|
virtual void insertElement(osg::Object& obj, unsigned int index, void* ptr) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& list = (object.*_getter)();
|
|
|
|
if (index>=list.size()) list.resize(index+1);
|
|
|
|
list.insert(list.begin()+index, *reinterpret_cast<ValueType*>(ptr));
|
|
|
|
}
|
|
|
|
virtual void setElement(osg::Object& obj, unsigned int index, void* ptr) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& list = (object.*_getter)();
|
|
|
|
if (index>=list.size()) list.resize(index+1);
|
|
|
|
list[index] = *reinterpret_cast<ValueType*>(ptr);
|
|
|
|
}
|
|
|
|
virtual void* getElement(osg::Object& obj, unsigned int index) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& list = (object.*_getter)();
|
|
|
|
if (index>=list.size()) return 0;
|
|
|
|
else return &list[index];
|
|
|
|
}
|
|
|
|
virtual const void* getElement(const osg::Object& obj, unsigned int index) const
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
|
|
|
const P& list = (object.*_constgetter)();
|
|
|
|
if (index>=list.size()) return 0;
|
|
|
|
else return &list[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
unsigned int size = 0;
|
|
|
|
P list;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> size;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
ValueType value;
|
|
|
|
is >> value;
|
|
|
|
list.push_back( value );
|
|
|
|
}
|
|
|
|
if ( size>0 ) (object.*_setter)( list );
|
|
|
|
}
|
|
|
|
else if ( is.matchString(_name) )
|
|
|
|
{
|
|
|
|
is >> size;
|
|
|
|
if ( size>0 ) is >> is.BEGIN_BRACKET;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
ValueType value;
|
|
|
|
is >> value;
|
|
|
|
list.push_back( value );
|
|
|
|
}
|
|
|
|
if ( size>0 )
|
|
|
|
{
|
|
|
|
is >> is.END_BRACKET;
|
|
|
|
(object.*_setter)( list );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
|
|
|
const P& list = (object.*_constgetter)();
|
|
|
|
unsigned int size = (unsigned int)list.size();
|
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
|
|
|
os << size;
|
|
|
|
for ( ConstIterator itr=list.begin();
|
|
|
|
itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( size>0 )
|
|
|
|
{
|
|
|
|
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
|
|
|
|
if (_numElementsOnRow==0)
|
|
|
|
{
|
|
|
|
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (_numElementsOnRow==1)
|
|
|
|
{
|
|
|
|
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr); os << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned int i = _numElementsOnRow-1;
|
|
|
|
for (ConstIterator itr=list.begin(); itr!=list.end(); ++itr)
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
if (i==0) { os << std::endl; i = _numElementsOnRow-1; }
|
|
|
|
else --i;
|
|
|
|
}
|
|
|
|
if (i!=_numElementsOnRow) os << std::endl;
|
|
|
|
}
|
|
|
|
os << os.END_BRACKET << std::endl;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
std::string _name;
|
|
|
|
ConstGetter _constgetter;
|
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
unsigned int _numElementsOnRow;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename C>
|
|
|
|
class IsAVectorSerializer : public VectorBaseSerializer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename C::value_type ValueType;
|
|
|
|
typedef typename C::const_iterator ConstIterator;
|
|
|
|
|
|
|
|
IsAVectorSerializer( const char* name, BaseSerializer::Type elementType, unsigned int numElementsOnRow) :
|
2014-02-26 16:26:51 +08:00
|
|
|
VectorBaseSerializer(elementType, sizeof(ValueType)),
|
2014-02-24 18:19:48 +08:00
|
|
|
_name(name),
|
|
|
|
_numElementsOnRow(numElementsOnRow) {}
|
|
|
|
|
|
|
|
virtual const std::string& getName() const { return _name; }
|
|
|
|
|
|
|
|
virtual unsigned int size(const osg::Object& obj) const
|
|
|
|
{
|
|
|
|
const C& list = OBJECT_CAST<const C&>(obj);
|
|
|
|
return static_cast<unsigned int>(list.size());
|
|
|
|
}
|
|
|
|
virtual void resize(osg::Object& obj, unsigned int numElements) const
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
list.resize(numElements);
|
|
|
|
}
|
|
|
|
virtual void reserve(osg::Object& obj, unsigned int numElements) const
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
list.reserve(numElements);
|
|
|
|
}
|
|
|
|
virtual void clear(osg::Object& obj) const
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
list.clear();
|
|
|
|
}
|
|
|
|
virtual void addElement(osg::Object& obj, void* ptr) const
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
list.push_back(*reinterpret_cast<ValueType*>(ptr));
|
|
|
|
}
|
|
|
|
virtual void insertElement(osg::Object& obj, unsigned int index, void* ptr) const
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
if (index>=list.size()) list.resize(index+1);
|
|
|
|
list.insert(list.begin()+index, *reinterpret_cast<ValueType*>(ptr));
|
|
|
|
}
|
|
|
|
virtual void setElement(osg::Object& obj, unsigned int index, void* ptr) const
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
if (index>=list.size()) list.resize(index+1);
|
|
|
|
list[index] = *reinterpret_cast<ValueType*>(ptr);
|
|
|
|
}
|
|
|
|
virtual void* getElement(osg::Object& obj, unsigned int index) const
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
if (index>=list.size()) return 0;
|
|
|
|
else return &list[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const void* getElement(const osg::Object& obj, unsigned int index) const
|
|
|
|
{
|
|
|
|
const C& list = OBJECT_CAST<const C&>(obj);
|
|
|
|
if (index>=list.size()) return 0;
|
|
|
|
else return &list[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& list = OBJECT_CAST<C&>(obj);
|
|
|
|
unsigned int size = 0;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> size;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
ValueType value;
|
|
|
|
is >> value;
|
|
|
|
list.push_back( value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( is.matchString(_name) )
|
|
|
|
{
|
|
|
|
is >> size;
|
|
|
|
if ( size>0 ) is >> is.BEGIN_BRACKET;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
ValueType value;
|
|
|
|
is >> value;
|
|
|
|
list.push_back( value );
|
|
|
|
}
|
|
|
|
if ( size>0 )
|
|
|
|
{
|
|
|
|
is >> is.END_BRACKET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& list = OBJECT_CAST<const C&>(obj);
|
|
|
|
unsigned int size = (unsigned int)list.size();
|
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
|
|
|
os << size;
|
|
|
|
for ( ConstIterator itr=list.begin();
|
|
|
|
itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( size>0 )
|
|
|
|
{
|
|
|
|
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
|
|
|
|
if (_numElementsOnRow==0)
|
|
|
|
{
|
|
|
|
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (_numElementsOnRow==1)
|
|
|
|
{
|
|
|
|
for ( ConstIterator itr=list.begin(); itr!=list.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << (*itr); os << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned int i = _numElementsOnRow-1;
|
|
|
|
for (ConstIterator itr=list.begin(); itr!=list.end(); ++itr)
|
|
|
|
{
|
|
|
|
os << (*itr);
|
|
|
|
if (i==0) { os << std::endl; i = _numElementsOnRow-1; }
|
|
|
|
else --i;
|
|
|
|
}
|
|
|
|
if (i!=_numElementsOnRow) os << std::endl;
|
|
|
|
}
|
|
|
|
os << os.END_BRACKET << std::endl;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
std::string _name;
|
|
|
|
unsigned int _numElementsOnRow;
|
|
|
|
};
|
|
|
|
|
2014-02-27 02:18:08 +08:00
|
|
|
class MapIteratorObject : public osg::Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MapIteratorObject():
|
|
|
|
_keyType(BaseSerializer::RW_UNDEFINED), _keySize(0),
|
|
|
|
_elementType(BaseSerializer::RW_UNDEFINED),_elementSize(0) {}
|
|
|
|
|
|
|
|
MapIteratorObject(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize):
|
|
|
|
_keyType(keyType), _keySize(keySize),
|
|
|
|
_elementType(elementType),_elementSize(elementSize) {}
|
|
|
|
|
|
|
|
MapIteratorObject(const MapIteratorObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):
|
|
|
|
osg::Object(rhs, copyop),
|
|
|
|
_keyType(rhs._keyType), _keySize(rhs._keySize),
|
|
|
|
_elementType(rhs._elementType),_elementSize(rhs._elementSize) {}
|
|
|
|
|
|
|
|
META_Object(osgDB, MapIteratorObject);
|
|
|
|
|
|
|
|
BaseSerializer::Type getKeyType() const { return _keyType; }
|
|
|
|
unsigned int getKeySize() const { return _keySize; }
|
|
|
|
|
|
|
|
BaseSerializer::Type getElementType() const { return _elementType; }
|
|
|
|
unsigned int getElementSize() const { return _elementSize; }
|
|
|
|
|
|
|
|
virtual bool advance() { return false; }
|
|
|
|
virtual bool valid() const { return false; }
|
|
|
|
virtual const void* getKey() const { return 0; }
|
|
|
|
virtual void* getElement() const { return 0; }
|
|
|
|
virtual void setElement(void* ptr) const {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BaseSerializer::Type _keyType;
|
|
|
|
unsigned int _keySize;
|
|
|
|
|
|
|
|
BaseSerializer::Type _elementType;
|
|
|
|
unsigned int _elementSize;
|
|
|
|
};
|
|
|
|
|
2014-02-26 16:26:51 +08:00
|
|
|
class MapBaseSerializer : public BaseSerializer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
MapBaseSerializer(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize):
|
2014-09-05 19:05:43 +08:00
|
|
|
BaseSerializer(READ_WRITE_PROPERTY|GET_SET_PROPERTY),
|
2014-02-26 16:26:51 +08:00
|
|
|
_keyType(keyType), _keySize(keySize),
|
|
|
|
_elementType(elementType),_elementSize(elementSize) {}
|
|
|
|
|
|
|
|
Type getKeyType() const { return _keyType; }
|
|
|
|
unsigned int getKeySize() const { return _keySize; }
|
|
|
|
|
|
|
|
Type getElementType() const { return _elementType; }
|
|
|
|
unsigned int getElementSize() const { return _elementSize; }
|
|
|
|
|
|
|
|
virtual void clear(osg::Object& obj) const {}
|
|
|
|
virtual void setElement(osg::Object& obj, void* ptrKey, void* ptrValue) const {}
|
|
|
|
virtual void* getElement(osg::Object& obj, void* ptrKey) const { return 0; }
|
|
|
|
virtual const void* getElement(const osg::Object& obj, void* ptrKey) const { return 0; }
|
2014-02-26 19:01:35 +08:00
|
|
|
virtual unsigned int size(const osg::Object& obj) const { return 0; }
|
2014-02-26 16:26:51 +08:00
|
|
|
|
2014-02-27 02:18:08 +08:00
|
|
|
virtual MapIteratorObject* createIterator(osg::Object& obj) const { return 0; }
|
2014-02-27 18:02:55 +08:00
|
|
|
virtual MapIteratorObject* createReverseIterator(osg::Object& obj) const { return 0; }
|
2014-02-27 02:18:08 +08:00
|
|
|
|
2014-02-26 16:26:51 +08:00
|
|
|
protected:
|
|
|
|
Type _keyType;
|
|
|
|
unsigned int _keySize;
|
|
|
|
|
|
|
|
Type _elementType;
|
|
|
|
unsigned int _elementSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename C, typename P>
|
|
|
|
class MapSerializer : public MapBaseSerializer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename P::value_type ValueType;
|
|
|
|
typedef typename P::key_type KeyType;
|
|
|
|
typedef typename P::mapped_type ElementType;
|
2014-02-27 02:18:08 +08:00
|
|
|
typedef typename P::iterator Iterator;
|
2014-02-27 18:02:55 +08:00
|
|
|
typedef typename P::reverse_iterator ReverseIterator;
|
2014-02-26 16:26:51 +08:00
|
|
|
typedef typename P::const_iterator ConstIterator;
|
|
|
|
typedef P& (C::*Getter)();
|
|
|
|
typedef const P& (C::*ConstGetter)() const;
|
|
|
|
typedef void (C::*Setter)( const P& );
|
|
|
|
|
|
|
|
MapSerializer( const char* name, ConstGetter cgf, Getter gf, Setter sf, BaseSerializer::Type keyType, BaseSerializer::Type elementType):
|
|
|
|
MapBaseSerializer(keyType, sizeof(KeyType), elementType, sizeof(ElementType)),
|
|
|
|
_name(name),
|
|
|
|
_constgetter(cgf), _getter(gf), _setter(sf) {}
|
|
|
|
|
|
|
|
virtual const std::string& getName() const { return _name; }
|
|
|
|
|
|
|
|
virtual void clear(osg::Object& obj) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& map = (object.*_getter)();
|
|
|
|
map.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setElement(osg::Object& obj, void* ptrKey, void* ptrValue) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& map = (object.*_getter)();
|
|
|
|
map[*reinterpret_cast<KeyType*>(ptrKey)] = *reinterpret_cast<ElementType*>(ptrValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void* getElement(osg::Object& obj, void* ptrKey) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& map = (object.*_getter)();
|
|
|
|
return &(map[*reinterpret_cast<KeyType*>(ptrKey)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const void* getElement(const osg::Object& obj, void* ptrKey) const
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
|
|
|
const P& map = (object.*_constgetter)();
|
|
|
|
ConstIterator itr = map.find(*reinterpret_cast<KeyType*>(ptrKey));
|
|
|
|
if (itr==map.end()) return 0;
|
|
|
|
else return &(itr->second);
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:01:35 +08:00
|
|
|
virtual unsigned int size(const osg::Object& obj) const
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
|
|
|
const P& map = (object.*_constgetter)();
|
|
|
|
return map.size();
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:18:08 +08:00
|
|
|
struct MapIterator : public MapIteratorObject
|
|
|
|
{
|
|
|
|
MapIterator(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize,
|
|
|
|
Iterator itr, Iterator endItr):
|
|
|
|
MapIteratorObject(keyType, keySize, elementType, elementSize),
|
|
|
|
_itr(itr),_endItr(endItr) {}
|
|
|
|
|
|
|
|
Iterator _itr;
|
|
|
|
Iterator _endItr;
|
|
|
|
|
|
|
|
virtual bool advance() { if (valid()) ++_itr; return valid(); }
|
|
|
|
virtual bool valid() const { return _itr!=_endItr; }
|
|
|
|
virtual const void* getKey() const { return valid() ? &(_itr->first) : 0; }
|
|
|
|
virtual void* getElement() const { return valid() ? &(_itr->second) : 0; }
|
|
|
|
virtual void setElement(void* ptr) const { if (valid()) _itr->second = *reinterpret_cast<ElementType*>(ptr); }
|
|
|
|
};
|
|
|
|
|
2014-02-27 18:02:55 +08:00
|
|
|
struct ReverseMapIterator : public MapIteratorObject
|
|
|
|
{
|
|
|
|
ReverseMapIterator(BaseSerializer::Type keyType, unsigned int keySize, BaseSerializer::Type elementType, unsigned int elementSize,
|
|
|
|
ReverseIterator itr, ReverseIterator endItr):
|
|
|
|
MapIteratorObject(keyType, keySize, elementType, elementSize),
|
|
|
|
_itr(itr),_endItr(endItr) {}
|
|
|
|
|
|
|
|
ReverseIterator _itr;
|
|
|
|
ReverseIterator _endItr;
|
|
|
|
|
|
|
|
virtual bool advance() { if (valid()) ++_itr; return valid(); }
|
|
|
|
virtual bool valid() const { return _itr!=_endItr; }
|
|
|
|
virtual const void* getKey() const { return valid() ? &(_itr->first) : 0; }
|
|
|
|
virtual void* getElement() const { return valid() ? &(_itr->second) : 0; }
|
|
|
|
virtual void setElement(void* ptr) const { if (valid()) _itr->second = *reinterpret_cast<ElementType*>(ptr); }
|
|
|
|
};
|
|
|
|
|
2014-02-27 02:18:08 +08:00
|
|
|
virtual MapIteratorObject* createIterator(osg::Object& obj) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& map = (object.*_getter)();
|
|
|
|
return new MapIterator(_keyType, _keySize, _elementType, _elementSize, map.begin(), map.end());
|
|
|
|
}
|
|
|
|
|
2014-02-27 18:02:55 +08:00
|
|
|
virtual MapIteratorObject* createReverseIterator(osg::Object& obj) const
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
P& map = (object.*_getter)();
|
|
|
|
return new ReverseMapIterator(_keyType, _keySize, _elementType, _elementSize, map.rbegin(), map.rend());
|
|
|
|
}
|
|
|
|
|
2014-02-26 16:26:51 +08:00
|
|
|
virtual bool read( InputStream& is, osg::Object& obj )
|
|
|
|
{
|
|
|
|
C& object = OBJECT_CAST<C&>(obj);
|
|
|
|
unsigned int size = 0;
|
|
|
|
P map;
|
|
|
|
if ( is.isBinary() )
|
|
|
|
{
|
|
|
|
is >> size;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
KeyType key;
|
|
|
|
ElementType value;
|
|
|
|
is >> key >> value;
|
|
|
|
map[key] = value;
|
|
|
|
}
|
|
|
|
(object.*_setter)( map );
|
|
|
|
}
|
|
|
|
else if ( is.matchString(_name) )
|
|
|
|
{
|
|
|
|
is >> size;
|
|
|
|
if ( size>0 )
|
|
|
|
{
|
|
|
|
is >> is.BEGIN_BRACKET;
|
|
|
|
for ( unsigned int i=0; i<size; ++i )
|
|
|
|
{
|
|
|
|
KeyType key;
|
|
|
|
ElementType value;
|
|
|
|
is >> key >> value;
|
|
|
|
map[key] = value;
|
|
|
|
}
|
|
|
|
is >> is.END_BRACKET;
|
|
|
|
}
|
|
|
|
(object.*_setter)( map );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool write( OutputStream& os, const osg::Object& obj )
|
|
|
|
{
|
|
|
|
const C& object = OBJECT_CAST<const C&>(obj);
|
|
|
|
const P& map = (object.*_constgetter)();
|
|
|
|
unsigned int size = (unsigned int)map.size();
|
|
|
|
if ( os.isBinary() )
|
|
|
|
{
|
|
|
|
os << size;
|
|
|
|
for ( ConstIterator itr=map.begin();
|
|
|
|
itr!=map.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << itr->first << itr->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( size>0 )
|
|
|
|
{
|
|
|
|
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
|
|
|
|
for ( ConstIterator itr=map.begin(); itr!=map.end(); ++itr )
|
|
|
|
{
|
|
|
|
os << itr->first << itr->second; os << std::endl;
|
|
|
|
}
|
|
|
|
os << os.END_BRACKET << std::endl;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
std::string _name;
|
|
|
|
ConstGetter _constgetter;
|
|
|
|
Getter _getter;
|
|
|
|
Setter _setter;
|
|
|
|
};
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
// ADDING MANIPULATORS
|
|
|
|
#define ADD_SERIALIZER(S) \
|
2010-04-20 18:29:04 +08:00
|
|
|
wrapper->addSerializer( (S) )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_USER_SERIALIZER(PROP) \
|
|
|
|
wrapper->addSerializer( new osgDB::UserSerializer<MyClass>( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, &check##PROP, &read##PROP, &write##PROP), osgDB::BaseSerializer::RW_USER )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_BOOL_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, bool >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOOL )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2011-06-03 06:07:16 +08:00
|
|
|
#define ADD_CHAR_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, char >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_CHAR )
|
|
|
|
|
|
|
|
#define ADD_UCHAR_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned char >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UCHAR )
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_SHORT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, short >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_SHORT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_USHORT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_USHORT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_HEXSHORT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_USHORT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_INT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, int >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2014-02-13 02:03:53 +08:00
|
|
|
#define ADD_INT_SERIALIZER_NO_SET(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, int >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_INT )
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_UINT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT )
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-02-13 02:03:53 +08:00
|
|
|
#define ADD_UINT_SERIALIZER_NO_SET(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_UINT )
|
|
|
|
|
2010-04-19 20:09:21 +08:00
|
|
|
#define ADD_GLINT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLint >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_HEXINT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_UINT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_FLOAT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, float >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_FLOAT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_DOUBLE_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, double >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_DOUBLE )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2011-06-03 06:07:16 +08:00
|
|
|
#define ADD_REF_BOOL_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, bool >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOOL )
|
|
|
|
|
|
|
|
#define ADD_REF_CHAR_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, char >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_CHAR )
|
|
|
|
|
|
|
|
#define ADD_REF_UCHAR_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned char >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UCHAR )
|
|
|
|
|
|
|
|
#define ADD_REF_SHORT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, short >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_SHORT )
|
|
|
|
|
|
|
|
#define ADD_REF_USHORT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned short >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_USHORT )
|
|
|
|
|
|
|
|
#define ADD_REF_HEXSHORT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned short >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_USHORT )
|
|
|
|
|
|
|
|
#define ADD_REF_INT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, int >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
|
|
|
|
|
|
|
|
#define ADD_REF_UINT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned int >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT )
|
|
|
|
|
|
|
|
#define ADD_REF_GLINT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, GLint >( \
|
|
|
|
#PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT )
|
|
|
|
|
|
|
|
#define ADD_REF_HEXINT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, unsigned int >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_UINT )
|
|
|
|
|
|
|
|
#define ADD_REF_FLOAT_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, float >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_FLOAT )
|
|
|
|
|
|
|
|
#define ADD_REF_DOUBLE_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, double >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_DOUBLE )
|
|
|
|
|
2013-06-03 21:13:18 +08:00
|
|
|
|
|
|
|
#define ADD_VEC2B_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2b >( \
|
2013-06-28 16:57:42 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2B )
|
|
|
|
|
|
|
|
#define ADD_VEC2UB_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2ub >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2UB )
|
2013-06-03 21:13:18 +08:00
|
|
|
|
|
|
|
#define ADD_VEC2S_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2s >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2S )
|
|
|
|
|
2013-06-28 16:57:42 +08:00
|
|
|
#define ADD_VEC2US_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2us >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2US )
|
|
|
|
|
2013-06-03 21:13:18 +08:00
|
|
|
#define ADD_VEC2I_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2i >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2I )
|
|
|
|
|
|
|
|
#define ADD_VEC2UI_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2ui >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2UI )
|
|
|
|
|
2010-04-20 18:29:04 +08:00
|
|
|
#define ADD_VEC2F_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2f >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2F )
|
2010-04-20 18:29:04 +08:00
|
|
|
|
|
|
|
#define ADD_VEC2D_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2d >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2D )
|
2010-04-20 18:29:04 +08:00
|
|
|
|
|
|
|
#define ADD_VEC2_SERIALIZER(PROP, DEF) ADD_VEC2F_SERIALIZER(PROP, DEF)
|
|
|
|
|
2013-06-03 21:13:18 +08:00
|
|
|
|
|
|
|
#define ADD_VEC3B_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3b >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3B )
|
|
|
|
|
2013-06-28 16:57:42 +08:00
|
|
|
#define ADD_VEC3UB_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3ub >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3UB )
|
|
|
|
|
2013-06-03 21:13:18 +08:00
|
|
|
#define ADD_VEC3S_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3s >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3S )
|
|
|
|
|
2013-06-28 16:57:42 +08:00
|
|
|
#define ADD_VEC3US_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3us >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3US )
|
|
|
|
|
2013-06-03 21:13:18 +08:00
|
|
|
#define ADD_VEC3I_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3i >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3I )
|
|
|
|
|
|
|
|
#define ADD_VEC3UI_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3ui >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3UI )
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_VEC3F_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3f >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3F )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_VEC3D_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3d >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3D )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_VEC3_SERIALIZER(PROP, DEF) ADD_VEC3F_SERIALIZER(PROP, DEF)
|
|
|
|
|
2013-06-03 21:13:18 +08:00
|
|
|
#define ADD_VEC4B_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4b >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4B )
|
|
|
|
|
|
|
|
#define ADD_VEC4UB_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4ub >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4UB )
|
|
|
|
|
|
|
|
#define ADD_VEC4S_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4s >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4S )
|
|
|
|
|
2013-06-28 16:57:42 +08:00
|
|
|
#define ADD_VEC4US_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4us >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4US )
|
|
|
|
|
2013-06-03 21:13:18 +08:00
|
|
|
#define ADD_VEC4I_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4i >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4I )
|
|
|
|
|
|
|
|
#define ADD_VEC4UI_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4ui >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4UI )
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_VEC4F_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4f >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4F )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_VEC4D_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4d >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4D )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_VEC4_SERIALIZER(PROP, DEF) ADD_VEC4F_SERIALIZER(PROP, DEF)
|
|
|
|
|
|
|
|
#define ADD_QUAT_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Quat >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_QUAT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_PLANE_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Plane >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_PLANE )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_MATRIXF_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixf >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXF )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_MATRIXD_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixd >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXD )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_MATRIX_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::MatrixSerializer< MyClass >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIX )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2014-02-11 00:44:13 +08:00
|
|
|
|
|
|
|
#define ADD_BOUNDINGBOXF_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingBoxf >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGBOXF )
|
|
|
|
|
|
|
|
#define ADD_BOUNDINGBOXD_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingBoxd >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGBOXD )
|
|
|
|
|
|
|
|
#define ADD_BOUNDINGSPHEREF_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingSpheref >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGSPHEREF )
|
|
|
|
|
|
|
|
#define ADD_BOUNDINGSPHERED_SERIALIZER(PROP, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::BoundingSphered >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOUNDINGSPHERED )
|
|
|
|
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_GLENUM_SERIALIZER(PROP, TYPE, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_GLENUM )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2014-02-13 02:03:53 +08:00
|
|
|
#define ADD_GLENUM_SERIALIZER_NO_SET(PROP, TYPE, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_GLENUM )
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_STRING_SERIALIZER(PROP, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::StringSerializer< MyClass >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_STRING )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_OBJECT_SERIALIZER(PROP, TYPE, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_OBJECT )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2014-08-26 00:56:47 +08:00
|
|
|
#define ADD_OBJECT_SERIALIZER_NO_SET(PROP, TYPE, DEF) \
|
|
|
|
wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \
|
|
|
|
#PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_OBJECT )
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_IMAGE_SERIALIZER(PROP, TYPE, DEF) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::ImageSerializer< MyClass, TYPE >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_IMAGE )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
|
|
|
#define ADD_LIST_SERIALIZER(PROP, TYPE) \
|
2010-02-26 23:54:37 +08:00
|
|
|
wrapper->addSerializer( new osgDB::ListSerializer< MyClass, TYPE >( \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#PROP, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_LIST )
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2014-02-24 18:19:48 +08:00
|
|
|
|
|
|
|
#define ADD_VECTOR_SERIALIZER(PROP, TYPE, ELEMENTTYPE, NUMELEMENTSONROW) \
|
|
|
|
wrapper->addSerializer( new osgDB::VectorSerializer< MyClass, TYPE >( \
|
|
|
|
#PROP, &MyClass::get##PROP, &MyClass::get##PROP, &MyClass::set##PROP, ELEMENTTYPE, NUMELEMENTSONROW), osgDB::BaseSerializer::RW_VECTOR )
|
|
|
|
|
|
|
|
#define ADD_ISAVECTOR_SERIALIZER(PROP, ELEMENTTYPE, NUMELEMENTSONROW) \
|
|
|
|
wrapper->addSerializer( new osgDB::IsAVectorSerializer< MyClass >( #PROP, ELEMENTTYPE, NUMELEMENTSONROW), osgDB::BaseSerializer::RW_VECTOR )
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define BEGIN_ENUM_SERIALIZER(PROP, DEF) \
|
|
|
|
{ typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, void> MySerializer; \
|
|
|
|
osg::ref_ptr<MySerializer> serializer = new MySerializer( \
|
|
|
|
#PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
|
|
|
|
|
|
|
|
#define BEGIN_ENUM_SERIALIZER2(PROP, TYPE, DEF) \
|
|
|
|
{ typedef osgDB::EnumSerializer<MyClass, TYPE, void> MySerializer; \
|
|
|
|
osg::ref_ptr<MySerializer> serializer = new MySerializer( \
|
|
|
|
#PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
|
|
|
|
|
|
|
|
#define BEGIN_ENUM_SERIALIZER3(PROP, DEF) \
|
|
|
|
{ typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, bool> MySerializer; \
|
|
|
|
osg::ref_ptr<MySerializer> serializer = new MySerializer( \
|
|
|
|
#PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
|
|
|
|
|
2010-03-17 02:44:27 +08:00
|
|
|
#define BEGIN_ENUM_SERIALIZER4(PROPERTIES_CLASS, PROP, DEF) \
|
|
|
|
{ typedef osgDB::EnumSerializer<MyClass, PROPERTIES_CLASS::PROP, void> MySerializer; \
|
|
|
|
osg::ref_ptr<MySerializer> serializer = new MySerializer( \
|
|
|
|
#PROP, PROPERTIES_CLASS::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
|
|
|
|
|
2014-02-13 02:03:53 +08:00
|
|
|
#define BEGIN_ENUM_SERIALIZER_NO_SET(PROP, DEF) \
|
|
|
|
{ typedef osgDB::EnumSerializer<MyClass, MyClass::PROP, void> MySerializer; \
|
|
|
|
osg::ref_ptr<MySerializer> serializer = new MySerializer( \
|
|
|
|
#PROP, MyClass::DEF, &MyClass::get##PROP, 0)
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define ADD_ENUM_VALUE(VALUE) \
|
|
|
|
serializer->add(#VALUE, MyClass::VALUE)
|
|
|
|
|
2010-03-17 02:44:27 +08:00
|
|
|
#define ADD_ENUM_CLASS_VALUE(CLASS, VALUE) \
|
|
|
|
serializer->add(#VALUE, CLASS::VALUE)
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
#define END_ENUM_SERIALIZER() \
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
wrapper->addSerializer(serializer.get(), osgDB::BaseSerializer::RW_ENUM); }
|
|
|
|
|
|
|
|
// VERSION CONTROL OPERATORS
|
|
|
|
#define UPDATE_TO_VERSION(VER) \
|
|
|
|
wrapper->setUpdatedVersion( (VER) );
|
|
|
|
|
2012-10-10 00:05:50 +08:00
|
|
|
#define UPDATE_TO_VERSION_SCOPED(VER) \
|
|
|
|
osgDB::UpdateWrapperVersionProxy uwvp(wrapper, (VER));
|
|
|
|
|
From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.
The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1
The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.
The new macro UPDATE_TO_VERSION can help indicate the InputStream (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):
REGISTER_OBJECT_WRAPPER( Geode, ... )
{
ADD_USER_SERIALIZER( Drawables ); // origin ones
UPDATE_TO_VERSION( 65 )
{
ADD_USER_SERIALIZER( Test ); // a serializer added from version 65
}
}
All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.
And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:
UPDATE_TO_VERSION( 70 )
{
REMOVE_SERIALIZER( Test );
}
This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"
2010-11-09 20:41:55 +08:00
|
|
|
#define REMOVE_SERIALIZER(PROP) \
|
|
|
|
wrapper->markSerializerAsRemoved( #PROP );
|
2010-01-21 04:13:33 +08:00
|
|
|
|
2014-05-28 18:06:14 +08:00
|
|
|
#define ADD_MAP_SERIALIZER(PROP, TYPE, KEYTYPE, ELEMENTTYPE) \
|
|
|
|
wrapper->addSerializer( new osgDB::MapSerializer< MyClass, TYPE >( \
|
|
|
|
#PROP, &MyClass::get##PROP, &MyClass::get##PROP, &MyClass::set##PROP, KEYTYPE, ELEMENTTYPE), osgDB::BaseSerializer::RW_MAP )
|
|
|
|
|
2014-05-22 00:15:02 +08:00
|
|
|
#define ADD_METHOD_OBJECT( METHODNAME, METHODOBJECTCLASS ) wrapper->addMethodObject(METHODNAME, new METHODOBJECTCLASS());
|
|
|
|
|
|
|
|
#define ADD_METHOD(METHODNAME) \
|
|
|
|
{ \
|
|
|
|
struct MethodCaller : public osgDB::MethodObject \
|
|
|
|
{ \
|
|
|
|
virtual bool run(void* objectPtr, osg::Parameters&, osg::Parameters&) const \
|
|
|
|
{ \
|
|
|
|
MyClass* obj = reinterpret_cast<MyClass*>(objectPtr); \
|
|
|
|
obj->METHODNAME(); \
|
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
wrapper->addMethodObject(#METHODNAME, new MethodCaller()); \
|
|
|
|
}
|
|
|
|
|
2014-09-05 19:05:43 +08:00
|
|
|
|
|
|
|
#define SET_USAGE(VALUE) wrapper->getLastSerializer()->setUsage(VALUE)
|
|
|
|
|
2010-01-21 04:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|