MaterialX 1.38.6
Loading...
Searching...
No Matches
Variant.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_VARIANT_H
7#define MATERIALX_VARIANT_H
8
11
13
15
16MATERIALX_NAMESPACE_BEGIN
17
18class Variant;
19class VariantSet;
20class VariantAssign;
21
23using VariantPtr = shared_ptr<Variant>;
25using ConstVariantPtr = shared_ptr<const Variant>;
26
28using VariantSetPtr = shared_ptr<VariantSet>;
30using ConstVariantSetPtr = shared_ptr<const VariantSet>;
31
33using VariantAssignPtr = shared_ptr<VariantAssign>;
35using ConstVariantAssignPtr = shared_ptr<const VariantAssign>;
36
39class MX_CORE_API Variant : public InterfaceElement
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
54class MX_CORE_API VariantSet : public Element
55{
56 public:
57 VariantSet(ElementPtr parent, const string& name) :
58 Element(parent, CATEGORY, name)
59 {
60 }
61 virtual ~VariantSet() { }
62
65
71 VariantPtr addVariant(const string& name = EMPTY_STRING)
72 {
73 return addChild<Variant>(name);
74 }
75
77 VariantPtr getVariant(const string& name) const
78 {
79 return getChildOfType<Variant>(name);
80 }
81
83 vector<VariantPtr> getVariants() const
84 {
85 return getChildrenOfType<Variant>();
86 }
87
89 void removeVariant(const string& name)
90 {
91 removeChildOfType<Variant>(name);
92 }
93
95
96 public:
97 static const string CATEGORY;
98};
99
104class MX_CORE_API VariantAssign : public Element
105{
106 public:
107 VariantAssign(ElementPtr parent, const string& name) :
108 Element(parent, CATEGORY, name)
109 {
110 }
111 virtual ~VariantAssign() { }
112
115
117 void setVariantSetString(const string& variantSet)
118 {
119 setAttribute(VARIANT_SET_ATTRIBUTE, variantSet);
120 }
121
124 {
125 return hasAttribute(VARIANT_SET_ATTRIBUTE);
126 }
127
129 const string& getVariantSetString() const
130 {
131 return getAttribute(VARIANT_SET_ATTRIBUTE);
132 }
133
137
139 void setVariantString(const string& variant)
140 {
141 setAttribute(VARIANT_ATTRIBUTE, variant);
142 }
143
145 bool hasVariantString() const
146 {
147 return hasAttribute(VARIANT_ATTRIBUTE);
148 }
149
151 const string& getVariantString() const
152 {
153 return getAttribute(VARIANT_ATTRIBUTE);
154 }
155
157
158 public:
159 static const string CATEGORY;
160 static const string VARIANT_SET_ATTRIBUTE;
161 static const string VARIANT_ATTRIBUTE;
162};
163
164MATERIALX_NAMESPACE_END
165
166#endif
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:30
Interface element subclasses.
Import and export declarations for the Core library.
shared_ptr< VariantSet > VariantSetPtr
A shared pointer to a VariantSet.
Definition: Variant.h:28
shared_ptr< const VariantAssign > ConstVariantAssignPtr
A shared pointer to a const VariantAssign.
Definition: Variant.h:35
shared_ptr< const Variant > ConstVariantPtr
A shared pointer to a const Variant.
Definition: Variant.h:25
shared_ptr< Variant > VariantPtr
A shared pointer to a Variant.
Definition: Variant.h:23
shared_ptr< const VariantSet > ConstVariantSetPtr
A shared pointer to a const VariantSet.
Definition: Variant.h:30
shared_ptr< VariantAssign > VariantAssignPtr
A shared pointer to a VariantAssign.
Definition: Variant.h:33
The base class for MaterialX elements.
Definition: Element.h:74
const string & getAttribute(const string &attrib) const
Return the value string of the given attribute.
Definition: Element.h:498
void setAttribute(const string &attrib, const string &value)
Set the value string of the given attribute.
Definition: Element.cpp:191
bool hasAttribute(const string &attrib) const
Return true if the given attribute is present.
Definition: Element.h:491
The base class for interface elements such as Node, NodeDef, and NodeGraph.
Definition: Interface.h:318
A variant assignment element within a Look.
Definition: Variant.h:105
bool hasVariantString() const
Return true if the given element has a variant string.
Definition: Variant.h:145
void setVariantString(const string &variant)
Set the element's variant string.
Definition: Variant.h:139
void setVariantSetString(const string &variantSet)
Set the element's variant set string.
Definition: Variant.h:117
const string & getVariantString() const
Return the element's variant string.
Definition: Variant.h:151
const string & getVariantSetString() const
Return the element's variant set string.
Definition: Variant.h:129
bool hasVariantSetString() const
Return true if the given element has a variant set string.
Definition: Variant.h:123
A variant element within a VariantSet.
Definition: Variant.h:40
A variant set element within a Document.
Definition: Variant.h:55
VariantPtr getVariant(const string &name) const
Return the Variant, if any, with the given name.
Definition: Variant.h:77
vector< VariantPtr > getVariants() const
Return a vector of all Variant elements in the look.
Definition: Variant.h:83
void removeVariant(const string &name)
Remove the Variant, if any, with the given name.
Definition: Variant.h:89
VariantPtr addVariant(const string &name=EMPTY_STRING)
Add a Variant to the variant set.
Definition: Variant.h:71