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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_SDR_SHADER_METADATA_HELPERS_H
9 #define PXR_USD_SDR_SHADER_METADATA_HELPERS_H
10 
11 /// \file sdr/shaderMetadataHelpers.h
12 
13 #include "pxr/pxr.h"
14 #include "pxr/usd/sdr/api.h"
15 #include "pxr/base/tf/token.h"
16 #include "pxr/usd/sdr/declare.h"
17 
18 #include <limits>
19 
21 
22 /// \namespace ShaderMetadataHelpers
23 ///
24 /// Various utilities for parsing metadata contained within shaders.
25 ///
26 namespace ShaderMetadataHelpers
27 {
28  /// Determines if the given metadatum in the metadata dictionary has a
29  /// truthy value. All values are considered to be true except the following
30  /// (case-insensitive): '0', 'false', and 'f'. The absence of `key`
31  /// in the metadata also evaluates to false.
32  SDR_API
33  bool
34  IsTruthy(const TfToken& key, const NdrTokenMap& metadata);
35 
36  /// Extracts the string value from the given metadatum if it exists,
37  /// otherwise returns \p defaultValue.
38  SDR_API
39  std::string
40  StringVal(const TfToken& key, const NdrTokenMap& metadata,
41  const std::string& defaultValue = std::string());
42 
43  /// Extracts the tokenized value from the given metadatum if it exists,
44  /// otherwise returns \p defaultValue.
45  SDR_API
46  TfToken
47  TokenVal(const TfToken& key, const NdrTokenMap& metadata,
48  const TfToken& defaultValue = TfToken());
49 
50  /// Extracts the int value from the given metadatum if it exists and is a
51  /// valid integer value, otherwise returns \p default value.
52  SDR_API
53  int
54  IntVal(const TfToken& key, const NdrTokenMap& metadata,
55  int defaultValue = std::numeric_limits<int>::max());
56 
57  /// Extracts a vector of strings from the given metadatum. An empty vector
58  /// is returned if the metadatum does not exist.
59  SDR_API
61  StringVecVal(const TfToken& key, const NdrTokenMap& metadata);
62 
63  /// Extracts a vector of tokenized values from the given metadatum. An empty
64  /// vector is returned if the metadatum does not exist.
65  SDR_API
67  TokenVecVal(const TfToken& key, const NdrTokenMap& metadata);
68 
69  /// Extracts an "options" vector from the given string.
70  SDR_API
72  OptionVecVal(const std::string& optionStr);
73 
74  /// Serializes a vector of strings into a string using the pipe character
75  /// as the delimiter.
76  SDR_API
77  std::string
78  CreateStringFromStringVec(const NdrStringVec& stringVec);
79 
80  /// Determines if the specified property metadata has a widget that
81  /// indicates the property is an asset identifier.
82  SDR_API
83  bool
85 
86  /// Determines if the specified property metadata has a 'renderType' that
87  /// indicates the property should be a SdrPropertyTypes->Terminal
88  SDR_API
89  bool
90  IsPropertyATerminal(const NdrTokenMap& metadata);
91 
92  /// Gets the "role" from metadata if one is provided. Only returns a value
93  // if it's a valid role as defined by SdrPropertyRole tokens.
94  SDR_API
95  TfToken
96  GetRoleFromMetadata(const NdrTokenMap& metadata);
97 }
98 
100 
101 #endif // PXR_USD_SDR_SHADER_METADATA_HELPERS_H
std::vector< TfToken > NdrTokenVec
Definition: declare.h:50
std::vector< NdrOption > NdrOptionVec
Definition: declare.h:72
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:70
std::vector< std::string > NdrStringVec
Definition: declare.h:70
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:1425
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:74
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > NdrTokenMap
Definition: declare.h:52
SDR_API NdrStringVec StringVecVal(const TfToken &key, const NdrTokenMap &metadata)
#define SDR_API
Definition: api.h:23
SDR_API std::string StringVal(const TfToken &key, const NdrTokenMap &metadata, const std::string &defaultValue=std::string())