domAny.h 4.7 KB

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