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#include <dae/daeMetaSequence.h> 10 11daeMetaSequence::daeMetaSequence( daeMetaElement *container, daeMetaCMPolicy *parent, daeUInt ordinal, 12 daeInt minO, daeInt maxO) : 13 daeMetaCMPolicy( container, parent, ordinal, minO, maxO ) 14{} 15 16daeMetaSequence::~daeMetaSequence() 17{} 18 19daeElement *daeMetaSequence::placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after ) { 20 (void)offset; 21 if ( _maxOccurs == -1 ) { 22 //Needed to prevent infinate loops. If unbounded check to see if you have the child before just trying to place 23 if ( findChild( child->getElementName() ) == NULL ) { 24 return NULL; 25 } 26 } 27 28 size_t cnt = _children.getCount(); 29 for ( daeInt i = 0; ( i < _maxOccurs || _maxOccurs == -1 ); i++ ) { 30 for ( size_t x = 0; x < cnt; x++ ) { 31 if ( _children[x]->placeElement( parent, child, ordinal, i, before, after ) != NULL ) { 32 ordinal = ordinal + (i * ( _maxOrdinal + 1 )) + _ordinalOffset; 33 return child; 34 } 35 } 36 } 37 return NULL; 38} 39 40daeBool daeMetaSequence::removeElement( daeElement *parent, daeElement *child ) { 41 size_t cnt = _children.getCount(); 42 for ( size_t x = 0; x < cnt; x++ ) { 43 if ( _children[x]->removeElement( parent, child ) ) { 44 return true; 45 } 46 } 47 return false; 48} 49 50daeMetaElement * daeMetaSequence::findChild( daeString elementName ) { 51 daeMetaElement *me = NULL; 52 size_t cnt = _children.getCount(); 53 for ( size_t x = 0; x < cnt; x++ ) { 54 me = _children[x]->findChild( elementName ); 55 if ( me != NULL ) { 56 return me; 57 } 58 } 59 return NULL; 60} 61 62void daeMetaSequence::getChildren( daeElement *parent, daeElementRefArray &array ) { 63 size_t cnt = _children.getCount(); 64 for ( size_t x = 0; x < cnt; x++ ) { 65 _children[x]->getChildren( parent, array ); 66 } 67} 68