daeMetaElementAttribute.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 __DAE_META_ELEMENT_ATTRIBUTE_H__
  9. #define __DAE_META_ELEMENT_ATTRIBUTE_H__
  10. #include <dae/daeTypes.h>
  11. #include <dae/daeMetaAttribute.h>
  12. #include <dae/daeMetaCMPolicy.h>
  13. class daeMetaElement;
  14. class daeElement;
  15. class daeDocument;
  16. /**
  17. * The @c daeMetaElementAttribute class represents a content model object that is an element.
  18. */
  19. class daeMetaElementAttribute : public daeMetaAttribute, public daeMetaCMPolicy
  20. {
  21. public:
  22. /** The metaElement that describes the element type of this attribute */
  23. daeMetaElement* _elementType;
  24. public:
  25. /**
  26. * Constructor.
  27. * @param container The daeMetaElement that this policy object belongs to.
  28. * @param parent The daeMetaCMPolicy parent of this policy object.
  29. * @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
  30. * correct order of child elements.
  31. * @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
  32. * @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
  33. */
  34. daeMetaElementAttribute( daeMetaElement *container, daeMetaCMPolicy *parent = NULL, daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1);
  35. /**
  36. * Destructor
  37. */
  38. virtual ~daeMetaElementAttribute();
  39. public:
  40. virtual daeElement *placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL);
  41. virtual daeBool removeElement(daeElement* parent, daeElement* child);
  42. daeMetaElement *findChild( daeString elementName );
  43. virtual void getChildren( daeElement* parent, daeElementRefArray &array );
  44. public:
  45. /**
  46. * Sets the element type for the element that this attribute points to.
  47. * @param elementType @c daeMetaElement representing the type.
  48. */
  49. void setElementType(daeMetaElement *elementType) {
  50. _elementType = elementType; }
  51. /**
  52. * Gets the element type for the element that this attribute points to.
  53. * @return Returns the @c daeMetaElement representing the type.
  54. */
  55. daeMetaElement* getElementType() { return _elementType; }
  56. /**
  57. * Sets the database document associated with this element.
  58. * @param parent The daeElement to set the document.
  59. * @param c The @c daeDocument to associate with this element.
  60. */
  61. virtual void setDocument(daeElement *parent, daeDocument* c );
  62. inline void setCollection(daeElement *parent, daeDocument* c ) {
  63. setDocument( parent, c );
  64. }
  65. /**
  66. * Gets the number of elements associated with this attribute in instance <tt><i>e.</i></tt>
  67. * @param e Containing element to run the operation on.
  68. * @return Returns the number of elements associated with this attribute
  69. * in instance <tt><i>e.</i></tt>
  70. */
  71. virtual daeInt getCount(daeElement* e);
  72. /// single-arg get() inherited from base class
  73. using daeMetaAttribute::get;
  74. /**
  75. * Gets an element from containing element <tt><i>e</i></tt> based on <tt><i>index.</i></tt>
  76. * @param e Containing element from which to get the element.
  77. * @param index Index of the element to retrieve if indeed
  78. * there is an array of elements rather than a singleton.
  79. * @return Returns the associated element out of parent element e, based on index, if necessary.
  80. */
  81. virtual daeMemoryRef get(daeElement* e, daeInt index);
  82. /**
  83. * Defines the override version of base method.
  84. * @param element Element on which to set this attribute.
  85. * @param s String containing the value to be converted via the
  86. * atomic type system.
  87. */
  88. virtual void set(daeElement* element, daeString s);
  89. /**
  90. * Defines the override version of base method.
  91. * @param toElement Pointer to a @c daeElement to copy this attribute to.
  92. * @param fromElement Pointer to a @c daeElement to copy this attribute from.
  93. */
  94. virtual void copy(daeElement* toElement, daeElement* fromElement);
  95. /**
  96. * Gets if this attribute is an array attribute.
  97. * @return Returns true if this attribute is an array type.
  98. */
  99. virtual daeBool isArrayAttribute() { return false; }
  100. };
  101. typedef daeSmartRef<daeMetaElementAttribute> daeMetaElementAttributeRef;
  102. typedef daeTArray<daeMetaElementAttributeRef> daeMetaElementAttributeArray;
  103. /**
  104. * The @c daeMetaElementArrayAttribute class is similar to daeMetaElementAttribute
  105. * except that this meta attribute describes an array of elements rather than a singleton.
  106. */
  107. class daeMetaElementArrayAttribute : public daeMetaElementAttribute
  108. {
  109. public:
  110. /**
  111. * Constructor.
  112. * @param container The daeMetaElement that this policy object belongs to.
  113. * @param parent The daeMetaCMPolicy parent of this policy object.
  114. * @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
  115. * correct order of child elements.
  116. * @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
  117. * @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
  118. */
  119. daeMetaElementArrayAttribute(daeMetaElement *container, daeMetaCMPolicy *parent = NULL, daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1);
  120. ~daeMetaElementArrayAttribute();
  121. public:
  122. virtual daeElement *placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL);
  123. virtual daeBool removeElement(daeElement* parent, daeElement* child);
  124. void getChildren( daeElement* parent, daeElementRefArray &array );
  125. /**
  126. * Sets the database document associated with this element.
  127. * @param c The @c daeDocument to associate with this element.
  128. */
  129. virtual void setDocument(daeElement *parent, daeDocument* c );
  130. inline void setCollection(daeElement *parent, daeDocument* c ) {
  131. setDocument( parent, c );
  132. }
  133. /**
  134. * Defines the override version of this method from @c daeMetaElement.
  135. * @param e Containing element to run the operation on.
  136. * @return Returns the number of particles associated with this attribute
  137. * in instance <tt><i>e.</i></tt>
  138. */
  139. virtual daeInt getCount(daeElement* e);
  140. /**
  141. * Defines the override version of this method from @c daeMetaElement.
  142. * @param e Containing element from which to get the element.
  143. * @param index Index of the particle to retrieve if indeed
  144. * there is an array of elements rather than a singleton.
  145. * @return Returns the associated particle out of parent element e, based on index, if necessary.
  146. */
  147. virtual daeMemoryRef get(daeElement* e, daeInt index);
  148. /**
  149. * Defines the override version of this method from @c daeMetaElement.
  150. * @param toElement Pointer to a @c daeElement to copy this attribute to.
  151. * @param fromElement Pointer to a @c daeElement to copy this attribute from.
  152. */
  153. virtual void copy(daeElement* toElement, daeElement* fromElement);
  154. /**
  155. * Gets if this attribute is an array attribute.
  156. * @return Returns true if this attribute is an array type.
  157. */
  158. virtual daeBool isArrayAttribute() { return true; }
  159. };
  160. typedef daeSmartRef<daeMetaElementArrayAttribute> daeMetaElementArrayAttributeRef;
  161. typedef daeTArray<daeMetaElementArrayAttributeRef> daeMetaElementArrayAttributeArray;
  162. #endif