HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
usdaFileFormat.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_USDA_FILE_FORMAT_H
8 #define PXR_USD_SDF_USDA_FILE_FORMAT_H
9 
10 #include "pxr/pxr.h"
12 #include "pxr/base/tf/envSetting.h"
14 #include "pxr/usd/sdf/api.h"
16 #include "pxr/usd/sdf/fileFormat.h"
18 
19 #include <iosfwd>
20 #include <string>
21 
23 
24 SDF_API
26 
27 #define SDF_USDA_FILE_FORMAT_TOKENS \
28  ((Id, "usda")) \
29  ((Version, "1.0"))
30 
32 
34 
36 
37 class ArAsset;
38 
39 /// Environment variable indicating the number of MB at which warnings
40 /// will be emitted when reading a SdfUsdaFileFormat-derived text file.
41 ///
42 /// \deprecated
43 /// The env variable functionality will remain, but its API exposure below
44 /// will be removed in a subsequent release.
45 SDF_API
47 
48 /// \class SdfUsdaFileFormat
49 ///
50 /// File format used by textual USD files.
51 ///
53 {
54 public:
55  // SdfFileFormat overrides.
56  SDF_API
57  virtual SdfAbstractDataRefPtr InitData(
58  const FileFormatArguments& args) const override;
59 
60  SDF_API
61  virtual bool CanRead(const std::string &file) const override;
62 
63  SDF_API
64  virtual bool Read(
65  SdfLayer* layer,
66  const std::string& resolvedPath,
67  bool metadataOnly) const override;
68 
69  /// \brief \c WriteToFile writes the layer contents to the file starting
70  /// with the default output version and upgrading as needed.
71  SDF_API
72  virtual bool WriteToFile(
73  const SdfLayer& layer,
74  const std::string& filePath,
75  const std::string& comment = std::string(),
76  const FileFormatArguments& args = FileFormatArguments()) const override;
77 
78  /// \brief \c SaveToFile writes the layer contents to the file starting
79  /// with the loaded layer's file version and upgrading as needed.
80  SDF_API
81  virtual bool SaveToFile(
82  const SdfLayer& layer,
83  const std::string& filePath,
84  const std::string& comment = std::string(),
85  const FileFormatArguments& args = FileFormatArguments()) const override;
86 
87  SDF_API
88  virtual bool ReadFromString(
89  SdfLayer* layer,
90  const std::string& str) const override;
91 
92  SDF_API
93  virtual bool WriteToString(
94  const SdfLayer& layer,
95  std::string* str,
96  const std::string& comment = std::string()) const override;
97 
98  SDF_API
99  virtual bool WriteToStream(
100  const SdfSpecHandle &spec,
101  std::ostream& out,
102  size_t indent) const override;
103 
104 public:
105  /// These methods return version info for the current version of the
106  /// \c SdfUsdaFileFormat. These versions will be kept in sync with the
107  /// abilities of the parsing and writing code, but it's convenient to
108  /// gather them all here.
109  /// @{
110 
111  /// Return the minimum version that is is possible for the software to read.
113 
114  /// Return the minimum version that it is possible for the software to write.
116 
117  /// Return the maximum version that is is possible for the software to read.
119 
120  /// Return the maximum version that it is possible for the software to write.
122 
123  /// Return the default version for newly created files.
125 
126  /// @}
127 
128 protected:
130 
131  /// Destructor.
132  SDF_API
133  virtual ~SdfUsdaFileFormat();
134 
135  /// Constructor.
136  SDF_API
138 
139  /// Constructor. This form of the constructor may be used by formats that
140  /// use the .usda text format as their internal representation.
141  /// If a non-empty versionString and target are provided, they will be
142  /// used as the file format version and target; otherwise the .usda format
143  /// version and target will be implicitly used.
144  SDF_API
145  explicit SdfUsdaFileFormat(const TfToken& formatId,
146  const TfToken& versionString = TfToken(),
147  const TfToken& target = TfToken());
148 
149  /// Return true if layer can be read from \p asset at \p resolvedPath.
150  SDF_API
151  bool _CanReadFromAsset(
152  const std::string& resolvedPath,
153  const std::shared_ptr<ArAsset>& asset) const;
154 
155  /// Read layer from \p asset at \p resolvedPath into \p layer.
156  SDF_API
157  bool _ReadFromAsset(
158  SdfLayer* layer,
159  const std::string& resolvedPath,
160  const std::shared_ptr<ArAsset>& asset,
161  bool metadataOnly) const;
162 
163 private:
164  // Override to return false. Reloading anonymous text layers clears their
165  // content.
166  SDF_API virtual bool _ShouldSkipAnonymousReload() const override;
167 
168  friend class SdfUsdFileFormat;
169 };
170 
172 
173 #endif // PXR_USD_SDF_USDA_FILE_FORMAT_H
TF_DECLARE_WEAK_AND_REF_PTRS(SdfUsdaFileFormat)
Definition: layer.h:81
static SdfFileVersion GetDefaultOutputVersion()
Return the default version for newly created files.
static SdfFileVersion GetMinInputVersion()
Return the minimum version that is is possible for the software to read.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
SDF_API bool _CanReadFromAsset(const std::string &resolvedPath, const std::shared_ptr< ArAsset > &asset) const
Return true if layer can be read from asset at resolvedPath.
virtual SDF_API bool WriteToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
WriteToFile writes the layer contents to the file starting with the default output version and upgrad...
Definition: asset.h:27
Definition: spec.h:32
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
virtual SDF_API bool ReadFromString(SdfLayer *layer, const std::string &str) 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
SaveToFile writes the layer contents to the file starting with the loaded layer's file version and up...
SDF_API SdfUsdaFileFormat()
Constructor.
SDF_API bool _ReadFromAsset(SdfLayer *layer, const std::string &resolvedPath, const std::shared_ptr< ArAsset > &asset, bool metadataOnly) const
Read layer from asset at resolvedPath into layer.
Definition: token.h:70
PXR_NAMESPACE_OPEN_SCOPE SDF_API TfEnvSetting< std::string > USD_WRITE_NEW_USDA_FILES_AS_VERSION
TF_DECLARE_PUBLIC_TOKENS(SdfUsdaFileFormatTokens, SDF_API, SDF_USDA_FILE_FORMAT_TOKENS)
GLenum target
Definition: glcorearb.h:1667
virtual SDF_API SdfAbstractDataRefPtr InitData(const FileFormatArguments &args) const override
SDF_DECLARE_HANDLES(SdfSpec)
#define SDF_API
Definition: api.h:23
virtual SDF_API bool WriteToString(const SdfLayer &layer, std::string *str, const std::string &comment=std::string()) const override
static SdfFileVersion GetMaxOutputVersion()
Return the maximum version that it is possible for the software to write.
static SdfFileVersion GetMinOutputVersion()
Return the minimum version that it is possible for the software to write.
#define SDF_USDA_FILE_FORMAT_TOKENS
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
**If you just want to fire and args
Definition: thread.h:618
virtual SDF_API ~SdfUsdaFileFormat()
Destructor.
virtual SDF_API bool CanRead(const std::string &file) const override
Returns true if file can be read by this format.
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.
static SdfFileVersion GetMaxInputVersion()
Return the maximum version that is is possible for the software to read.
std::map< std::string, std::string > FileFormatArguments
Definition: fileFormat.h:102
virtual SDF_API bool Read(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
SDF_API TfEnvSetting< int > SDF_TEXTFILE_SIZE_WARNING_MB