Loading...
Searching...
No Matches
textFileFormat.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_TEXT_FILE_FORMAT_H
8#define PXR_USD_SDF_TEXT_FILE_FORMAT_H
9
13
14#include "pxr/pxr.h"
15#include "pxr/usd/sdf/api.h"
19
20#include <iosfwd>
21#include <string>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25#define SDF_TEXT_FILE_FORMAT_TOKENS \
26 ((Id, "sdf")) \
27 ((Version, "1.4.32")) \
28 ((Target, "sdf"))
29
30TF_DECLARE_PUBLIC_TOKENS(SdfTextFileFormatTokens,
31 SDF_API, SDF_TEXT_FILE_FORMAT_TOKENS);
32
34
35SDF_DECLARE_HANDLES(SdfSpec);
36
37class ArAsset;
38
47{
48public:
49 // SdfFileFormat overrides.
50 SDF_API
51 virtual SdfAbstractDataRefPtr InitData(
52 const FileFormatArguments& args) const override;
53
54 SDF_API
55 virtual bool CanRead(const std::string &file) const override;
56
57 SDF_API
58 virtual bool Read(
59 SdfLayer* layer,
60 const std::string& resolvedPath,
61 bool metadataOnly) const override;
62
63 SDF_API
64 virtual bool WriteToFile(
65 const SdfLayer& layer,
66 const std::string& filePath,
67 const std::string& comment = std::string(),
68 const FileFormatArguments& args = FileFormatArguments()) const override;
69
70 SDF_API
71 virtual bool ReadFromString(
72 SdfLayer* layer,
73 const std::string& str) const override;
74
75 SDF_API
76 virtual bool WriteToString(
77 const SdfLayer& layer,
78 std::string* str,
79 const std::string& comment = std::string()) const override;
80
81 SDF_API
82 virtual bool WriteToStream(
83 const SdfSpecHandle &spec,
84 std::ostream& out,
85 size_t indent) const override;
86
87protected:
88 SDF_FILE_FORMAT_FACTORY_ACCESS;
89
91 SDF_API
93
95 SDF_API
97
103 SDF_API
104 explicit SdfTextFileFormat(const TfToken& formatId,
105 const TfToken& versionString = TfToken(),
106 const TfToken& target = TfToken());
107
109 SDF_API
111 const std::string& resolvedPath,
112 const std::shared_ptr<ArAsset>& asset) const;
113
115 SDF_API
117 SdfLayer* layer,
118 const std::string& resolvedPath,
119 const std::shared_ptr<ArAsset>& asset,
120 bool metadataOnly) const;
121
122private:
123 // Override to return false. Reloading anonymous text layers clears their
124 // content.
125 SDF_API virtual bool _ShouldSkipAnonymousReload() const override;
126};
127
128PXR_NAMESPACE_CLOSE_SCOPE
129
130#endif // SDF_TEXT_FILE_FORMAT_H
Interface for accessing the contents of an asset.
Definition: asset.h:27
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
Base class for all Sdf spec classes.
Definition: spec.h:33
Sdf text file 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.
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 Read(SdfLayer *layer, const std::string &resolvedPath, bool metadataOnly) const override
Reads scene description from the asset specified by resolvedPath into the layer layer.
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_API SdfTextFileFormat()
Constructor.
SDF_API SdfTextFileFormat(const TfToken &formatId, const TfToken &versionString=TfToken(), const TfToken &target=TfToken())
Constructor.
virtual SDF_API bool ReadFromString(SdfLayer *layer, const std::string &str) const override
Reads data in the string str into the layer layer.
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 ~SdfTextFileFormat()
Destructor.
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:87