From 5b89e2eb174fe0d3149a223a45227589d92f5b68 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 11 May 2009 16:38:40 +0000 Subject: [PATCH] Moved ReadFile/WriteFile/FindFile/FileLocationCallbacks from include/osg/Options into their own Callbacks header/source file. --- include/osgDB/Callbacks | 110 ++++++++++++++++++++++++ include/osgDB/Options | 85 +------------------ src/osgDB/CMakeLists.txt | 2 + src/osgDB/Callbacks.cpp | 94 +++++++++++++++++++++ src/osgDB/Options.cpp | 82 ------------------ src/osgWrappers/osgDB/Options.cpp | 129 +---------------------------- src/osgWrappers/osgDB/Registry.cpp | 1 + 7 files changed, 209 insertions(+), 294 deletions(-) create mode 100644 include/osgDB/Callbacks create mode 100644 src/osgDB/Callbacks.cpp diff --git a/include/osgDB/Callbacks b/include/osgDB/Callbacks new file mode 100644 index 000000000..62d5983b8 --- /dev/null +++ b/include/osgDB/Callbacks @@ -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 +#include +#include + +#include +#include +#include + +namespace osgDB { + +/** list of directories to search through which searching for files. */ +typedef std::deque 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 diff --git a/include/osgDB/Options b/include/osgDB/Options index f22f1f050..febb7db72 100644 --- a/include/osgDB/Options +++ b/include/osgDB/Options @@ -14,9 +14,7 @@ #ifndef OSGDB_OPTIONS #define OSGDB_OPTIONS 1 -#include -#include -#include +#include #include #include @@ -24,87 +22,6 @@ namespace osgDB { -/** list of directories to search through which searching for files. */ -typedef std::deque 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 diff --git a/src/osgDB/CMakeLists.txt b/src/osgDB/CMakeLists.txt index 183040290..052d7baf0 100644 --- a/src/osgDB/CMakeLists.txt +++ b/src/osgDB/CMakeLists.txt @@ -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 diff --git a/src/osgDB/Callbacks.cpp b/src/osgDB/Callbacks.cpp new file mode 100644 index 000000000..f5f8600d9 --- /dev/null +++ b/src/osgDB/Callbacks.cpp @@ -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 +#include + +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); +} \ No newline at end of file diff --git a/src/osgDB/Options.cpp b/src/osgDB/Options.cpp index 279cedeaa..d7cbf9b17 100644 --- a/src/osgDB/Options.cpp +++ b/src/osgDB/Options.cpp @@ -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), diff --git a/src/osgWrappers/osgDB/Options.cpp b/src/osgWrappers/osgDB/Options.cpp index b6aacf848..51507c97c 100644 --- a/src/osgWrappers/osgDB/Options.cpp +++ b/src/osgWrappers/osgDB/Options.cpp @@ -11,15 +11,11 @@ #include #include -#include -#include #include -#include -#include #include +#include #include #include -#include // 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 >) - diff --git a/src/osgWrappers/osgDB/Registry.cpp b/src/osgWrappers/osgDB/Registry.cpp index 6f7598da4..8bceee329 100644 --- a/src/osgWrappers/osgDB/Registry.cpp +++ b/src/osgWrappers/osgDB/Registry.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include