Added support for openArchive into osgDB
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#define OSGDB_ARCHIVE 1
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
@@ -23,8 +24,6 @@ namespace osgDB {
|
||||
|
||||
|
||||
/** Base class for implementing database Archives. */
|
||||
|
||||
|
||||
class OSGDB_EXPORT Archive : public ReaderWriter
|
||||
{
|
||||
public:
|
||||
@@ -37,15 +36,8 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
||||
|
||||
virtual bool acceptsExtension(const std::string& /*extension*/) { return true; }
|
||||
|
||||
enum Status
|
||||
{
|
||||
READ,
|
||||
WRITE,
|
||||
CREATE
|
||||
};
|
||||
|
||||
/** open the archive.*/
|
||||
virtual bool open(const std::string& filename, Status status, unsigned int indexBlockSizeHint=4096);
|
||||
virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096);
|
||||
|
||||
/** close the archive.*/
|
||||
virtual void close();
|
||||
@@ -98,9 +90,9 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
||||
|
||||
void write(std::ostream& out);
|
||||
|
||||
inline bool spaceAvailable(pos_type position, size_type size, const std::string& filename) const
|
||||
inline bool spaceAvailable(pos_type, size_type, const std::string& filename) const
|
||||
{
|
||||
unsigned requiredSize = sizeof(position)+sizeof(unsigned int)+filename.size();
|
||||
unsigned requiredSize = sizeof(pos_type)+sizeof(unsigned int)+filename.size();
|
||||
return (_offsetOfNextAvailableSpace + requiredSize)<_blockSize;
|
||||
}
|
||||
|
||||
@@ -132,7 +124,7 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
||||
|
||||
static float s_currentSupportedVersion;
|
||||
float _version;
|
||||
Status _status;
|
||||
ArchiveStatus _status;
|
||||
std::ifstream _input;
|
||||
std::fstream _output;
|
||||
|
||||
@@ -142,6 +134,12 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
||||
|
||||
};
|
||||
|
||||
/** Open an archive for reading or writing.*/
|
||||
Archive* openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint=4096);
|
||||
|
||||
/** Open an archive for reading or writing.*/
|
||||
osgDB::Archive* osgDB::openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint,Registry::CacheHintOptions useObjectCache);
|
||||
|
||||
}
|
||||
|
||||
#endif // OSGDB_ARCHIVE
|
||||
|
||||
@@ -21,18 +21,23 @@
|
||||
|
||||
#include <osgDB/Export>
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osgDB {
|
||||
|
||||
class Archive;
|
||||
|
||||
/** pure virtual base class for reading and writing of non native formats. */
|
||||
class OSGDB_EXPORT ReaderWriter : public osg::Referenced
|
||||
class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
{
|
||||
public:
|
||||
virtual ~ReaderWriter(); // {}
|
||||
virtual const char* className() const = 0;
|
||||
|
||||
|
||||
ReaderWriter() {}
|
||||
ReaderWriter(const ReaderWriter& rw,const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):Object(rw,copyop) {}
|
||||
|
||||
virtual ~ReaderWriter();
|
||||
|
||||
META_Object(osgDB,ReaderWriter);
|
||||
|
||||
virtual bool acceptsExtension(const std::string& /*extension*/) { return false; }
|
||||
|
||||
/** Options base class used for passing options into plugins to control their operation.*/
|
||||
@@ -85,20 +90,23 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
|
||||
ReadResult(const ReadResult& rr):_status(rr._status),_message(rr._message),_object(rr._object) {}
|
||||
ReadResult& operator = (const ReadResult& rr) { if (this==&rr) return *this; _status=rr._status; _message=rr._message;_object=rr._object; return *this; }
|
||||
|
||||
osg::Object* getObject() { return _object.get(); }
|
||||
osg::Image* getImage() { return dynamic_cast<osg::Image*>(_object.get()); }
|
||||
osg::HeightField* getHeightField() { return dynamic_cast<osg::HeightField*>(_object.get()); }
|
||||
osg::Node* getNode() { return dynamic_cast<osg::Node*>(_object.get()); }
|
||||
osg::Object* getObject();
|
||||
osg::Image* getImage();
|
||||
osg::HeightField* getHeightField();
|
||||
osg::Node* getNode();
|
||||
osgDB::Archive* getArchive();
|
||||
|
||||
bool validObject() { return _object.valid(); }
|
||||
bool validImage() { return getImage()!=0; }
|
||||
bool validHeightField() { return getHeightField()!=0; }
|
||||
bool validNode() { return getNode()!=0; }
|
||||
bool validArchive() { return getArchive()!=0; }
|
||||
|
||||
osg::Object* takeObject() { osg::Object* obj = _object.get(); if (obj) { obj->ref(); _object=NULL; obj->unref_nodelete(); } return obj; }
|
||||
osg::Image* takeImage() { osg::Image* image=dynamic_cast<osg::Image*>(_object.get()); if (image) { image->ref(); _object=NULL; image->unref_nodelete(); } return image; }
|
||||
osg::HeightField* takeHeightField() { osg::HeightField* hf=dynamic_cast<osg::HeightField*>(_object.get()); if (hf) { hf->ref(); _object=NULL; hf->unref_nodelete(); } return hf; }
|
||||
osg::Node* takeNode() { osg::Node* node=dynamic_cast<osg::Node*>(_object.get()); if (node) { node->ref(); _object=NULL; node->unref_nodelete(); } return node; }
|
||||
osg::Object* takeObject();
|
||||
osg::Image* takeImage();
|
||||
osg::HeightField* takeHeightField();
|
||||
osg::Node* takeNode();
|
||||
osgDB::Archive* takeArchive();
|
||||
|
||||
const std::string& message() const { return _message; }
|
||||
|
||||
@@ -146,6 +154,15 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
|
||||
std::string _message;
|
||||
};
|
||||
|
||||
enum ArchiveStatus
|
||||
{
|
||||
READ,
|
||||
WRITE,
|
||||
CREATE
|
||||
};
|
||||
|
||||
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
|
||||
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||
|
||||
@@ -81,14 +81,18 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
|
||||
/// cache heightfield loaded via readHeightField(filename)
|
||||
CACHE_HEIGHTFIELDS = 4,
|
||||
|
||||
/// cache heightfield loaded via readHeightField(filename)
|
||||
CACHE_ARCHIVES = 8,
|
||||
|
||||
/// cache objects loaded via readObject(filename)
|
||||
CACHE_OBJECTS = 8,
|
||||
CACHE_OBJECTS = 16,
|
||||
|
||||
/// cache on all read*(filename) calls
|
||||
CACHE_ALL = CACHE_NODES |
|
||||
CACHE_IMAGES |
|
||||
CACHE_HEIGHTFIELDS |
|
||||
CACHE_ARCHIVES |
|
||||
CACHE_OBJECTS
|
||||
};
|
||||
|
||||
@@ -147,6 +151,11 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ReaderWriter::ReadResult openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, CacheHintOptions useObjectCache)
|
||||
{
|
||||
return osgDB::Registry::instance()->openArchiveImplementation(filename, status, indexBlockSizeHint, useObjectCache);
|
||||
}
|
||||
|
||||
virtual ReaderWriter::ReadResult readObject(const std::string& filename, CacheHintOptions options)
|
||||
{
|
||||
return osgDB::Registry::instance()->readObjectImplementation(filename,options);
|
||||
@@ -181,6 +190,13 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
const ReadFileCallback* getReadFileCallback() const { return _readFileCallback.get(); }
|
||||
|
||||
|
||||
ReaderWriter::ReadResult openArchive(const std::string& fileName,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, CacheHintOptions useObjectCache)
|
||||
{
|
||||
if (_readFileCallback.valid()) return _readFileCallback->openArchive(fileName, status, indexBlockSizeHint, useObjectCache);
|
||||
else return openArchiveImplementation(fileName, status, indexBlockSizeHint, useObjectCache);
|
||||
}
|
||||
ReaderWriter::ReadResult openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, CacheHintOptions useObjectCache);
|
||||
|
||||
ReaderWriter::ReadResult readObject(const std::string& fileName,CacheHintOptions useObjectCache)
|
||||
{
|
||||
if (_readFileCallback.valid()) return _readFileCallback->readObject(fileName,useObjectCache);
|
||||
@@ -210,6 +226,11 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
ReaderWriter::ReadResult readNodeImplementation(const std::string& fileName,CacheHintOptions useObjectCache);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class WriteFileCallback : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
@@ -277,6 +298,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
ReaderWriter::WriteResult writeNodeImplementation(const osg::Node& node, const std::string& fileName);
|
||||
|
||||
|
||||
|
||||
void setCreateNodeFromImage(bool flag) { _createNodeFromImage = flag; }
|
||||
bool getCreateNodeFromImage() const { return _createNodeFromImage; }
|
||||
|
||||
@@ -401,6 +423,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
|
||||
void eraseWrapper(DotOsgWrapperMap& wrappermap,DotOsgWrapper* wrapper);
|
||||
|
||||
ReaderWriter::ReadResult openArchive(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint);
|
||||
ReaderWriter::ReadResult readObject(const std::string& fileName);
|
||||
ReaderWriter::ReadResult readImage(const std::string& fileName);
|
||||
ReaderWriter::ReadResult readHeightField(const std::string& fileName);
|
||||
|
||||
Reference in New Issue
Block a user