daeMetaCMPolicy.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_CM_POLICY_H__
  14. #define __DAE_META_CM_POLICY_H__
  15. #include <dae/daeTypes.h>
  16. #include <dae/daeElement.h>
  17. //class daeElement;
  18. class daeMetaElement;
  19. /**
  20. * The daeMetaCMPolicy class is the base class for the content model policy classes which are used to
  21. * describe the availability and ordering of an element's children.
  22. */
  23. class daeMetaCMPolicy
  24. {
  25. public:
  26. /**
  27. * Places an element into the parent element based on this content model policy object.
  28. * @param parent The parent element for which the child element will be placed.
  29. * @param child The new child element.
  30. * @param ordinal A reference to a daeUInt which holds the ordinal return value for a placed child. Used
  31. * to maintain proper ording of child elements.
  32. * @param offset The offset to used when attempting to place this element. Affects comparison against
  33. * minOccurs and maxOccurs.
  34. * @param before The element that the child should appear before. Optional.
  35. * @param after The element that the child should appear after. Optional.
  36. * @return Returns The child element that was placed within this content model object or any of its
  37. * children. NULL if placement failed.
  38. */
  39. virtual daeElement *placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL ) = 0;
  40. /**
  41. * Removes an element from the parent based on this content model object.
  42. * @param parent The parent element for which child you want to remove.
  43. * @param child The child that will be removed from the parent.
  44. * @return Returns true if the child was successfully removed from this content model object or any of
  45. * its children. False otherwise.
  46. */
  47. virtual daeBool removeElement(daeElement* parent, daeElement* child ) = 0;
  48. /**
  49. * Gets the daeMetaElement of an acceptable child of this content model object.
  50. * @param elementName The name of the element whos metaElement information you are interested in.
  51. * @return Returns a pointer to a daeMetaElement class that describes the element interested in.
  52. * Returns NULL if the element is not valid in this content model.
  53. */
  54. virtual daeMetaElement *findChild( daeString elementName ) = 0;
  55. /**
  56. * Populates an array with the children of parent based on this content model object.
  57. * @param parent The parent element whos children you want.
  58. * @param array The array where you the children will be appended to.
  59. */
  60. virtual void getChildren( daeElement* parent, daeElementRefArray &array ) = 0;
  61. /**
  62. * Adds a child to this content model object.
  63. * @param p The child content model policy object.
  64. */
  65. void appendChild( daeMetaCMPolicy *p ) { _children.append( p ); }
  66. /**
  67. * Gets the parent of this content model policy object.
  68. * @return Returns a pointer to the parent node.
  69. */
  70. daeMetaCMPolicy *getParent() { return _parent; }
  71. /**
  72. * Sets the maximum ordinal value of this policy objects children. Used to keep proper ordering for
  73. * cm objects that may appear multiple times.
  74. * @param ord The maximum ordinal value for this content model object.
  75. */
  76. void setMaxOrdinal( daeUInt ord ) { _maxOrdinal = ord; }
  77. protected:
  78. /**
  79. * Constructor.
  80. * @param container The daeMetaElement that this policy object belongs to.
  81. * @param parent The daeMetaCMPolicy parent of this policy object.
  82. * @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
  83. * correct order of child elements.
  84. * @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
  85. * @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
  86. */
  87. daeMetaCMPolicy( daeMetaElement *container ,daeMetaCMPolicy *parent, daeUInt ordinal,
  88. daeInt minO, daeInt maxO ) : _container( container ), _parent( parent ), _minOccurs( minO ),
  89. _maxOccurs( maxO ), _maxOrdinal( 0 ), _ordinalOffset( ordinal ) {}
  90. public:
  91. /**
  92. * Destructor.
  93. */
  94. virtual ~daeMetaCMPolicy();
  95. protected:
  96. daeMetaElement * _container;
  97. daeMetaCMPolicy * _parent;
  98. daeTArray<daeMetaCMPolicy*> _children;
  99. /** Minimum number of times this meta element can occur. */
  100. daeInt _minOccurs;
  101. /** Maximum number of times this meta element can occur. -1 for unbounded */
  102. daeInt _maxOccurs;
  103. daeUInt _maxOrdinal;
  104. daeUInt _ordinalOffset;
  105. };
  106. #endif