ExternalFileWriter
Go to the documentation of this file.
/* -*-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_PLUGIN_IMAGE_WRITER
#define OSGDB_PLUGIN_IMAGE_WRITER 1
#include <osgDB/Export>
#include <string>
#include <map>
namespace osg
{
class Object;
}
namespace osgDB
{
class Options;
class OSGDB_EXPORT ExternalFileWriter
{
public:
ExternalFileWriter(const std::string & srcDirectory, const std::string & destDirectory, bool keepRelativePaths, unsigned int allowUpDirs=0);
ExternalFileWriter(const std::string & destDirectory);
bool write(const osg::Object & obj, const osgDB::Options * options, std::string * out_absolutePath=NULL, std::string * out_relativePath=NULL);
struct ObjectData
{
ObjectData() : written(false) {}
ObjectData(const std::string & in_absolutePath, const std::string & in_relativePath, bool in_written) : absolutePath(in_absolutePath), relativePath(in_relativePath), written(in_written) {}
std::string absolutePath;
std::string relativePath;
bool written;
};
typedef std::map<const osg::Object*, ObjectData> ObjectsSet;
const ObjectsSet & getObjects() const { return _objects; }
protected:
// Dev note:
// A multi-indexed structure would be more efficient for ObjectsSet (such as boost::multi_index, indexed on object pointer (unique), and hashed indexed on absolute path (unique)).
// In order to get a correct search time, SearchMap "replaces" the multi-index structure for hashed indexes on absolute paths.
typedef std::multimap<unsigned int, const osg::Object*> SearchMap;
typedef unsigned int ObjectIndex;
ObjectsSet _objects;
SearchMap _searchMap;
ObjectIndex _lastGeneratedObjectIndex;
const std::string _srcDirectory;
const std::string _destDirectory;
bool _keepRelativePaths;
const unsigned int _allowUpDirs;
void generateObjectName(std::string & out_relativePath, std::string & out_absolutePath, int type);
bool absoluteObjectPathExists(const std::string & path);
private:
// Prevent copy
ExternalFileWriter & operator=(const ExternalFileWriter &);
ExternalFileWriter(const ExternalFileWriter &);
};
}
#endif // OSGDB_PLUGIN_IMAGE_WRITER
osgDB::ExternalFileWriter::generateObjectName
void generateObjectName(std::string &out_relativePath, std::string &out_absolutePath, int type)
osgDB::ExternalFileWriter::write
bool write(const osg::Object &obj, const osgDB::Options *options, std::string *out_absolutePath=NULL, std::string *out_relativePath=NULL)
osgDB::ExternalFileWriter::_keepRelativePaths
bool _keepRelativePaths
Definition ExternalFileWriter:89
osgDB::ExternalFileWriter::getObjects
const ObjectsSet & getObjects() const
Returns the written objects.
Definition ExternalFileWriter:76
osgDB::ExternalFileWriter::_srcDirectory
const std::string _srcDirectory
Definition ExternalFileWriter:87
osgDB::ExternalFileWriter::ObjectIndex
unsigned int ObjectIndex
Integer type used for indices of unnamed objects.
Definition ExternalFileWriter:83
osgDB::ExternalFileWriter::absoluteObjectPathExists
bool absoluteObjectPathExists(const std::string &path)
osgDB::ExternalFileWriter::_lastGeneratedObjectIndex
ObjectIndex _lastGeneratedObjectIndex
Definition ExternalFileWriter:86
osgDB::ExternalFileWriter::ExternalFileWriter
ExternalFileWriter(const std::string &srcDirectory, const std::string &destDirectory, bool keepRelativePaths, unsigned int allowUpDirs=0)
osgDB::ExternalFileWriter::SearchMap
std::multimap< unsigned int, const osg::Object * > SearchMap
Definition ExternalFileWriter:82
osgDB::ExternalFileWriter::_searchMap
SearchMap _searchMap
Map used to search by absolute file path.
Definition ExternalFileWriter:85
osgDB::ExternalFileWriter::_destDirectory
const std::string _destDirectory
Definition ExternalFileWriter:88
osgDB::ExternalFileWriter::ExternalFileWriter
ExternalFileWriter(const std::string &destDirectory)
Short constructor used when not relativising objects paths, or when having no initial model file (whi...
osgDB::ExternalFileWriter::_objects
ObjectsSet _objects
Definition ExternalFileWriter:84
osgDB::ExternalFileWriter::ObjectsSet
std::map< const osg::Object *, ObjectData > ObjectsSet
Definition ExternalFileWriter:73
osgDB::ExternalFileWriter::_allowUpDirs
const unsigned int _allowUpDirs
Definition ExternalFileWriter:90
osgDB::Options
Definition Options:30
osg::Object
Definition Object:61
osgDB
Definition Archive:24
osg
Definition AlphaFunc:19
Export
OSGDB_EXPORT
#define OSGDB_EXPORT
Definition osgDB/Export:39
NULL
#define NULL
Definition osg/Export:55
osgDB::ExternalFileWriter::ObjectData::ObjectData
ObjectData()
Definition ExternalFileWriter:64
osgDB::ExternalFileWriter::ObjectData::absolutePath
std::string absolutePath
Definition ExternalFileWriter:66
osgDB::ExternalFileWriter::ObjectData::relativePath
std::string relativePath
Definition ExternalFileWriter:67
osgDB::ExternalFileWriter::ObjectData::ObjectData
ObjectData(const std::string &in_absolutePath, const std::string &in_relativePath, bool in_written)
Definition ExternalFileWriter:65
osgDB::ExternalFileWriter::ObjectData::written
bool written
Says if write succeeded or not.
Definition ExternalFileWriter:68