HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Element.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_ELEMENT_H
7 #define MATERIALX_ELEMENT_H
8 
9 /// @file
10 /// Base and generic element classes
11 
12 #include <MaterialXCore/Export.h>
13 
15 #include <MaterialXCore/Util.h>
16 #include <MaterialXCore/Value.h>
17 
19 
20 class Element;
21 class TypedElement;
22 class ValueElement;
23 class Token;
24 class CommentElement;
25 class NewlineElement;
26 class GenericElement;
27 class StringResolver;
28 class Document;
29 
30 /// A shared pointer to an Element
31 using ElementPtr = shared_ptr<Element>;
32 /// A shared pointer to a const Element
33 using ConstElementPtr = shared_ptr<const Element>;
34 
35 /// A shared pointer to a TypedElement
36 using TypedElementPtr = shared_ptr<TypedElement>;
37 /// A shared pointer to a const TypedElement
38 using ConstTypedElementPtr = shared_ptr<const TypedElement>;
39 
40 /// A shared pointer to a ValueElement
41 using ValueElementPtr = shared_ptr<ValueElement>;
42 /// A shared pointer to a const ValueElement
43 using ConstValueElementPtr = shared_ptr<const ValueElement>;
44 
45 /// A shared pointer to a Token
46 using TokenPtr = shared_ptr<Token>;
47 /// A shared pointer to a const Token
48 using ConstTokenPtr = shared_ptr<const Token>;
49 
50 /// A shared pointer to a CommentElement
51 using CommentElementPtr = shared_ptr<CommentElement>;
52 /// A shared pointer to a const CommentElement
53 using ConstCommentElementPtr = shared_ptr<const CommentElement>;
54 
55 /// A shared pointer to a NewlineElement
56 using NewlineElementPtr = shared_ptr<NewlineElement>;
57 /// A shared pointer to a const NewlineElement
58 using ConstNewlineElementPtr = shared_ptr<const NewlineElement>;
59 
60 /// A shared pointer to a GenericElement
61 using GenericElementPtr = shared_ptr<GenericElement>;
62 /// A shared pointer to a const GenericElement
63 using ConstGenericElementPtr = shared_ptr<const GenericElement>;
64 
65 /// A shared pointer to a StringResolver
66 using StringResolverPtr = shared_ptr<StringResolver>;
67 
68 /// A hash map from strings to elements
69 using ElementMap = std::unordered_map<string, ElementPtr>;
70 
71 /// A standard function taking an ElementPtr and returning a boolean.
72 using ElementPredicate = std::function<bool(ConstElementPtr)>;
73 
74 /// @class Element
75 /// The base class for MaterialX elements.
76 ///
77 /// An Element is a named object within a Document, which may possess any
78 /// number of child elements and attributes.
79 class MX_CORE_API Element : public std::enable_shared_from_this<Element>
80 {
81  protected:
82  Element(ElementPtr parent, const string& category, const string& name) :
83  _category(category),
84  _name(name),
85  _parent(parent),
86  _root(parent ? parent->getRoot() : nullptr)
87  {
88  }
89 
90  public:
91  virtual ~Element() { }
92  Element(const Element&) = delete;
93  Element& operator=(const Element&) = delete;
94 
95  protected:
96  using DocumentPtr = shared_ptr<Document>;
97  using ConstDocumentPtr = shared_ptr<const Document>;
98 
99  template <class T> friend class ElementRegistry;
100 
101  public:
102  /// Return true if the given element tree, including all descendants,
103  /// is identical to this one.
104  bool operator==(const Element& rhs) const;
105 
106  /// Return true if the given element tree, including all descendants,
107  /// differs from this one.
108  bool operator!=(const Element& rhs) const;
109 
110  /// @name Category
111  /// @{
112 
113  /// Set the element's category string.
114  void setCategory(const string& category)
115  {
116  _category = category;
117  }
118 
119  /// Return the element's category string. The category of a MaterialX
120  /// element represents its role within the document, with common examples
121  /// being "material", "nodegraph", and "image".
122  const string& getCategory() const
123  {
124  return _category;
125  }
126 
127  /// @}
128  /// @name Name
129  /// @{
130 
131  /// Set the element's name string. The name of a MaterialX element must be
132  /// unique among all elements at the same scope.
133  /// @throws Exception if an element at the same scope already possesses the
134  /// given name.
135  void setName(const string& name);
136 
137  /// Return the element's name string.
138  const string& getName() const
139  {
140  return _name;
141  }
142 
143  /// Return the element's hierarchical name path, relative to the root
144  /// document. The name of each ancestor will be prepended in turn,
145  /// separated by forward slashes.
146  /// @param relativeTo If a valid ancestor element is specified, then
147  /// the returned path will be relative to this ancestor.
148  string getNamePath(ConstElementPtr relativeTo = nullptr) const;
149 
150  /// Return the element specified by the given hierarchical name path,
151  /// relative to the current element. If the name path is empty then the
152  /// current element is returned. If no element is found at the given path,
153  /// then an empty shared pointer is returned.
154  /// @param namePath The relative name path of the specified element.
155  ElementPtr getDescendant(const string& namePath) const;
156 
157  /// @}
158  /// @name File Prefix
159  /// @{
160 
161  /// Set the element's file prefix string.
162  void setFilePrefix(const string& prefix)
163  {
164  setAttribute(FILE_PREFIX_ATTRIBUTE, prefix);
165  }
166 
167  /// Return true if the given element has a file prefix string.
168  bool hasFilePrefix() const
169  {
170  return hasAttribute(FILE_PREFIX_ATTRIBUTE);
171  }
172 
173  /// Return the element's file prefix string.
174  const string& getFilePrefix() const
175  {
176  return getAttribute(FILE_PREFIX_ATTRIBUTE);
177  }
178 
179  /// Return the file prefix string that is active at the scope of this
180  /// element, taking all ancestor elements into account.
181  const string& getActiveFilePrefix() const
182  {
183  for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent())
184  {
185  if (elem->hasFilePrefix())
186  {
187  return elem->getFilePrefix();
188  }
189  }
190  return EMPTY_STRING;
191  }
192 
193  /// @}
194  /// @name Geom Prefix
195  /// @{
196 
197  /// Set the element's geom prefix string.
198  void setGeomPrefix(const string& prefix)
199  {
200  setAttribute(GEOM_PREFIX_ATTRIBUTE, prefix);
201  }
202 
203  /// Return true if the given element has a geom prefix string.
204  bool hasGeomPrefix() const
205  {
206  return hasAttribute(GEOM_PREFIX_ATTRIBUTE);
207  }
208 
209  /// Return the element's geom prefix string.
210  const string& getGeomPrefix() const
211  {
212  return getAttribute(GEOM_PREFIX_ATTRIBUTE);
213  }
214 
215  /// Return the geom prefix string that is active at the scope of this
216  /// element, taking all ancestor elements into account.
217  const string& getActiveGeomPrefix() const
218  {
219  for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent())
220  {
221  if (elem->hasGeomPrefix())
222  {
223  return elem->getGeomPrefix();
224  }
225  }
226  return EMPTY_STRING;
227  }
228 
229  /// @}
230  /// @name Color Space
231  /// @{
232 
233  /// Set the element's color space string.
234  void setColorSpace(const string& colorSpace)
235  {
236  setAttribute(COLOR_SPACE_ATTRIBUTE, colorSpace);
237  }
238 
239  /// Return true if the given element has a color space string.
240  bool hasColorSpace() const
241  {
242  return hasAttribute(COLOR_SPACE_ATTRIBUTE);
243  }
244 
245  /// Return the element's color space string.
246  const string& getColorSpace() const
247  {
248  return getAttribute(COLOR_SPACE_ATTRIBUTE);
249  }
250 
251  /// Return the color space string that is active at the scope of this
252  /// element, taking all ancestor elements into account.
253  const string& getActiveColorSpace() const
254  {
255  for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent())
256  {
257  if (elem->hasColorSpace())
258  {
259  return elem->getColorSpace();
260  }
261  }
262  return EMPTY_STRING;
263  }
264 
265  /// @}
266  /// @name Inheritance
267  /// @{
268 
269  /// Set the inherit string of this element.
270  void setInheritString(const string& inherit)
271  {
272  setAttribute(INHERIT_ATTRIBUTE, inherit);
273  }
274 
275  /// Return true if this element has an inherit string.
276  bool hasInheritString() const
277  {
278  return hasAttribute(INHERIT_ATTRIBUTE);
279  }
280 
281  /// Return the inherit string of this element.
282  const string& getInheritString() const
283  {
284  return getAttribute(INHERIT_ATTRIBUTE);
285  }
286 
287  /// Set the element that this one directly inherits from.
289  {
290  if (super)
291  {
292  setInheritString(super->getName());
293  }
294  else
295  {
296  removeAttribute(INHERIT_ATTRIBUTE);
297  }
298  }
299 
300  /// Return the element, if any, that this one directly inherits from.
302  {
303  return hasInheritString() ? resolveNameReference<Element>(getInheritString()) : nullptr;
304  }
305 
306  /// Return true if this element has the given element as an inherited base,
307  /// taking the full inheritance chain into account.
308  bool hasInheritedBase(ConstElementPtr base) const;
309 
310  /// Return true if the inheritance chain for this element contains a cycle.
311  bool hasInheritanceCycle() const;
312 
313  /// @}
314  /// @name Namespace
315  /// @{
316 
317  /// Set the namespace string of this element.
318  void setNamespace(const string& space)
319  {
320  setAttribute(NAMESPACE_ATTRIBUTE, space);
321  }
322 
323  /// Return true if this element has a namespace string.
324  bool hasNamespace() const
325  {
326  return hasAttribute(NAMESPACE_ATTRIBUTE);
327  }
328 
329  /// Return the namespace string of this element.
330  const string& getNamespace() const
331  {
332  return getAttribute(NAMESPACE_ATTRIBUTE);
333  }
334 
335  /// Return a qualified version of the given name, taking the namespace at the
336  /// scope of this element into account.
337  string getQualifiedName(const string& name) const
338  {
339  for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent())
340  {
341  const string& namespaceStr = elem->getNamespace();
342  if (!namespaceStr.empty())
343  {
344  // Check if the name is qualified already.
345  const size_t i = name.find_first_of(NAME_PREFIX_SEPARATOR);
346  if (i != string::npos && name.substr(0, i) == namespaceStr)
347  {
348  // The name is already qualified with this namespace,
349  // so just return it as is.
350  return name;
351  }
352  return namespaceStr + NAME_PREFIX_SEPARATOR + name;
353  }
354  }
355  return name;
356  }
357 
358  /// @}
359  /// @name Documentation String
360  /// @{
361 
362  /// Set the documentation string of this element.
363  void setDocString(const string& doc)
364  {
365  setAttribute(DOC_ATTRIBUTE, doc);
366  }
367 
368  /// Return the documentation string of this element
369  string getDocString() const
370  {
371  return getAttribute(DOC_ATTRIBUTE);
372  }
373 
374  /// @}
375  /// @name Subclass
376  /// @{
377 
378  /// Return true if this element belongs to the given subclass.
379  /// If a category string is specified, then both subclass and category
380  /// matches are required.
381  template <class T> bool isA(const string& category = EMPTY_STRING) const
382  {
383  if (!asA<T>())
384  return false;
385  if (!category.empty() && getCategory() != category)
386  return false;
387  return true;
388  }
389 
390  /// Dynamic cast to an instance of the given subclass.
391  template <class T> shared_ptr<T> asA();
392 
393  /// Dynamic cast to a const instance of the given subclass.
394  template <class T> shared_ptr<const T> asA() const;
395 
396  /// @}
397  /// @name Child Elements
398  /// @{
399 
400  /// Add a child element of the given subclass and name.
401  /// @param name The name of the new child element.
402  /// If no name is specified, then a unique name will automatically be
403  /// generated.
404  /// @throws Exception if a child of this element already possesses the
405  /// given name.
406  /// @return A shared pointer to the new child element.
407  template <class T> shared_ptr<T> addChild(const string& name = EMPTY_STRING);
408 
409  /// Add a child element of the given category and name.
410  /// @param category The category string of the new child element.
411  /// If the category string is recognized, then the correponding Element
412  /// subclass is generated; otherwise, a GenericElement is generated.
413  /// @param name The name of the new child element.
414  /// If no name is specified, then a unique name will automatically be
415  /// generated.
416  /// @throws Exception if a child of this element already possesses the
417  /// given name.
418  /// @return A shared pointer to the new child element.
419  ElementPtr addChildOfCategory(const string& category, string name = EMPTY_STRING);
420 
421  /// Change the category of the given child element.
422  /// @param child The child element that will be modified.
423  /// @param category The new category string for the child element.
424  /// @return A shared pointer to a new child element, containing the contents
425  /// of the original child but with a new category and subclass.
426  ElementPtr changeChildCategory(ElementPtr child, const string& category);
427 
428  /// Return the child element, if any, with the given name.
429  ElementPtr getChild(const string& name) const
430  {
431  ElementMap::const_iterator it = _childMap.find(name);
432  return (it != _childMap.end()) ? it->second : ElementPtr();
433  }
434 
435  /// Return the child element, if any, with the given name and subclass.
436  /// If a child with the given name exists, but belongs to a different
437  /// subclass, then an empty shared pointer is returned.
438  template <class T> shared_ptr<T> getChildOfType(const string& name) const
439  {
440  ElementPtr child = getChild(name);
441  return child ? child->asA<T>() : shared_ptr<T>();
442  }
443 
444  /// Return a constant vector of all child elements.
445  /// The returned vector maintains the order in which children were added.
446  const vector<ElementPtr>& getChildren() const
447  {
448  return _childOrder;
449  }
450 
451  /// Return a vector of all child elements that are instances of the given
452  /// subclass, optionally filtered by the given category string. The returned
453  /// vector maintains the order in which children were added.
454  template <class T> vector<shared_ptr<T>> getChildrenOfType(const string& category = EMPTY_STRING) const
455  {
456  vector<shared_ptr<T>> children;
457  for (ElementPtr child : _childOrder)
458  {
459  shared_ptr<T> instance = child->asA<T>();
460  if (!instance)
461  continue;
462  if (!category.empty() && child->getCategory() != category)
463  continue;
464  children.push_back(instance);
465  }
466  return children;
467  }
468 
469  /// Set the index of the child, if any, with the given name.
470  /// If the given index is out of bounds, then an exception is thrown.
471  void setChildIndex(const string& name, int index);
472 
473  /// Return the index of the child, if any, with the given name.
474  /// If no child with the given name is found, then -1 is returned.
475  int getChildIndex(const string& name) const;
476 
477  /// Remove the child element, if any, with the given name.
478  void removeChild(const string& name);
479 
480  /// Remove the child element, if any, with the given name and subclass.
481  /// If a child with the given name exists, but belongs to a different
482  /// subclass, then this method has no effect.
483  template <class T> void removeChildOfType(const string& name)
484  {
485  if (getChildOfType<T>(name))
486  removeChild(name);
487  }
488 
489  /// @}
490  /// @name Attributes
491  /// @{
492 
493  /// Set the value string of the given attribute.
494  void setAttribute(const string& attrib, const string& value);
495 
496  /// Return true if the given attribute is present.
497  bool hasAttribute(const string& attrib) const
498  {
499  return _attributeMap.count(attrib) != 0;
500  }
501 
502  /// Return the value string of the given attribute. If the given attribute
503  /// is not present, then an empty string is returned.
504  const string& getAttribute(const string& attrib) const
505  {
506  StringMap::const_iterator it = _attributeMap.find(attrib);
507  return (it != _attributeMap.end()) ? it->second : EMPTY_STRING;
508  }
509 
510  /// Return a vector of stored attribute names, in the order they were set.
512  {
513  return _attributeOrder;
514  }
515 
516  /// Set the value of an implicitly typed attribute. Since an attribute
517  /// stores no explicit type, the same type argument must be used in
518  /// corresponding calls to getTypedAttribute.
519  template <class T> void setTypedAttribute(const string& attrib, const T& data)
520  {
521  setAttribute(attrib, toValueString(data));
522  }
523 
524  /// Return the value of an implicitly typed attribute. If the given
525  /// attribute is not present, or cannot be converted to the given data
526  /// type, then the zero value for the data type is returned.
527  template <class T> T getTypedAttribute(const string& attrib) const
528  {
529  if (hasAttribute(attrib))
530  {
531  try
532  {
533  return fromValueString<T>(getAttribute(attrib));
534  }
535  catch (ExceptionTypeError&)
536  {
537  }
538  }
539  return {};
540  }
541 
542  /// Remove the given attribute, if present.
543  void removeAttribute(const string& attrib);
544 
545  /// @}
546  /// @name Self And Ancestor Elements
547  /// @{
548 
549  /// Return our self pointer.
551  {
552  return shared_from_this();
553  }
554 
555  /// Return our self pointer.
557  {
558  return shared_from_this();
559  }
560 
561  /// Return our parent element.
563  {
564  return _parent.lock();
565  }
566 
567  /// Return our parent element.
569  {
570  return _parent.lock();
571  }
572 
573  /// Return the root element of our tree.
574  ElementPtr getRoot();
575 
576  /// Return the root element of our tree.
577  ConstElementPtr getRoot() const;
578 
579  /// Return the root document of our tree.
580  DocumentPtr getDocument();
581 
582  /// Return the root document of our tree.
583  ConstDocumentPtr getDocument() const;
584 
585  /// Return the first ancestor of the given subclass, or an empty shared
586  /// pointer if no ancestor of this subclass is found.
587  template <class T> shared_ptr<const T> getAncestorOfType() const
588  {
589  for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent())
590  {
591  shared_ptr<const T> typedElem = elem->asA<T>();
592  if (typedElem)
593  {
594  return typedElem;
595  }
596  }
597  return nullptr;
598  }
599 
600  /// @}
601  /// @name Traversal
602  /// @{
603 
604  /// Traverse the tree from the given element to each of its descendants in
605  /// depth-first order, using pre-order visitation.
606  /// @return A TreeIterator object.
607  /// @details Example usage with an implicit iterator:
608  /// @code
609  /// for (ElementPtr elem : inputElem->traverseTree())
610  /// {
611  /// cout << elem->asString() << endl;
612  /// }
613  /// @endcode
614  /// Example usage with an explicit iterator:
615  /// @code
616  /// for (mx::TreeIterator it = inputElem->traverseTree().begin(); it != mx::TreeIterator::end(); ++it)
617  /// {
618  /// mx::ElementPtr elem = it.getElement();
619  /// cout << elem->asString() << " at depth " << it.getElementDepth() << endl;
620  /// }
621  /// @endcode
622  TreeIterator traverseTree() const;
623 
624  /// Traverse the dataflow graph from the given element to each of its
625  /// upstream sources in depth-first order, using pre-order visitation.
626  /// @throws ExceptionFoundCycle if a cycle is encountered.
627  /// @return A GraphIterator object.
628  /// @details Example usage with an implicit iterator:
629  /// @code
630  /// for (Edge edge : inputElem->traverseGraph())
631  /// {
632  /// ElementPtr upElem = edge.getUpstreamElement();
633  /// ElementPtr downElem = edge.getDownstreamElement();
634  /// cout << upElem->asString() << " lies upstream from " << downElem->asString() << endl;
635  /// }
636  /// @endcode
637  /// Example usage with an explicit iterator:
638  /// @code
639  /// for (mx::GraphIterator it = inputElem->traverseGraph().begin(); it != mx::GraphIterator::end(); ++it)
640  /// {
641  /// mx::ElementPtr elem = it.getUpstreamElement();
642  /// cout << elem->asString() << " at depth " << it.getElementDepth() << endl;
643  /// }
644  /// @endcode
645  /// @sa getUpstreamEdge
646  /// @sa getUpstreamElement
647  GraphIterator traverseGraph() const;
648 
649  /// Return the Edge with the given index that lies directly upstream from
650  /// this element in the dataflow graph.
651  /// @param index An optional index of the edge to be returned, where the
652  /// valid index range may be determined with getUpstreamEdgeCount.
653  /// @return The upstream Edge, if valid, or an empty Edge object.
654  virtual Edge getUpstreamEdge(size_t index = 0) const;
655 
656  /// Return the number of queriable upstream edges for this element.
657  virtual size_t getUpstreamEdgeCount() const
658  {
659  return 0;
660  }
661 
662  /// Return the Element with the given index that lies directly upstream
663  /// from this one in the dataflow graph.
664  /// @param index An optional index of the element to be returned, where the
665  /// valid index range may be determined with getUpstreamEdgeCount.
666  /// @return The upstream Element, if valid, or an empty ElementPtr.
667  ElementPtr getUpstreamElement(size_t index = 0) const;
668 
669  /// Traverse the inheritance chain from the given element to each element
670  /// from which it inherits.
671  /// @throws ExceptionFoundCycle if a cycle is encountered.
672  /// @return An InheritanceIterator object.
673  /// @details Example usage:
674  /// @code
675  /// ConstElementPtr derivedElem;
676  /// for (ConstElementPtr elem : inputElem->traverseInheritance())
677  /// {
678  /// if (derivedElem)
679  /// cout << derivedElem->asString() << " inherits from " << elem->asString() << endl;
680  /// derivedElem = elem;
681  /// }
682  /// @endcode
683  InheritanceIterator traverseInheritance() const;
684 
685  /// @}
686  /// @name Source URI
687  /// @{
688 
689  /// Set the element's source URI.
690  /// @param sourceUri A URI string representing the resource from which
691  /// this element originates. This string may be used by serialization
692  /// and deserialization routines to maintain hierarchies of include
693  /// references.
694  void setSourceUri(const string& sourceUri)
695  {
696  _sourceUri = sourceUri;
697  }
698 
699  /// Return true if this element has a source URI.
700  bool hasSourceUri() const
701  {
702  return !_sourceUri.empty();
703  }
704 
705  /// Return the element's source URI.
706  const string& getSourceUri() const
707  {
708  return _sourceUri;
709  }
710 
711  /// Return the source URI that is active at the scope of this
712  /// element, taking all ancestor elements into account.
713  const string& getActiveSourceUri() const
714  {
715  for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent())
716  {
717  if (elem->hasSourceUri())
718  {
719  return elem->getSourceUri();
720  }
721  }
722  return EMPTY_STRING;
723  }
724 
725  /// @}
726  /// @name Validation
727  /// @{
728 
729  /// Validate that the given element tree, including all descendants, is
730  /// consistent with the MaterialX specification.
731  virtual bool validate(string* message = nullptr) const;
732 
733  /// @}
734  /// @name Utility
735  /// @{
736 
737  /// Copy all attributes and descendants from the given element to this one.
738  /// @param source The element from which content is copied.
739  void copyContentFrom(const ConstElementPtr& source);
740 
741  /// Clear all attributes and descendants from this element.
742  virtual void clearContent();
743 
744  /// Using the input name as a starting point, modify it to create a valid,
745  /// unique name for a child element.
746  string createValidChildName(string name) const
747  {
748  name = name.empty() ? "_" : createValidName(name);
749  while (_childMap.count(name))
750  {
751  name = incrementName(name);
752  }
753  return name;
754  }
755 
756  /// Construct a StringResolver at the scope of this element. The returned
757  /// object may be used to apply substring modifiers to data values in the
758  /// context of a specific element, geometry, and material.
759  /// @param geom An optional geometry name, which will be used to select the
760  /// applicable set of geometry token substitutions. By default, no
761  /// geometry token substitutions are applied. If the universal geometry
762  /// name "/" is given, then all geometry token substitutions are applied,
763  /// @return A shared pointer to a StringResolver.
764  StringResolverPtr createStringResolver(const string& geom = EMPTY_STRING) const;
765 
766  /// Return a single-line description of this element, including its category,
767  /// name, and attributes.
768  string asString() const;
769 
770  /// @}
771 
772  protected:
773  // Resolve a reference to a named element at the scope of the given parent,
774  // taking the namespace at the scope of this element into account. If no parent
775  // is provided, then the root scope of the document is used.
776  template <class T> shared_ptr<T> resolveNameReference(const string& name, ConstElementPtr parent = nullptr) const
777  {
778  ConstElementPtr scope = parent ? parent : getRoot();
779  shared_ptr<T> child = scope->getChildOfType<T>(getQualifiedName(name));
780  return child ? child : scope->getChildOfType<T>(name);
781  }
782 
783  // Enforce a requirement within a validate method, updating the validation
784  // state and optional output text if the requirement is not met.
785  void validateRequire(bool expression, bool& res, string* message, const string& errorDesc) const;
786 
787  public:
788  static const string NAME_ATTRIBUTE;
789  static const string FILE_PREFIX_ATTRIBUTE;
790  static const string GEOM_PREFIX_ATTRIBUTE;
791  static const string COLOR_SPACE_ATTRIBUTE;
792  static const string INHERIT_ATTRIBUTE;
793  static const string NAMESPACE_ATTRIBUTE;
794  static const string DOC_ATTRIBUTE;
795 
796  protected:
797  virtual void registerChildElement(ElementPtr child);
798  virtual void unregisterChildElement(ElementPtr child);
799 
800  // Return a non-const copy of our self pointer, for use in constructing
801  // graph traversal objects that require non-const storage.
803  {
804  return std::const_pointer_cast<Element>(shared_from_this());
805  }
806 
807  protected:
808  string _category;
809  string _name;
810  string _sourceUri;
811 
813  vector<ElementPtr> _childOrder;
814 
817 
818  weak_ptr<Element> _parent;
819  weak_ptr<Element> _root;
820 
821  private:
822  template <class T> static ElementPtr createElement(ElementPtr parent, const string& name)
823  {
824  return std::make_shared<T>(parent, name);
825  }
826 
827  private:
828  using CreatorFunction = ElementPtr (*)(ElementPtr, const string&);
829  using CreatorMap = std::unordered_map<string, CreatorFunction>;
830 
831  static CreatorMap _creatorMap;
832 };
833 
834 /// @class TypedElement
835 /// The base class for typed elements.
837 {
838  protected:
839  TypedElement(ElementPtr parent, const string& category, const string& name) :
840  Element(parent, category, name)
841  {
842  }
843 
844  public:
845  virtual ~TypedElement() { }
846 
847  protected:
848  using TypeDefPtr = shared_ptr<class TypeDef>;
849 
850  public:
851  /// @name Type String
852  /// @{
853 
854  /// Set the element's type string.
855  void setType(const string& type)
856  {
857  setAttribute(TYPE_ATTRIBUTE, type);
858  }
859 
860  /// Return true if the given element has a type string.
861  bool hasType() const
862  {
863  return hasAttribute(TYPE_ATTRIBUTE);
864  }
865 
866  /// Return the element's type string.
867  virtual const string& getType() const
868  {
869  return getAttribute(TYPE_ATTRIBUTE);
870  }
871 
872  /// Return true if the element is of color type.
873  bool isColorType() const
874  {
875  return getType() == "color3" || getType() == "color4";
876  }
877 
878  /// Return true if the element is of multi-output type.
879  bool isMultiOutputType() const
880  {
881  return getType() == MULTI_OUTPUT_TYPE_STRING;
882  }
883 
884  /// @}
885  /// @name TypeDef References
886  /// @{
887 
888  /// Return the TypeDef declaring the type string of this element. If no
889  /// matching TypeDef is found, then an empty shared pointer is returned.
890  TypeDefPtr getTypeDef() const;
891 
892  /// @}
893 
894  public:
895  static const string TYPE_ATTRIBUTE;
896 };
897 
898 /// @class ValueElement
899 /// The base class for elements that support typed values.
901 {
902  protected:
903  ValueElement(ElementPtr parent, const string& category, const string& name) :
904  TypedElement(parent, category, name)
905  {
906  }
907 
908  public:
909  virtual ~ValueElement() { }
910 
911  /// @name Value String
912  /// @{
913 
914  /// Set the value string of an element.
915  void setValueString(const string& value)
916  {
917  setAttribute(VALUE_ATTRIBUTE, value);
918  }
919 
920  /// Return true if the given element has a value string.
921  bool hasValueString() const
922  {
923  return hasAttribute(VALUE_ATTRIBUTE);
924  }
925 
926  /// Get the value string of a element.
927  const string& getValueString() const
928  {
929  return getAttribute(VALUE_ATTRIBUTE);
930  }
931 
932  /// Return the resolved value string of an element, applying any string
933  /// substitutions that are defined at the element's scope.
934  /// @param resolver An optional string resolver, which will be used to
935  /// apply string substitutions. By default, a new string resolver
936  /// will be created at this scope and applied to the return value.
937  string getResolvedValueString(StringResolverPtr resolver = nullptr) const;
938 
939  /// @}
940  /// @name Interface Names
941  /// @{
942 
943  /// Set the interface name of an element.
944  void setInterfaceName(const string& name)
945  {
946  setAttribute(INTERFACE_NAME_ATTRIBUTE, name);
947  }
948 
949  /// Return true if the given element has an interface name.
950  bool hasInterfaceName() const
951  {
952  return hasAttribute(INTERFACE_NAME_ATTRIBUTE);
953  }
954 
955  /// Return the interface name of an element.
956  const string& getInterfaceName() const
957  {
958  return getAttribute(INTERFACE_NAME_ATTRIBUTE);
959  }
960 
961  /// @}
962  /// @name Implementation Names
963  /// @{
964 
965  /// Set the implementation name of an element.
966  void setImplementationName(const string& name)
967  {
968  setAttribute(IMPLEMENTATION_NAME_ATTRIBUTE, name);
969  }
970 
971  /// Return true if the given element has an implementation name.
973  {
974  return hasAttribute(IMPLEMENTATION_NAME_ATTRIBUTE);
975  }
976 
977  /// Return the implementation name of an element.
978  const string& getImplementationName() const
979  {
980  return getAttribute(IMPLEMENTATION_NAME_ATTRIBUTE);
981  }
982 
983  /// @}
984  /// @name Typed Value
985  /// @{
986 
987  /// Set the typed value of an element.
988  template <class T> void setValue(const T& value, const string& type = EMPTY_STRING)
989  {
990  setType(!type.empty() ? type : getTypeString<T>());
991  setValueString(toValueString(value));
992  }
993 
994  /// Set the typed value of an element from a C-style string.
995  void setValue(const char* value, const string& type = EMPTY_STRING)
996  {
997  setValue(value ? string(value) : EMPTY_STRING, type);
998  }
999 
1000  /// Return true if the element possesses a typed value.
1001  bool hasValue() const
1002  {
1003  return hasAttribute(VALUE_ATTRIBUTE);
1004  }
1005 
1006  /// Return the typed value of an element as a generic value object, which
1007  /// may be queried to access its data.
1008  ///
1009  /// @return A shared pointer to the typed value of this element, or an
1010  /// empty shared pointer if no value is present.
1012  {
1013  if (!hasValue())
1014  return ValuePtr();
1015  return Value::createValueFromStrings(getValueString(), getType());
1016  }
1017 
1018  /// Return the resolved value of an element as a generic value object, which
1019  /// may be queried to access its data.
1020  ///
1021  /// @param resolver An optional string resolver, which will be used to
1022  /// apply string substitutions. By default, a new string resolver
1023  /// will be created at this scope and applied to the return value.
1024  /// @return A shared pointer to the typed value of this element, or an
1025  /// empty shared pointer if no value is present.
1026  ValuePtr getResolvedValue(StringResolverPtr resolver = nullptr) const
1027  {
1028  if (!hasValue())
1029  return ValuePtr();
1030  return Value::createValueFromStrings(getResolvedValueString(resolver), getType());
1031  }
1032 
1033  /// Return the default value for this element as a generic value object, which
1034  /// may be queried to access its data.
1035  ///
1036  /// @return A shared pointer to a typed value, or an empty shared pointer if
1037  /// no default value was found.
1038  ValuePtr getDefaultValue() const;
1039 
1040  /// @}
1041  /// @name Units
1042  /// @{
1043 
1044  /// Set the unit string of an element.
1045  void setUnit(const string& unit)
1046  {
1047  setAttribute(UNIT_ATTRIBUTE, unit);
1048  }
1049 
1050  /// Return true if the given element has a unit string.
1051  bool hasUnit() const
1052  {
1053  return hasAttribute(UNIT_ATTRIBUTE);
1054  }
1055 
1056  /// Return the unit string of an element.
1057  const string& getUnit() const
1058  {
1059  return getAttribute(UNIT_ATTRIBUTE);
1060  }
1061 
1062  /// Return the unit defined by the assocaited NodeDef if this element
1063  /// is a child of a Node.
1064  const string& getActiveUnit() const;
1065 
1066  /// Set the unit type of an element.
1067  void setUnitType(const string& unit)
1068  {
1069  setAttribute(UNITTYPE_ATTRIBUTE, unit);
1070  }
1071 
1072  /// Return true if the given element has a unit type.
1073  bool hasUnitType() const
1074  {
1075  return hasAttribute(UNITTYPE_ATTRIBUTE);
1076  }
1077 
1078  /// Return the unit type of an element.
1079  const string& getUnitType() const
1080  {
1081  return getAttribute(UNITTYPE_ATTRIBUTE);
1082  }
1083 
1084  /// @}
1085  /// @name Uniform attribute
1086  /// @{
1087 
1088  /// Set the uniform attribute flag on this element.
1089  void setIsUniform(bool value)
1090  {
1091  setTypedAttribute<bool>(UNIFORM_ATTRIBUTE, value);
1092  }
1093 
1094  /// The the uniform attribute flag for this element.
1095  bool getIsUniform() const
1096  {
1097  return getTypedAttribute<bool>(UNIFORM_ATTRIBUTE);
1098  }
1099 
1100  /// @}
1101  /// @name Validation
1102  /// @{
1103 
1104  /// Validate that the given element tree, including all descendants, is
1105  /// consistent with the MaterialX specification.
1106  bool validate(string* message = nullptr) const override;
1107 
1108  /// @}
1109 
1110  public:
1111  static const string VALUE_ATTRIBUTE;
1112  static const string INTERFACE_NAME_ATTRIBUTE;
1113  static const string IMPLEMENTATION_NAME_ATTRIBUTE;
1114  static const string IMPLEMENTATION_TYPE_ATTRIBUTE;
1115  static const string ENUM_ATTRIBUTE;
1116  static const string ENUM_VALUES_ATTRIBUTE;
1117  static const string UI_NAME_ATTRIBUTE;
1118  static const string UI_FOLDER_ATTRIBUTE;
1119  static const string UI_MIN_ATTRIBUTE;
1120  static const string UI_MAX_ATTRIBUTE;
1121  static const string UI_SOFT_MIN_ATTRIBUTE;
1122  static const string UI_SOFT_MAX_ATTRIBUTE;
1123  static const string UI_STEP_ATTRIBUTE;
1124  static const string UI_ADVANCED_ATTRIBUTE;
1125  static const string UNIT_ATTRIBUTE;
1126  static const string UNITTYPE_ATTRIBUTE;
1127  static const string UNIFORM_ATTRIBUTE;
1128 };
1129 
1130 /// @class Token
1131 /// A token element representing a string value.
1132 ///
1133 /// Token elements are used to define input and output values for string
1134 /// substitutions in image filenames.
1136 {
1137  public:
1138  Token(ElementPtr parent, const string& name) :
1139  ValueElement(parent, CATEGORY, name)
1140  {
1141  }
1142  virtual ~Token() { }
1143 
1144  public:
1145  static const string CATEGORY;
1146 };
1147 
1148 /// @class CommentElement
1149 /// An element representing a block of descriptive text within a document, which will
1150 /// be stored a comment when the document is written out.
1151 ///
1152 /// The comment text may be accessed with the methods Element::setDocString and
1153 /// Element::getDocString.
1154 ///
1156 {
1157  public:
1158  CommentElement(ElementPtr parent, const string& name) :
1159  Element(parent, CATEGORY, name)
1160  {
1161  }
1162  virtual ~CommentElement() { }
1163 
1164  public:
1165  static const string CATEGORY;
1166 };
1167 
1168 /// @class NewlineElement
1169 /// An element representing a newline within a document.
1171 {
1172  public:
1173  NewlineElement(ElementPtr parent, const string& name) :
1174  Element(parent, CATEGORY, name)
1175  {
1176  }
1177  virtual ~NewlineElement() { }
1178 
1179  public:
1180  static const string CATEGORY;
1181 };
1182 
1183 /// @class GenericElement
1184 /// A generic element subclass, for instantiating elements with unrecognized categories.
1186 {
1187  public:
1188  GenericElement(ElementPtr parent, const string& name) :
1189  Element(parent, CATEGORY, name)
1190  {
1191  }
1192  virtual ~GenericElement() { }
1193 
1194  public:
1195  static const string CATEGORY;
1196 };
1197 
1198 /// @class StringResolver
1199 /// A helper object for applying string modifiers to data values in the context
1200 /// of a specific element and geometry.
1201 ///
1202 /// A StringResolver may be constructed through the Element::createStringResolver
1203 /// method, which initializes it in the context of a specific element, geometry,
1204 /// and material.
1205 ///
1206 /// Calling the StringResolver::resolve method applies all modifiers to a
1207 /// particular string value.
1208 ///
1209 /// Methods such as StringResolver::setFilePrefix may be used to edit the
1210 /// stored string modifiers before calling StringResolver::resolve.
1212 {
1213  public:
1214  /// Create a new string resolver.
1216  {
1217  return StringResolverPtr(new StringResolver());
1218  }
1219 
1220  virtual ~StringResolver() { }
1221 
1222  /// @name File Prefix
1223  /// @{
1224 
1225  /// Set the file prefix for this context.
1226  void setFilePrefix(const string& filePrefix)
1227  {
1228  _filePrefix = filePrefix;
1229  }
1230 
1231  /// Return the file prefix for this context.
1232  const string& getFilePrefix() const
1233  {
1234  return _filePrefix;
1235  }
1236 
1237  /// @}
1238  /// @name Geom Prefix
1239  /// @{
1240 
1241  /// Set the geom prefix for this context.
1242  void setGeomPrefix(const string& geomPrefix)
1243  {
1244  _geomPrefix = geomPrefix;
1245  }
1246 
1247  /// Return the geom prefix for this context.
1248  const string& getGeomPrefix() const
1249  {
1250  return _geomPrefix;
1251  }
1252 
1253  /// @}
1254  /// @name Filename Substitutions
1255  /// @{
1256 
1257  /// Set the UDIM substring substitution for filename data values.
1258  /// This string will be used to replace the standard <UDIM> token.
1259  void setUdimString(const string& udim);
1260 
1261  /// Set the UV-tile substring substitution for filename data values.
1262  /// This string will be used to replace the standard <UVTILE> token.
1263  void setUvTileString(const string& uvTile);
1264 
1265  /// Set an arbitrary substring substitution for filename data values.
1266  void setFilenameSubstitution(const string& key, const string& value)
1267  {
1268  _filenameMap[key] = value;
1269  }
1270 
1271  /// Add filename token substitutions for a given element
1272  void addTokenSubstitutions(ConstElementPtr element);
1273 
1274  /// Return the map of filename substring substitutions.
1276  {
1277  return _filenameMap;
1278  }
1279 
1280  /// @}
1281  /// @name Geometry Name Substitutions
1282  /// @{
1283 
1284  /// Set an arbitrary substring substitution for geometry name data values.
1285  void setGeomNameSubstitution(const string& key, const string& value)
1286  {
1287  _geomNameMap[key] = value;
1288  }
1289 
1290  /// Return the map of geometry name substring substitutions.
1292  {
1293  return _geomNameMap;
1294  }
1295 
1296  /// @}
1297  /// @name Resolution
1298  /// @{
1299 
1300  /// Given an input string and type, apply all appropriate modifiers and
1301  /// return the resulting string.
1302  virtual string resolve(const string& str, const string& type) const;
1303 
1304  /// Return true if the given type may be resolved by this class.
1305  static bool isResolvedType(const string& type)
1306  {
1307  return type == FILENAME_TYPE_STRING || type == GEOMNAME_TYPE_STRING;
1308  }
1309 
1310  /// @}
1311 
1312  protected:
1314 
1315  protected:
1316  string _filePrefix;
1317  string _geomPrefix;
1320 };
1321 
1322 /// @class ExceptionOrphanedElement
1323 /// An exception that is thrown when an ElementPtr is used after its owning
1324 /// Document has gone out of scope.
1326 {
1327  public:
1328  using Exception::Exception;
1329 };
1330 
1331 template <class T> shared_ptr<T> Element::addChild(const string& name)
1332 {
1333  string childName = name;
1334  if (childName.empty())
1335  {
1336  childName = createValidChildName(T::CATEGORY + "1");
1337  }
1338 
1339  if (_childMap.count(childName))
1340  throw Exception("Child name is not unique: " + childName);
1341 
1342  shared_ptr<T> child = std::make_shared<T>(getSelf(), childName);
1343  registerChildElement(child);
1344 
1345  return child;
1346 }
1347 
1348 /// Given two target strings, each containing a string array of target names,
1349 /// return true if they have any targets in common. An empty target string
1350 /// matches all targets.
1351 MX_CORE_API bool targetStringsMatch(const string& target1, const string& target2);
1352 
1353 /// Pretty print the given element tree, calling asString recursively on each
1354 /// element in depth-first order.
1356 
1358 
1359 #endif
static const string UI_ADVANCED_ATTRIBUTE
Definition: Element.h:1124
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
ValueElement(ElementPtr parent, const string &category, const string &name)
Definition: Element.h:903
const string & getFilePrefix() const
Return the element's file prefix string.
Definition: Element.h:174
const string & getNamespace() const
Return the namespace string of this element.
Definition: Element.h:330
string _geomPrefix
Definition: Element.h:1317
virtual const string & getType() const
Return the element's type string.
Definition: Element.h:867
shared_ptr< const Element > ConstElementPtr
A shared pointer to a const Element.
Definition: Element.h:33
void setType(const string &type)
Set the element's type string.
Definition: Element.h:855
void setGeomPrefix(const string &prefix)
Set the element's geom prefix string.
Definition: Element.h:198
string _sourceUri
Definition: Element.h:810
weak_ptr< Element > _parent
Definition: Element.h:818
ValuePtr getResolvedValue(StringResolverPtr resolver=nullptr) const
Definition: Element.h:1026
bool hasValue() const
Return true if the element possesses a typed value.
Definition: Element.h:1001
bool hasInterfaceName() const
Return true if the given element has an interface name.
Definition: Element.h:950
TypedElement(ElementPtr parent, const string &category, const string &name)
Definition: Element.h:839
shared_ptr< TypeDef > TypeDefPtr
A shared pointer to a TypeDef.
Definition: Definition.h:42
shared_ptr< const T > getAncestorOfType() const
Definition: Element.h:587
string _filePrefix
Definition: Element.h:1316
static const string IMPLEMENTATION_NAME_ATTRIBUTE
Definition: Element.h:1113
shared_ptr< T > addChild(const string &name=EMPTY_STRING)
Definition: Element.h:1331
static const string ENUM_ATTRIBUTE
Definition: Element.h:1115
const string & getFilePrefix() const
Return the file prefix for this context.
Definition: Element.h:1232
void setDocString(const string &doc)
Set the documentation string of this element.
Definition: Element.h:363
ElementPtr getSelf()
Return our self pointer.
Definition: Element.h:550
static const string UI_NAME_ATTRIBUTE
Definition: Element.h:1117
std::function< bool(ConstElementPtr)> ElementPredicate
A standard function taking an ElementPtr and returning a boolean.
Definition: Element.h:72
bool isColorType() const
Return true if the element is of color type.
Definition: Element.h:873
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
StringMap _attributeMap
Definition: Element.h:815
virtual ~GenericElement()
Definition: Element.h:1192
vector< string > StringVec
A vector of strings.
Definition: Library.h:57
shared_ptr< NewlineElement > NewlineElementPtr
A shared pointer to a NewlineElement.
Definition: Element.h:56
bool hasImplementationName() const
Return true if the given element has an implementation name.
Definition: Element.h:972
std::unordered_map< string, ElementPtr > ElementMap
A hash map from strings to elements.
Definition: Element.h:69
GLsizei const GLfloat * value
Definition: glcorearb.h:824
MX_CORE_API const string FILENAME_TYPE_STRING
static const string CATEGORY
Definition: Element.h:1165
void setIsUniform(bool value)
Set the uniform attribute flag on this element.
Definition: Element.h:1089
shared_ptr< TypedElement > TypedElementPtr
A shared pointer to a TypedElement.
Definition: Element.h:36
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
static const string CATEGORY
Definition: Element.h:1180
static StringResolverPtr create()
Create a new string resolver.
Definition: Element.h:1215
static const string UNIFORM_ATTRIBUTE
Definition: Element.h:1127
const string & getAttribute(const string &attrib) const
Definition: Element.h:504
ValuePtr getValue() const
Definition: Element.h:1011
static const string UI_MIN_ATTRIBUTE
Definition: Element.h:1119
void setValue(const T &value, const string &type=EMPTY_STRING)
Set the typed value of an element.
Definition: Element.h:988
StringMap _geomNameMap
Definition: Element.h:1319
static const string IMPLEMENTATION_TYPE_ATTRIBUTE
Definition: Element.h:1114
__hostdev__ void setValue(uint32_t offset, bool v)
Definition: NanoVDB.h:5750
virtual ~CommentElement()
Definition: Element.h:1162
void setValueString(const string &value)
Set the value string of an element.
Definition: Element.h:915
void setFilenameSubstitution(const string &key, const string &value)
Set an arbitrary substring substitution for filename data values.
Definition: Element.h:1266
string createValidChildName(string name) const
Definition: Element.h:746
shared_ptr< T > getChildOfType(const string &name) const
Definition: Element.h:438
bool hasUnit() const
Return true if the given element has a unit string.
Definition: Element.h:1051
shared_ptr< Token > TokenPtr
A shared pointer to a Token.
Definition: Element.h:46
class OCIOEXPORT Exception
static const string GEOM_PREFIX_ATTRIBUTE
Definition: Element.h:790
const string & getImplementationName() const
Return the implementation name of an element.
Definition: Element.h:978
vector< ElementPtr > _childOrder
Definition: Element.h:813
#define MX_CORE_API
Definition: Export.h:18
MX_CORE_API string prettyPrint(ConstElementPtr elem)
bool hasValueString() const
Return true if the given element has a value string.
Definition: Element.h:921
virtual ~StringResolver()
Definition: Element.h:1220
void setImplementationName(const string &name)
Set the implementation name of an element.
Definition: Element.h:966
ElementPtr getChild(const string &name) const
Return the child element, if any, with the given name.
Definition: Element.h:429
const string & getInterfaceName() const
Return the interface name of an element.
Definition: Element.h:956
shared_ptr< GenericElement > GenericElementPtr
A shared pointer to a GenericElement.
Definition: Element.h:61
bool hasColorSpace() const
Return true if the given element has a color space string.
Definition: Element.h:240
shared_ptr< const GenericElement > ConstGenericElementPtr
A shared pointer to a const GenericElement.
Definition: Element.h:63
const string & getActiveColorSpace() const
Definition: Element.h:253
MX_CORE_API string incrementName(const string &name)
Increment the numeric suffix of a name.
const vector< ElementPtr > & getChildren() const
Definition: Element.h:446
Definition: Traversal.h:29
static const string INTERFACE_NAME_ATTRIBUTE
Definition: Element.h:1112
NewlineElement(ElementPtr parent, const string &name)
Definition: Element.h:1173
void setInheritsFrom(ConstElementPtr super)
Set the element that this one directly inherits from.
Definition: Element.h:288
string getDocString() const
Return the documentation string of this element.
Definition: Element.h:369
weak_ptr< Element > _root
Definition: Element.h:819
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
static const string NAME_ATTRIBUTE
Definition: Element.h:788
ElementPtr getParent()
Return our parent element.
Definition: Element.h:562
const string & getActiveFilePrefix() const
Definition: Element.h:181
const string & getName() const
Return the element's name string.
Definition: Element.h:138
shared_ptr< const TypedElement > ConstTypedElementPtr
A shared pointer to a const TypedElement.
Definition: Element.h:38
shared_ptr< const Document > ConstDocumentPtr
Definition: Element.h:97
virtual ~Element()
Definition: Element.h:91
void setInterfaceName(const string &name)
Set the interface name of an element.
Definition: Element.h:944
void setValue(const char *value, const string &type=EMPTY_STRING)
Set the typed value of an element from a C-style string.
Definition: Element.h:995
virtual bool validate(string *message=nullptr) const
shared_ptr< T > resolveNameReference(const string &name, ConstElementPtr parent=nullptr) const
Definition: Element.h:776
static const string CATEGORY
Definition: Element.h:1145
bool hasType() const
Return true if the given element has a type string.
Definition: Element.h:861
const string & getUnitType() const
Return the unit type of an element.
Definition: Element.h:1079
bool hasNamespace() const
Return true if this element has a namespace string.
Definition: Element.h:324
MX_CORE_API const string GEOMNAME_TYPE_STRING
static bool isResolvedType(const string &type)
Return true if the given type may be resolved by this class.
Definition: Element.h:1305
void setSourceUri(const string &sourceUri)
Definition: Element.h:694
GenericElement(ElementPtr parent, const string &name)
Definition: Element.h:1188
void setUnit(const string &unit)
Set the unit string of an element.
Definition: Element.h:1045
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
void setUnitType(const string &unit)
Set the unit type of an element.
Definition: Element.h:1067
MX_CORE_API const string MULTI_OUTPUT_TYPE_STRING
shared_ptr< const ValueElement > ConstValueElementPtr
A shared pointer to a const ValueElement.
Definition: Element.h:43
virtual ~ValueElement()
Definition: Element.h:909
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
T getTypedAttribute(const string &attrib) const
Definition: Element.h:527
void setColorSpace(const string &colorSpace)
Set the element's color space string.
Definition: Element.h:234
static const string UI_MAX_ATTRIBUTE
Definition: Element.h:1120
const string & getSourceUri() const
Return the element's source URI.
Definition: Element.h:706
MX_CORE_API const string NAME_PREFIX_SEPARATOR
MX_CORE_API bool targetStringsMatch(const string &target1, const string &target2)
static const string ENUM_VALUES_ATTRIBUTE
Definition: Element.h:1116
png_const_structrp png_const_inforp int * unit
Definition: png.h:2161
void setTypedAttribute(const string &attrib, const T &data)
Definition: Element.h:519
ElementPtr getInheritsFrom() const
Return the element, if any, that this one directly inherits from.
Definition: Element.h:301
GLuint const GLchar * name
Definition: glcorearb.h:786
static const string VALUE_ATTRIBUTE
Definition: Element.h:1111
ElementPtr getSelfNonConst() const
Definition: Element.h:802
vector< shared_ptr< T > > getChildrenOfType(const string &category=EMPTY_STRING) const
Definition: Element.h:454
virtual ~NewlineElement()
Definition: Element.h:1177
const string & getCategory() const
Definition: Element.h:122
static const string UI_SOFT_MAX_ATTRIBUTE
Definition: Element.h:1122
bool isMultiOutputType() const
Return true if the element is of multi-output type.
Definition: Element.h:879
void setFilePrefix(const string &filePrefix)
Set the file prefix for this context.
Definition: Element.h:1226
Element(ElementPtr parent, const string &category, const string &name)
Definition: Element.h:82
ConstElementPtr getParent() const
Return our parent element.
Definition: Element.h:568
bool hasUnitType() const
Return true if the given element has a unit type.
Definition: Element.h:1073
const StringMap & getGeomNameSubstitutions() const
Return the map of geometry name substring substitutions.
Definition: Element.h:1291
const string & getValueString() const
Get the value string of a element.
Definition: Element.h:927
const string & getActiveSourceUri() const
Definition: Element.h:713
void setNamespace(const string &space)
Set the namespace string of this element.
Definition: Element.h:318
static ValuePtr createValueFromStrings(const string &value, const string &type)
shared_ptr< const NewlineElement > ConstNewlineElementPtr
A shared pointer to a const NewlineElement.
Definition: Element.h:58
shared_ptr< const Token > ConstTokenPtr
A shared pointer to a const Token.
Definition: Element.h:48
virtual ~Token()
Definition: Element.h:1142
static const string UNITTYPE_ATTRIBUTE
Definition: Element.h:1126
shared_ptr< StringResolver > StringResolverPtr
A shared pointer to a StringResolver.
Definition: Element.h:66
string _category
Definition: Element.h:808
void setAttribute(const string &attrib, const string &value)
Set the value string of the given attribute.
shared_ptr< Document > DocumentPtr
Definition: Element.h:96
bool hasInheritString() const
Return true if this element has an inherit string.
Definition: Element.h:276
const StringVec & getAttributeNames() const
Return a vector of stored attribute names, in the order they were set.
Definition: Element.h:511
void setFilePrefix(const string &prefix)
Set the element's file prefix string.
Definition: Element.h:162
Exception(const string &msg)
Definition: Exception.h:24
shared_ptr< const CommentElement > ConstCommentElementPtr
A shared pointer to a const CommentElement.
Definition: Element.h:53
const string & getActiveGeomPrefix() const
Definition: Element.h:217
bool hasFilePrefix() const
Return true if the given element has a file prefix string.
Definition: Element.h:168
string getQualifiedName(const string &name) const
Definition: Element.h:337
void setInheritString(const string &inherit)
Set the inherit string of this element.
Definition: Element.h:270
static const string COLOR_SPACE_ATTRIBUTE
Definition: Element.h:791
bool hasAttribute(const string &attrib) const
Return true if the given attribute is present.
Definition: Element.h:497
MX_CORE_API string createValidName(string name, char replaceChar= '_')
Create a valid MaterialX name from the given string.
shared_ptr< CommentElement > CommentElementPtr
A shared pointer to a CommentElement.
Definition: Element.h:51
const StringMap & getFilenameSubstitutions() const
Return the map of filename substring substitutions.
Definition: Element.h:1275
LeafData & operator=(const LeafData &)=delete
GLuint index
Definition: glcorearb.h:786
static const string UI_STEP_ATTRIBUTE
Definition: Element.h:1123
bool isA(const string &category=EMPTY_STRING) const
Definition: Element.h:381
const string & getUnit() const
Return the unit string of an element.
Definition: Element.h:1057
static const string TYPE_ATTRIBUTE
Definition: Element.h:895
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:59
static const string CATEGORY
Definition: Element.h:1195
void setGeomPrefix(const string &geomPrefix)
Set the geom prefix for this context.
Definition: Element.h:1242
static const string UI_FOLDER_ATTRIBUTE
Definition: Element.h:1118
bool hasGeomPrefix() const
Return true if the given element has a geom prefix string.
Definition: Element.h:204
static const string INHERIT_ATTRIBUTE
Definition: Element.h:792
virtual void registerChildElement(ElementPtr child)
bool getIsUniform() const
The the uniform attribute flag for this element.
Definition: Element.h:1095
Definition: core.h:1131
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
const string & getGeomPrefix() const
Return the element's geom prefix string.
Definition: Element.h:210
ConstElementPtr getSelf() const
Return our self pointer.
Definition: Element.h:556
shared_ptr< ValueElement > ValueElementPtr
A shared pointer to a ValueElement.
Definition: Element.h:41
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
static const string FILE_PREFIX_ATTRIBUTE
Definition: Element.h:789
static const string DOC_ATTRIBUTE
Definition: Element.h:794
const string & getGeomPrefix() const
Return the geom prefix for this context.
Definition: Element.h:1248
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
virtual size_t getUpstreamEdgeCount() const
Return the number of queriable upstream edges for this element.
Definition: Element.h:657
const string & getColorSpace() const
Return the element's color space string.
Definition: Element.h:246
bool hasSourceUri() const
Return true if this element has a source URI.
Definition: Element.h:700
Token(ElementPtr parent, const string &name)
Definition: Element.h:1138
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition: Value.h:29
static const string UI_SOFT_MIN_ATTRIBUTE
Definition: Element.h:1121
type
Definition: core.h:1059
virtual ~TypedElement()
Definition: Element.h:845
static const string NAMESPACE_ATTRIBUTE
Definition: Element.h:793
shared_ptr< T >(*)( CreatorFunction)
Definition: Library.h:44
string _name
Definition: Element.h:809
shared_ptr< const Document > ConstDocumentPtr
A shared pointer to a const Document.
Definition: Document.h:24
void setGeomNameSubstitution(const string &key, const string &value)
Set an arbitrary substring substitution for geometry name data values.
Definition: Element.h:1285
ElementMap _childMap
Definition: Element.h:812
shared_ptr< class TypeDef > TypeDefPtr
Definition: Element.h:848
void setCategory(const string &category)
Set the element's category string.
Definition: Element.h:114
static const string UNIT_ATTRIBUTE
Definition: Element.h:1125
StringVec _attributeOrder
Definition: Element.h:816
MX_CORE_API string toValueString(const T &data)
Convert the given data value to a value string.
void removeChildOfType(const string &name)
Definition: Element.h:483
const string & getInheritString() const
Return the inherit string of this element.
Definition: Element.h:282
StringMap _filenameMap
Definition: Element.h:1318
Definition: format.h:895
CommentElement(ElementPtr parent, const string &name)
Definition: Element.h:1158