HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
textFileFormat.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_SDF_TEXT_FILE_FORMAT_H
25 #define PXR_USD_SDF_TEXT_FILE_FORMAT_H
26 
27 /// \file sdf/textFileFormat.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
32 #include "pxr/usd/sdf/fileFormat.h"
34 
35 #include <iosfwd>
36 #include <string>
37 
39 
40 #define SDF_TEXT_FILE_FORMAT_TOKENS \
41  ((Id, "sdf")) \
42  ((Version, "1.4.32")) \
43  ((Target, "sdf"))
44 
45 TF_DECLARE_PUBLIC_TOKENS(SdfTextFileFormatTokens,
47 
49 
51 
52 class ArAsset;
53 
54 /// \class SdfTextFileFormat
55 ///
56 /// Sdf text file format
57 ///
59 {
60 public:
61  // SdfFileFormat overrides.
62  SDF_API
63  virtual bool CanRead(const std::string &file) const override;
64 
65  SDF_API
66  virtual bool Read(
67  SdfLayer* layer,
68  const std::string& resolvedPath,
69  bool metadataOnly) const override;
70 
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  SDF_API
79  virtual bool ReadFromString(
80  SdfLayer* layer,
81  const std::string& str) const override;
82 
83  SDF_API
84  virtual bool WriteToString(
85  const SdfLayer& layer,
86  std::string* str,
87  const std::string& comment = std::string()) const override;
88 
89  SDF_API
90  virtual bool WriteToStream(
91  const SdfSpecHandle &spec,
92  std::ostream& out,
93  size_t indent) const override;
94 
95 protected:
97 
98  /// Destructor.
99  SDF_API
100  virtual ~SdfTextFileFormat();
101 
102  /// Constructor.
103  SDF_API
105 
106  /// Constructor. This form of the constructor may be used by formats that
107  /// use the .sdf text format as their internal representation.
108  /// If a non-empty versionString and target are provided, they will be
109  /// used as the file format version and target; otherwise the .sdf format
110  /// version and target will be implicitly used.
111  SDF_API
112  explicit SdfTextFileFormat(const TfToken& formatId,
113  const TfToken& versionString = TfToken(),
114  const TfToken& target = TfToken());
115 
116  /// Return true if layer can be read from \p asset at \p resolvedPath.
117  SDF_API
118  bool _CanReadFromAsset(
119  const std::string& resolvedPath,
120  const std::shared_ptr<ArAsset>& asset) const;
121 
122  /// Read layer from \p asset at \p resolvedPath into \p layer.
123  SDF_API
124  bool _ReadFromAsset(
125  SdfLayer* layer,
126  const std::string& resolvedPath,
127  const std::shared_ptr<ArAsset>& asset,
128  bool metadataOnly) const;
129 
130 private:
131  // Override to return false. Reloading anonymous text layers clears their
132  // content.
133  SDF_API virtual bool _ShouldSkipAnonymousReload() const override;
134 };
135 
137 
138 #endif // SDF_TEXT_FILE_FORMAT_H
Definition: layer.h:97
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.
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.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
Definition: asset.h:44
Definition: spec.h:49
virtual SDF_API bool WriteToString(const SdfLayer &layer, std::string *str, const std::string &comment=std::string()) const override
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
virtual SDF_API bool CanRead(const std::string &file) const override
Returns true if file can be read by this format.
Definition: token.h:87
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.
SDF_DECLARE_HANDLES(SdfSpec)
GLenum target
Definition: glcorearb.h:1667
virtual SDF_API bool WriteToFile(const SdfLayer &layer, const std::string &filePath, const std::string &comment=std::string(), const FileFormatArguments &args=FileFormatArguments()) const override
virtual SDF_API ~SdfTextFileFormat()
Destructor.
#define SDF_API
Definition: api.h:40
#define SDF_TEXT_FILE_FORMAT_TOKENS
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual SDF_API bool Read(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
**If you just want to fire and args
Definition: thread.h:609
TF_DECLARE_WEAK_AND_REF_PTRS(SdfTextFileFormat)
virtual SDF_API bool ReadFromString(SdfLayer *layer, const std::string &str) const override
std::map< std::string, std::string > FileFormatArguments
Definition: fileFormat.h:119
TF_DECLARE_PUBLIC_TOKENS(SdfTextFileFormatTokens, SDF_API, SDF_TEXT_FILE_FORMAT_TOKENS)
SDF_API SdfTextFileFormat()
Constructor.