All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SdfFileFormat Class Referenceabstract

Base class for file format implementations. More...

+ Inheritance diagram for SdfFileFormat:

Public Types

typedef std::map< std::string,
std::string > 
FileFormatArguments
 Type for specifying additional file format-specific arguments to the various API below. More...
 
- Public Types inherited from TfRefBase
typedef void(* UniqueChangedFuncPtr )(TfRefBase const *, bool)
 

Public Member Functions

SDF_API const SdfSchemaBaseGetSchema () const
 Returns the schema for this format. More...
 
SDF_API const TfTokenGetFormatId () const
 Returns the format identifier. More...
 
SDF_API const TfTokenGetTarget () const
 Returns the target for this file format. More...
 
SDF_API const std::string & GetFileCookie () const
 Returns the cookie to be used when writing files with this format. More...
 
SDF_API const TfTokenGetVersionString () const
 Returns the current version of this file format. More...
 
SDF_API bool IsPrimaryFormatForExtensions () const
 Returns true if this file format is the primary format for the extensions it handles. More...
 
SDF_API const std::vector
< std::string > & 
GetFileExtensions () const
 Returns a list of extensions that this format supports. More...
 
SDF_API const std::string & GetPrimaryFileExtension () const
 Returns the primary file extension for this format. More...
 
SDF_API bool IsSupportedExtension (const std::string &extension) const
 Returns true if extension matches one of the extensions returned by GetFileExtensions. More...
 
virtual SDF_API bool IsPackage () const
 Returns true if this file format is a package containing other assets. More...
 
virtual SDF_API std::string GetPackageRootLayerPath (const std::string &resolvedPath) const
 Returns the path of the "root" layer contained in the package layer at resolvedPath produced by this file format. More...
 
virtual SDF_API FileFormatArguments GetDefaultFileFormatArguments () const
 Returns the FileFormatArguments that correspond to the default behavior of this file format when no FileFormatArguments are passed to NewLayer or InitData. More...
 
virtual SDF_API
SdfAbstractDataRefPtr 
InitData (const FileFormatArguments &args) const
 This method allows the file format to bind to whatever data container is appropriate. More...
 
SDF_API SdfLayerRefPtr NewLayer (const SdfFileFormatConstPtr &fileFormat, const std::string &identifier, const std::string &realPath, const ArAssetInfo &assetInfo, const FileFormatArguments &args) const
 Instantiate a layer. More...
 
SDF_API bool ShouldSkipAnonymousReload () const
 Return true if this file format prefers to skip reloading anonymous layers. More...
 
SDF_API bool LayersAreFileBased () const
 Return true if layers produced by this file format are based on physical files on disk. More...
 
virtual SDF_API bool CanRead (const std::string &file) const =0
 Returns true if file can be read by this format. More...
 
virtual SDF_API bool Read (SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const =0
 Reads scene description from the asset specified by resolvedPath into the layer layer. More...
 
virtual SDF_API bool WriteToFile (const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const
 Writes the content in layer into the file at filePath. More...
 
virtual SDF_API bool ReadFromString (SdfLayer *layer, const std::string &str) const
 Reads data in the string str into the layer layer. More...
 
virtual SDF_API bool WriteToStream (const SdfSpecHandle &spec, std::ostream &out, size_t indent) const
 Write the provided spec to out indented indent levels. More...
 
virtual SDF_API bool WriteToString (const SdfLayer &layer, std::string *str, const std::string &comment=std::string()) const
 Writes the content in layer to the string str. More...
 
- Public Member Functions inherited from TfRefBase
size_t GetCurrentCount () const
 Return the current reference count of this object. More...
 
bool IsUnique () const
 Return true if only one TfRefPtr points to this object. More...
 
const TfRefCountGetRefCount () const
 
void SetShouldInvokeUniqueChangedListener (bool shouldCall)
 
- Public Member Functions inherited from TfWeakBase
 TfWeakBase (const TfWeakBase &)
 
const TfWeakBase__GetTfWeakBase__ () const
 
const TfWeakBaseoperator= (const TfWeakBase &)
 
void EnableNotification2 () const
 
TF_API void const * GetUniqueIdentifier () const
 

Static Public Member Functions

static SDF_API std::string GetFileExtension (const std::string &s)
 Returns the file extension for path or file name s, without the leading dot character. More...
 
static SDF_API std::set
< std::string > 
FindAllFileFormatExtensions ()
 Returns a set containing the extension(s) corresponding to all registered file formats. More...
 
static SDF_API
SdfFileFormatConstPtr 
FindById (const TfToken &formatId)
 Returns the file format instance with the specified formatId identifier. More...
 
static SDF_API
SdfFileFormatConstPtr 
FindByExtension (const std::string &extension, const std::string &target=std::string())
 Returns the file format instance that supports the specified file extension. More...
 
- Static Public Member Functions inherited from TfRefBase
static TF_API void SetUniqueChangedListener (UniqueChangedListener listener)
 

Protected Member Functions

SDF_API SdfFileFormat (const TfToken &formatId, const TfToken &versionString, const TfToken &target, const std::string &extension)
 Constructor. More...
 
SDF_API SdfFileFormat (const TfToken &formatId, const TfToken &versionString, const TfToken &target, const std::string &extension, const SdfSchemaBase &schema)
 Constructor. More...
 
SDF_API SdfFileFormat (const TfToken &formatId, const TfToken &versionString, const TfToken &target, const std::string &extension, const SdfSchemaBase &&schema)=delete
 Disallow temporary SdfSchemaBase objects being passed to the c'tor. More...
 
SDF_API SdfFileFormat (const TfToken &formatId, const TfToken &versionString, const TfToken &target, const std::vector< std::string > &extensions)
 Constructor. More...
 
SDF_API SdfFileFormat (const TfToken &formatId, const TfToken &versionString, const TfToken &target, const std::vector< std::string > &extensions, const SdfSchemaBase &schema)
 Constructor. More...
 
SDF_API SdfFileFormat (const TfToken &formatId, const TfToken &versionString, const TfToken &target, const std::vector< std::string > &extensions, const SdfSchemaBase &&schema)=delete
 Disallow temporary SdfSchemaBase objects being passed to the c'tor. More...
 
virtual SDF_API ~SdfFileFormat ()
 Destructor. More...
 
- Protected Member Functions inherited from TfWeakBase
TfRefPtr< Tf_Remnant > _Register () const
 
template<class T >
TfRefPtr< Tf_Remnant > _Register (T *tempRmnt) const
 
bool _HasRemnant () const
 

Static Protected Member Functions

static SDF_API void _SetLayerData (SdfLayer *layer, SdfAbstractDataRefPtr &data)
 Set the internal data for layer to data, possibly transferring ownership of data. More...
 
static SDF_API
SdfAbstractDataConstPtr 
_GetLayerData (const SdfLayer &layer)
 Get the internal data for layer. More...
 

Detailed Description

Base class for file format implementations.

Definition at line 63 of file fileFormat.h.

Member Typedef Documentation

typedef std::map<std::string, std::string> FileFormatArguments

Type for specifying additional file format-specific arguments to the various API below.

Definition at line 113 of file fileFormat.h.

Constructor & Destructor Documentation

SDF_API SdfFileFormat ( const TfToken formatId,
const TfToken versionString,
const TfToken target,
const std::string &  extension 
)
protected

Constructor.

SDF_API SdfFileFormat ( const TfToken formatId,
const TfToken versionString,
const TfToken target,
const std::string &  extension,
const SdfSchemaBase schema 
)
protected

Constructor.

schema must remain valid for the lifetime of this file format.

SDF_API SdfFileFormat ( const TfToken formatId,
const TfToken versionString,
const TfToken target,
const std::string &  extension,
const SdfSchemaBase &&  schema 
)
protecteddelete

Disallow temporary SdfSchemaBase objects being passed to the c'tor.

SDF_API SdfFileFormat ( const TfToken formatId,
const TfToken versionString,
const TfToken target,
const std::vector< std::string > &  extensions 
)
protected

Constructor.

SDF_API SdfFileFormat ( const TfToken formatId,
const TfToken versionString,
const TfToken target,
const std::vector< std::string > &  extensions,
const SdfSchemaBase schema 
)
protected

Constructor.

schema must remain valid for the lifetime of this file format.

SDF_API SdfFileFormat ( const TfToken formatId,
const TfToken versionString,
const TfToken target,
const std::vector< std::string > &  extensions,
const SdfSchemaBase &&  schema 
)
protecteddelete

Disallow temporary SdfSchemaBase objects being passed to the c'tor.

virtual SDF_API ~SdfFileFormat ( )
protectedvirtual

Destructor.

Member Function Documentation

static SDF_API SdfAbstractDataConstPtr _GetLayerData ( const SdfLayer layer)
staticprotected

Get the internal data for layer.

static SDF_API void _SetLayerData ( SdfLayer layer,
SdfAbstractDataRefPtr &  data 
)
staticprotected

Set the internal data for layer to data, possibly transferring ownership of data.

virtual SDF_API bool CanRead ( const std::string &  file) const
pure virtual

Returns true if file can be read by this format.

Implemented in SdfTextFileFormat, UsdUsdFileFormat, UsdUsdzFileFormat, and UsdUsdcFileFormat.

static SDF_API std::set<std::string> FindAllFileFormatExtensions ( )
static

Returns a set containing the extension(s) corresponding to all registered file formats.

static SDF_API SdfFileFormatConstPtr FindByExtension ( const std::string &  extension,
const std::string &  target = std::string() 
)
static

Returns the file format instance that supports the specified file extension.

If a format with a matching extension is not found, this returns a null file format pointer.

An extension may be handled by multiple file formats, but each with a different target. In such cases, if no target is specified, the file format that is registered as the primary plugin will be returned. Otherwise, the file format whose target matches target will be returned.

static SDF_API SdfFileFormatConstPtr FindById ( const TfToken formatId)
static

Returns the file format instance with the specified formatId identifier.

If a format with a matching identifier is not found, this returns a null file format pointer.

virtual SDF_API FileFormatArguments GetDefaultFileFormatArguments ( ) const
virtual

Returns the FileFormatArguments that correspond to the default behavior of this file format when no FileFormatArguments are passed to NewLayer or InitData.

SDF_API const std::string& GetFileCookie ( ) const

Returns the cookie to be used when writing files with this format.

static SDF_API std::string GetFileExtension ( const std::string &  s)
static

Returns the file extension for path or file name s, without the leading dot character.

SDF_API const std::vector<std::string>& GetFileExtensions ( ) const

Returns a list of extensions that this format supports.

SDF_API const TfToken& GetFormatId ( ) const

Returns the format identifier.

virtual SDF_API std::string GetPackageRootLayerPath ( const std::string &  resolvedPath) const
virtual

Returns the path of the "root" layer contained in the package layer at resolvedPath produced by this file format.

If this file format is not a package, returns the empty string.

The package root layer is the layer in the package layer that is used when that package is opened via SdfLayer.

Reimplemented in UsdUsdzFileFormat.

SDF_API const std::string& GetPrimaryFileExtension ( ) const

Returns the primary file extension for this format.

This is the extension that is reported for layers using this file format.

SDF_API const SdfSchemaBase& GetSchema ( ) const

Returns the schema for this format.

SDF_API const TfToken& GetTarget ( ) const

Returns the target for this file format.

SDF_API const TfToken& GetVersionString ( ) const

Returns the current version of this file format.

virtual SDF_API SdfAbstractDataRefPtr InitData ( const FileFormatArguments args) const
virtual

This method allows the file format to bind to whatever data container is appropriate.

Returns a shared pointer to an SdfAbstractData implementation.

Reimplemented in UsdUsdFileFormat, UsdUsdzFileFormat, and UsdUsdcFileFormat.

virtual SDF_API bool IsPackage ( ) const
virtual

Returns true if this file format is a package containing other assets.

Reimplemented in UsdUsdzFileFormat.

SDF_API bool IsPrimaryFormatForExtensions ( ) const

Returns true if this file format is the primary format for the extensions it handles.

SDF_API bool IsSupportedExtension ( const std::string &  extension) const

Returns true if extension matches one of the extensions returned by GetFileExtensions.

SDF_API bool LayersAreFileBased ( ) const

Return true if layers produced by this file format are based on physical files on disk.

If so, this file format requires layers to be serialized to and read from files on disk.

For file formats where this function returns true, when opening a layer Sdf will fetch layers to the filesystem via calls to ArResolver::FetchToLocalResolvedPath prior to calling ReadFromFile.

This allows asset systems that do not store layers as individual files to operate with file formats that require these files.

See Also
ArResolver::Resolve
ArResolver::FetchToLocalResolvedPath
SDF_API SdfLayerRefPtr NewLayer ( const SdfFileFormatConstPtr &  fileFormat,
const std::string &  identifier,
const std::string &  realPath,
const ArAssetInfo assetInfo,
const FileFormatArguments args 
) const

Instantiate a layer.

virtual SDF_API bool Read ( SdfLayer layer,
const std::string &  resolvedPath,
bool  metadataOnly 
) const
pure virtual

Reads scene description from the asset specified by resolvedPath into the layer layer.

metadataOnly is a flag that asks for only the layer metadata to be read in, which can be much faster if that is all that is required. Note that this is just a hint: some FileFormat readers may disregard this flag and still fully populate the layer contents.

Returns true if the asset is successfully read into layer, false otherwise.

Implemented in SdfTextFileFormat, UsdUsdFileFormat, UsdUsdzFileFormat, and UsdUsdcFileFormat.

virtual SDF_API bool ReadFromString ( SdfLayer layer,
const std::string &  str 
) const
virtual

Reads data in the string str into the layer layer.

If the file is successfully read, this method returns true. Otherwise, false is returned and errors are posted.

Reimplemented in SdfTextFileFormat, UsdUsdFileFormat, UsdUsdzFileFormat, and UsdUsdcFileFormat.

SDF_API bool ShouldSkipAnonymousReload ( ) const

Return true if this file format prefers to skip reloading anonymous layers.

virtual SDF_API bool WriteToFile ( const SdfLayer layer,
const std::string &  filePath,
const std::string &  comment = std::string(),
const FileFormatArguments args = FileFormatArguments() 
) const
virtual

Writes the content in layer into the file at filePath.

If the content is successfully written, this method returns true. Otherwise, false is returned and errors are posted. The default implementation returns false.

Reimplemented in SdfTextFileFormat, UsdUsdFileFormat, UsdUsdzFileFormat, and UsdUsdcFileFormat.

virtual SDF_API bool WriteToStream ( const SdfSpecHandle &  spec,
std::ostream &  out,
size_t  indent 
) const
virtual

Write the provided spec to out indented indent levels.

Reimplemented in SdfTextFileFormat, UsdUsdFileFormat, UsdUsdzFileFormat, and UsdUsdcFileFormat.

virtual SDF_API bool WriteToString ( const SdfLayer layer,
std::string *  str,
const std::string &  comment = std::string() 
) const
virtual

Writes the content in layer to the string str.

This function should write a textual representation of layer to the stream that can be read back in via ReadFromString.

Reimplemented in SdfTextFileFormat, UsdUsdFileFormat, UsdUsdzFileFormat, and UsdUsdcFileFormat.


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