forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariant.h
167 lines (135 loc) · 3.95 KB
/
Variant.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#ifndef MATERIALX_VARIANT_H
#define MATERIALX_VARIANT_H
/// @file
/// Variant element subclasses
#include <MaterialXCore/Library.h>
#include <MaterialXCore/Interface.h>
namespace MaterialX
{
class Variant;
class VariantSet;
class VariantAssign;
/// A shared pointer to a Variant
using VariantPtr = shared_ptr<Variant>;
/// A shared pointer to a const Variant
using ConstVariantPtr = shared_ptr<const Variant>;
/// A shared pointer to a VariantSet
using VariantSetPtr = shared_ptr<VariantSet>;
/// A shared pointer to a const VariantSet
using ConstVariantSetPtr = shared_ptr<const VariantSet>;
/// A shared pointer to a VariantAssign
using VariantAssignPtr = shared_ptr<VariantAssign>;
/// A shared pointer to a const VariantAssign
using ConstVariantAssignPtr = shared_ptr<const VariantAssign>;
/// @class Variant
/// A variant element within a VariantSet
class Variant : public InterfaceElement
{
public:
Variant(ElementPtr parent, const string& name) :
InterfaceElement(parent, CATEGORY, name)
{
}
virtual ~Variant() { }
public:
static const string CATEGORY;
};
/// @class VariantSet
/// A variant set element within a Document.
class VariantSet : public Element
{
public:
VariantSet(ElementPtr parent, const string& name) :
Element(parent, CATEGORY, name)
{
}
virtual ~VariantSet() { }
/// @name Variant Elements
/// @{
/// Add a Variant to the variant set.
/// @param name The name of the new Variant.
/// If no name is specified, then a unique name will automatically be
/// generated.
/// @return A shared pointer to the new Variant.
VariantPtr addVariant(const string& name = EMPTY_STRING)
{
return addChild<Variant>(name);
}
/// Return the Variant, if any, with the given name.
VariantPtr getVariant(const string& name) const
{
return getChildOfType<Variant>(name);
}
/// Return a vector of all Variant elements in the look.
vector<VariantPtr> getVariants() const
{
return getChildrenOfType<Variant>();
}
/// Remove the Variant, if any, with the given name.
void removeVariant(const string& name)
{
removeChildOfType<Variant>(name);
}
/// @}
public:
static const string CATEGORY;
};
/// @class VariantAssign
/// A variant assignment element within a Look.
/// @todo Add support for variant assignments in graph traversal and
/// string resolution.
class VariantAssign : public Element
{
public:
VariantAssign(ElementPtr parent, const string& name) :
Element(parent, CATEGORY, name)
{
}
virtual ~VariantAssign() { }
/// @name Variant Set String
/// @{
/// Set the element's variant set string.
void setVariantSetString(const string& variantSet)
{
setAttribute(VARIANT_SET_ATTRIBUTE, variantSet);
}
/// Return true if the given element has a variant set string.
bool hasVariantSetString() const
{
return hasAttribute(VARIANT_SET_ATTRIBUTE);
}
/// Return the element's variant set string.
const string& getVariantSetString() const
{
return getAttribute(VARIANT_SET_ATTRIBUTE);
}
/// @}
/// @name Variant String
/// @{
/// Set the element's variant string.
void setVariantString(const string& variant)
{
setAttribute(VARIANT_ATTRIBUTE, variant);
}
/// Return true if the given element has a variant string.
bool hasVariantString() const
{
return hasAttribute(VARIANT_ATTRIBUTE);
}
/// Return the element's variant string.
const string& getVariantString() const
{
return getAttribute(VARIANT_ATTRIBUTE);
}
/// @}
public:
static const string CATEGORY;
static const string VARIANT_SET_ATTRIBUTE;
static const string VARIANT_ATTRIBUTE;
};
} // namespace MaterialX
#endif