HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Variant.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_VARIANT_H
7 #define MATERIALX_VARIANT_H
8 
9 /// @file
10 /// Variant element subclasses
11 
12 #include <MaterialXCore/Export.h>
13 
15 
17 
18 class Variant;
19 class VariantSet;
20 class VariantAssign;
21 
22 /// A shared pointer to a Variant
23 using VariantPtr = shared_ptr<Variant>;
24 /// A shared pointer to a const Variant
25 using ConstVariantPtr = shared_ptr<const Variant>;
26 
27 /// A shared pointer to a VariantSet
28 using VariantSetPtr = shared_ptr<VariantSet>;
29 /// A shared pointer to a const VariantSet
30 using ConstVariantSetPtr = shared_ptr<const VariantSet>;
31 
32 /// A shared pointer to a VariantAssign
33 using VariantAssignPtr = shared_ptr<VariantAssign>;
34 /// A shared pointer to a const VariantAssign
35 using ConstVariantAssignPtr = shared_ptr<const VariantAssign>;
36 
37 /// @class Variant
38 /// A variant element within a VariantSet
40 {
41  public:
42  Variant(ElementPtr parent, const string& name) :
43  InterfaceElement(parent, CATEGORY, name)
44  {
45  }
46  virtual ~Variant() { }
47 
48  public:
49  static const string CATEGORY;
50 };
51 
52 /// @class VariantSet
53 /// A variant set element within a Document.
55 {
56  public:
57  VariantSet(ElementPtr parent, const string& name) :
58  Element(parent, CATEGORY, name)
59  {
60  }
61  virtual ~VariantSet() { }
62 
63  /// @name Variant Elements
64  /// @{
65 
66  /// Add a Variant to the variant set.
67  /// @param name The name of the new Variant.
68  /// If no name is specified, then a unique name will automatically be
69  /// generated.
70  /// @return A shared pointer to the new Variant.
72  {
73  return addChild<Variant>(name);
74  }
75 
76  /// Return the Variant, if any, with the given name.
77  VariantPtr getVariant(const string& name) const
78  {
79  return getChildOfType<Variant>(name);
80  }
81 
82  /// Return a vector of all Variant elements in the look.
83  vector<VariantPtr> getVariants() const
84  {
85  return getChildrenOfType<Variant>();
86  }
87 
88  /// Remove the Variant, if any, with the given name.
89  void removeVariant(const string& name)
90  {
91  removeChildOfType<Variant>(name);
92  }
93 
94  /// @}
95 
96  public:
97  static const string CATEGORY;
98 };
99 
100 /// @class VariantAssign
101 /// A variant assignment element within a Look.
102 /// @todo Add support for variant assignments in graph traversal and
103 /// string resolution.
105 {
106  public:
107  VariantAssign(ElementPtr parent, const string& name) :
108  Element(parent, CATEGORY, name)
109  {
110  }
111  virtual ~VariantAssign() { }
112 
113  /// @name Variant Set String
114  /// @{
115 
116  /// Set the element's variant set string.
117  void setVariantSetString(const string& variantSet)
118  {
119  setAttribute(VARIANT_SET_ATTRIBUTE, variantSet);
120  }
121 
122  /// Return true if the given element has a variant set string.
123  bool hasVariantSetString() const
124  {
125  return hasAttribute(VARIANT_SET_ATTRIBUTE);
126  }
127 
128  /// Return the element's variant set string.
129  const string& getVariantSetString() const
130  {
131  return getAttribute(VARIANT_SET_ATTRIBUTE);
132  }
133 
134  /// @}
135  /// @name Variant String
136  /// @{
137 
138  /// Set the element's variant string.
139  void setVariantString(const string& variant)
140  {
141  setAttribute(VARIANT_ATTRIBUTE, variant);
142  }
143 
144  /// Return true if the given element has a variant string.
145  bool hasVariantString() const
146  {
147  return hasAttribute(VARIANT_ATTRIBUTE);
148  }
149 
150  /// Return the element's variant string.
151  const string& getVariantString() const
152  {
153  return getAttribute(VARIANT_ATTRIBUTE);
154  }
155 
156  /// @}
157 
158  public:
159  static const string CATEGORY;
160  static const string VARIANT_SET_ATTRIBUTE;
161  static const string VARIANT_ATTRIBUTE;
162 };
163 
165 
166 #endif
shared_ptr< const VariantAssign > ConstVariantAssignPtr
A shared pointer to a const VariantAssign.
Definition: Variant.h:35
shared_ptr< Variant > VariantPtr
A shared pointer to a Variant.
Definition: Variant.h:23
static const string VARIANT_SET_ATTRIBUTE
Definition: Variant.h:160
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
static const string CATEGORY
Definition: Variant.h:97
void setVariantSetString(const string &variantSet)
Set the element's variant set string.
Definition: Variant.h:117
static const string CATEGORY
Definition: Variant.h:159
const string & getVariantSetString() const
Return the element's variant set string.
Definition: Variant.h:129
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
const string & getAttribute(const string &attrib) const
Definition: Element.h:504
VariantSet(ElementPtr parent, const string &name)
Definition: Variant.h:57
#define MX_CORE_API
Definition: Export.h:18
virtual ~Variant()
Definition: Variant.h:46
VariantPtr addVariant(const string &name=EMPTY_STRING)
Definition: Variant.h:71
shared_ptr< VariantSet > VariantSetPtr
A shared pointer to a VariantSet.
Definition: Variant.h:28
bool hasVariantSetString() const
Return true if the given element has a variant set string.
Definition: Variant.h:123
void setVariantString(const string &variant)
Set the element's variant string.
Definition: Variant.h:139
bool hasVariantString() const
Return true if the given element has a variant string.
Definition: Variant.h:145
const string & getVariantString() const
Return the element's variant string.
Definition: Variant.h:151
shared_ptr< VariantAssign > VariantAssignPtr
A shared pointer to a VariantAssign.
Definition: Variant.h:33
static const string VARIANT_ATTRIBUTE
Definition: Variant.h:161
GLuint const GLchar * name
Definition: glcorearb.h:786
shared_ptr< const VariantSet > ConstVariantSetPtr
A shared pointer to a const VariantSet.
Definition: Variant.h:30
static const string CATEGORY
Definition: Variant.h:49
void setAttribute(const string &attrib, const string &value)
Set the value string of the given attribute.
void removeVariant(const string &name)
Remove the Variant, if any, with the given name.
Definition: Variant.h:89
bool hasAttribute(const string &attrib) const
Return true if the given attribute is present.
Definition: Element.h:497
virtual ~VariantSet()
Definition: Variant.h:61
VariantPtr getVariant(const string &name) const
Return the Variant, if any, with the given name.
Definition: Variant.h:77
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
shared_ptr< const Variant > ConstVariantPtr
A shared pointer to a const Variant.
Definition: Variant.h:25
Variant(ElementPtr parent, const string &name)
Definition: Variant.h:42
virtual ~VariantAssign()
Definition: Variant.h:111
vector< VariantPtr > getVariants() const
Return a vector of all Variant elements in the look.
Definition: Variant.h:83
VariantAssign(ElementPtr parent, const string &name)
Definition: Variant.h:107