From bc29eab0b71756e93e735cc3806e1422edfbf48b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 30 Apr 2009 08:50:43 +0000 Subject: [PATCH] Added support for reading from streams --- applications/present3D/ReaderWriterP3D.cpp | 31 +++++++++++++++++----- src/osgPlugins/p3d/ReaderWriterP3D.cpp | 30 ++++++++++++++++----- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/applications/present3D/ReaderWriterP3D.cpp b/applications/present3D/ReaderWriterP3D.cpp index b0fe3a5db..b11d6cee0 100644 --- a/applications/present3D/ReaderWriterP3D.cpp +++ b/applications/present3D/ReaderWriterP3D.cpp @@ -111,6 +111,10 @@ public: virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const; + virtual ReadResult readNode(std::istream& fin, const Options* options) const; + + ReadResult readNode(osgDB::XmlNode::Input& input, const osgDB::ReaderWriter::Options* options) const; + void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; @@ -1384,24 +1388,38 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { - - bool readOnlyHoldingPage = options ? options->getOptionString()=="holding_slide" : false; - std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; std::string fileName = osgDB::findDataFile( file ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + osgDB::XmlNode::Input input; + input.open(fileName); + input.readAllDataIntoBuffer(); + + return readNode(input, options); +} + +osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(std::istream& fin, const Options* options) const +{ + osgDB::XmlNode::Input input; + input.attach(fin); + input.readAllDataIntoBuffer(); + + return readNode(input, options); +} + +osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, const osgDB::ReaderWriter::Options* options) const +{ + bool readOnlyHoldingPage = options ? options->getOptionString()=="holding_slide" : false; + // create a keyPosition just in case we need it. osgPresentation::KeyPosition keyPosition; osg::ref_ptr doc = new osgDB::XmlNode; osgDB::XmlNode* root = 0; - osgDB::XmlNode::Input input; - input.open(fileName); - input.readAllDataIntoBuffer(); doc->read(input); @@ -1568,4 +1586,3 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& std::cout<<"node="<getOptionString()=="holding_slide" : false; - std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; std::string fileName = osgDB::findDataFile( file ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + osgDB::XmlNode::Input input; + input.open(fileName); + input.readAllDataIntoBuffer(); + + return readNode(input, options); +} + +osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(std::istream& fin, const Options* options) const +{ + osgDB::XmlNode::Input input; + input.attach(fin); + input.readAllDataIntoBuffer(); + + return readNode(input, options); +} + +osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, const osgDB::ReaderWriter::Options* options) const +{ + bool readOnlyHoldingPage = options ? options->getOptionString()=="holding_slide" : false; + // create a keyPosition just in case we need it. osgPresentation::KeyPosition keyPosition; osg::ref_ptr doc = new osgDB::XmlNode; osgDB::XmlNode* root = 0; - osgDB::XmlNode::Input input; - input.open(fileName); - input.readAllDataIntoBuffer(); doc->read(input);