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