shaderMetadataHelpers.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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 
25 #ifndef PXR_USD_SDR_SHADER_METADATA_HELPERS_H
26 #define PXR_USD_SDR_SHADER_METADATA_HELPERS_H
27 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/sdr/api.h"
32 #include "pxr/base/tf/token.h"
33 #include "pxr/usd/sdr/declare.h"
34 
35 #include <limits>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
43 namespace ShaderMetadataHelpers
44 {
49  SDR_API
50  bool
51  IsTruthy(const TfToken& key, const NdrTokenMap& metadata);
52 
55  SDR_API
56  std::string
57  StringVal(const TfToken& key, const NdrTokenMap& metadata,
58  const std::string& defaultValue = std::string());
59 
62  SDR_API
63  TfToken
64  TokenVal(const TfToken& key, const NdrTokenMap& metadata,
65  const TfToken& defaultValue = TfToken());
66 
69  SDR_API
70  int
71  IntVal(const TfToken& key, const NdrTokenMap& metadata,
72  int defaultValue = std::numeric_limits<int>::max());
73 
76  SDR_API
77  NdrStringVec
78  StringVecVal(const TfToken& key, const NdrTokenMap& metadata);
79 
82  SDR_API
83  NdrTokenVec
84  TokenVecVal(const TfToken& key, const NdrTokenMap& metadata);
85 
87  SDR_API
88  NdrOptionVec
89  OptionVecVal(const std::string& optionStr);
90 
93  SDR_API
94  std::string
95  CreateStringFromStringVec(const NdrStringVec& stringVec);
96 
99  SDR_API
100  bool
101  IsPropertyAnAssetIdentifier(const NdrTokenMap& metadata);
102 
105  SDR_API
106  bool
107  IsPropertyATerminal(const NdrTokenMap& metadata);
108 
110  // if it's a valid role as defined by SdrPropertyRole tokens.
111  SDR_API
112  TfToken
113  GetRoleFromMetadata(const NdrTokenMap& metadata);
114 }
115 
116 PXR_NAMESPACE_CLOSE_SCOPE
117 
118 #endif // PXR_USD_SDR_SHADER_METADATA_HELPERS_H
SDR_API NdrTokenVec TokenVecVal(const TfToken &key, const NdrTokenMap &metadata)
Extracts a vector of tokenized values from the given metadatum.
SDR_API int IntVal(const TfToken &key, const NdrTokenMap &metadata, int defaultValue=std::numeric_limits< int >::max())
Extracts the int value from the given metadatum if it exists and is a valid integer value,...
SDR_API NdrOptionVec OptionVecVal(const std::string &optionStr)
Extracts an "options" vector from the given string.
SDR_API TfToken TokenVal(const TfToken &key, const NdrTokenMap &metadata, const TfToken &defaultValue=TfToken())
Extracts the tokenized value from the given metadatum if it exists, otherwise returns defaultValue.
SDR_API bool IsPropertyAnAssetIdentifier(const NdrTokenMap &metadata)
Determines if the specified property metadata has a widget that indicates the property is an asset id...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
SDR_API bool IsTruthy(const TfToken &key, const NdrTokenMap &metadata)
Determines if the given metadatum in the metadata dictionary has a truthy value.
SDR_API TfToken GetRoleFromMetadata(const NdrTokenMap &metadata)
Gets the "role" from metadata if one is provided. Only returns a value.
SDR_API std::string CreateStringFromStringVec(const NdrStringVec &stringVec)
Serializes a vector of strings into a string using the pipe character as the delimiter.
SDR_API bool IsPropertyATerminal(const NdrTokenMap &metadata)
Determines if the specified property metadata has a 'renderType' that indicates the property should b...
SDR_API NdrStringVec StringVecVal(const TfToken &key, const NdrTokenMap &metadata)
Extracts a vector of strings from the given metadatum.
Various utilities for parsing metadata contained within shaders.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
SDR_API std::string StringVal(const TfToken &key, const NdrTokenMap &metadata, const std::string &defaultValue=std::string())
Extracts the string value from the given metadatum if it exists, otherwise returns defaultValue.