domAny.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2006 Sony Computer Entertainment Inc.
  3. *
  4. * Licensed under the MIT Open Source License, for details please see license.txt or the website
  5. * http://www.opensource.org/licenses/mit-license.php
  6. *
  7. */
  8. #ifndef __domAny_h__
  9. #define __domAny_h__
  10. #include <dae/daeElement.h>
  11. #include <dae/daeMetaElement.h>
  12. #include <dae/daeArray.h>
  13. #include <dae/daeURI.h>
  14. #include <dae/daeIDRef.h>
  15. #include <dom/domTypes.h>
  16. /**
  17. * The domAny class allows for weakly typed xml elements. This class is used anywhere in the
  18. * COLLADA schema where an xs:any element appears. The content and type information for a domAny
  19. * object is generated at runtime.
  20. */
  21. class domAny : public daeElement
  22. {
  23. friend class domAnyAttribute;
  24. protected: // Attribute
  25. /**
  26. * The array of daeStrings to hold attribute data for this element.
  27. */
  28. daeTArray<daeString> attrs;
  29. /**
  30. * The domString value of the text data of this element.
  31. */
  32. daeString _value;
  33. /**
  34. * Used to preserve order in elements that do not specify strict sequencing of sub-elements.
  35. */
  36. daeElementRefArray _contents;
  37. /**
  38. * Used to preserve order in elements that have a complex content model.
  39. */
  40. daeUIntArray _contentsOrder;
  41. public:
  42. /**
  43. * Gets the _contents array.
  44. * @return Returns a reference to the _contents element array.
  45. */
  46. daeElementRefArray &getContents() { return _contents; }
  47. /**
  48. * Gets the _contents array.
  49. * @return Returns a constant reference to the _contents element array.
  50. */
  51. const daeElementRefArray &getContents() const { return _contents; }
  52. /**
  53. * Gets the number of attributes this element has.
  54. * @return Returns the number of attributes on this element.
  55. */
  56. daeUInt getAttributeCount() const { return (daeUInt)_meta->getMetaAttributes().getCount(); }
  57. /**
  58. * Gets an attribute's name.
  59. * @param index The index into the attribute list.
  60. * @return Returns the attribute's name.
  61. */
  62. daeString getAttributeName( daeUInt index ) const { return _meta->getMetaAttributes()[index]->getName(); }
  63. /**
  64. * Gets an attribute's value.
  65. * @param index The index into the attribute list.
  66. * @return Returns the attribute's value as a string.
  67. */
  68. daeString getAttributeValue( daeUInt index ) const { return attrs[ index ]; }
  69. /**
  70. * Gets the value of this element.
  71. * @return Returns a daeString of the value.
  72. */
  73. daeString getValue() const { return _value; }
  74. /**
  75. * Sets the _value of this element.
  76. * @param val The new value for this element.
  77. */
  78. void setValue( daeString val ) { *(daeStringRef*)&_value = val; }
  79. /**
  80. * Gets the element type.
  81. * @return Returns the COLLADA_TYPE::TypeEnum value corresponding to this element's type.
  82. */
  83. virtual COLLADA_TYPE::TypeEnum getElementType() const { return COLLADA_TYPE::ANY; }
  84. static daeInt ID() { return colladaTypeCount()-1; }
  85. virtual daeInt typeID() const { return colladaTypeCount()-1; }
  86. protected:
  87. /**
  88. * Constructor
  89. */
  90. domAny() : _value() {}
  91. /**
  92. * Destructor
  93. */
  94. virtual ~domAny();
  95. /**
  96. * Copy Constructor
  97. */
  98. domAny( const domAny &cpy ) : daeElement() { (void)cpy; }
  99. /**
  100. * Overloaded assignment operator
  101. */
  102. virtual domAny &operator=( const domAny &cpy ) { (void)cpy; return *this; }
  103. public: //METHODS
  104. /**
  105. * Override of the Base class method. Creates and registers an attribute field with its meta
  106. * and assigns its value as the <tt><i> attrValue </i></tt> String.
  107. * @param attrName Attribute to set.
  108. * @param attrValue String-based value to apply to the attribute.
  109. * @return Returns true if the attribute was created and the value was set, false otherwise.
  110. */
  111. virtual DLLSPEC daeBool setAttribute(daeString attrName, daeString attrValue);
  112. public: // STATIC METHODS
  113. /**
  114. * Creates an instance of this class and returns a daeElementRef referencing it.
  115. * @return a daeElementRef referencing an instance of this object.
  116. */
  117. static DLLSPEC daeElementRef create(DAE& dae);
  118. /**
  119. * Creates a daeMetaElement object that describes this element in the meta object reflection framework.
  120. * @return A daeMetaElement describing this COLLADA element.
  121. * @remarks Unlike other dom* elements, domAny will always create a new daeMetaElement when this
  122. * function is called.
  123. */
  124. static DLLSPEC daeMetaElement* registerElement(DAE& dae);
  125. };
  126. typedef daeSmartRef<domAny> domAnyRef;
  127. typedef daeTArray<domAnyRef> domAny_Array;
  128. #endif