daeMetaElementAttribute.h 7.5 KB

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