OpenSceneGraph 3.6.5
ExternalFileWriter
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGDB_PLUGIN_IMAGE_WRITER
15#define OSGDB_PLUGIN_IMAGE_WRITER 1
16
17#include <osgDB/Export>
18#include <string>
19#include <map>
20
21namespace osg
22{
23 class Object;
24}
25
26namespace osgDB
27{
28
29 class Options;
30
42 {
43 public:
49 ExternalFileWriter(const std::string & srcDirectory, const std::string & destDirectory, bool keepRelativePaths, unsigned int allowUpDirs=0);
50
52 ExternalFileWriter(const std::string & destDirectory);
53
60 bool write(const osg::Object & obj, const osgDB::Options * options, std::string * out_absolutePath=NULL, std::string * out_relativePath=NULL);
61
63 {
64 ObjectData() : written(false) {}
65 ObjectData(const std::string & in_absolutePath, const std::string & in_relativePath, bool in_written) : absolutePath(in_absolutePath), relativePath(in_relativePath), written(in_written) {}
66 std::string absolutePath;
67 std::string relativePath;
68 bool written;
69 };
70
73 typedef std::map<const osg::Object*, ObjectData> ObjectsSet;
74
76 const ObjectsSet & getObjects() const { return _objects; }
77
78 protected:
79 // Dev note:
80 // 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)).
81 // In order to get a correct search time, SearchMap "replaces" the multi-index structure for hashed indexes on absolute paths.
82 typedef std::multimap<unsigned int, const osg::Object*> SearchMap;
83 typedef unsigned int ObjectIndex;
87 const std::string _srcDirectory;
88 const std::string _destDirectory;
90 const unsigned int _allowUpDirs;
91
94 void generateObjectName(std::string & out_relativePath, std::string & out_absolutePath, int type);
95
96 bool absoluteObjectPathExists(const std::string & path);
97
98 private:
99 // Prevent copy
100 ExternalFileWriter & operator=(const ExternalFileWriter &);
102 };
103}
104
105#endif // OSGDB_PLUGIN_IMAGE_WRITER
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
The osgDB library provides support for reading and writing scene graphs, providing a plugin framework...
Definition Archive:24
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
void generateObjectName(std::string &out_relativePath, std::string &out_absolutePath, int type)
Generates a unique name for an object to be written on disk.
bool write(const osg::Object &obj, const osgDB::Options *options, std::string *out_absolutePath=NULL, std::string *out_relativePath=NULL)
Writes the current object if not already done.
bool _keepRelativePaths
Definition ExternalFileWriter:89
const ObjectsSet & getObjects() const
Returns the written objects.
Definition ExternalFileWriter:76
const std::string _srcDirectory
Definition ExternalFileWriter:87
unsigned int ObjectIndex
Integer type used for indices of unnamed objects.
Definition ExternalFileWriter:83
bool absoluteObjectPathExists(const std::string &path)
ObjectIndex _lastGeneratedObjectIndex
Definition ExternalFileWriter:86
ExternalFileWriter(const std::string &srcDirectory, const std::string &destDirectory, bool keepRelativePaths, unsigned int allowUpDirs=0)
Builds the helper class with all options.
std::multimap< unsigned int, const osg::Object * > SearchMap
Definition ExternalFileWriter:82
SearchMap _searchMap
Map used to search by absolute file path.
Definition ExternalFileWriter:85
const std::string _destDirectory
Definition ExternalFileWriter:88
ExternalFileWriter(const std::string &destDirectory)
Short constructor used when not relativising objects paths, or when having no initial model file (whi...
ObjectsSet _objects
Definition ExternalFileWriter:84
std::map< const osg::Object *, ObjectData > ObjectsSet
Set of written objects, with their absolute writing path.
Definition ExternalFileWriter:73
const unsigned int _allowUpDirs
Definition ExternalFileWriter:90
ObjectData()
Definition ExternalFileWriter:64
std::string absolutePath
Definition ExternalFileWriter:66
std::string relativePath
Definition ExternalFileWriter:67
ObjectData(const std::string &in_absolutePath, const std::string &in_relativePath, bool in_written)
Definition ExternalFileWriter:65
bool written
Says if write succeeded or not.
Definition ExternalFileWriter:68
Options base class used for passing options into plugins to control their operation.
Definition Options:30
#define NULL
Definition Export:55
#define OSGDB_EXPORT
Definition Export:39

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.