All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
usdFileFormat.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_USD_USD_FILE_FORMAT_H
8#define PXR_USD_USD_USD_FILE_FORMAT_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usd/api.h"
14
15#include <string>
16
17PXR_NAMESPACE_OPEN_SCOPE
18
20
21#define USD_USD_FILE_FORMAT_TOKENS \
22 ((Id, "usd")) \
23 ((Version, "1.0")) \
24 ((Target, "usd")) \
25 ((FormatArg, "format"))
26
27TF_DECLARE_PUBLIC_TOKENS(UsdUsdFileFormatTokens, USD_API, USD_USD_FILE_FORMAT_TOKENS);
28
43{
44public:
46
47 USD_API
48 virtual SdfAbstractDataRefPtr
49 InitData(const FileFormatArguments& args) const override;
50
51 USD_API
52 virtual bool CanRead(const std::string &file) const override;
53
54 USD_API
55 virtual bool Read(
56 SdfLayer* layer,
57 const std::string& resolvedPath,
58 bool metadataOnly) const override;
59
60 USD_API
61 virtual bool WriteToFile(
62 const SdfLayer& layer,
63 const std::string& filePath,
64 const std::string& comment = std::string(),
65 const FileFormatArguments& args = FileFormatArguments()) const override;
66
67 USD_API
68 virtual bool SaveToFile(
69 const SdfLayer& layer,
70 const std::string& filePath,
71 const std::string& comment = std::string(),
72 const FileFormatArguments& args = FileFormatArguments()) const override;
73
74 USD_API
75 virtual bool ReadFromString(
76 SdfLayer* layer,
77 const std::string& str) const override;
78
79 USD_API
80 virtual bool WriteToString(
81 const SdfLayer& layer,
82 std::string* str,
83 const std::string& comment = std::string()) const override;
84
85 USD_API
86 virtual bool WriteToStream(
87 const SdfSpecHandle &spec,
88 std::ostream& out,
89 size_t indent) const override;
90
96 USD_API
98
99protected:
100 SDF_FILE_FORMAT_FACTORY_ACCESS;
101
102 SdfAbstractDataRefPtr _InitDetachedData(
103 const FileFormatArguments& args) const override;
104
106 SdfLayer* layer,
107 const std::string& resolvedPath,
108 bool metadataOnly) const override;
109
110private:
112 virtual ~UsdUsdFileFormat();
113
114 static SdfFileFormatConstPtr
115 _GetUnderlyingFileFormatForLayer(const SdfLayer& layer);
116
117 template <bool Detached>
118 bool _ReadHelper(
119 SdfLayer* layer,
120 const std::string& resolvedPath,
121 bool metadataOnly) const;
122};
123
124PXR_NAMESPACE_CLOSE_SCOPE
125
126#endif // PXR_USD_USD_USD_FILE_FORMAT_H
Base class for file format implementations.
Definition: fileFormat.h:50
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to the various API below.
Definition: fileFormat.h:102
A scene description container that can combine with other such containers to form simple component as...
Definition: layer.h:84
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
File format for USD files.
Definition: usdFileFormat.h:43
virtual USD_API bool WriteToString(const SdfLayer &layer, std::string *str, const std::string &comment=std::string()) const override
Writes the content in layer to the string str.
virtual USD_API bool WriteToStream(const SdfSpecHandle &spec, std::ostream &out, size_t indent) const override
Write the provided spec to out indented indent levels.
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to the various API below.
Definition: fileFormat.h:102
bool _ReadDetached(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
virtual USD_API SdfAbstractDataRefPtr InitData(const FileFormatArguments &args) const override
This method allows the file format to bind to whatever data container is appropriate.
virtual USD_API bool SaveToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
Write the content in layer to the file at filePath, which is the backing store for layer itself.
virtual USD_API bool Read(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
Reads scene description from the asset specified by resolvedPath into the layer layer.
virtual USD_API bool ReadFromString(SdfLayer *layer, const std::string &str) const override
Reads data in the string str into the layer layer.
SdfAbstractDataRefPtr _InitDetachedData(const FileFormatArguments &args) const override
static USD_API TfToken GetUnderlyingFormatForLayer(const SdfLayer &layer)
Returns the value of the "format" argument to be used in the FileFormatArguments when exporting or sa...
virtual USD_API bool CanRead(const std::string &file) const override
Returns true if file can be read by this format.
virtual USD_API bool WriteToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
Writes the content in layer into the file at filePath.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:81