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