Moved ReadFile/WriteFile/FindFile/FileLocationCallbacks from include/osg/Options into their own Callbacks header/source file.

This commit is contained in:
Robert Osfield 2009-05-11 16:38:40 +00:00
parent ee1f5da3b6
commit 5b89e2eb17
7 changed files with 209 additions and 294 deletions

110
include/osgDB/Callbacks Normal file
View File

@ -0,0 +1,110 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGDB_CALLBACKS
#define OSGDB_CALLBACKS 1
#include <osgDB/AuthenticationMap>
#include <osgDB/ReaderWriter>
#include <osgDB/FileCache>
#include <deque>
#include <list>
#include <iosfwd>
namespace osgDB {
/** list of directories to search through which searching for files. */
typedef std::deque<std::string> FilePathList;
enum CaseSensitivity
{
CASE_SENSITIVE,
CASE_INSENSITIVE
};
// forward decare
class Options;
class OSGDB_EXPORT FindFileCallback : public virtual osg::Referenced
{
public:
virtual std::string findDataFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity);
virtual std::string findLibraryFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity);
protected:
virtual ~FindFileCallback() {}
};
class OSGDB_EXPORT ReadFileCallback : public virtual osg::Referenced
{
public:
virtual ReaderWriter::ReadResult openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* useObjectCache);
virtual ReaderWriter::ReadResult readObject(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readImage(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readHeightField(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readNode(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readShader(const std::string& filename, const Options* options);
protected:
virtual ~ReadFileCallback() {}
};
class OSGDB_EXPORT WriteFileCallback : public virtual osg::Referenced
{
public:
virtual ReaderWriter::WriteResult writeObject(const osg::Object& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeImage(const osg::Image& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeHeightField(const osg::HeightField& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeNode(const osg::Node& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options);
protected:
virtual ~WriteFileCallback() {}
};
class OSGDB_EXPORT FileLocationCallback : public virtual osg::Referenced
{
public:
enum Location
{
LOCAL_FILE,
REMOTE_FILE
};
virtual Location fileLocation(const std::string& filename, const Options* options) = 0;
virtual bool useFileCache() const = 0;
protected:
virtual ~FileLocationCallback() {}
};
}
#endif // OSGDB_OPTIONS

View File

@ -14,9 +14,7 @@
#ifndef OSGDB_OPTIONS
#define OSGDB_OPTIONS 1
#include <osgDB/AuthenticationMap>
#include <osgDB/ReaderWriter>
#include <osgDB/FileCache>
#include <osgDB/Callbacks>
#include <deque>
#include <list>
@ -24,87 +22,6 @@
namespace osgDB {
/** list of directories to search through which searching for files. */
typedef std::deque<std::string> FilePathList;
enum CaseSensitivity
{
CASE_SENSITIVE,
CASE_INSENSITIVE
};
// forward decare
class Options;
class OSGDB_EXPORT FindFileCallback : public virtual osg::Referenced
{
public:
virtual std::string findDataFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity);
virtual std::string findLibraryFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity);
protected:
virtual ~FindFileCallback() {}
};
class OSGDB_EXPORT ReadFileCallback : public virtual osg::Referenced
{
public:
virtual ReaderWriter::ReadResult openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* useObjectCache);
virtual ReaderWriter::ReadResult readObject(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readImage(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readHeightField(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readNode(const std::string& filename, const Options* options);
virtual ReaderWriter::ReadResult readShader(const std::string& filename, const Options* options);
protected:
virtual ~ReadFileCallback() {}
};
class OSGDB_EXPORT WriteFileCallback : public virtual osg::Referenced
{
public:
virtual ReaderWriter::WriteResult writeObject(const osg::Object& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeImage(const osg::Image& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeHeightField(const osg::HeightField& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeNode(const osg::Node& obj, const std::string& fileName,const Options* options);
virtual ReaderWriter::WriteResult writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options);
protected:
virtual ~WriteFileCallback() {}
};
class OSGDB_EXPORT FileLocationCallback : public virtual osg::Referenced
{
public:
enum Location
{
LOCAL_FILE,
REMOTE_FILE
};
virtual Location fileLocation(const std::string& filename, const Options* options) = 0;
virtual bool useFileCache() const = 0;
protected:
virtual ~FileLocationCallback() {}
};
/** Options base class used for passing options into plugins to control their operation.*/
class OSGDB_EXPORT Options : public osg::Object

View File

@ -21,6 +21,7 @@ SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/Archive
${HEADER_PATH}/AuthenticationMap
${HEADER_PATH}/Callbacks
${HEADER_PATH}/ConvertUTF
${HEADER_PATH}/DatabasePager
${HEADER_PATH}/DotOsgWrapper
@ -56,6 +57,7 @@ ADD_LIBRARY(${LIB_NAME}
${LIB_PUBLIC_HEADERS}
Archive.cpp
AuthenticationMap.cpp
Callbacks.cpp
ConvertUTF.cpp
DatabasePager.cpp
DotOsgWrapper.cpp

94
src/osgDB/Callbacks.cpp Normal file
View File

@ -0,0 +1,94 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osgDB/Callbacks>
#include <osgDB/Registry>
using namespace osgDB;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// FindFileCallback default implementation
//
std::string FindFileCallback::findDataFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity)
{
return osgDB::Registry::instance()->findDataFileImplementation(filename, options, caseSensitivity);
}
std::string FindFileCallback::findLibraryFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity)
{
return osgDB::Registry::instance()->findLibraryFileImplementation(filename, options, caseSensitivity);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ReadFileCallback default implementation
//
ReaderWriter::ReadResult ReadFileCallback::openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* useObjectCache)
{
return osgDB::Registry::instance()->openArchiveImplementation(filename, status, indexBlockSizeHint, useObjectCache);
}
ReaderWriter::ReadResult ReadFileCallback::readObject(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readObjectImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readImage(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readImageImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readHeightField(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readHeightFieldImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readNode(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readNodeImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readShader(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readShaderImplementation(filename,options);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// WriteFileCallback default implementation
//
ReaderWriter::WriteResult WriteFileCallback::writeObject(const osg::Object& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeObjectImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeImage(const osg::Image& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeImageImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeHeightField(const osg::HeightField& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeHeightFieldImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeNode(const osg::Node& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeNodeImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeShaderImplementation(obj,fileName,options);
}

View File

@ -16,88 +16,6 @@
using namespace osgDB;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// FindFileCallback default implementation
//
std::string FindFileCallback::findDataFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity)
{
return osgDB::Registry::instance()->findDataFileImplementation(filename, options, caseSensitivity);
}
std::string FindFileCallback::findLibraryFile(const std::string& filename, const Options* options, CaseSensitivity caseSensitivity)
{
return osgDB::Registry::instance()->findLibraryFileImplementation(filename, options, caseSensitivity);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ReadFileCallback default implementation
//
ReaderWriter::ReadResult ReadFileCallback::openArchive(const std::string& filename,ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const Options* useObjectCache)
{
return osgDB::Registry::instance()->openArchiveImplementation(filename, status, indexBlockSizeHint, useObjectCache);
}
ReaderWriter::ReadResult ReadFileCallback::readObject(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readObjectImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readImage(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readImageImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readHeightField(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readHeightFieldImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readNode(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readNodeImplementation(filename,options);
}
ReaderWriter::ReadResult ReadFileCallback::readShader(const std::string& filename, const Options* options)
{
return osgDB::Registry::instance()->readShaderImplementation(filename,options);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// WriteFileCallback default implementation
//
ReaderWriter::WriteResult WriteFileCallback::writeObject(const osg::Object& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeObjectImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeImage(const osg::Image& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeImageImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeHeightField(const osg::HeightField& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeHeightFieldImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeNode(const osg::Node& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeNodeImplementation(obj,fileName,options);
}
ReaderWriter::WriteResult WriteFileCallback::writeShader(const osg::Shader& obj, const std::string& fileName,const Options* options)
{
return osgDB::Registry::instance()->writeShaderImplementation(obj,fileName,options);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Options constructor
//
Options::Options(const Options& options,const osg::CopyOp& copyop):
osg::Object(options,copyop),
_str(options._str),

View File

@ -11,15 +11,11 @@
#include <osgIntrospection/Attributes>
#include <osg/CopyOp>
#include <osg/Image>
#include <osg/Node>
#include <osg/Object>
#include <osg/Shader>
#include <osg/Shape>
#include <osgDB/AuthenticationMap>
#include <osgDB/Callbacks>
#include <osgDB/FileCache>
#include <osgDB/Options>
#include <osgDB/ReaderWriter>
// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
@ -29,48 +25,6 @@
#undef OUT
#endif
BEGIN_ENUM_REFLECTOR(osgDB::FileLocationCallback::Location)
I_DeclaringFile("osgDB/Options");
I_EnumLabel(osgDB::FileLocationCallback::LOCAL_FILE);
I_EnumLabel(osgDB::FileLocationCallback::REMOTE_FILE);
END_REFLECTOR
BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgDB::FileLocationCallback)
I_DeclaringFile("osgDB/Options");
I_VirtualBaseType(osg::Referenced);
I_Constructor0(____FileLocationCallback,
"",
"");
I_Method2(osgDB::FileLocationCallback::Location, fileLocation, IN, const std::string &, filename, IN, const osgDB::Options *, options,
Properties::PURE_VIRTUAL,
__Location__fileLocation__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method0(bool, useFileCache,
Properties::PURE_VIRTUAL,
__bool__useFileCache,
"",
"");
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgDB::FindFileCallback)
I_DeclaringFile("osgDB/Options");
I_VirtualBaseType(osg::Referenced);
I_Constructor0(____FindFileCallback,
"",
"");
I_Method3(std::string, findDataFile, IN, const std::string &, filename, IN, const osgDB::Options *, options, IN, osgDB::CaseSensitivity, caseSensitivity,
Properties::VIRTUAL,
__std_string__findDataFile__C5_std_string_R1__C5_Options_P1__CaseSensitivity,
"",
"");
I_Method3(std::string, findLibraryFile, IN, const std::string &, filename, IN, const osgDB::Options *, options, IN, osgDB::CaseSensitivity, caseSensitivity,
Properties::VIRTUAL,
__std_string__findLibraryFile__C5_std_string_R1__C5_Options_P1__CaseSensitivity,
"",
"");
END_REFLECTOR
BEGIN_ENUM_REFLECTOR(osgDB::Options::CacheHintOptions)
I_DeclaringFile("osgDB/Options");
I_EnumLabel(osgDB::Options::CACHE_NONE);
@ -318,84 +272,3 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Options)
__void__setWriteFileCallback__WriteFileCallback_P1);
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgDB::ReadFileCallback)
I_DeclaringFile("osgDB/Options");
I_VirtualBaseType(osg::Referenced);
I_Constructor0(____ReadFileCallback,
"",
"");
I_Method4(osgDB::ReaderWriter::ReadResult, openArchive, IN, const std::string &, filename, IN, osgDB::ReaderWriter::ArchiveStatus, status, IN, unsigned int, indexBlockSizeHint, IN, const osgDB::Options *, useObjectCache,
Properties::VIRTUAL,
__ReaderWriter_ReadResult__openArchive__C5_std_string_R1__ReaderWriter_ArchiveStatus__unsigned_int__C5_Options_P1,
"",
"");
I_Method2(osgDB::ReaderWriter::ReadResult, readObject, IN, const std::string &, filename, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_ReadResult__readObject__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method2(osgDB::ReaderWriter::ReadResult, readImage, IN, const std::string &, filename, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_ReadResult__readImage__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method2(osgDB::ReaderWriter::ReadResult, readHeightField, IN, const std::string &, filename, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_ReadResult__readHeightField__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method2(osgDB::ReaderWriter::ReadResult, readNode, IN, const std::string &, filename, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_ReadResult__readNode__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method2(osgDB::ReaderWriter::ReadResult, readShader, IN, const std::string &, filename, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_ReadResult__readShader__C5_std_string_R1__C5_Options_P1,
"",
"");
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgDB::WriteFileCallback)
I_DeclaringFile("osgDB/Options");
I_VirtualBaseType(osg::Referenced);
I_Constructor0(____WriteFileCallback,
"",
"");
I_Method3(osgDB::ReaderWriter::WriteResult, writeObject, IN, const osg::Object &, obj, IN, const std::string &, fileName, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_WriteResult__writeObject__C5_osg_Object_R1__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method3(osgDB::ReaderWriter::WriteResult, writeImage, IN, const osg::Image &, obj, IN, const std::string &, fileName, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_WriteResult__writeImage__C5_osg_Image_R1__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method3(osgDB::ReaderWriter::WriteResult, writeHeightField, IN, const osg::HeightField &, obj, IN, const std::string &, fileName, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_WriteResult__writeHeightField__C5_osg_HeightField_R1__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method3(osgDB::ReaderWriter::WriteResult, writeNode, IN, const osg::Node &, obj, IN, const std::string &, fileName, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_WriteResult__writeNode__C5_osg_Node_R1__C5_std_string_R1__C5_Options_P1,
"",
"");
I_Method3(osgDB::ReaderWriter::WriteResult, writeShader, IN, const osg::Shader &, obj, IN, const std::string &, fileName, IN, const osgDB::Options *, options,
Properties::VIRTUAL,
__ReaderWriter_WriteResult__writeShader__C5_osg_Shader_R1__C5_std_string_R1__C5_Options_P1,
"",
"");
END_REFLECTOR
BEGIN_ENUM_REFLECTOR(osgDB::CaseSensitivity)
I_DeclaringFile("osgDB/Options");
I_EnumLabel(osgDB::CASE_SENSITIVE);
I_EnumLabel(osgDB::CASE_INSENSITIVE);
END_REFLECTOR
TYPE_NAME_ALIAS(std::deque< std::string >, osgDB::FilePathList)
STD_VECTOR_REFLECTOR(std::deque< std::string >)

View File

@ -23,6 +23,7 @@
#include <osg/Uniform>
#include <osgDB/Archive>
#include <osgDB/AuthenticationMap>
#include <osgDB/Callbacks>
#include <osgDB/DotOsgWrapper>
#include <osgDB/DynamicLibrary>
#include <osgDB/FileCache>