All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
17
18#include <iosfwd>
19#include <string>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23#define SDF_TEXT_FILE_FORMAT_TOKENS \
24 ((Id, "sdf")) \
25 ((Version, "1.4.32")) \
26 ((Target, "sdf"))
27
28TF_DECLARE_PUBLIC_TOKENS(SdfTextFileFormatTokens,
29 SDF_API, SDF_TEXT_FILE_FORMAT_TOKENS);
30
32
33SDF_DECLARE_HANDLES(SdfSpec);
34
35class ArAsset;
36
42{
43public:
44 // SdfFileFormat overrides.
45 SDF_API
46 virtual bool CanRead(const std::string &file) const override;
47
48 SDF_API
49 virtual bool Read(
50 SdfLayer* layer,
51 const std::string& resolvedPath,
52 bool metadataOnly) const override;
53
54 SDF_API
55 virtual bool WriteToFile(
56 const SdfLayer& layer,
57 const std::string& filePath,
58 const std::string& comment = std::string(),
59 const FileFormatArguments& args = FileFormatArguments()) const override;
60
61 SDF_API
62 virtual bool ReadFromString(
63 SdfLayer* layer,
64 const std::string& str) const override;
65
66 SDF_API
67 virtual bool WriteToString(
68 const SdfLayer& layer,
69 std::string* str,
70 const std::string& comment = std::string()) const override;
71
72 SDF_API
73 virtual bool WriteToStream(
74 const SdfSpecHandle &spec,
75 std::ostream& out,
76 size_t indent) const override;
77
78protected:
79 SDF_FILE_FORMAT_FACTORY_ACCESS;
80
82 SDF_API
84
86 SDF_API
88
94 SDF_API
95 explicit SdfTextFileFormat(const TfToken& formatId,
96 const TfToken& versionString = TfToken(),
97 const TfToken& target = TfToken());
98
100 SDF_API
102 const std::string& resolvedPath,
103 const std::shared_ptr<ArAsset>& asset) const;
104
106 SDF_API
108 SdfLayer* layer,
109 const std::string& resolvedPath,
110 const std::shared_ptr<ArAsset>& asset,
111 bool metadataOnly) const;
112
113private:
114 // Override to return false. Reloading anonymous text layers clears their
115 // content.
116 SDF_API virtual bool _ShouldSkipAnonymousReload() const override;
117};
118
119PXR_NAMESPACE_CLOSE_SCOPE
120
121#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 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:81