Hi,

I have created a new class derived from osg::Object. I would like to add
the ability to serialize the class to the human readable "osg" format.
Currently, serialization only works for "osgb".

Here is a simplified version of my code:

// In "MyObject", I have:

namespace osgMyLibrary {

class MyObject: public osg::Object
{
public:
MyObject(): _symbol("") {}
MyObject(MyObject const& other, osg::CopyOp const& =
osg::CopyOp::SHALLOW_COPY): _symbol(other._symbol) {}

std::string const& getSymbol() const { return _symbol; }
void setSymbol(std::string const& symbol) { _symbol = symbol; }

META_Object(osgMyLibrary, MyObject);

protected:
// Use reference counting.
virtual ~MyObject();

private:
std::string _symbol;
};

}

// In "MyObject.cpp", I have:

REGISTER_OBJECT_WRAPPER(MyObject,
new osgMyLibrary::MyObject, osgMyLibrary::MyObject,
"osg::Object osgMyLibrary::MyObject")
{
ADD_STRING_SERIALIZER(Symbol, "#1");
}

// In "main.cpp", I have:

osg::ref_ptr<osgMyLibrary::MyObject> test = new osgMyLibrary::MyObject();
std::ostringstream sstream;
osgDB::ReaderWriter::WriteResult wr
= 
osgDB::Registry::instance()->getReaderWriterForExtension("osg")->writeObject(*test,
sstream, 0);
std::cout << sstream.str() << std::endl;

However, nothing is written to the console. If I change the extension to
"osgb", I can see the object, but it is obviously using the binary format.
What do I need to change in order to get human readable serialization?

Cheers,
Peter
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to