Updates to osgDB::Archive
This commit is contained in:
parent
e79feb1004
commit
676f204cdb
@ -65,16 +65,6 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
|||||||
virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL);
|
virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL);
|
||||||
virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL);
|
virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL);
|
||||||
|
|
||||||
virtual ReadResult readObject(std::istream& fin,const Options* options=NULL);
|
|
||||||
virtual ReadResult readImage(std::istream& fin,const Options* options=NULL);
|
|
||||||
virtual ReadResult readHeightField(std::istream& fin,const Options* options=NULL);
|
|
||||||
virtual ReadResult readNode(std::istream& fin,const Options* options=NULL);
|
|
||||||
|
|
||||||
virtual WriteResult writeObject(const osg::Object& obj,std::ostream& fout,const Options* options=NULL);
|
|
||||||
virtual WriteResult writeImage(const osg::Image& image,std::ostream& fout,const Options* options=NULL);
|
|
||||||
virtual WriteResult writeHeightField(const osg::HeightField& heightField,std::ostream& fout,const Options* options=NULL);
|
|
||||||
virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* options=NULL);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
typedef std::istream::pos_type pos_type;
|
typedef std::istream::pos_type pos_type;
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
* OpenSceneGraph Public License for more details.
|
* OpenSceneGraph Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <osg/Notify>
|
||||||
|
|
||||||
|
#include <osgDB/Registry>
|
||||||
|
#include <osgDB/FileNameUtils>
|
||||||
#include <osgDB/Archive>
|
#include <osgDB/Archive>
|
||||||
|
|
||||||
using namespace osgDB;
|
using namespace osgDB;
|
||||||
@ -26,17 +30,21 @@ Archive::~Archive()
|
|||||||
|
|
||||||
void Archive::create(const std::string& filename, unsigned int indexBlockSize)
|
void Archive::create(const std::string& filename, unsigned int indexBlockSize)
|
||||||
{
|
{
|
||||||
|
_status = WRITE;
|
||||||
|
_output.open(filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Archive::open(const std::string& filename, Status status)
|
void Archive::open(const std::string& filename, Status status)
|
||||||
{
|
{
|
||||||
if (status==READ)
|
if (status==READ)
|
||||||
{
|
{
|
||||||
|
_status = status;
|
||||||
_input.open(filename.c_str());
|
_input.open(filename.c_str());
|
||||||
}
|
}
|
||||||
else // status==WRITE
|
else // status==WRITE
|
||||||
{
|
{
|
||||||
_input.open(filename.c_str());
|
_status = status;
|
||||||
|
_output.open(filename.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,22 +60,87 @@ bool Archive::fileExists(const std::string& filename) const
|
|||||||
return (_indexMap.count(filename)!=0);
|
return (_indexMap.count(filename)!=0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReaderWriter::ReadResult Archive::readObject(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
ReaderWriter::ReadResult Archive::readObject(const std::string& fileName,const Options* options)
|
||||||
|
{
|
||||||
|
if (_status!=READ)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::readObject(obj, "<<fileName<<") failed, archive opened as read only."<<std::endl;
|
||||||
|
return ReadResult(ReadResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileNamePositionMap::const_iterator itr = _indexMap.find(fileName);
|
||||||
|
if (itr==_indexMap.end())
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::readObject(obj, "<<fileName<<") failed, file not found in archive"<<std::endl;
|
||||||
|
return ReadResult(ReadResult::FILE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(getLowerCaseFileExtension(fileName));
|
||||||
|
if (!rw)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::readObject(obj, "<<fileName<<") failed to find appropriate plugin to write file."<<std::endl;
|
||||||
|
return ReadResult(ReadResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::readObject(obj, "<<fileName<<")"<<std::endl;
|
||||||
|
return rw->readObject(_input, options);
|
||||||
|
}
|
||||||
|
|
||||||
ReaderWriter::ReadResult Archive::readImage(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
ReaderWriter::ReadResult Archive::readImage(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||||
ReaderWriter::ReadResult Archive::readHeightField(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
ReaderWriter::ReadResult Archive::readHeightField(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||||
ReaderWriter::ReadResult Archive::readNode(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
ReaderWriter::ReadResult Archive::readNode(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||||
|
|
||||||
ReaderWriter::WriteResult Archive::writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
|
||||||
ReaderWriter::WriteResult Archive::writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
|
||||||
ReaderWriter::WriteResult Archive::writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
|
||||||
ReaderWriter::WriteResult Archive::writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options*) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
|
||||||
|
|
||||||
ReaderWriter::ReadResult Archive::readObject(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
|
||||||
ReaderWriter::ReadResult Archive::readImage(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
|
||||||
ReaderWriter::ReadResult Archive::readHeightField(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
|
||||||
ReaderWriter::ReadResult Archive::readNode(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
|
||||||
|
|
||||||
ReaderWriter::WriteResult Archive::writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
|
||||||
ReaderWriter::WriteResult Archive::writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
ReaderWriter::WriteResult Archive::writeObject(const osg::Object& obj,const std::string& fileName,const Options* options)
|
||||||
ReaderWriter::WriteResult Archive::writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
{
|
||||||
ReaderWriter::WriteResult Archive::writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options*) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
if (_status!=WRITE)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeObject(obj, "<<fileName<<") failed, archive opened as read only."<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(getLowerCaseFileExtension(fileName));
|
||||||
|
if (!rw)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeObject(obj, "<<fileName<<") failed to find appropriate plugin to write file."<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeObject(obj, "<<fileName<<")"<<std::endl;
|
||||||
|
return rw->writeObject(obj, _output, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReaderWriter::WriteResult Archive::writeImage(const osg::Image& /*image*/,const std::string& fileName,const Options* options)
|
||||||
|
{
|
||||||
|
if (_status==READ)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeImage(obj, "<<fileName<<") failed, archive opened as read only."<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeImage(obj, "<<fileName<<")"<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReaderWriter::WriteResult Archive::writeHeightField(const osg::HeightField& /*heightField*/,const std::string& fileName,const Options* options)
|
||||||
|
{
|
||||||
|
if (_status!=WRITE)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeHeightField(obj, "<<fileName<<") failed, archive opened as read only."<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeHeightField(obj, "<<fileName<<")"<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReaderWriter::WriteResult Archive::writeNode(const osg::Node& /*node*/,const std::string& fileName,const Options* options)
|
||||||
|
{
|
||||||
|
if (_status!=WRITE)
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeNode(obj, "<<fileName<<") failed, archive opened as read only."<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
osg::notify(osg::NOTICE)<<"Archive::writeNode(obj, "<<fileName<<")"<<std::endl;
|
||||||
|
return WriteResult(WriteResult::FILE_NOT_HANDLED);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user