OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExternalFileWriter.h
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 
21 namespace osg
22 {
23  class Object;
24 }
25 
26 namespace osgDB
27 {
28 
29  class Options;
30 
43  {
44  public:
50  ExternalFileWriter(const std::string & srcDirectory, const std::string & destDirectory, bool keepRelativePaths, unsigned int allowUpDirs=0);
51 
53  ExternalFileWriter(const std::string & destDirectory);
54 
61  bool write(const osg::Object & obj, const osgDB::Options * options, std::string * out_absolutePath=NULL, std::string * out_relativePath=NULL);
62 
63  struct ObjectData
64  {
65  ObjectData() : written(false) {}
66  ObjectData(const std::string & absolutePath, const std::string & relativePath, bool written) : absolutePath(absolutePath), relativePath(relativePath), written(written) {}
67  std::string absolutePath;
68  std::string relativePath;
69  bool written;
70  };
71 
74  typedef std::map<const osg::Object*, ObjectData> ObjectsSet;
75 
77  const ObjectsSet & getObjects() const { return _objects; }
78 
79  protected:
80  // Dev note:
81  // 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)).
82  // In order to get a correct search time, SearchMap "replaces" the multi-index structure for hashed indexes on absolute paths.
83  typedef std::multimap<unsigned int, const osg::Object*> SearchMap;
84  typedef unsigned int ObjectIndex;
85  ObjectsSet _objects;
86  SearchMap _searchMap;
88  const std::string _srcDirectory;
89  const std::string _destDirectory;
91  const unsigned int _allowUpDirs;
92 
95  void generateObjectName(std::string & out_relativePath, std::string & out_absolutePath, int type);
96 
97  bool absoluteObjectPathExists(const std::string & path);
98 
99  private:
100  // Prevent copy
101  ExternalFileWriter & operator=(const ExternalFileWriter &);
103  };
104 }
105 
106 #endif // OSGDB_PLUGIN_IMAGE_WRITER
#define NULL
Definition: Export.h:59
const unsigned int _allowUpDirs
const std::string _srcDirectory
const std::string _destDirectory
ObjectData(const std::string &absolutePath, const std::string &relativePath, bool written)
const ObjectsSet & getObjects() const
Returns the written objects.
Definition: Archive.h:24
bool written
Says if write succeeded or not.
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: GLU.h:71
#define OSGDB_EXPORT
Definition: Export.h:39
unsigned int ObjectIndex
Integer type used for indices of unnamed objects.
Definition: AlphaFunc.h:19
std::map< const osg::Object *, ObjectData > ObjectsSet
std::multimap< unsigned int, const osg::Object * > SearchMap
SearchMap _searchMap
Map used to search by absolute file path.