From 0e119ec26c683bf81369eb709a6e80c13e61b782 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 1 Oct 2004 07:39:15 +0000 Subject: [PATCH] Added support for write to ostream into .osg plugin --- src/osgPlugins/osg/ReaderWriterOSG.cpp | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index df0b6efb1..00ab1d258 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -22,7 +22,9 @@ class OSGReaderWriter : public ReaderWriter return equalCaseInsensitive(extension,"osg"); } - virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName,opt); } + virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName, opt); } + + virtual ReadResult readObject(std::istream& fin, const Options* opt) { return readNode(fin, opt); } virtual ReadResult readNode(const std::string& file, const Options* opt) { @@ -111,6 +113,24 @@ class OSGReaderWriter : public ReaderWriter return WriteResult("Unable to open file for output"); } + virtual WriteResult writeObject(const Object& obj,std::ostream& fout, const osgDB::ReaderWriter::Options* options) + { + Output foutput; + + std::ios &fios = foutput; + fios.rdbuf(fout.rdbuf()); + + if (fout) + { + setPrecision(foutput,options); + + foutput.writeObject(obj); + return WriteResult::FILE_SAVED; + } + return WriteResult("Unable to write to output stream"); + } + + virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) { std::string ext = getFileExtension(fileName); @@ -129,6 +149,23 @@ class OSGReaderWriter : public ReaderWriter return WriteResult("Unable to open file for output"); } + virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) + { + Output foutput; + + std::ios &fios = foutput; + fios.rdbuf(fout.rdbuf()); + + if (fout) + { + setPrecision(foutput,options); + + foutput.writeObject(node); + return WriteResult::FILE_SAVED; + } + return WriteResult("Unable to write to output stream"); + } + }; // now register with Registry to instantiate the above