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