[osg-users] How do I Subclass a file loader?

brettwiesner brettwiesner at gmail.com
Wed Oct 1 13:27:00 PDT 2008


Hey Robert,

I'm confused about what you mean here. Many plugins have read/ write 
methods that take istreams/ ostreams (ReaderWriterIVE being one of 
them). However, since I can't subclass them I can't attach to the 
stream. For example, in ReaderWriterIVE::writeNode() a std::ofstream is 
created but there's no way for me to attach it to a stream buffer.

It seems like the osga plugin would have the same problem. The doread()/ 
dowrite() methods call up to whatever ReaderWriter was passed in and I 
can't subclass those.

Thanks,
Brett

Robert Osfield wrote:
> Hi Brett,
>
> A number of the plugins support reading a writing from istream/ostream
> which means you can implement your std::streambuffer and attach to the
> stream and then pass this to the plugin.  This technique allows you to
> do items like compression/decompression/encription/decription.  Have a
> look at the osga and curl plugins as they provide examples of using
> streams this way.
>
> Robert.
>
> On Wed, Oct 1, 2008 at 5:02 PM, brettwiesner <brettwiesner at gmail.com> wrote:
>   
>> Hi,
>>
>> I've got a requirement to ship certain 3rd party model data only in an
>> encrypted format. So I wrote my own loader that does the encryption/
>> decryption but uses the IVE loader for everything. This works except for
>> files that reference other files. The master file is encrypted, but the
>> referenced files are saved out as .ive's.
>>
>> Ideally all I would have to do is subclass ReaderWriterIVE and override the
>> following stream methods:
>>
>>  virtual osgDB::ReaderWriter::ReadResult readObject(std::istream& fin,
>>     const osgDB::ReaderWriter::Options* options) const;
>>
>>  virtual osgDB::ReaderWriter::ReadResult readImage(std::istream& fin,
>>     const osgDB::ReaderWriter::Options* options) const;
>>
>>  virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
>>     const osgDB::ReaderWriter::Options* options) const;
>>
>>  virtual osgDB::ReaderWriter::WriteResult writeObject(const osg::Object&
>> object,
>>     std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;
>>
>>  virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image&
>> image,
>>     std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;
>>
>>  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node& node,
>>     std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;
>>
>> For writing I could get the raw data from the ive loader encrypt it and
>> write it out. For reading I could decrypt the data, then pass the
>> unencrypted data up to the ive loader for use.
>>
>> There is one fatal flaw... I can't subclass the ReaderWriterIVE plugin. :(
>>
>> 1) Has anyone besides me ever wanted to derive from a file loader? Would it
>> make sense to keep the logic in a lib with headers, then have another
>> library that is just the plugin?
>>
>> 2) Is there some other mechanism in OSG that will let me do this?
>>
>> Thanks,
>> Brett
>> _______________________________________________
>> osg-users mailing list
>> osg-users at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>>     
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>   




More information about the osg-users mailing list