osgDB::ExternalFileWriter Class Reference

`#include <ExternalFileWriter>`

## Classes

struct | ObjectData

## Public Types

typedef std::map< const osg::Object *, ObjectData > | ObjectsSet

## Public Member Functions

| ExternalFileWriter (const std::string &srcDirectory, const std::string &destDirectory, bool keepRelativePaths, unsigned int allowUpDirs=0)
| ExternalFileWriter (const std::string &destDirectory)
| Short constructor used when not relativising objects paths, or when having no initial model file (which is pretty the same here).
bool | write (const osg::Object &obj, const osgDB::Options *options, std::string *out_absolutePath=NULL, std::string *out_relativePath=NULL)
const ObjectsSet & | getObjects () const
| Returns the written objects.

## Protected Types

typedef std::multimap< unsigned int, const osg::Object * > | SearchMap
typedef unsigned int | ObjectIndex
| Integer type used for indices of unnamed objects.

## Protected Member Functions

void | generateObjectName (std::string &out_relativePath, std::string &out_absolutePath, int type)
bool | absoluteObjectPathExists (const std::string &path)

## Protected Attributes

ObjectsSet | _objects
SearchMap | _searchMap
| Map used to search by absolute file path.
ObjectIndex | _lastGeneratedObjectIndex
const std::string | _srcDirectory
const std::string | _destDirectory
bool | _keepRelativePaths
const unsigned int | _allowUpDirs

## Detailed Description

Helper allowing 'intelligent' writing of external files (images, shaders, etc.), regarding to a main file (a scene), especially in plugins. Goals are:

- Enable writing out objects only once (even if referenced multiple times)
- Handle duplicates (avoid writing two different objects at the same place, renaming files as needed)
- Handle directory creation when paths don't just exist
- Generate writing paths which may keep original directory structure (depending on user wishes). Ex: Reading: model.osg and images/img1.jpg Writing with 'keepRelativePaths': /somePath/newmodel.osg and /somePath/images/img1.jpg Writing without 'keepRelativePaths': /somePath/newmodel.osg and /somePath/img1.jpg
  Author
    Sukender

## Member Typedef Documentation

## ObjectIndex

typedef unsigned int osgDB::ExternalFileWriter::ObjectIndex

protected

Integer type used for indices of unnamed objects.

## ObjectsSet

typedef std::map<const osg::Object*, ObjectData> osgDB::ExternalFileWriter::ObjectsSet

Set of written objects, with their absolute writing path. Objects being passed to the write() method but which have failed to be effectively written are also included.

## SearchMap

typedef std::multimap<unsigned int, const osg::Object*> osgDB::ExternalFileWriter::SearchMap

protected

## Constructor & Destructor Documentation

## ExternalFileWriter() [1/2]

osgDB::ExternalFileWriter::ExternalFileWriter | ( | const std::string & | srcDirectory,
|  | const std::string & | destDirectory,
|  | bool | keepRelativePaths,
|  | unsigned int | allowUpDirs = 0 )

Builds the helper class with all options.

Parameters

  srcDirectory | Directory of the initial main file (if any), used as a base when relativising objects names. Not used if keepRelativePaths==false.
  destDirectory | Directory where to write the main file.
  keepRelativePaths | If true, then relative paths of source objects are kept if possible (ex: If an image is initially "imageDir/image.jpg" relatively to the source dir, then we'd like to get "destDir/imageDir/image.jpg"). If false, then only the simple file name is used to write the object file.

  allowUpDirs

  When relativising objects paths, sets the maximum number of directories the objects can be written "up" the destination directory. Not used if keepRelativePaths==false. Examples: If an image is initially "../image.jpg" relatively to the source dir AND if we allow one dir level up, then we'd like to get "destDirParent/destDir/../image.jpg" (= "destDirParent/image.jpg"). If we DO NOT allow one dir level up, then we'd like to get "destDir/image.jpg".

Referenced by absoluteObjectPathExists().

## ExternalFileWriter() [2/2]

osgDB::ExternalFileWriter::ExternalFileWriter | ( | const std::string & | destDirectory | ) |

Short constructor used when not relativising objects paths, or when having no initial model file (which is pretty the same here).

## Member Function Documentation

## absoluteObjectPathExists()

bool osgDB::ExternalFileWriter::absoluteObjectPathExists | ( | const std::string & | path | ) |

protected

References ExternalFileWriter().

## generateObjectName()

void osgDB::ExternalFileWriter::generateObjectName | ( | std::string & | out_relativePath,
|  | std::string & | out_absolutePath,
|  | int | type )

protected

Generates a unique name for an object to be written on disk. Side effect: updates _lastGeneratedObjectIndex to the index associated with the returned name.

## getObjects()

const ObjectsSet & osgDB::ExternalFileWriter::getObjects | ( |  | ) | const

inline

Returns the written objects.

References _objects.

## write()

bool osgDB::ExternalFileWriter::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.

Parameters

  | obj | Object to write, using corresponding osgDB::write method.
  | options | Writing options to pass to corresponding osgDB::write method.
  [out] | out_absolutePath | Pointer to a string to be filled with absolute writing path, or NULL.
  [out] | out_relativePath | Pointer to a string to be filled with write path relative to the destination directory if possible (absolute path if not), or NULL.

Returns
  true on success, false otherwise.

References NULL.

## Member Data Documentation

## _allowUpDirs

const unsigned int osgDB::ExternalFileWriter::_allowUpDirs

protected

## _destDirectory

const std::string osgDB::ExternalFileWriter::_destDirectory

protected

## _keepRelativePaths

bool osgDB::ExternalFileWriter::_keepRelativePaths

protected

## _lastGeneratedObjectIndex

ObjectIndex osgDB::ExternalFileWriter::_lastGeneratedObjectIndex

protected

## _objects

ObjectsSet osgDB::ExternalFileWriter::_objects

protected

Referenced by getObjects().

## _searchMap

SearchMap osgDB::ExternalFileWriter::_searchMap

protected

Map used to search by absolute file path.

## _srcDirectory

const std::string osgDB::ExternalFileWriter::_srcDirectory

protected

The documentation for this class was generated from the following file:

- ExternalFileWriter