HDK
|
#include <Element.h>
Public Member Functions | |
virtual | ~Element () |
Element (const Element &)=delete | |
Element & | operator= (const Element &)=delete |
bool | operator== (const Element &rhs) const |
bool | operator!= (const Element &rhs) const |
Category | |
void | setCategory (const string &category) |
Set the element's category string. More... | |
const string & | getCategory () const |
Name | |
void | setName (const string &name) |
const string & | getName () const |
Return the element's name string. More... | |
string | getNamePath (ConstElementPtr relativeTo=nullptr) const |
ElementPtr | getDescendant (const string &namePath) const |
File Prefix | |
void | setFilePrefix (const string &prefix) |
Set the element's file prefix string. More... | |
bool | hasFilePrefix () const |
Return true if the given element has a file prefix string. More... | |
const string & | getFilePrefix () const |
Return the element's file prefix string. More... | |
const string & | getActiveFilePrefix () const |
Geom Prefix | |
void | setGeomPrefix (const string &prefix) |
Set the element's geom prefix string. More... | |
bool | hasGeomPrefix () const |
Return true if the given element has a geom prefix string. More... | |
const string & | getGeomPrefix () const |
Return the element's geom prefix string. More... | |
const string & | getActiveGeomPrefix () const |
Color Space | |
void | setColorSpace (const string &colorSpace) |
Set the element's color space string. More... | |
bool | hasColorSpace () const |
Return true if the given element has a color space string. More... | |
const string & | getColorSpace () const |
Return the element's color space string. More... | |
const string & | getActiveColorSpace () const |
Inheritance | |
void | setInheritString (const string &inherit) |
Set the inherit string of this element. More... | |
bool | hasInheritString () const |
Return true if this element has an inherit string. More... | |
const string & | getInheritString () const |
Return the inherit string of this element. More... | |
void | setInheritsFrom (ConstElementPtr super) |
Set the element that this one directly inherits from. More... | |
ElementPtr | getInheritsFrom () const |
Return the element, if any, that this one directly inherits from. More... | |
bool | hasInheritedBase (ConstElementPtr base) const |
bool | hasInheritanceCycle () const |
Return true if the inheritance chain for this element contains a cycle. More... | |
Namespace | |
void | setNamespace (const string &space) |
Set the namespace string of this element. More... | |
bool | hasNamespace () const |
Return true if this element has a namespace string. More... | |
const string & | getNamespace () const |
Return the namespace string of this element. More... | |
string | getQualifiedName (const string &name) const |
Documentation String | |
void | setDocString (const string &doc) |
Set the documentation string of this element. More... | |
string | getDocString () const |
Return the documentation string of this element. More... | |
Subclass | |
template<class T > | |
bool | isA (const string &category=EMPTY_STRING) const |
template<class T > | |
shared_ptr< T > | asA () |
Dynamic cast to an instance of the given subclass. More... | |
template<class T > | |
shared_ptr< const T > | asA () const |
Dynamic cast to a const instance of the given subclass. More... | |
Child Elements | |
template<class T > | |
shared_ptr< T > | addChild (const string &name=EMPTY_STRING) |
ElementPtr | addChildOfCategory (const string &category, string name=EMPTY_STRING) |
ElementPtr | changeChildCategory (ElementPtr child, const string &category) |
ElementPtr | getChild (const string &name) const |
Return the child element, if any, with the given name. More... | |
template<class T > | |
shared_ptr< T > | getChildOfType (const string &name) const |
const vector< ElementPtr > & | getChildren () const |
template<class T > | |
vector< shared_ptr< T > > | getChildrenOfType (const string &category=EMPTY_STRING) const |
void | setChildIndex (const string &name, int index) |
int | getChildIndex (const string &name) const |
void | removeChild (const string &name) |
Remove the child element, if any, with the given name. More... | |
template<class T > | |
void | removeChildOfType (const string &name) |
Attributes | |
void | setAttribute (const string &attrib, const string &value) |
Set the value string of the given attribute. More... | |
bool | hasAttribute (const string &attrib) const |
Return true if the given attribute is present. More... | |
const string & | getAttribute (const string &attrib) const |
const StringVec & | getAttributeNames () const |
Return a vector of stored attribute names, in the order they were set. More... | |
template<class T > | |
void | setTypedAttribute (const string &attrib, const T &data) |
template<class T > | |
T | getTypedAttribute (const string &attrib) const |
void | removeAttribute (const string &attrib) |
Remove the given attribute, if present. More... | |
Self And Ancestor Elements | |
ElementPtr | getSelf () |
Return our self pointer. More... | |
ConstElementPtr | getSelf () const |
Return our self pointer. More... | |
ElementPtr | getParent () |
Return our parent element. More... | |
ConstElementPtr | getParent () const |
Return our parent element. More... | |
ElementPtr | getRoot () |
Return the root element of our tree. More... | |
ConstElementPtr | getRoot () const |
Return the root element of our tree. More... | |
DocumentPtr | getDocument () |
Return the root document of our tree. More... | |
ConstDocumentPtr | getDocument () const |
Return the root document of our tree. More... | |
template<class T > | |
shared_ptr< const T > | getAncestorOfType () const |
Traversal | |
TreeIterator | traverseTree () const |
GraphIterator | traverseGraph () const |
virtual Edge | getUpstreamEdge (size_t index=0) const |
virtual size_t | getUpstreamEdgeCount () const |
Return the number of queriable upstream edges for this element. More... | |
ElementPtr | getUpstreamElement (size_t index=0) const |
InheritanceIterator | traverseInheritance () const |
Source URI | |
void | setSourceUri (const string &sourceUri) |
bool | hasSourceUri () const |
Return true if this element has a source URI. More... | |
const string & | getSourceUri () const |
Return the element's source URI. More... | |
const string & | getActiveSourceUri () const |
Validation | |
virtual bool | validate (string *message=nullptr) const |
Utility | |
void | copyContentFrom (const ConstElementPtr &source) |
virtual void | clearContent () |
Clear all attributes and descendants from this element. More... | |
string | createValidChildName (string name) const |
StringResolverPtr | createStringResolver (const string &geom=EMPTY_STRING) const |
string | asString () const |
Static Public Attributes | |
static const string | NAME_ATTRIBUTE |
static const string | FILE_PREFIX_ATTRIBUTE |
static const string | GEOM_PREFIX_ATTRIBUTE |
static const string | COLOR_SPACE_ATTRIBUTE |
static const string | INHERIT_ATTRIBUTE |
static const string | NAMESPACE_ATTRIBUTE |
static const string | DOC_ATTRIBUTE |
Protected Types | |
using | DocumentPtr = shared_ptr< Document > |
using | ConstDocumentPtr = shared_ptr< const Document > |
Protected Member Functions | |
Element (ElementPtr parent, const string &category, const string &name) | |
template<class T > | |
shared_ptr< T > | resolveNameReference (const string &name, ConstElementPtr parent=nullptr) const |
void | validateRequire (bool expression, bool &res, string *message, const string &errorDesc) const |
virtual void | registerChildElement (ElementPtr child) |
virtual void | unregisterChildElement (ElementPtr child) |
ElementPtr | getSelfNonConst () const |
Protected Attributes | |
string | _category |
string | _name |
string | _sourceUri |
ElementMap | _childMap |
vector< ElementPtr > | _childOrder |
StringMap | _attributeMap |
StringVec | _attributeOrder |
weak_ptr< Element > | _parent |
weak_ptr< Element > | _root |
Friends | |
template<class T > | |
class | ElementRegistry |
The base class for MaterialX elements.
An Element is a named object within a Document, which may possess any number of child elements and attributes.
|
protected |
|
protected |
|
inlineprotected |
|
delete |
shared_ptr< T > Element::addChild | ( | const string & | name = EMPTY_STRING | ) |
Add a child element of the given subclass and name.
name | The name of the new child element. If no name is specified, then a unique name will automatically be generated. |
Exception | if a child of this element already possesses the given name. |
ElementPtr Element::addChildOfCategory | ( | const string & | category, |
string | name = EMPTY_STRING |
||
) |
Add a child element of the given category and name.
category | The category string of the new child element. If the category string is recognized, then the correponding Element subclass is generated; otherwise, a GenericElement is generated. |
name | The name of the new child element. If no name is specified, then a unique name will automatically be generated. |
Exception | if a child of this element already possesses the given name. |
shared_ptr<T> Element::asA | ( | ) |
Dynamic cast to an instance of the given subclass.
shared_ptr<const T> Element::asA | ( | ) | const |
Dynamic cast to a const instance of the given subclass.
string Element::asString | ( | ) | const |
Return a single-line description of this element, including its category, name, and attributes.
ElementPtr Element::changeChildCategory | ( | ElementPtr | child, |
const string & | category | ||
) |
Change the category of the given child element.
child | The child element that will be modified. |
category | The new category string for the child element. |
|
virtual |
Clear all attributes and descendants from this element.
Reimplemented in InterfaceElement.
void Element::copyContentFrom | ( | const ConstElementPtr & | source | ) |
Copy all attributes and descendants from the given element to this one.
source | The element from which content is copied. |
StringResolverPtr Element::createStringResolver | ( | const string & | geom = EMPTY_STRING | ) | const |
Construct a StringResolver at the scope of this element. The returned object may be used to apply substring modifiers to data values in the context of a specific element, geometry, and material.
geom | An optional geometry name, which will be used to select the applicable set of geometry token substitutions. By default, no geometry token substitutions are applied. If the universal geometry name "/" is given, then all geometry token substitutions are applied, |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Return the index of the child, if any, with the given name. If no child with the given name is found, then -1 is returned.
|
inline |
|
inline |
|
inline |
ElementPtr Element::getDescendant | ( | const string & | namePath | ) | const |
Return the element specified by the given hierarchical name path, relative to the current element. If the name path is empty then the current element is returned. If no element is found at the given path, then an empty shared pointer is returned.
namePath | The relative name path of the specified element. |
|
inline |
DocumentPtr Element::getDocument | ( | ) |
Return the root document of our tree.
ConstDocumentPtr Element::getDocument | ( | ) | const |
Return the root document of our tree.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
string Element::getNamePath | ( | ConstElementPtr | relativeTo = nullptr | ) | const |
Return the element's hierarchical name path, relative to the root document. The name of each ancestor will be prepended in turn, separated by forward slashes.
relativeTo | If a valid ancestor element is specified, then the returned path will be relative to this ancestor. |
|
inline |
|
inline |
|
inline |
ElementPtr Element::getRoot | ( | ) |
Return the root element of our tree.
ConstElementPtr Element::getRoot | ( | ) | const |
Return the root element of our tree.
|
inline |
|
inline |
|
inlineprotected |
|
inline |
|
virtual |
Return the Edge with the given index that lies directly upstream from this element in the dataflow graph.
index | An optional index of the edge to be returned, where the valid index range may be determined with getUpstreamEdgeCount. |
|
inlinevirtual |
ElementPtr Element::getUpstreamElement | ( | size_t | index = 0 | ) | const |
Return the Element with the given index that lies directly upstream from this one in the dataflow graph.
index | An optional index of the element to be returned, where the valid index range may be determined with getUpstreamEdgeCount. |
|
inline |
|
inline |
|
inline |
|
inline |
bool Element::hasInheritanceCycle | ( | ) | const |
Return true if the inheritance chain for this element contains a cycle.
bool Element::hasInheritedBase | ( | ConstElementPtr | base | ) | const |
Return true if this element has the given element as an inherited base, taking the full inheritance chain into account.
|
inline |
|
inline |
|
inline |
|
inline |
bool Element::operator!= | ( | const Element & | rhs | ) | const |
Return true if the given element tree, including all descendants, differs from this one.
bool Element::operator== | ( | const Element & | rhs | ) | const |
Return true if the given element tree, including all descendants, is identical to this one.
|
protectedvirtual |
Reimplemented in InterfaceElement.
Remove the child element, if any, with the given name.
|
inlineprotected |
Set the value string of the given attribute.
Set the index of the child, if any, with the given name. If the given index is out of bounds, then an exception is thrown.
|
inline |
Set the element's name string. The name of a MaterialX element must be unique among all elements at the same scope.
Exception | if an element at the same scope already possesses the given name. |
GraphIterator Element::traverseGraph | ( | ) | const |
Traverse the dataflow graph from the given element to each of its upstream sources in depth-first order, using pre-order visitation.
ExceptionFoundCycle | if a cycle is encountered. |
Example usage with an implicit iterator:
Example usage with an explicit iterator:
InheritanceIterator Element::traverseInheritance | ( | ) | const |
Traverse the inheritance chain from the given element to each element from which it inherits.
ExceptionFoundCycle | if a cycle is encountered. |
Example usage:
TreeIterator Element::traverseTree | ( | ) | const |
Traverse the tree from the given element to each of its descendants in depth-first order, using pre-order visitation.
Example usage with an implicit iterator:
Example usage with an explicit iterator:
|
protectedvirtual |
Reimplemented in InterfaceElement.
|
virtual |
Validate that the given element tree, including all descendants, is consistent with the MaterialX specification.
Reimplemented in ValueElement, Document, Collection, Backdrop, NodeGraph, Output, Implementation, Input, GeomElement, PortElement, Node, and NodeDef.
|
protected |
|
protected |
|
protected |