Changeset 11902
- Timestamp:
- 11/09/10 13:41:55 (3 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 7 modified
-
include/osgDB/InputStream (modified) (2 diffs)
-
include/osgDB/ObjectWrapper (modified) (5 diffs)
-
include/osgDB/Registry (modified) (1 diff)
-
include/osgDB/Serializer (modified) (7 diffs)
-
src/osgDB/InputStream.cpp (modified) (4 diffs)
-
src/osgDB/ObjectWrapper.cpp (modified) (5 diffs)
-
src/osgDB/OutputStream.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgDB/InputStream
r11816 r11902 70 70 71 71 bool isBinary() const { return _in->isBinary(); } 72 int getFileVersion() const { return _fileVersion; } 72 73 const osgDB::Options* getOptions() const { return _options.get(); } 73 74 … … 160 161 IdentifierMap _identifierMap; 161 162 163 int _fileVersion; 162 164 int _byteSwap; 163 165 bool _useSchemaData; -
OpenSceneGraph/trunk/include/osgDB/ObjectWrapper
r11859 r11902 51 51 ObjectWrapper( osg::Object* proto, const std::string& name, 52 52 const std::string& associates ); 53 void setUpdatedVersion( int ver ) { _version = ver; } 53 54 54 55 const osg::Object* getProto() const { return _proto.get(); } 55 56 const std::string& getName() const { return _name; } 56 57 const StringList& getAssociates() const { return _associates; } 57 58 void addSerializer( BaseSerializer* s ) { _serializers.push_back(s); } 58 59 void addSerializer( BaseSerializer* s, BaseSerializer::Type t=BaseSerializer::RW_UNDEFINED ) 60 { s->_version = _version; _serializers.push_back(s); _typeList.push_back(static_cast<int>(t)); } 61 62 void markSerializerAsRemoved( const std::string& name ); 63 BaseSerializer* getSerializer( const std::string& name ); 59 64 void addFinishedObjectReadCallback ( FinishedObjectReadCallback* forc) { _finishedObjectReadCallbacks.push_back(forc); } 60 65 61 62 66 bool read( InputStream&, osg::Object& ); 63 67 bool write( OutputStream&, const osg::Object& ); 64 65 bool readSchema( const StringList& properties );66 void writeSchema( StringList& properties );68 69 bool readSchema( const StringList& properties, const std::vector<int>& types ); 70 void writeSchema( StringList& properties, std::vector<int>& types ); 67 71 void resetSchema() 68 72 { if ( _backupSerializers.size()>0 ) _serializers = _backupSerializers; } 69 73 70 74 protected: 71 ObjectWrapper() {}75 ObjectWrapper() : _version(0) {} 72 76 virtual ~ObjectWrapper() {} 73 77 74 78 osg::ref_ptr<osg::Object> _proto; 75 79 std::string _name; … … 77 81 SerializerList _serializers; 78 82 SerializerList _backupSerializers; 83 std::vector<int> _typeList; 79 84 FinishedObjectReadCallbackList _finishedObjectReadCallbacks; 85 int _version; // Last updated version of the wrapper 80 86 }; 81 87 … … 144 150 145 151 #define REGISTER_OBJECT_WRAPPER(NAME, PROTO, CLASS, ASSOCIATES) \ 152 extern "C" void wrapper_serializer_##NAME(void) {} \ 146 153 extern void wrapper_propfunc_##NAME(osgDB::ObjectWrapper*); \ 147 154 static osgDB::RegisterWrapperProxy wrapper_proxy_##NAME( \ … … 151 158 152 159 #define REGISTER_OBJECT_WRAPPER2(NAME, PROTO, CLASS, CLASSNAME, ASSOCIATES) \ 160 extern "C" void wrapper_serializer_##NAME(void) {} \ 153 161 extern void wrapper_propfunc_##NAME(osgDB::ObjectWrapper*); \ 154 162 static osgDB::RegisterWrapperProxy wrapper_proxy_##NAME( \ … … 168 176 169 177 #define REGISTER_COMPRESSOR(NAME, CLASS) \ 178 extern "C" void wrapper_compressor_##CLASS(void) {} \ 170 179 static osgDB::RegisterCompressorProxy compressor_proxy_##CLASS(NAME, new CLASS); 171 180 -
OpenSceneGraph/trunk/include/osgDB/Registry
r11084 r11902 638 638 static osgDB::PluginFunctionProxy proxy_dotosgwrapper_##classname(dotosgwrapper_##classname); 639 639 640 #define USE_SERIALIZER_WRAPPER(classname) \ 641 extern "C" void wrapper_serializer_##classname(void); \ 642 static osgDB::PluginFunctionProxy proxy_serializer_##classname(wrapper_serializer_##classname); 643 644 #define USE_COMPRESSOR_WRAPPER(classname) \ 645 extern "C" void wrapper_serializer_##classname(void); \ 646 static osgDB::PluginFunctionProxy proxy_compressor_##classname(wrapper_compressor_##classname); 647 640 648 #define REGISTER_OSGPLUGIN(ext, classname) \ 641 649 extern "C" void osgdb_##ext(void) {} \ -
OpenSceneGraph/trunk/include/osgDB/Serializer
r11816 r11902 117 117 class BaseSerializer : public osg::Referenced 118 118 { 119 public: 120 BaseSerializer() {} 119 friend class ObjectWrapper; 120 public: 121 enum Type 122 { 123 RW_UNDEFINED = 0, RW_USER, RW_OBJECT, RW_IMAGE, RW_LIST, 124 RW_BOOL, RW_SHORT, RW_USHORT, RW_INT, RW_UINT, RW_FLOAT, RW_DOUBLE, 125 RW_VEC2F, RW_VEC2D, RW_VEC3F, RW_VEC3D, RW_VEC4F, RW_VEC4D, RW_QUAT, RW_PLANE, 126 RW_MATRIXF, RW_MATRIXD, RW_MATRIX, RW_GLENUM, RW_STRING, RW_ENUM 127 }; 128 129 BaseSerializer() : _version(0) {} 121 130 virtual bool read( InputStream&, osg::Object& ) = 0; 122 131 virtual bool write( OutputStream&, const osg::Object& ) = 0; 123 132 virtual const std::string& getName() const = 0; 133 134 protected: 135 int _version; // Library version when the serializer is added, or removed (neg value) 124 136 }; 125 137 … … 768 780 #define ADD_USER_SERIALIZER(PROP) \ 769 781 wrapper->addSerializer( new osgDB::UserSerializer<MyClass>( \ 770 #PROP, &check##PROP, &read##PROP, &write##PROP) )782 #PROP, &check##PROP, &read##PROP, &write##PROP), osgDB::BaseSerializer::RW_USER ) 771 783 772 784 #define ADD_BOOL_SERIALIZER(PROP, DEF) \ 773 785 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, bool >( \ 774 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )786 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOOL ) 775 787 776 788 #define ADD_SHORT_SERIALIZER(PROP, DEF) \ 777 789 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, short >( \ 778 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )790 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_SHORT ) 779 791 780 792 #define ADD_USHORT_SERIALIZER(PROP, DEF) \ 781 793 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \ 782 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )794 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_USHORT ) 783 795 784 796 #define ADD_HEXSHORT_SERIALIZER(PROP, DEF) \ 785 797 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \ 786 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true) )798 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_USHORT ) 787 799 788 800 #define ADD_INT_SERIALIZER(PROP, DEF) \ 789 801 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, int >( \ 790 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )802 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT ) 791 803 792 804 #define ADD_UINT_SERIALIZER(PROP, DEF) \ 793 805 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \ 794 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )806 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT ) 795 807 796 808 #define ADD_GLINT_SERIALIZER(PROP, DEF) \ 797 809 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLint >( \ 798 #PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP) )810 #PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT ) 799 811 800 812 #define ADD_HEXINT_SERIALIZER(PROP, DEF) \ 801 813 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \ 802 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true) )814 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_UINT ) 803 815 804 816 #define ADD_FLOAT_SERIALIZER(PROP, DEF) \ 805 817 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, float >( \ 806 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )818 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_FLOAT ) 807 819 808 820 #define ADD_DOUBLE_SERIALIZER(PROP, DEF) \ 809 821 wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, double >( \ 810 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )822 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_DOUBLE ) 811 823 812 824 #define ADD_VEC2F_SERIALIZER(PROP, DEF) \ 813 825 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2f >( \ 814 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )826 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2F ) 815 827 816 828 #define ADD_VEC2D_SERIALIZER(PROP, DEF) \ 817 829 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2d >( \ 818 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )830 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2D ) 819 831 820 832 #define ADD_VEC2_SERIALIZER(PROP, DEF) ADD_VEC2F_SERIALIZER(PROP, DEF) … … 822 834 #define ADD_VEC3F_SERIALIZER(PROP, DEF) \ 823 835 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3f >( \ 824 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )836 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3F ) 825 837 826 838 #define ADD_VEC3D_SERIALIZER(PROP, DEF) \ 827 839 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3d >( \ 828 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )840 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3D ) 829 841 830 842 #define ADD_VEC3_SERIALIZER(PROP, DEF) ADD_VEC3F_SERIALIZER(PROP, DEF) … … 832 844 #define ADD_VEC4F_SERIALIZER(PROP, DEF) \ 833 845 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4f >( \ 834 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )846 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4F ) 835 847 836 848 #define ADD_VEC4D_SERIALIZER(PROP, DEF) \ 837 849 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4d >( \ 838 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )850 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4D ) 839 851 840 852 #define ADD_VEC4_SERIALIZER(PROP, DEF) ADD_VEC4F_SERIALIZER(PROP, DEF) … … 842 854 #define ADD_QUAT_SERIALIZER(PROP, DEF) \ 843 855 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Quat >( \ 844 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )856 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_QUAT ) 845 857 846 858 #define ADD_PLANE_SERIALIZER(PROP, DEF) \ 847 859 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Plane >( \ 848 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )860 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_PLANE ) 849 861 850 862 #define ADD_MATRIXF_SERIALIZER(PROP, DEF) \ 851 863 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixf >( \ 852 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )864 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXF ) 853 865 854 866 #define ADD_MATRIXD_SERIALIZER(PROP, DEF) \ 855 867 wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixd >( \ 856 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )868 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXD ) 857 869 858 870 #define ADD_MATRIX_SERIALIZER(PROP, DEF) \ 859 871 wrapper->addSerializer( new osgDB::MatrixSerializer< MyClass >( \ 860 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )872 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIX ) 861 873 862 874 #define ADD_GLENUM_SERIALIZER(PROP, TYPE, DEF) \ 863 875 wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \ 864 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )876 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_GLENUM ) 865 877 866 878 #define ADD_STRING_SERIALIZER(PROP, DEF) \ 867 879 wrapper->addSerializer( new osgDB::StringSerializer< MyClass >( \ 868 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )880 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_STRING ) 869 881 870 882 #define ADD_OBJECT_SERIALIZER(PROP, TYPE, DEF) \ 871 883 wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \ 872 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )884 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_OBJECT ) 873 885 874 886 #define ADD_IMAGE_SERIALIZER(PROP, TYPE, DEF) \ 875 887 wrapper->addSerializer( new osgDB::ImageSerializer< MyClass, TYPE >( \ 876 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) )888 #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_IMAGE ) 877 889 878 890 #define ADD_LIST_SERIALIZER(PROP, TYPE) \ 879 891 wrapper->addSerializer( new osgDB::ListSerializer< MyClass, TYPE >( \ 880 #PROP, &MyClass::get##PROP, &MyClass::set##PROP) )892 #PROP, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_LIST ) 881 893 882 894 #define BEGIN_ENUM_SERIALIZER(PROP, DEF) \ … … 900 912 #PROP, PROPERTIES_CLASS::DEF, &MyClass::get##PROP, &MyClass::set##PROP) 901 913 902 903 914 #define ADD_ENUM_VALUE(VALUE) \ 904 915 serializer->add(#VALUE, MyClass::VALUE) … … 908 919 909 920 #define END_ENUM_SERIALIZER() \ 910 wrapper->addSerializer(serializer.get()); } 921 wrapper->addSerializer(serializer.get(), osgDB::BaseSerializer::RW_ENUM); } 922 923 // VERSION CONTROL OPERATORS 924 #define UPDATE_TO_VERSION(VER) \ 925 wrapper->setUpdatedVersion( (VER) ); 926 927 #define REMOVE_SERIALIZER(PROP) \ 928 wrapper->markSerializerAsRemoved( #PROP ); 911 929 912 930 } -
OpenSceneGraph/trunk/src/osgDB/InputStream.cpp
r11816 r11902 25 25 26 26 InputStream::InputStream( const osgDB::Options* options ) 27 : _ byteSwap(0), _useSchemaData(false), _forceReadingImage(false), _dataDecompress(0)27 : _fileVersion(0), _byteSwap(0), _useSchemaData(false), _forceReadingImage(false), _dataDecompress(0) 28 28 { 29 29 if ( !options ) return; … … 31 31 32 32 std::string schema; 33 StringList optionList; 34 split( options->getOptionString(), optionList ); 35 for ( StringList::iterator itr=optionList.begin(); itr!=optionList.end(); ++itr ) 36 { 37 const std::string& option = *itr; 38 if ( option=="Ascii" ) 39 { 40 // Omit this 41 } 42 else if ( option=="ForceReadingImage" ) 43 { 44 _forceReadingImage = true; 45 } 46 else 47 { 48 StringList keyAndValues; 49 split( option, keyAndValues, '=' ); 50 if ( keyAndValues.size()<2 ) continue; 51 52 if ( keyAndValues[0]=="SchemaFile" ) 53 { 54 schema = keyAndValues[1]; 55 if ( s_lastSchema!=schema ) 56 { 57 osgDB::ifstream schemaStream( schema.c_str(), std::ios::in ); 58 if ( !schemaStream.fail() ) readSchema( schemaStream ); 59 schemaStream.close(); 60 s_lastSchema = schema; 61 } 62 } 63 else 64 OSG_WARN << "InputStream: Unknown option " << option << std::endl; 65 } 66 } 33 if ( options->getPluginStringData("ForceReadingImage")=="true" ) 34 _forceReadingImage = true; 35 if ( !options->getPluginStringData("SchemaFile").empty() ) 36 { 37 schema = options->getPluginStringData("SchemaFile"); 38 if ( s_lastSchema!=schema ) 39 { 40 osgDB::ifstream schemaStream( schema.c_str(), std::ios::in ); 41 if ( !schemaStream.fail() ) readSchema( schemaStream ); 42 schemaStream.close(); 43 s_lastSchema = schema; 44 } 45 } 46 67 47 if ( schema.empty() ) 68 48 { … … 734 714 } 735 715 736 // Check file version 737 if ( version!=PLUGIN_VERSION ) 738 { 739 OSG_WARN << "InputStream: Input data version " << version 740 << " may be incompatible with current reader version " 741 << PLUGIN_VERSION << std::endl; 742 } 716 // Record file version for back-compatibility checking of wrappers 717 _fileVersion = version; 743 718 _fields.pop_back(); 744 719 return type; … … 794 769 } 795 770 796 StringList schema; 771 StringList schema, methods, keyAndValue; 772 std::vector<int> types; 797 773 split( properties, schema ); 798 wrapper->readSchema( schema ); 774 for ( StringList::iterator itr=schema.begin(); itr!=schema.end(); ++itr ) 775 { 776 split( *itr, keyAndValue, ':' ); 777 if ( keyAndValue.size()>1 ) 778 { 779 methods.push_back( keyAndValue.front() ); 780 types.push_back( atoi(keyAndValue.back().c_str()) ); 781 } 782 else 783 { 784 methods.push_back( *itr ); 785 types.push_back( 0 ); 786 } 787 keyAndValue.clear(); 788 } 789 wrapper->readSchema( methods, types ); 799 790 } 800 791 -
OpenSceneGraph/trunk/src/osgDB/ObjectWrapper.cpp
r11859 r11902 87 87 const std::string& associates ) 88 88 : osg::Referenced(), 89 _proto(proto), _name(name) 89 _proto(proto), _name(name), _version(0) 90 90 { 91 91 split( associates, _associates ); 92 } 93 94 void ObjectWrapper::markSerializerAsRemoved( const std::string& name ) 95 { 96 for ( SerializerList::iterator itr=_serializers.begin(); itr!=_serializers.end(); ++itr ) 97 { 98 // When a serializer is marked as 'removed', it means that this serializer won't be used any more 99 // from specified OSG version (by macro UPDATE_TO_VERSION). The read() functions of higher versions 100 // will thus ignore it according to the sign and value of the _version variable. 101 if ( (*itr)->getName()==name ) 102 (*itr)->_version = -_version; 103 } 104 } 105 106 BaseSerializer* ObjectWrapper::getSerializer( const std::string& name ) 107 { 108 for ( SerializerList::iterator itr=_serializers.begin(); itr!=_serializers.end(); ++itr ) 109 { 110 if ( (*itr)->getName()==name ) 111 return *itr; 112 } 113 114 for ( StringList::const_iterator itr=_associates.begin(); itr!=_associates.end(); ++itr ) 115 { 116 const std::string& assocName = *itr; 117 ObjectWrapper* assocWrapper = Registry::instance()->getObjectWrapperManager()->findWrapper(assocName); 118 if ( !assocWrapper ) 119 { 120 osg::notify(osg::WARN) << "ObjectWrapper::getSerializer(): Unsupported associated class " 121 << assocName << std::endl; 122 continue; 123 } 124 125 for ( SerializerList::iterator aitr=assocWrapper->_serializers.begin(); 126 aitr!=assocWrapper->_serializers.end(); ++aitr ) 127 { 128 if ( (*aitr)->getName()==name ) 129 return *aitr; 130 } 131 } 132 return NULL; 92 133 } 93 134 … … 98 139 itr!=_serializers.end(); ++itr ) 99 140 { 141 int serializerVersion = (*itr)->_version; 142 if ( serializerVersion!=0 ) 143 { 144 if ( serializerVersion<0 ) 145 { 146 serializerVersion = -serializerVersion; 147 148 // The serializer is removed from a specified version, 149 // and the file in reading is at the same or higher version, ignore it. 150 if ( is.getFileVersion()>=serializerVersion ) continue; 151 } 152 else 153 { 154 // The serializer is added at a specified version, 155 // but the file in reading is at a lower version, ignore it. 156 if ( is.getFileVersion()<serializerVersion ) continue; 157 } 158 } 159 100 160 if ( (*itr)->read(is, obj) ) continue; 101 161 OSG_WARN << "ObjectWrapper::read(): Error reading property " … … 128 188 } 129 189 130 bool ObjectWrapper::readSchema( const StringList& properties ) 131 { 190 bool ObjectWrapper::readSchema( const StringList& properties, const std::vector<int>& ) 191 { 192 // FIXME: At present, I didn't do anything to determine serializers from their types... 132 193 if ( !_backupSerializers.size() ) 133 194 _backupSerializers = _serializers; … … 170 231 } 171 232 172 void ObjectWrapper::writeSchema( StringList& properties )233 void ObjectWrapper::writeSchema( StringList& properties, std::vector<int>& types ) 173 234 { 174 235 for ( SerializerList::iterator itr=_serializers.begin(); … … 176 237 { 177 238 properties.push_back( (*itr)->getName() ); 239 } 240 241 for ( std::vector<int>::iterator itr=_typeList.begin(); 242 itr!=_typeList.end(); ++itr ) 243 { 244 types.push_back( (*itr) ); 178 245 } 179 246 } -
OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp
r11816 r11902 19 19 #include <osgDB/ObjectWrapper> 20 20 #include <fstream> 21 #include <sstream> 21 22 22 23 using namespace osgDB; … … 28 29 _options = options; 29 30 30 StringList optionList; 31 split( options->getOptionString(), optionList ); 32 for ( StringList::iterator itr=optionList.begin(); itr!=optionList.end(); ++itr ) 33 { 34 const std::string& option = *itr; 35 if ( option=="Ascii" ) 36 { 37 // Omit this 38 } 39 else if ( option=="SchemaData" ) 40 { 41 _useSchemaData = true; 42 } 43 else 44 { 45 StringList keyAndValues; 46 split( option, keyAndValues, '=' ); 47 if ( keyAndValues.size()<2 ) continue; 48 49 if ( keyAndValues[0]=="SchemaFile" ) 50 _schemaName = keyAndValues[1]; 51 else if ( keyAndValues[0]=="Compressor" ) 52 _compressorName = keyAndValues[1]; 53 else if ( keyAndValues[0]=="WriteImageHint" ) 54 { 55 if ( keyAndValues[1]=="IncludeData" ) _writeImageHint = WRITE_INLINE_DATA; 56 else if ( keyAndValues[1]=="IncludeFile" ) _writeImageHint = WRITE_INLINE_FILE; 57 else if ( keyAndValues[1]=="UseExternal" ) _writeImageHint = WRITE_USE_EXTERNAL; 58 else if ( keyAndValues[1]=="WriteOut" ) _writeImageHint = WRITE_EXTERNAL_FILE; 59 } 60 else 61 OSG_WARN << "OutputStream: Unknown option " << option << std::endl; 62 } 31 if ( options->getPluginStringData("SchemaData")=="true" ) 32 _useSchemaData = true; 33 if ( !options->getPluginStringData("SchemaFile").empty() ) 34 _schemaName = options->getPluginStringData("SchemaFile"); 35 if ( !options->getPluginStringData("Compressor").empty() ) 36 _compressorName = options->getPluginStringData("Compressor"); 37 if ( !options->getPluginStringData("WriteImageHint").empty() ) 38 { 39 std::string hintString = options->getPluginStringData("WriteImageHint"); 40 if ( hintString=="IncludeData" ) _writeImageHint = WRITE_INLINE_DATA; 41 else if ( hintString=="IncludeFile" ) _writeImageHint = WRITE_INLINE_FILE; 42 else if ( hintString=="UseExternal" ) _writeImageHint = WRITE_USE_EXTERNAL; 43 else if ( hintString=="WriteOut" ) _writeImageHint = WRITE_EXTERNAL_FILE; 63 44 } 64 45 } … … 491 472 { 492 473 StringList properties; 493 assocWrapper->writeSchema( properties ); 494 if ( properties.size()>0 ) 474 std::vector<int> types; 475 assocWrapper->writeSchema( properties, types ); 476 477 unsigned int size = osg::minimum( properties.size(), types.size() ); 478 if ( size>0 ) 495 479 { 496 std::string propertiesString;497 for ( StringList::iterator sitr=properties.begin(); sitr!=properties.end(); ++sitr)480 std::stringstream propertiesStream; 481 for ( unsigned int i=0; i<size; ++i ) 498 482 { 499 propertiesString += *sitr; 500 propertiesString += ' '; 483 propertiesStream << properties[i] << ":" << types[i] << " "; 501 484 } 502 _inbuiltSchemaMap[assocName] = propertiesStr ing;485 _inbuiltSchemaMap[assocName] = propertiesStream.str(); 503 486 } 504 487 } … … 527 510 if ( isBinary() ) 528 511 { 529 *this << (unsigned int)type << (unsigned int) PLUGIN_VERSION;512 *this << (unsigned int)type << (unsigned int)OPENSCENEGRAPH_SOVERSION; 530 513 531 514 bool useCompressSource = false; … … 575 558 576 559 *this << typeString << std::endl; 577 *this << PROPERTY("#Version") << (unsigned int) PLUGIN_VERSION << std::endl;560 *this << PROPERTY("#Version") << (unsigned int)OPENSCENEGRAPH_SOVERSION << std::endl; 578 561 *this << PROPERTY("#Generator") << std::string("OpenSceneGraph") 579 562 << std::string(osgGetVersion()) << std::endl; … … 643 626 644 627 StringList properties; 645 wrapper->writeSchema( properties ); 646 if ( properties.size()>0 ) 647 { 648 for ( StringList::iterator sitr=properties.begin(); sitr!=properties.end(); ++sitr ) 649 { 650 fout << ' ' << *sitr; 651 } 628 std::vector<int> types; 629 wrapper->writeSchema( properties, types ); 630 631 std::string propertiesString; 632 unsigned int size = osg::minimum( properties.size(), types.size() ); 633 for ( unsigned int i=0; i<size; ++i ) 634 { 635 fout << " " << properties[i] << ":" << types[i]; 652 636 } 653 637 fout << std::endl;
