HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
28 /// \file sdr/shaderMetadataHelpers.h
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 
38 
39 /// \namespace ShaderMetadataHelpers
40 ///
41 /// Various utilities for parsing metadata contained within shaders.
42 ///
43 namespace ShaderMetadataHelpers
44 {
45  /// Determines if the given metadatum in the metadata dictionary has a
46  /// truthy value. All values are considered to be true except the following
47  /// (case-insensitive): '0', 'false', and 'f'. The absence of `key`
48  /// in the metadata also evaluates to false.
49  SDR_API
50  bool
51  IsTruthy(const TfToken& key, const NdrTokenMap& metadata);
52 
53  /// Extracts the string value from the given metadatum if it exists,
54  /// otherwise returns \p defaultValue.
55  SDR_API
57  StringVal(const TfToken& key, const NdrTokenMap& metadata,
58  const std::string& defaultValue = std::string());
59 
60  /// Extracts the tokenized value from the given metadatum if it exists,
61  /// otherwise returns \p defaultValue.
62  SDR_API
63  TfToken
64  TokenVal(const TfToken& key, const NdrTokenMap& metadata,
65  const TfToken& defaultValue = TfToken());
66 
67  /// Extracts the int value from the given metadatum if it exists and is a
68  /// valid integer value, otherwise returns \p default value.
69  SDR_API
70  int
71  IntVal(const TfToken& key, const NdrTokenMap& metadata,
72  int defaultValue = std::numeric_limits<int>::max());
73 
74  /// Extracts a vector of strings from the given metadatum. An empty vector
75  /// is returned if the metadatum does not exist.
76  SDR_API
78  StringVecVal(const TfToken& key, const NdrTokenMap& metadata);
79 
80  /// Extracts a vector of tokenized values from the given metadatum. An empty
81  /// vector is returned if the metadatum does not exist.
82  SDR_API
84  TokenVecVal(const TfToken& key, const NdrTokenMap& metadata);
85 
86  /// Extracts an "options" vector from the given string.
87  SDR_API
89  OptionVecVal(const std::string& optionStr);
90 
91  /// Serializes a vector of strings into a string using the pipe character
92  /// as the delimiter.
93  SDR_API
95  CreateStringFromStringVec(const NdrStringVec& stringVec);
96 
97  /// Determines if the specified property metadata has a widget that
98  /// indicates the property is an asset identifier.
99  SDR_API
100  bool
101  IsPropertyAnAssetIdentifier(const NdrTokenMap& metadata);
102 
103  /// Determines if the specified property metadata has a 'renderType' that
104  /// indicates the property should be a SdrPropertyTypes->Terminal
105  SDR_API
106  bool
107  IsPropertyATerminal(const NdrTokenMap& metadata);
108 
109  /// Gets the "role" from metadata if one is provided. Only returns a value
110  // if it's a valid role as defined by SdrPropertyRole tokens.
111  SDR_API
112  TfToken
113  GetRoleFromMetadata(const NdrTokenMap& metadata);
114 }
115 
117 
118 #endif // PXR_USD_SDR_SHADER_METADATA_HELPERS_H
std::vector< TfToken > NdrTokenVec
Definition: declare.h:59
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
std::vector< NdrOption > NdrOptionVec
Definition: declare.h:81
SDR_API NdrTokenVec TokenVecVal(const TfToken &key, const NdrTokenMap &metadata)
SDR_API int IntVal(const TfToken &key, const NdrTokenMap &metadata, int defaultValue=std::numeric_limits< int >::max())
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())
SDR_API bool IsPropertyAnAssetIdentifier(const NdrTokenMap &metadata)
Definition: token.h:87
std::vector< std::string > NdrStringVec
Definition: declare.h:79
SDR_API bool IsTruthy(const TfToken &key, const NdrTokenMap &metadata)
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)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
SDR_API bool IsPropertyATerminal(const NdrTokenMap &metadata)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > NdrTokenMap
Definition: declare.h:61
SDR_API NdrStringVec StringVecVal(const TfToken &key, const NdrTokenMap &metadata)
#define SDR_API
Definition: api.h:40
SDR_API std::string StringVal(const TfToken &key, const NdrTokenMap &metadata, const std::string &defaultValue=std::string())