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