HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
usdFileFormat.h
Go to the documentation of this file.
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"
12 #include "pxr/usd/sdf/fileFormat.h"
14 
15 #include <string>
16 
18 
20 
21 #define USD_USD_FILE_FORMAT_TOKENS \
22  ((Id, "usd")) \
23  ((Version, "1.0")) \
24  ((Target, "usd")) \
25  ((FormatArg, "format"))
26 
28 
29 /// \class UsdUsdFileFormat
30 ///
31 /// File format for USD files.
32 ///
33 /// When creating a file through the SdfLayer::CreateNew() interface, the
34 /// meaningful SdfFileFormat::FileFormatArguments are as follows:
35 /// \li UsdUsdFileFormatTokens->FormatArg , which must be a supported format's
36 /// 'Id'. The possible values are UsdUsdaFileFormatTokens->Id
37 /// or UsdUsdcFileFormatTokens->Id.
38 ///
39 /// If no UsdUsdFileFormatTokens->FormatArg is supplied, the default is
40 /// UsdUsdcFileFormatTokens->Id.
41 ///
43 {
44 public:
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 
91  /// Returns the value of the "format" argument to be used in the
92  /// FileFormatArguments when exporting or saving the given layer.
93  ///
94  /// Returns an empty token if the given layer does not have this
95  /// file format.
96  USD_API
97  static TfToken GetUnderlyingFormatForLayer(const SdfLayer& layer);
98 
99 protected:
101 
102  SdfAbstractDataRefPtr _InitDetachedData(
103  const FileFormatArguments& args) const override;
104 
105  bool _ReadDetached(
106  SdfLayer* layer,
107  const std::string& resolvedPath,
108  bool metadataOnly) const override;
109 
110 private:
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 
125 
126 #endif // PXR_USD_USD_USD_FILE_FORMAT_H
Definition: layer.h:81
virtual USD_API bool WriteToString(const SdfLayer &layer, std::string *str, const std::string &comment=std::string()) const override
#define USD_API
Definition: api.h:23
virtual USD_API SdfAbstractDataRefPtr InitData(const FileFormatArguments &args) const override
virtual USD_API bool WriteToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
Definition: token.h:70
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.
static USD_API TfToken GetUnderlyingFormatForLayer(const SdfLayer &layer)
#define USD_USD_FILE_FORMAT_TOKENS
Definition: usdFileFormat.h:21
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
SdfAbstractDataRefPtr _InitDetachedData(const FileFormatArguments &args) const override
virtual USD_API bool CanRead(const std::string &file) const override
Returns true if file can be read by this format.
TF_DECLARE_PUBLIC_TOKENS(UsdUsdFileFormatTokens, USD_API, USD_USD_FILE_FORMAT_TOKENS)
virtual USD_API bool Read(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool _ReadDetached(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
**If you just want to fire and args
Definition: thread.h:618
virtual USD_API bool ReadFromString(SdfLayer *layer, const std::string &str) const override
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_AND_REF_PTRS(UsdUsdFileFormat)
virtual USD_API bool SaveToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
std::map< std::string, std::string > FileFormatArguments
Definition: fileFormat.h:102