Loading...
Searching...
No Matches
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_SDF_USD_FILE_FORMAT_H
8#define PXR_USD_SDF_USD_FILE_FORMAT_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/sdf/api.h"
14
15#include <string>
16
17PXR_NAMESPACE_OPEN_SCOPE
18
20
21#define SDF_USD_FILE_FORMAT_TOKENS \
22 ((Id, "usd")) \
23 ((Version, "1.0")) \
24 ((Target, "usd")) \
25 ((FormatArg, "format"))
26
27TF_DECLARE_PUBLIC_TOKENS(SdfUsdFileFormatTokens, SDF_API,
28 SDF_USD_FILE_FORMAT_TOKENS);
29
44{
45public:
47
48 SDF_API
49 virtual SdfAbstractDataRefPtr
50 InitData(const FileFormatArguments& args) const override;
51
52 SDF_API
53 virtual bool CanRead(const std::string &file) const override;
54
55 SDF_API
56 virtual bool Read(
57 SdfLayer* layer,
58 const std::string& resolvedPath,
59 bool metadataOnly) const override;
60
61 SDF_API
62 virtual bool WriteToFile(
63 const SdfLayer& layer,
64 const std::string& filePath,
65 const std::string& comment = std::string(),
66 const FileFormatArguments& args = FileFormatArguments()) const override;
67
68 SDF_API
69 virtual bool SaveToFile(
70 const SdfLayer& layer,
71 const std::string& filePath,
72 const std::string& comment = std::string(),
73 const FileFormatArguments& args = FileFormatArguments()) const override;
74
75 SDF_API
76 virtual bool ReadFromString(
77 SdfLayer* layer,
78 const std::string& str) const override;
79
80 SDF_API
81 virtual bool WriteToString(
82 const SdfLayer& layer,
83 std::string* str,
84 const std::string& comment = std::string()) const override;
85
86 SDF_API
87 virtual bool WriteToStream(
88 const SdfSpecHandle &spec,
89 std::ostream& out,
90 size_t indent) const override;
91
97 SDF_API
99
100protected:
101 SDF_FILE_FORMAT_FACTORY_ACCESS;
102
103 SdfAbstractDataRefPtr _InitDetachedData(
104 const FileFormatArguments& args) const override;
105
107 SdfLayer* layer,
108 const std::string& resolvedPath,
109 bool metadataOnly) const override;
110
111private:
113 virtual ~SdfUsdFileFormat();
114
115 static SdfFileFormatConstPtr
116 _GetUnderlyingFileFormatForLayer(const SdfLayer& layer);
117
118 template <bool Detached>
119 bool _ReadHelper(
120 SdfLayer* layer,
121 const std::string& resolvedPath,
122 bool metadataOnly) const;
123};
124
125PXR_NAMESPACE_CLOSE_SCOPE
126
127#endif // PXR_USD_SDF_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
File format for USD files.
Definition: usdFileFormat.h:44
std::map< std::string, std::string > FileFormatArguments
Type for specifying additional file format-specific arguments to the various API below.
Definition: fileFormat.h:102
virtual SDF_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 SDF_API bool WriteToStream(const SdfSpecHandle &spec, std::ostream &out, size_t indent) const override
Write the provided spec to out indented indent levels.
virtual SDF_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.
bool _ReadDetached(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
static SDF_API TfToken GetUnderlyingFormatForLayer(const SdfLayer &layer)
Returns the value of the "format" argument to be used in the FileFormatArguments when exporting or sa...
virtual SDF_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
virtual SDF_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.
virtual SDF_API SdfAbstractDataRefPtr InitData(const FileFormatArguments &args) const override
This method allows the file format to bind to whatever data container is appropriate.
virtual SDF_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 SDF_API bool CanRead(const std::string &file) const override
Returns true if file can be read by this format.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
#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:92