updated COLLADA-DOM to the latest bleeding-edge (1.4.1) SVN version of today
This commit is contained in:
@@ -170,7 +170,8 @@ daeInt DAE::load(daeString name, daeString docBuffer)
|
||||
registerFunc();
|
||||
|
||||
if ( !plugin || !database ) {
|
||||
printf( "no plugin or database\n" );
|
||||
//printf( "no plugin or database\n" );
|
||||
daeErrorHandler::get()->handleError("no plugin or database\n");
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
|
||||
@@ -460,6 +460,7 @@ daeResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
// This URI was never successfully resolved, so write out it's original value
|
||||
s = thisURI->getOriginalURI();
|
||||
if ( s == NULL ) s = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -471,6 +472,7 @@ daeResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
// we will send back the original URI if we're pointing at ourselves
|
||||
s = thisURI->getOriginalURI();
|
||||
if ( s == NULL ) s = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -478,17 +480,19 @@ daeResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
#if 1
|
||||
// we will send back the full resolved URI
|
||||
s = thisURI->getURI();
|
||||
if ( s == NULL ) s = "";
|
||||
#else
|
||||
// Makes the URI relative to the document being written, EXPERIMENTAL, not fully tested!!!
|
||||
thisURI->makeRelativeTo(thisURI->getDocument()->getCollection()->getDocumentURI());
|
||||
s = thisURI->getOriginalURI();
|
||||
if ( s == NULL ) s = "";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// Copy at most dstSize-1 characters, null terminate and return error if the string was too long
|
||||
daeChar *d;
|
||||
int i;
|
||||
for(d = dst, i = 1; *s != 0 && i<dstSize; s++, d++, i++)
|
||||
for(d = dst, i = 1; *s != 0 && i<dstSize; s++, d++, i++)
|
||||
{
|
||||
// If the URI contains spaces, substitute %20
|
||||
if(*s == ' ')
|
||||
@@ -512,7 +516,7 @@ daeResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
}
|
||||
}
|
||||
*d = 0;
|
||||
if(*s == 0)
|
||||
if( *s == 0)
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
@@ -594,7 +598,7 @@ daeStringRefType::stringToMemory(daeChar* srcChars, daeChar* dstMemory)
|
||||
daeBool
|
||||
daeEnumType::stringToMemory(daeChar* src, daeChar* dst )
|
||||
{
|
||||
size_t index;
|
||||
size_t index(0);
|
||||
if ( _strings->find(src,index) == DAE_ERR_QUERY_NO_MATCH ) return false;
|
||||
daeEnum val = _values->get( index );
|
||||
*((daeEnum*)dst) = val;
|
||||
@@ -618,7 +622,7 @@ daeEnumType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
daeBool
|
||||
daeBoolType::stringToMemory(daeChar* srcChars, daeChar* dstMemory)
|
||||
{
|
||||
if (strncmp(srcChars,"true",4)==0)
|
||||
if (strncmp(srcChars,"true",4)==0 || strncmp(srcChars,"1",1)==0)
|
||||
*((daeBool*)dstMemory) = true;
|
||||
else
|
||||
*((daeBool*)dstMemory) = false;
|
||||
|
||||
@@ -13,6 +13,33 @@
|
||||
|
||||
#include <dae/daeDocument.h>
|
||||
|
||||
void daeDocument::insertElement( daeElementRef element ) {
|
||||
daeElement *parent = element->getParentElement();
|
||||
size_t idx;
|
||||
while ( parent != NULL ) {
|
||||
if ( insertedElements.find( parent, idx ) == DAE_OK ) {
|
||||
//found an ancestor in the list.. this child will already be added to the database
|
||||
return;
|
||||
}
|
||||
parent = parent->getParentElement();
|
||||
}
|
||||
//if no ancestors are scheduled to be added then we can add element.
|
||||
insertedElements.append( element );
|
||||
}
|
||||
|
||||
void daeDocument::removeElement( daeElementRef element ) {
|
||||
daeElement *parent = element->getParentElement();
|
||||
size_t idx;
|
||||
while ( parent != NULL ) {
|
||||
if ( removedElements.find( parent, idx ) == DAE_OK ) {
|
||||
//found an ancestor in the list.. this child will already be added to the database
|
||||
return;
|
||||
}
|
||||
parent = parent->getParentElement();
|
||||
}
|
||||
removedElements.append( element );
|
||||
}
|
||||
|
||||
void daeDocument::addExternalReference( daeURI &uri ) {
|
||||
if ( uri.getContainer() == NULL || uri.getContainer()->getDocument() != this ) {
|
||||
return;
|
||||
@@ -48,7 +75,7 @@ void daeDocument::removeExternalReference( daeURI &uri ) {
|
||||
}
|
||||
|
||||
void daeDocument::resolveExternals( daeString docURI ) {
|
||||
size_t idx;
|
||||
size_t idx(0);
|
||||
if ( referencedDocuments.find( docURI, idx ) == DAE_OK ) {
|
||||
for ( unsigned int j = 0; j < externalURIs[idx]->getCount(); j++ ) {
|
||||
daeURI *tempURI = externalURIs[idx]->get(j);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <dae/daeElement.h>
|
||||
#include <dae/daeArray.h>
|
||||
#include <dae/daeMetaAttribute.h>
|
||||
#include <dae/daeMetaElementAttribute.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
#include <dae/daeDatabase.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
@@ -107,210 +108,48 @@ daeElement::placeElement(daeElement* e)
|
||||
{
|
||||
if (e == NULL || e == this)
|
||||
return false;
|
||||
if (e->getMeta()->getIsAbstract()) {
|
||||
return false;
|
||||
}
|
||||
daeMetaElementAttributeArray &meas = _meta->getMetaElements();
|
||||
if (_meta->getAllowsAny()) {
|
||||
//remove element from praent
|
||||
if ( e->_parent ) {
|
||||
e->_parent->removeChildElement( e );
|
||||
}
|
||||
e->_parent = this;
|
||||
//add element to contents if one exists
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
contents->append(e);
|
||||
}
|
||||
//update document pointer
|
||||
e->setDocument( _document );
|
||||
if ( _document ) {
|
||||
_document->insertElement( e );
|
||||
_document->setModified(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int cnt = (int)meas.getCount();
|
||||
int i;
|
||||
daeString nm = e->getElementName();
|
||||
if ( !nm ) {
|
||||
nm = e->getTypeName();
|
||||
}
|
||||
for(i=0;i<cnt;i++) {
|
||||
if (strcmp(meas[i]->getName(), nm ) == 0 || strcmp(meas[i]->_elementType->getName(), nm ) == 0) {
|
||||
//add element to meta
|
||||
meas[i]->placeElement(this,e);
|
||||
//remove element from praent
|
||||
if ( e->_parent ) {
|
||||
e->_parent->removeChildElement( e );
|
||||
}
|
||||
e->_parent = this;
|
||||
//add element to contents if one exists
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
contents->append(e);
|
||||
}
|
||||
//update document pointer
|
||||
e->setDocument( _document );
|
||||
if ( _document ) {
|
||||
_document->insertElement( e );
|
||||
_document->setModified(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for ( unsigned int c = 0; c < _meta->getPossibleChildrenCount(); c++ ) {
|
||||
if (strcmp(_meta->getPossibleChildName(c), e->_meta->getName()) == 0 ||
|
||||
strcmp(_meta->getPossibleChildType(c), e->_meta->getName()) == 0 ) {
|
||||
|
||||
daeMetaElementAttribute *cont = _meta->getPossibleChildContainer(c);
|
||||
int elCnt = cont->getCount(this);
|
||||
daeMemoryRef mem = cont->get(this, elCnt );
|
||||
daeElementRef el;
|
||||
if ( mem != 0 ) {
|
||||
el = *(daeElementRef*)mem;
|
||||
}
|
||||
if ( el == NULL ) {
|
||||
cont->placeElement(this, cont->_elementType->create() );
|
||||
el = *(daeElementRef*)cont->get(this, elCnt );
|
||||
el->_parent = this;
|
||||
}
|
||||
if ( el->placeElement( e ) ) {
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
contents->append(el);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return _meta->place( this, e );
|
||||
}
|
||||
|
||||
daeBool daeElement::placeElementAt(daeInt index, daeElement* e) {
|
||||
if (e == NULL || e == this)
|
||||
return false;
|
||||
if (e->getMeta()->getIsAbstract()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
daeMetaElementAttributeArray &meas = _meta->getMetaElements();
|
||||
if (_meta->getAllowsAny()) {
|
||||
//remove element from praent
|
||||
if ( e->_parent ) {
|
||||
e->_parent->removeChildElement( e );
|
||||
}
|
||||
e->_parent = this;
|
||||
//add element to contents if one exists
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
contents->insertAt(index, e);
|
||||
}
|
||||
//update document pointer
|
||||
e->setDocument( _document );
|
||||
if ( _document ) {
|
||||
_document->insertElement( e );
|
||||
_document->setModified(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int cnt = (int)meas.getCount();
|
||||
int i;
|
||||
daeString nm = e->getElementName();
|
||||
if ( !nm ) {
|
||||
nm = e->getTypeName();
|
||||
}
|
||||
for(i=0;i<cnt;i++) {
|
||||
if (strcmp(meas[i]->getName(), nm ) == 0 || strcmp(meas[i]->_elementType->getName(), nm ) == 0) {
|
||||
//add element to meta
|
||||
meas[i]->placeElement(this,e);
|
||||
//remove element from praent
|
||||
if ( e->_parent ) {
|
||||
e->_parent->removeChildElement( e );
|
||||
}
|
||||
e->_parent = this;
|
||||
//add element to contents if one exists
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
contents->insertAt( index, e );
|
||||
}
|
||||
//update document pointer
|
||||
e->setDocument( _document );
|
||||
if ( _document ) {
|
||||
_document->insertElement( e );
|
||||
_document->setModified(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for ( unsigned int c = 0; c < _meta->getPossibleChildrenCount(); c++ ) {
|
||||
if (strcmp(_meta->getPossibleChildName(c), e->_meta->getName()) == 0 ||
|
||||
strcmp(_meta->getPossibleChildType(c), e->_meta->getName()) == 0 ) {
|
||||
|
||||
daeMetaElementAttribute *cont = _meta->getPossibleChildContainer(c);
|
||||
int elCnt = cont->getCount(this);
|
||||
daeMemoryRef mem = cont->get(this, elCnt );
|
||||
daeElementRef el;
|
||||
if ( mem != 0 ) {
|
||||
el = *(daeElementRef*)mem;
|
||||
}
|
||||
if ( el == NULL ) {
|
||||
cont->placeElement(this, cont->_elementType->create() );
|
||||
el = *(daeElementRef*)cont->get(this, elCnt );
|
||||
el->_parent = this;
|
||||
}
|
||||
if ( el->placeElement( e ) ) {
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
contents->insertAt(index, el);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return _meta->placeAt( index, this, e );
|
||||
}
|
||||
|
||||
daeBool daeElement::placeElementBefore( daeElement *marker, daeElement *element ) {
|
||||
if (marker == NULL || element == NULL || marker->getXMLParentElement() != this ) {
|
||||
return false;
|
||||
}
|
||||
if ( _meta->getContents() != NULL ) {
|
||||
size_t idx;
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
if ( contents->find( marker, idx ) != DAE_OK ) {
|
||||
return false;
|
||||
}
|
||||
return placeElementAt( (daeInt)idx, element );
|
||||
}
|
||||
if ( strcmp( marker->getTypeName(), element->getTypeName() ) == 0 ) {
|
||||
//same type
|
||||
daeMetaElementAttribute *mea = _meta->getChildMetaElementAttribute( element->getTypeName() );
|
||||
daeElementRefArray* era = (daeElementRefArray*)mea->getWritableMemory(this);
|
||||
size_t idx;
|
||||
if ( era->find( marker, idx ) != DAE_OK ) {
|
||||
return false;
|
||||
}
|
||||
era->insertAt( idx, element );
|
||||
return true;
|
||||
}
|
||||
return placeElement( element );
|
||||
//if ( _meta->getContents() != NULL ) {
|
||||
// size_t idx;
|
||||
// daeElementRefArray* contents =
|
||||
// (daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
// if ( contents->find( marker, idx ) != DAE_OK ) {
|
||||
// return false;
|
||||
// }
|
||||
// return placeElementAt( (daeInt)idx, element );
|
||||
//}
|
||||
//if ( strcmp( marker->getTypeName(), element->getTypeName() ) == 0 ) {
|
||||
// //same type
|
||||
// daeMetaElementAttribute *mea = _meta->getChildMetaElementAttribute( element->getTypeName() );
|
||||
// daeElementRefArray* era = (daeElementRefArray*)mea->getWritableMemory(this);
|
||||
// size_t idx;
|
||||
// if ( era->find( marker, idx ) != DAE_OK ) {
|
||||
// return false;
|
||||
// }
|
||||
// era->insertAt( idx, element );
|
||||
// return true;
|
||||
//}
|
||||
//return placeElement( element );
|
||||
return _meta->placeBefore( marker, this, element );
|
||||
}
|
||||
|
||||
daeBool daeElement::placeElementAfter( daeElement *marker, daeElement *element ) {
|
||||
if (marker == NULL || element == NULL || marker->getXMLParentElement() != this ) {
|
||||
return false;
|
||||
}
|
||||
if ( _meta->getContents() != NULL ) {
|
||||
/*if ( _meta->getContents() != NULL ) {
|
||||
size_t idx;
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
@@ -328,8 +167,8 @@ daeBool daeElement::placeElementAfter( daeElement *marker, daeElement *element )
|
||||
}
|
||||
era->insertAt( idx+1, element );
|
||||
return true;
|
||||
}
|
||||
return placeElement( element );
|
||||
}*/
|
||||
return _meta->placeAfter( marker, this, element );
|
||||
}
|
||||
|
||||
daeInt daeElement::findLastIndexOf( daeString elementName ) {
|
||||
@@ -345,15 +184,6 @@ daeInt daeElement::findLastIndexOf( daeString elementName ) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
daeInt idx = 0;
|
||||
size_t cnt = _meta->getMetaElements().getCount();
|
||||
for ( unsigned int i = 0; i < cnt; ++i ) {
|
||||
idx += (daeInt)((daeElementRefArray*)(_meta->getMetaElements().get(i)->getWritableMemory(this)))->getCount();
|
||||
if ( strcmp( _meta->getMetaElements().get(i)->getName(), elementName ) == 0 ) {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -369,36 +199,9 @@ daeElement::removeChildElement(daeElement* element)
|
||||
|
||||
// Clear the element's parent pointer, if the element has references outside
|
||||
// 'this' it won't go away, so we want to make sure it's parent is valid
|
||||
|
||||
element->_parent = NULL;
|
||||
|
||||
// Remove the element from our contents array (if we have one)
|
||||
|
||||
if (_meta->getContents() != NULL)
|
||||
{
|
||||
daeElementRefArray* contents = (daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
contents->remove(element);
|
||||
}
|
||||
|
||||
// Remove the element from wherever else it appears in 'this'
|
||||
|
||||
daeMetaElementAttributeArray &meas = _meta->getMetaElements();
|
||||
int cnt = (int)meas.getCount();
|
||||
int i;
|
||||
// Look for a meta element with a matching name
|
||||
for(i=0;i<cnt;i++)
|
||||
{
|
||||
if (strcmp(meas[i]->getName(), element->_meta->getName()) == 0)
|
||||
{
|
||||
if ( _document ) {
|
||||
_document->removeElement( element );
|
||||
_document->setModified(true);
|
||||
}
|
||||
// Remove it, if the element's ref count goes to zero it might be destructed,
|
||||
// so don't touch "element" again after this point.
|
||||
meas[i]->removeElement(this,element);
|
||||
return true;
|
||||
}
|
||||
if ( _meta->remove( this, element ) ) {
|
||||
element->_parent = NULL;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -410,12 +213,11 @@ void daeElement::setDocument( daeDocument *c ) {
|
||||
}
|
||||
_document = c;
|
||||
|
||||
daeMetaElementAttributeArray &meas = _meta->getMetaElements();
|
||||
int cnt = (int)meas.getCount();
|
||||
for( int i = 0; i < cnt; i++) {
|
||||
meas[i]->setDocument( this, c );
|
||||
daeElementRefArray ea;
|
||||
getChildren( ea );
|
||||
for ( size_t x = 0; x < ea.getCount(); x++ ) {
|
||||
ea[x]->setDocument( c );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
daeBool
|
||||
@@ -441,6 +243,7 @@ daeElement::setAttribute(daeString attrName, daeString attrValue)
|
||||
if (metaAttrs[i]->getType() != NULL)
|
||||
{
|
||||
metaAttrs[i]->set(this,attrValue);
|
||||
_validAttributeArray[i] = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -448,6 +251,57 @@ daeElement::setAttribute(daeString attrName, daeString attrValue)
|
||||
return false;
|
||||
}
|
||||
|
||||
daeBool daeElement::isAttributeSet( daeString attrName ) {
|
||||
if (_meta == NULL)
|
||||
return false;
|
||||
|
||||
daeMetaAttributeRefArray& metaAttrs = _meta->getMetaAttributes();
|
||||
int n = (int)metaAttrs.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
if ((metaAttrs[i]->getName() != NULL) &&
|
||||
(strcmp(metaAttrs[i]->getName(),attrName)==0)) {
|
||||
|
||||
return _validAttributeArray[i];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
daeBool daeElement::hasAttribute( daeString attrName ) {
|
||||
if (_meta == NULL)
|
||||
return false;
|
||||
|
||||
daeMetaAttributeRefArray& metaAttrs = _meta->getMetaAttributes();
|
||||
int n = (int)metaAttrs.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
if ((metaAttrs[i]->getName() != NULL) &&
|
||||
(strcmp(metaAttrs[i]->getName(),attrName)==0)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
daeMemoryRef daeElement::getAttributeValue( daeString attrName ) {
|
||||
if (_meta == NULL)
|
||||
return false;
|
||||
|
||||
daeMetaAttributeRefArray& metaAttrs = _meta->getMetaAttributes();
|
||||
int n = (int)metaAttrs.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
if ((metaAttrs[i]->getName() != NULL) &&
|
||||
(strcmp(metaAttrs[i]->getName(),attrName)==0)) {
|
||||
|
||||
return metaAttrs[i]->getWritableMemory(this);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
daeElement::appendResolveElement(daeElement* elem)
|
||||
{
|
||||
@@ -500,11 +354,19 @@ daeElement::setup(daeMetaElement* meta)
|
||||
}
|
||||
daeMetaAttributeRefArray& attrs = meta->getMetaAttributes();
|
||||
int macnt = (int)attrs.getCount();
|
||||
|
||||
|
||||
_validAttributeArray.setCount( macnt );
|
||||
|
||||
int i;
|
||||
for(i=0;i<macnt;i++)
|
||||
if (attrs[i]->getDefault() != NULL)
|
||||
for(i=0;i<macnt;i++) {
|
||||
if (attrs[i]->getDefault() != NULL) {
|
||||
attrs[i]->set(this, attrs[i]->getDefault());
|
||||
_validAttributeArray[i] = true;
|
||||
}
|
||||
else {
|
||||
_validAttributeArray[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Setup resolvers to know their containers and thus their file context
|
||||
@@ -564,21 +426,7 @@ daeString daeElement::getID() const
|
||||
}
|
||||
|
||||
void daeElement::getChildren( daeElementRefArray &array ) {
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeMetaElementArrayAttribute *contents = _meta->getContents();
|
||||
for ( int i = 0; i < contents->getCount( this ); i++ ) {
|
||||
array.append( *(daeElementRef*)contents->get( this, i ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
daeMetaElementAttributeArray &meas = _meta->getMetaElements();
|
||||
for(unsigned int i = 0; i < meas.getCount(); i++) {
|
||||
for ( int c = 0; c < meas[i]->getCount( this ); c++ ) {
|
||||
array.append( *(daeElementRef*)meas[i]->get( this, c ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
_meta->getChildren( this, array );
|
||||
}
|
||||
|
||||
daeSmartRef<daeElement> daeElement::clone(daeString idSuffix, daeString nameSuffix) {
|
||||
@@ -596,22 +444,12 @@ daeSmartRef<daeElement> daeElement::clone(daeString idSuffix, daeString nameSuff
|
||||
//memcpy( val->getWritableMemory( ret ), val->getWritableMemory( this ), val->getSize() );
|
||||
val->copy( ret, this );
|
||||
}
|
||||
//use meta system to child elements
|
||||
if ( _meta->getContents() != NULL ) {
|
||||
daeMetaElementArrayAttribute *contents = _meta->getContents();
|
||||
for ( int i = 0; i < contents->getCount( this ); i++ ) {
|
||||
ret->placeElement( (*(daeElementRef*)contents->get( this, i ))->clone(idSuffix, nameSuffix) );
|
||||
}
|
||||
daeElementRefArray children;
|
||||
_meta->getChildren( this, children );
|
||||
for ( size_t x = 0; x < children.getCount(); x++ ) {
|
||||
ret->placeElement( children.get(x)->clone( idSuffix, nameSuffix ) );
|
||||
}
|
||||
else {
|
||||
daeMetaElementAttributeArray &meas = _meta->getMetaElements();
|
||||
for(unsigned int i = 0; i < meas.getCount(); i++) {
|
||||
for ( int c = 0; c < meas[i]->getCount( this ); c++ ) {
|
||||
ret->placeElement( (*(daeElementRef*)meas[i]->get( this, c ))->clone(idSuffix, nameSuffix) );
|
||||
}
|
||||
}
|
||||
}
|
||||
//ret->ref(); //called because the cast to daeElement* releases a reference causing premature deletion
|
||||
|
||||
//mangle the id
|
||||
daeMetaAttribute *id = _meta->getIDAttribute();
|
||||
if ( idSuffix != NULL && id != NULL ) {
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <dae/daeIDRef.h>
|
||||
#include <dae/daeDatabase.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
|
||||
daeIDRefResolverPtrArray daeIDRefResolver::_KnownResolvers;
|
||||
|
||||
void
|
||||
@@ -154,9 +156,9 @@ daeIDRefResolver::attemptResolveID(daeIDRef& id)
|
||||
return;
|
||||
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
fprintf(stderr,
|
||||
"daeIDRefResolver::attemptResolveID(%s) - failed\n",
|
||||
id.getID());
|
||||
char msg[128];
|
||||
sprintf(msg,"daeIDRefResolver::attemptResolveID(%s) - failed\n",id.getID());
|
||||
daeErrorHandler::get()->handleWarning( msg );
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -212,10 +214,9 @@ daeDefaultIDRefResolver::resolveElement(daeIDRef& idref, daeString typeNameHint)
|
||||
|
||||
if (status||(resolved==NULL)) {
|
||||
idref.setState( daeIDRef::id_failed_id_not_found );
|
||||
fprintf(stderr,
|
||||
"daeDefaultIDRefResolver::resolveElement() - failed to resolve %s\n",
|
||||
idref.getID());
|
||||
fflush(stderr);
|
||||
char msg[128];
|
||||
sprintf(msg,"daeDefaultIDRefResolver::resolveElement() - failed to resolve %s\n",idref.getID());
|
||||
daeErrorHandler::get()->handleWarning( msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
60
Extras/COLLADA_DOM/src/dae/daeMetaAny.cpp
Normal file
60
Extras/COLLADA_DOM/src/dae/daeMetaAny.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include <dae/daeMetaAny.h>
|
||||
#include <dae/domAny.h>
|
||||
#include <dae/daeMetaElementAttribute.h>
|
||||
|
||||
daeMetaAny::daeMetaAny( daeMetaElement *container, daeMetaCMPolicy *parent, daeUInt ordinal,
|
||||
daeInt minO, daeInt maxO) : daeMetaCMPolicy( container, parent, ordinal, minO, maxO )
|
||||
{}
|
||||
|
||||
daeMetaAny::~daeMetaAny()
|
||||
{}
|
||||
|
||||
daeElement *daeMetaAny::placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after ) {
|
||||
//remove element from praent
|
||||
(void)offset;
|
||||
(void)before;
|
||||
(void)after;
|
||||
daeElement::removeFromParent( child );
|
||||
child->setParentElement( parent );
|
||||
//*************************************************************************
|
||||
ordinal = 0;
|
||||
return child;
|
||||
}
|
||||
|
||||
daeBool daeMetaAny::removeElement( daeElement *parent, daeElement *child ) {
|
||||
(void)parent;
|
||||
(void)child;
|
||||
return true;
|
||||
}
|
||||
|
||||
daeMetaElement * daeMetaAny::findChild( daeString elementName ) {
|
||||
if ( elementName != NULL ) {
|
||||
const daeMetaElementRefArray &metas = daeMetaElement::getAllMetas();
|
||||
for ( size_t x = 0; x < metas.getCount(); x++ ) {
|
||||
if ( !metas[x]->getIsInnerClass() && strcmp( elementName, metas[x]->getName() ) == 0 ) {
|
||||
return metas[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return domAny::registerElement();
|
||||
}
|
||||
|
||||
void daeMetaAny::getChildren( daeElement *parent, daeElementRefArray &array ) {
|
||||
(void)parent;
|
||||
(void)array;
|
||||
//this is taken care of by the _contents in metaElement
|
||||
}
|
||||
|
||||
@@ -13,36 +13,24 @@
|
||||
|
||||
#include <dae/daeMetaAttribute.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
|
||||
daeStringRefArrayArray daeMetaAttribute::_NameBindings;
|
||||
daeMetaAttributeRefArray daeMetaAttribute::_FactoryTemplates;
|
||||
#include <dae/daeErrorHandler.h>
|
||||
|
||||
void
|
||||
daeMetaAttribute::set(daeElement* e, daeString s)
|
||||
{
|
||||
if( _type->getTypeEnum() == daeAtomicType::FloatType || _type->getTypeEnum() == daeAtomicType::DoubleType ) {
|
||||
if ( strcmp(s, "NaN") == 0 ) {
|
||||
fprintf(stderr, "NaN encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
fflush(stderr);
|
||||
char msg[256];
|
||||
sprintf(msg, "NaN encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
daeErrorHandler::get()->handleWarning(msg);
|
||||
}
|
||||
else if ( strcmp(s, "INF") == 0 ) {
|
||||
fprintf(stderr, "INF encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
fflush(stderr);
|
||||
char msg[256];
|
||||
sprintf(msg, "INF encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
daeErrorHandler::get()->handleWarning( msg );
|
||||
}
|
||||
}
|
||||
_type->stringToMemory((char*)s, getWritableMemory(e));
|
||||
_isValid=true;
|
||||
}
|
||||
|
||||
void daeMetaElementAttribute::set(daeElement* e, daeString s)
|
||||
{
|
||||
//_type->stringToMemory((char*)s, getWritableMemory(e));
|
||||
daeElementRef *ref = (daeElementRef*)(getWritableMemory(e));
|
||||
if ((*ref) == NULL) {
|
||||
(*ref) = _elementType->create();
|
||||
}
|
||||
(*ref)->getMeta()->getValueAttribute()->set((*ref), s);
|
||||
_isValid=true;
|
||||
}
|
||||
|
||||
void daeMetaAttribute::copy(daeElement* to, daeElement *from) {
|
||||
@@ -50,7 +38,6 @@ void daeMetaAttribute::copy(daeElement* to, daeElement *from) {
|
||||
_type->memoryToString( getWritableMemory(from), str, 2048 );
|
||||
_type->stringToMemory( str, getWritableMemory( to ) );
|
||||
//memcpy( getWritableMemory( to ), getWritableMemory( from ), getSize() );
|
||||
_isValid=true;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -58,12 +45,14 @@ daeMetaArrayAttribute::set(daeElement* e, daeString s)
|
||||
{
|
||||
if( _type->getTypeEnum() == daeAtomicType::FloatType || _type->getTypeEnum() == daeAtomicType::DoubleType ) {
|
||||
if ( strcmp(s, "NaN") == 0 ) {
|
||||
fprintf(stderr, "NaN encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
fflush(stderr);
|
||||
char msg[256];
|
||||
sprintf(msg, "NaN encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
daeErrorHandler::get()->handleWarning(msg);
|
||||
}
|
||||
else if ( strcmp(s, "INF") == 0 ) {
|
||||
fprintf(stderr, "INF encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
fflush(stderr);
|
||||
char msg[256];
|
||||
sprintf(msg, "INF encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
|
||||
daeErrorHandler::get()->handleWarning( msg );
|
||||
}
|
||||
}
|
||||
daeArray* array = (daeArray*)getWritableMemory(e);
|
||||
@@ -71,7 +60,6 @@ daeMetaArrayAttribute::set(daeElement* e, daeString s)
|
||||
daeInt cnt = (daeInt)array->getCount();
|
||||
array->setRawCount(++cnt);
|
||||
_type->stringToMemory((char*)s, array->getRawData()+(cnt-1)*typeSize);
|
||||
_isValid=true;
|
||||
}
|
||||
|
||||
void daeMetaArrayAttribute::copy(daeElement* to, daeElement *from) {
|
||||
@@ -90,208 +78,6 @@ void daeMetaArrayAttribute::copy(daeElement* to, daeElement *from) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void daeMetaElementAttribute::copy(daeElement* to, daeElement *from) {
|
||||
daeElement *cpy = (*(daeElementRef*)(getWritableMemory(from)))->clone();
|
||||
(*(daeElementRef*)(getWritableMemory(to))) = cpy;
|
||||
}
|
||||
void daeMetaElementArrayAttribute::copy(daeElement* to, daeElement *from) {
|
||||
(void)to;
|
||||
(void)from;
|
||||
}
|
||||
|
||||
daeMetaElementArrayAttribute::daeMetaElementArrayAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElementAttribute::placeElement(daeElement* parent, daeElement* child)
|
||||
{
|
||||
if (parent == NULL)
|
||||
return;
|
||||
|
||||
daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
|
||||
*er = child;
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElementArrayAttribute::placeElement(daeElement* parent,
|
||||
daeElement* child)
|
||||
{
|
||||
if ((parent == NULL)||(child == NULL))
|
||||
return;
|
||||
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
|
||||
era->append(child);
|
||||
}
|
||||
// !!!GAC added for testing 7/8/05
|
||||
// These are the opposite of the placeElement functions above
|
||||
void
|
||||
daeMetaElementAttribute::removeElement(daeElement* parent, daeElement* child)
|
||||
{
|
||||
(void)child; // silence unused variable warning
|
||||
|
||||
if (parent == NULL)
|
||||
return;
|
||||
|
||||
daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
|
||||
*er = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElementArrayAttribute::removeElement(daeElement* parent,
|
||||
daeElement* child)
|
||||
{
|
||||
if ((parent == NULL)||(child == NULL))
|
||||
return;
|
||||
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
|
||||
era->remove(child);
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElementAttribute::setDocument( daeElement * parent, daeDocument* c )
|
||||
{
|
||||
daeElementRef* er = (daeElementRef*)getWritableMemory( parent );
|
||||
if ( ((daeElement*)(*er)) != NULL ) {
|
||||
(*er)->setDocument( c );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElementArrayAttribute::setDocument( daeElement * parent, daeDocument* c )
|
||||
{
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory( parent );
|
||||
for ( unsigned int i = 0; i < era->getCount(); i++ ) {
|
||||
era->get(i)->setDocument( c );
|
||||
}
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeMetaElementAttribute::getCount(daeElement* e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return 0;
|
||||
return ((*((daeElementRef*)getWritableMemory(e))) != NULL);
|
||||
}
|
||||
|
||||
daeMemoryRef
|
||||
daeMetaElementAttribute::get(daeElement *e, daeInt index)
|
||||
{
|
||||
(void)index;
|
||||
return getWritableMemory(e);
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeMetaElementArrayAttribute::getCount(daeElement *e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return 0;
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(e);
|
||||
if (era == NULL)
|
||||
return 0;
|
||||
return (daeInt)era->getCount();
|
||||
}
|
||||
|
||||
daeMemoryRef
|
||||
daeMetaElementArrayAttribute::get(daeElement* e, daeInt index)
|
||||
{
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(e);
|
||||
if (era == NULL || index >= (daeInt)era->getCount() )
|
||||
return NULL;
|
||||
return (daeMemoryRef)&(era->get(index));
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaAttribute::InitializeKnownTypes()
|
||||
{
|
||||
daeInt index;
|
||||
index = (daeInt)_FactoryTemplates.append(new daeMetaAttribute);
|
||||
_NameBindings[index].append("int");
|
||||
_NameBindings[index].append("float");
|
||||
_NameBindings[index].append("string");
|
||||
_NameBindings[index].append("enum");
|
||||
|
||||
index = (daeInt)_FactoryTemplates.append(new daeMetaArrayAttribute);
|
||||
_NameBindings[index].append("ListOfFloats");
|
||||
_NameBindings[index].append("ListOfInts");
|
||||
_NameBindings[index].append("ListOfTokens");
|
||||
|
||||
index = (daeInt)_FactoryTemplates.append(new daeMetaElementAttribute);
|
||||
_NameBindings[index].append("xs:element");
|
||||
|
||||
index = (daeInt)_FactoryTemplates.append(new daeMetaElementArrayAttribute);
|
||||
_NameBindings[index].append("element");
|
||||
|
||||
//index = (daeInt)_FactoryTemplates.append(new daeMetaEnumAttribute);
|
||||
//_NameBindings[index].append("__enum");
|
||||
}
|
||||
|
||||
daeMetaAttributeRef
|
||||
daeMetaAttribute::Factory(daeStringRef xmlTypeName)
|
||||
{
|
||||
unsigned int i;
|
||||
for(i=0;i<_FactoryTemplates.getCount();i++) {
|
||||
|
||||
daeStringRefArray& nameBindings = _NameBindings[i];
|
||||
int count = (int)nameBindings.getCount();
|
||||
int j;
|
||||
for(j=0;j<count;j++)
|
||||
if (!strcmp(nameBindings[j],xmlTypeName))
|
||||
break;
|
||||
if (j!=count)
|
||||
return _FactoryTemplates[i]->clone();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeMetaAttributeRef
|
||||
daeMetaAttribute::clone()
|
||||
{
|
||||
return new daeMetaAttribute;
|
||||
}
|
||||
|
||||
daeMetaAttributeRef
|
||||
daeMetaArrayAttribute::clone()
|
||||
{
|
||||
return new daeMetaArrayAttribute;
|
||||
}
|
||||
//daeMetaAttributeRef
|
||||
//daeMetaEnumAttribute::clone()
|
||||
//{
|
||||
// return new daeMetaEnumAttribute;
|
||||
//}
|
||||
|
||||
daeMetaElementAttribute::daeMetaElementAttribute()
|
||||
{
|
||||
_minOccurs = 1;
|
||||
_maxOccurs = 1;
|
||||
_isInChoice = false;
|
||||
_isInSequence = false;
|
||||
//_ref = "noref";
|
||||
_previousInSequence = NULL;
|
||||
_elementType = NULL;
|
||||
}
|
||||
|
||||
daeMetaAttributeRef
|
||||
daeMetaElementAttribute::clone()
|
||||
{
|
||||
return new daeMetaElementAttribute;
|
||||
}
|
||||
|
||||
daeMetaAttributeRef
|
||||
daeMetaElementArrayAttribute::clone()
|
||||
{
|
||||
return new daeMetaElementArrayAttribute;
|
||||
}
|
||||
|
||||
//daeMetaEnumAttribute::daeMetaEnumAttribute()
|
||||
//{
|
||||
//}
|
||||
|
||||
daeMetaAttribute::daeMetaAttribute()
|
||||
{
|
||||
_name = "noname";
|
||||
@@ -299,7 +85,6 @@ daeMetaAttribute::daeMetaAttribute()
|
||||
_type = NULL;
|
||||
_container = NULL;
|
||||
_default = NULL;
|
||||
_isValid = false;
|
||||
_isRequired = false;
|
||||
}
|
||||
|
||||
@@ -321,7 +106,6 @@ daeMetaAttribute::getAlignment()
|
||||
return _type->getAlignment();
|
||||
}
|
||||
|
||||
//!!!ACL 10-18
|
||||
daeInt
|
||||
daeMetaAttribute::getCount(daeElement* e)
|
||||
{
|
||||
@@ -358,4 +142,4 @@ daeMetaArrayAttribute::get(daeElement* e, daeInt index)
|
||||
return NULL;
|
||||
return era->getRawData()+(index*era->getElementSize());
|
||||
}
|
||||
//******************************************************
|
||||
|
||||
|
||||
22
Extras/COLLADA_DOM/src/dae/daeMetaCMPolicy.cpp
Normal file
22
Extras/COLLADA_DOM/src/dae/daeMetaCMPolicy.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include <dae/daeMetaCMPolicy.h>
|
||||
|
||||
daeMetaCMPolicy::~daeMetaCMPolicy()
|
||||
{
|
||||
for( size_t i = 0; i < _children.getCount(); i++ ) {
|
||||
delete _children[i];
|
||||
}
|
||||
}
|
||||
|
||||
95
Extras/COLLADA_DOM/src/dae/daeMetaChoice.cpp
Normal file
95
Extras/COLLADA_DOM/src/dae/daeMetaChoice.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include <dae/daeMetaChoice.h>
|
||||
|
||||
daeMetaChoice::daeMetaChoice( daeMetaElement *container, daeMetaCMPolicy *parent, daeUInt ordinal,
|
||||
daeInt minO, daeInt maxO) : daeMetaCMPolicy( container, parent, ordinal, minO, maxO )
|
||||
{}
|
||||
|
||||
daeMetaChoice::~daeMetaChoice()
|
||||
{}
|
||||
|
||||
daeElement *daeMetaChoice::placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after ) {
|
||||
(void)offset;
|
||||
if ( _maxOccurs == -1 ) {
|
||||
//Needed to prevent infinate loops. If unbounded check to see if you have the child before just trying to place
|
||||
daeString nm = child->getElementName();
|
||||
if ( nm == NULL ) {
|
||||
nm = child->getTypeName();
|
||||
}
|
||||
if ( findChild( nm ) == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
daeElement *retVal = NULL;
|
||||
for ( daeInt i = 0; ( i < _maxOccurs || _maxOccurs == -1 ); i++ ) {
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
if ( _children[x]->placeElement( parent, child, ordinal, i, before, after ) != NULL ) {
|
||||
retVal = child;
|
||||
ordinal = ordinal + _ordinalOffset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( retVal != NULL ) break;
|
||||
}
|
||||
/*if ( retVal && _maxOccurs != -1 ) {
|
||||
//check if the place was valid - only if we aren't unbounded. unbounded is always valid
|
||||
daeInt cnt = 0;
|
||||
daeElementRefArray array;
|
||||
size_t arrayCnt = 0; //saves us from having to clear the array every child
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
_children[x]->getChildren( parent, array );
|
||||
if ( array.getCount() != arrayCnt ) {
|
||||
//this part of the content model has children.
|
||||
cnt++;
|
||||
if ( cnt > _maxOccurs ) {
|
||||
//picked too many choices - remove element and return false
|
||||
removeElement( parent, child );
|
||||
return false;
|
||||
}
|
||||
arrayCnt = array.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
return retVal;
|
||||
}
|
||||
|
||||
daeBool daeMetaChoice::removeElement( daeElement *parent, daeElement *child ) {
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
if ( _children[x]->removeElement( parent, child ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
daeMetaElement * daeMetaChoice::findChild( daeString elementName ) {
|
||||
daeMetaElement *me = NULL;
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
me = _children[x]->findChild( elementName );
|
||||
if ( me != NULL ) {
|
||||
return me;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void daeMetaChoice::getChildren( daeElement *parent, daeElementRefArray &array ) {
|
||||
(void)parent;
|
||||
(void)array;
|
||||
//this is taken care of by the _contents in metaElement
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
|
||||
#include <dae/daeMetaElement.h>
|
||||
#include <dae/daeElement.h>
|
||||
#include <dae/daeDocument.h>
|
||||
#include <dae/domAny.h>
|
||||
#include <dae/daeMetaCMPolicy.h>
|
||||
#include <dae/daeMetaElementAttribute.h>
|
||||
|
||||
daeMetaElementRefArray daeMetaElement::_metas;
|
||||
|
||||
@@ -30,6 +33,33 @@ daeMetaElement::create()
|
||||
return ret;
|
||||
}
|
||||
|
||||
daeElementRef
|
||||
daeMetaElement::create(daeString s)
|
||||
{
|
||||
daeMetaElement* me = NULL;
|
||||
if ( strcmp( s, _name ) == 0 ) {
|
||||
//looking for this meta
|
||||
me = this;
|
||||
}
|
||||
else {
|
||||
me = _contentModel->findChild(s);
|
||||
}
|
||||
if (me != NULL) {
|
||||
daeElementRef ret = me->create();
|
||||
if ( strcmp(s, me->getName() ) != 0 ) {
|
||||
ret->setElementName(s);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if ( getAllowsAny() ) {
|
||||
daeElementRef ret = domAny::registerElement()->create();
|
||||
ret->setElementName(s);
|
||||
return ret;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
daeMetaElement*
|
||||
daeMetaElement::findChild(daeString s)
|
||||
{
|
||||
@@ -61,119 +91,39 @@ daeMetaElement::findChild(daeString s)
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeElementRef
|
||||
daeMetaElement::create(daeString s)
|
||||
{
|
||||
daeMetaElement* me = findChild(s);
|
||||
if (me != NULL) {
|
||||
daeElementRef ret = me->create();
|
||||
if ( strcmp(s, me->getName() ) != 0 ) {
|
||||
ret->setElementName(s);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if ( getAllowsAny() ) {
|
||||
daeElementRef ret = domAny::registerElement()->create();
|
||||
ret->setElementName(s);
|
||||
return ret;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeMetaElement *
|
||||
daeMetaElement::getChildMetaElement(daeString s)
|
||||
{
|
||||
int n = (int)_metaElements.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
if (strcmp(_metaElements[i]->_elementType->_name,s)==0)
|
||||
return _metaElements[i]->_elementType;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeMetaElementAttribute *
|
||||
daeMetaElement::getChildMetaElementAttribute(daeString s)
|
||||
{
|
||||
int n = (int)_metaElements.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
if (strcmp(_metaElements[i]->_elementType->_name,s)==0)
|
||||
return _metaElements[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define defMAEA(class,maename) \
|
||||
{ \
|
||||
defMetaAttributeElement* maea = new daeMetaAttributeArrayElement; \
|
||||
maea->
|
||||
|
||||
#define defME(class, name) \
|
||||
daeMetaElement* parent = active; \
|
||||
daeMetaElement* active = new daeMetaElement; \
|
||||
active->_name = "##name##"; \
|
||||
active->_elementSize = sizeof( class ); \
|
||||
if (parent != NULL) \
|
||||
parent->appendElement(active, daeOffsetOf( parent, name ));
|
||||
|
||||
|
||||
#define defMA(class,matype,maname) \
|
||||
{ \
|
||||
daeMetaAttribute* ma = new daeMetaAttribute; \
|
||||
ma->_name = "##maname##";\
|
||||
ma->_type = daeAtomicType::get("##matype##");\
|
||||
ma->_offset = daeOffsetOf( class , _##maname );\
|
||||
ma->_container = active; \
|
||||
active->appendAttribute(ma); \
|
||||
}
|
||||
|
||||
daeMetaElement* daeMetaElement::_Schema = NULL;
|
||||
|
||||
void
|
||||
daeMetaElement::initializeSchemaMeta()
|
||||
{
|
||||
}
|
||||
}*/
|
||||
|
||||
daeMetaElement::daeMetaElement()
|
||||
{
|
||||
_name = "noname";
|
||||
_createFunc = NULL;
|
||||
_minOccurs = 1;
|
||||
_maxOccurs = 1;
|
||||
_ref = "none";
|
||||
_isSequence = false;
|
||||
_isChoice = false;
|
||||
_needsResolve = false;
|
||||
_elementSize = sizeof(daeElement);
|
||||
_metaValue = NULL;
|
||||
_metaContents = NULL;
|
||||
_metaIntegration = NULL;
|
||||
_metaID = NULL;
|
||||
_parent = NULL;
|
||||
_staticPointerAddress = NULL;
|
||||
_isTrackableForQueries = true;
|
||||
_usesStringContents = false;
|
||||
_isTransparent = false;
|
||||
_isAbstract = false;
|
||||
_allowsAny = false;
|
||||
_innerClass = false;
|
||||
_metas.append(this);
|
||||
|
||||
_contentModel = NULL;
|
||||
}
|
||||
|
||||
daeMetaElement::~daeMetaElement()
|
||||
{
|
||||
if (_metaContents)
|
||||
delete _metaContents;
|
||||
if (_staticPointerAddress != NULL)
|
||||
*_staticPointerAddress = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElement::addContents(daeInt offset)
|
||||
{
|
||||
daeMetaElementArrayAttribute* meaa = new daeMetaElementArrayAttribute;
|
||||
daeMetaElementArrayAttribute* meaa = new daeMetaElementArrayAttribute( this, NULL, 0, 1, -1 );
|
||||
meaa->setType(daeAtomicType::get("element"));
|
||||
meaa->setName("contents");
|
||||
meaa->setOffset(offset);
|
||||
@@ -181,9 +131,19 @@ daeMetaElement::addContents(daeInt offset)
|
||||
meaa->setElementType( daeElement::getMeta() );
|
||||
_metaContents = meaa;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
daeMetaElement::addContentsOrder(daeInt offset)
|
||||
{
|
||||
daeMetaArrayAttribute* meaa = new daeMetaArrayAttribute();
|
||||
meaa->setType(daeAtomicType::get("uint"));
|
||||
meaa->setName("contentsOrder");
|
||||
meaa->setOffset(offset);
|
||||
meaa->setContainer( this);
|
||||
_metaContentsOrder = meaa;
|
||||
}
|
||||
|
||||
|
||||
/*void
|
||||
daeMetaElement::appendArrayElement(daeMetaElement* element, daeInt offset, daeString name)
|
||||
{
|
||||
daeMetaElementArrayAttribute* meaa = new daeMetaElementArrayAttribute;
|
||||
@@ -198,7 +158,6 @@ daeMetaElement::appendArrayElement(daeMetaElement* element, daeInt offset, daeSt
|
||||
meaa->setContainer(this);
|
||||
meaa->setElementType( element);
|
||||
_metaElements.append(meaa);
|
||||
element->_parent = this;
|
||||
}
|
||||
void
|
||||
daeMetaElement::appendElement(daeMetaElement* element, daeInt offset, daeString name)
|
||||
@@ -215,8 +174,7 @@ daeMetaElement::appendElement(daeMetaElement* element, daeInt offset, daeString
|
||||
meaa->setContainer( this );
|
||||
meaa->setElementType( element );
|
||||
_metaElements.append(meaa);
|
||||
element->_parent = this;
|
||||
}
|
||||
}*/
|
||||
|
||||
void
|
||||
daeMetaElement::appendAttribute(daeMetaAttribute* attr)
|
||||
@@ -282,10 +240,225 @@ void daeMetaElement::releaseMetas()
|
||||
_metas.clear();
|
||||
}
|
||||
|
||||
void daeMetaElement::appendPossibleChild( daeString name, daeMetaElementAttribute* cont, daeString type ) {
|
||||
_otherChildren.append( name );
|
||||
_otherChildrenContainer.append( cont );
|
||||
if ( type ) _otherChildrenTypes.append( type );
|
||||
else _otherChildrenTypes.append( "" );
|
||||
daeBool daeMetaElement::place(daeElement *parent, daeElement *child, daeUInt *ordinal )
|
||||
{
|
||||
if (child->getMeta()->getIsAbstract() || parent->getMeta() != this ) {
|
||||
return false;
|
||||
}
|
||||
daeUInt ord;
|
||||
daeElement *retVal = _contentModel->placeElement( parent, child, ord );
|
||||
if ( retVal != NULL ) {
|
||||
//update document pointer
|
||||
child->setDocument( parent->getDocument() );
|
||||
if ( parent->getDocument() ) {
|
||||
parent->getDocument()->insertElement( retVal );
|
||||
parent->getDocument()->setModified(true);
|
||||
}
|
||||
//add to _contents array
|
||||
if (_metaContents != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_metaContents->getWritableMemory(parent);
|
||||
daeUIntArray* contentsOrder =
|
||||
(daeUIntArray*)_metaContentsOrder->getWritableMemory(parent);
|
||||
daeBool needsAppend = true;
|
||||
for ( size_t x = 0; x < contentsOrder->getCount(); x++ ) {
|
||||
if ( contentsOrder->get(x) > ord ) {
|
||||
contents->insertAt( x, retVal );
|
||||
contentsOrder->insertAt( x, ord );
|
||||
needsAppend = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( needsAppend ) {
|
||||
contents->append(retVal);
|
||||
contentsOrder->append( ord );
|
||||
}
|
||||
}
|
||||
if ( ordinal != NULL ) {
|
||||
*ordinal = ord;
|
||||
}
|
||||
}
|
||||
return retVal!=NULL;
|
||||
}
|
||||
|
||||
daeBool daeMetaElement::placeAt( daeInt index, daeElement *parent, daeElement *child )
|
||||
{
|
||||
if (child->getMeta()->getIsAbstract() || parent->getMeta() != this || index < 0 ) {
|
||||
return false;
|
||||
}
|
||||
daeUInt ord;
|
||||
daeElement *retVal = _contentModel->placeElement( parent, child, ord );
|
||||
if ( retVal != NULL ) {
|
||||
//add to _contents array
|
||||
if (_metaContents != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_metaContents->getWritableMemory(parent);
|
||||
daeUIntArray* contentsOrder =
|
||||
(daeUIntArray*)_metaContentsOrder->getWritableMemory(parent);
|
||||
daeBool validLoc;
|
||||
if ( index > 0 ) {
|
||||
validLoc = contentsOrder->get(index) >= ord && contentsOrder->get(index) <= ord;
|
||||
}
|
||||
else {
|
||||
validLoc = contentsOrder->get(index) >= ord;
|
||||
}
|
||||
if ( validLoc ) {
|
||||
contents->insertAt( index, retVal );
|
||||
contentsOrder->insertAt( index, ord );
|
||||
}
|
||||
else {
|
||||
_contentModel->removeElement( parent, retVal );
|
||||
retVal = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( retVal != NULL ) {
|
||||
//update document pointer
|
||||
child->setDocument( parent->getDocument() );
|
||||
if ( parent->getDocument() ) {
|
||||
parent->getDocument()->insertElement( retVal );
|
||||
parent->getDocument()->setModified(true);
|
||||
}
|
||||
}
|
||||
return retVal!=NULL;
|
||||
}
|
||||
|
||||
daeBool daeMetaElement::placeBefore( daeElement *marker, daeElement *parent, daeElement *child, daeUInt *ordinal )
|
||||
{
|
||||
if (child->getMeta()->getIsAbstract() || parent->getMeta() != this ) {
|
||||
return false;
|
||||
}
|
||||
daeUInt ord;
|
||||
daeElement *retVal = _contentModel->placeElement( parent, child, ord, 0, marker, NULL );
|
||||
if ( retVal != NULL ) {
|
||||
//add to _contents array
|
||||
if (_metaContents != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_metaContents->getWritableMemory(parent);
|
||||
daeUIntArray* contentsOrder =
|
||||
(daeUIntArray*)_metaContentsOrder->getWritableMemory(parent);
|
||||
size_t index(0);
|
||||
daeBool validLoc = false;
|
||||
if ( contents->find( marker, index ) == DAE_OK ) {
|
||||
if ( index > 0 ) {
|
||||
daeUInt gt = contentsOrder->get(index-1);
|
||||
daeUInt lt = contentsOrder->get(index);
|
||||
validLoc = gt <= ord && lt >= ord;
|
||||
}
|
||||
else {
|
||||
validLoc = contentsOrder->get(index) >= ord;
|
||||
}
|
||||
}
|
||||
if ( validLoc ) {
|
||||
contents->insertAt( index, retVal );
|
||||
contentsOrder->insertAt( index, ord );
|
||||
if ( ordinal != NULL ) {
|
||||
*ordinal = ord;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_contentModel->removeElement( parent, retVal );
|
||||
retVal = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( retVal != NULL ) {
|
||||
//update document pointer
|
||||
child->setDocument( parent->getDocument() );
|
||||
if ( parent->getDocument() ) {
|
||||
parent->getDocument()->insertElement( retVal );
|
||||
parent->getDocument()->setModified(true);
|
||||
}
|
||||
}
|
||||
return retVal!=NULL;
|
||||
}
|
||||
|
||||
daeBool daeMetaElement::placeAfter( daeElement *marker, daeElement *parent, daeElement *child, daeUInt *ordinal )
|
||||
{
|
||||
if (child->getMeta()->getIsAbstract() || parent->getMeta() != this ) {
|
||||
return false;
|
||||
}
|
||||
daeUInt ord;
|
||||
daeElement *retVal = _contentModel->placeElement( parent, child, ord, 0, marker, NULL );
|
||||
if ( retVal != NULL ) {
|
||||
//add to _contents array
|
||||
if (_metaContents != NULL) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_metaContents->getWritableMemory(parent);
|
||||
daeUIntArray* contentsOrder =
|
||||
(daeUIntArray*)_metaContentsOrder->getWritableMemory(parent);
|
||||
size_t index(0);
|
||||
daeBool validLoc = false;
|
||||
if ( contents->find( marker, index ) == DAE_OK ) {
|
||||
if ( index < contentsOrder->getCount()-1 ) {
|
||||
validLoc = contentsOrder->get(index) <= ord && contentsOrder->get(index+1) >= ord;
|
||||
}
|
||||
else {
|
||||
validLoc = contentsOrder->get(index) <= ord;
|
||||
}
|
||||
}
|
||||
if ( validLoc ) {
|
||||
contents->insertAt( index+1, retVal );
|
||||
contentsOrder->insertAt( index+1, ord );
|
||||
if ( ordinal != NULL ) {
|
||||
*ordinal = ord;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_contentModel->removeElement( parent, retVal );
|
||||
retVal = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( retVal != NULL ) {
|
||||
//update document pointer
|
||||
child->setDocument( parent->getDocument() );
|
||||
if ( parent->getDocument() ) {
|
||||
parent->getDocument()->insertElement( retVal );
|
||||
parent->getDocument()->setModified(true);
|
||||
}
|
||||
}
|
||||
return retVal!=NULL;
|
||||
}
|
||||
|
||||
daeBool daeMetaElement::remove(daeElement *parent, daeElement *child)
|
||||
{
|
||||
if ( parent->getMeta() != this ) {
|
||||
return false;
|
||||
}
|
||||
//prevent child from being deleted
|
||||
daeElementRef el( child );
|
||||
if ( _contentModel->removeElement( parent, child ) ) {
|
||||
if ( _metaContents != NULL)
|
||||
{
|
||||
daeElementRefArray* contents = (daeElementRefArray*)_metaContents->getWritableMemory(parent);
|
||||
daeUIntArray* contentsOrder = (daeUIntArray*)_metaContentsOrder->getWritableMemory(parent);
|
||||
size_t idx(0);
|
||||
if ( contents->remove(child, &idx) == DAE_OK ) {
|
||||
contentsOrder->removeIndex( idx );
|
||||
}
|
||||
}
|
||||
if ( child->getDocument() ) {
|
||||
child->getDocument()->removeElement( child );
|
||||
child->getDocument()->setModified(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void daeMetaElement::getChildren( daeElement* parent, daeElementRefArray &array )
|
||||
{
|
||||
if ( parent->getMeta() != this ) {
|
||||
return;
|
||||
}
|
||||
if ( _metaContents != NULL ) {
|
||||
daeElementRefArray* contents = (daeElementRefArray*)_metaContents->getWritableMemory(parent);
|
||||
for ( size_t x = 0; x < contents->getCount(); x++ ) {
|
||||
array.append( contents->get(x) );
|
||||
}
|
||||
}
|
||||
else if ( _contentModel != NULL ) {
|
||||
_contentModel->getChildren( parent, array );
|
||||
}
|
||||
}
|
||||
|
||||
231
Extras/COLLADA_DOM/src/dae/daeMetaElementAttribute.cpp
Normal file
231
Extras/COLLADA_DOM/src/dae/daeMetaElementAttribute.cpp
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include <dae/daeMetaElementAttribute.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
|
||||
daeMetaElementAttribute::daeMetaElementAttribute( daeMetaElement *container, daeMetaCMPolicy *parent, daeUInt ordinal,
|
||||
daeInt minO, daeInt maxO) : daeMetaCMPolicy( container, parent, ordinal, minO, maxO )
|
||||
{
|
||||
_elementType = NULL;
|
||||
}
|
||||
|
||||
daeMetaElementAttribute::~daeMetaElementAttribute()
|
||||
{}
|
||||
|
||||
daeMetaElementArrayAttribute::daeMetaElementArrayAttribute( daeMetaElement *container, daeMetaCMPolicy *parent, daeUInt ordinal,
|
||||
daeInt minO, daeInt maxO) : daeMetaElementAttribute( container, parent, ordinal, minO, maxO )
|
||||
{
|
||||
}
|
||||
|
||||
daeMetaElementArrayAttribute::~daeMetaElementArrayAttribute()
|
||||
{}
|
||||
|
||||
|
||||
void daeMetaElementAttribute::set(daeElement* e, daeString s)
|
||||
{
|
||||
//_type->stringToMemory((char*)s, getWritableMemory(e));
|
||||
daeElementRef *ref = (daeElementRef*)(getWritableMemory(e));
|
||||
if ((*ref) == NULL) {
|
||||
(*ref) = _elementType->create();
|
||||
}
|
||||
(*ref)->getMeta()->getValueAttribute()->set((*ref), s);
|
||||
}
|
||||
|
||||
void daeMetaElementAttribute::copy(daeElement* to, daeElement *from) {
|
||||
daeElement *cpy = (*(daeElementRef*)(getWritableMemory(from)))->clone();
|
||||
(*(daeElementRef*)(getWritableMemory(to))) = cpy;
|
||||
}
|
||||
|
||||
void daeMetaElementArrayAttribute::copy(daeElement* to, daeElement *from) {
|
||||
(void)to;
|
||||
(void)from;
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElementAttribute::setDocument( daeElement * parent, daeDocument* c )
|
||||
{
|
||||
daeElementRef* er = (daeElementRef*)getWritableMemory( parent );
|
||||
if ( ((daeElement*)(*er)) != NULL ) {
|
||||
(*er)->setDocument( c );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElementArrayAttribute::setDocument( daeElement * parent, daeDocument* c )
|
||||
{
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory( parent );
|
||||
for ( unsigned int i = 0; i < era->getCount(); i++ ) {
|
||||
era->get(i)->setDocument( c );
|
||||
}
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeMetaElementAttribute::getCount(daeElement* e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return 0;
|
||||
return ((*((daeElementRef*)getWritableMemory(e))) != NULL);
|
||||
}
|
||||
|
||||
daeMemoryRef
|
||||
daeMetaElementAttribute::get(daeElement *e, daeInt index)
|
||||
{
|
||||
(void)index;
|
||||
return getWritableMemory(e);
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeMetaElementArrayAttribute::getCount(daeElement *e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return 0;
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(e);
|
||||
if (era == NULL)
|
||||
return 0;
|
||||
return (daeInt)era->getCount();
|
||||
}
|
||||
|
||||
daeMemoryRef
|
||||
daeMetaElementArrayAttribute::get(daeElement* e, daeInt index)
|
||||
{
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(e);
|
||||
if (era == NULL || index >= (daeInt)era->getCount() )
|
||||
return NULL;
|
||||
return (daeMemoryRef)&(era->get(index));
|
||||
}
|
||||
|
||||
daeElement *
|
||||
daeMetaElementAttribute::placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after )
|
||||
{
|
||||
(void)offset;
|
||||
(void)before;
|
||||
(void)after;
|
||||
if ((parent == NULL)||(child == NULL))
|
||||
return NULL;
|
||||
if ( child->getMeta() != _elementType || ( child->getElementName() != NULL && strcmp( child->getElementName(), _name ) != 0 ) ) {
|
||||
return NULL;
|
||||
}
|
||||
if (child->getParentElement() == parent) {
|
||||
//I Don't know why this gets called when the child already has this as parent.
|
||||
return child;
|
||||
}
|
||||
daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
|
||||
|
||||
daeElement::removeFromParent( child );
|
||||
child->setParentElement( parent );
|
||||
|
||||
*er = child;
|
||||
ordinal = _ordinalOffset;
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
daeElement *
|
||||
daeMetaElementArrayAttribute::placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after )
|
||||
{
|
||||
if ((parent == NULL)||(child == NULL))
|
||||
return NULL;
|
||||
if ( child->getMeta() != _elementType || ( child->getElementName() != NULL && strcmp( child->getElementName(), _name ) != 0 ) ) {
|
||||
return NULL;
|
||||
}
|
||||
if (child->getParentElement() == parent) {
|
||||
//I Don't know why this gets called when the child already has this as parent.
|
||||
return child;
|
||||
}
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
|
||||
if ( _maxOccurs != -1 && (daeInt)era->getCount()-offset >= _maxOccurs ) {
|
||||
return NULL;
|
||||
}
|
||||
removeElement( child->getParentElement(), child );
|
||||
child->setParentElement( parent );
|
||||
|
||||
if ( before != NULL || after != NULL ) {
|
||||
if ( before != NULL && before->getMeta() == _elementType ) {
|
||||
size_t idx(0);
|
||||
if ( era->find( before, idx ) == DAE_OK ) {
|
||||
era->insertAt( idx, child );
|
||||
}
|
||||
}
|
||||
else if ( after != NULL && after->getMeta() == _elementType ) {
|
||||
size_t idx(0);
|
||||
if ( era->find( after, idx ) == DAE_OK ) {
|
||||
era->insertAt( idx+1, child );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
era->append(child);
|
||||
}
|
||||
ordinal = _ordinalOffset;
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
// These are the opposite of the placeElement functions above
|
||||
daeBool
|
||||
daeMetaElementAttribute::removeElement(daeElement* parent, daeElement* child)
|
||||
{
|
||||
(void)child; // silence unused variable warning
|
||||
|
||||
if ((parent == NULL)||(child == NULL ))
|
||||
return false;
|
||||
|
||||
daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
|
||||
if ( *er != child ) {
|
||||
return false;
|
||||
}
|
||||
*er = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeMetaElementArrayAttribute::removeElement(daeElement* parent,
|
||||
daeElement* child)
|
||||
{
|
||||
if ((parent == NULL)||(child == NULL))
|
||||
return false ;
|
||||
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
|
||||
/* if ( (daeInt)era->getCount() <= _minOccurs ) {
|
||||
return false;
|
||||
}*/
|
||||
daeInt error = era->remove(child);
|
||||
if ( error != DAE_OK ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
daeMetaElement *daeMetaElementAttribute::findChild( daeString elementName ) {
|
||||
if ( strcmp( elementName, _name ) == 0 ) {
|
||||
return _elementType;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void daeMetaElementAttribute::getChildren( daeElement *parent, daeElementRefArray &array ) {
|
||||
daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
|
||||
if ( *er != NULL ) {
|
||||
array.append( *er );
|
||||
}
|
||||
}
|
||||
|
||||
void daeMetaElementArrayAttribute::getChildren( daeElement *parent, daeElementRefArray &array ) {
|
||||
daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
|
||||
for ( size_t x = 0; x < era->getCount(); x++ ) {
|
||||
array.append( era->get(x) );
|
||||
}
|
||||
}
|
||||
139
Extras/COLLADA_DOM/src/dae/daeMetaGroup.cpp
Normal file
139
Extras/COLLADA_DOM/src/dae/daeMetaGroup.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include <dae/daeMetaGroup.h>
|
||||
#include <dae/daeMetaElementAttribute.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
|
||||
daeMetaGroup::daeMetaGroup( daeMetaElementAttribute *econ, daeMetaElement *container,
|
||||
daeMetaCMPolicy *parent, daeUInt ordinal, daeInt minO, daeInt maxO) :
|
||||
daeMetaCMPolicy( container, parent, ordinal, minO, maxO ), _elementContainer( econ )
|
||||
{}
|
||||
|
||||
daeMetaGroup::~daeMetaGroup()
|
||||
{
|
||||
if ( _elementContainer != NULL ) {
|
||||
delete _elementContainer;
|
||||
}
|
||||
}
|
||||
|
||||
daeElement *daeMetaGroup::placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after ) {
|
||||
(void)offset;
|
||||
daeString nm = child->getElementName();
|
||||
if ( nm == NULL ) {
|
||||
nm = child->getTypeName();
|
||||
}
|
||||
if ( findChild( nm ) == NULL ) {
|
||||
return false;
|
||||
}
|
||||
daeElementRef el;
|
||||
#if 0
|
||||
daeInt elCnt = _elementContainer->getCount(parent);
|
||||
//check existing groups
|
||||
//This doesn't work properly. Because the choice can't check if you make two decisions you cannot fail
|
||||
//here when you are supposed to. Luckily the current schema just has groups with single choices so
|
||||
//every element needs a new group container. Wasteful but thats how the schema is and its how it works.
|
||||
for ( daeInt x = 0; x < elCnt; x++ ) {
|
||||
daeMemoryRef mem = _elementContainer->get(parent, x );
|
||||
if ( mem != NULL ) {
|
||||
el = *(daeElementRef*)mem;
|
||||
}
|
||||
if ( el == NULL ) {
|
||||
continue;
|
||||
}
|
||||
if ( before != NULL ) {
|
||||
if ( _elementContainer->_elementType->placeBefore( before, el, child, &ordinal ) ) {
|
||||
ordinal = ordinal + _ordinalOffset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ( after != NULL ) {
|
||||
if ( _elementContainer->_elementType->placeAfter( after, el, child, &ordinal ) ) {
|
||||
ordinal = ordinal + _ordinalOffset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( _elementContainer->_elementType->place( el, child, &ordinal ) ) {
|
||||
ordinal = ordinal + _ordinalOffset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//check if the element trying to be placed is a group element. If so Just add it don't create a new one.
|
||||
if ( strcmp( nm, _elementContainer->getName() ) == 0 ) {
|
||||
if ( _elementContainer->placeElement(parent, child, ordinal, offset ) != NULL ) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
//if you couldn't place in existing groups make a new one if you can
|
||||
el = _elementContainer->placeElement(parent, _elementContainer->_elementType->create(), ordinal, offset );
|
||||
if ( el != NULL ) {
|
||||
//el = *(daeElementRef*)_elementContainer->get(parent, elCnt );
|
||||
if ( before != NULL ) {
|
||||
if ( _elementContainer->_elementType->placeBefore( before, el, child, &ordinal ) ) {
|
||||
ordinal = ordinal + _ordinalOffset;
|
||||
return el;
|
||||
}
|
||||
}
|
||||
else if ( after != NULL ) {
|
||||
if ( _elementContainer->_elementType->placeAfter( after, el, child, &ordinal ) ) {
|
||||
ordinal = ordinal + _ordinalOffset;
|
||||
return el;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( _elementContainer->_elementType->place( el, child, &ordinal ) ) {
|
||||
ordinal = ordinal + _ordinalOffset;
|
||||
return el;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeBool daeMetaGroup::removeElement( daeElement *parent, daeElement *child ) {
|
||||
daeElementRef el;
|
||||
daeInt elCnt = _elementContainer->getCount(parent);
|
||||
for ( daeInt x = 0; x < elCnt; x++ ) {
|
||||
daeMemoryRef mem = _elementContainer->get(parent, x );
|
||||
if ( mem != NULL ) {
|
||||
el = *(daeElementRef*)mem;
|
||||
}
|
||||
if ( el == NULL ) {
|
||||
continue;
|
||||
}
|
||||
if ( el->removeChildElement( child ) ) {
|
||||
_elementContainer->removeChildElement( el );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
daeMetaElement * daeMetaGroup::findChild( daeString elementName ) {
|
||||
if ( strcmp( _elementContainer->getName(), elementName ) == 0 ) {
|
||||
return _elementContainer->getElementType();
|
||||
}
|
||||
return _elementContainer->_elementType->getCMRoot()->findChild( elementName );
|
||||
}
|
||||
|
||||
void daeMetaGroup::getChildren( daeElement *parent, daeElementRefArray &array ) {
|
||||
size_t cnt = _elementContainer->getCount( parent );
|
||||
for ( size_t x = 0; x < cnt; x++ ) {
|
||||
(*((daeElementRef*)_elementContainer->get(parent, (daeInt)x )))->getChildren(array);
|
||||
}
|
||||
//_elementContainer->_elementType->getChildren( parent, array );
|
||||
}
|
||||
|
||||
72
Extras/COLLADA_DOM/src/dae/daeMetaSequence.cpp
Normal file
72
Extras/COLLADA_DOM/src/dae/daeMetaSequence.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include <dae/daeMetaSequence.h>
|
||||
|
||||
daeMetaSequence::daeMetaSequence( daeMetaElement *container, daeMetaCMPolicy *parent, daeUInt ordinal,
|
||||
daeInt minO, daeInt maxO) :
|
||||
daeMetaCMPolicy( container, parent, ordinal, minO, maxO )
|
||||
{}
|
||||
|
||||
daeMetaSequence::~daeMetaSequence()
|
||||
{}
|
||||
|
||||
daeElement *daeMetaSequence::placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after ) {
|
||||
(void)offset;
|
||||
if ( _maxOccurs == -1 ) {
|
||||
//Needed to prevent infinate loops. If unbounded check to see if you have the child before just trying to place
|
||||
daeString nm = child->getElementName();
|
||||
if ( nm == NULL ) {
|
||||
nm = child->getTypeName();
|
||||
}
|
||||
if ( findChild( nm ) == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for ( daeInt i = 0; ( i < _maxOccurs || _maxOccurs == -1 ); i++ ) {
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
if ( _children[x]->placeElement( parent, child, ordinal, i, before, after ) != NULL ) {
|
||||
ordinal = ordinal + (i * ( _maxOrdinal + 1 )) + _ordinalOffset;
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeBool daeMetaSequence::removeElement( daeElement *parent, daeElement *child ) {
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
if ( _children[x]->removeElement( parent, child ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
daeMetaElement * daeMetaSequence::findChild( daeString elementName ) {
|
||||
daeMetaElement *me = NULL;
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
me = _children[x]->findChild( elementName );
|
||||
if ( me != NULL ) {
|
||||
return me;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void daeMetaSequence::getChildren( daeElement *parent, daeElementRefArray &array ) {
|
||||
for ( size_t x = 0; x < _children.getCount(); x++ ) {
|
||||
_children[x]->getChildren( parent, array );
|
||||
}
|
||||
}
|
||||
364
Extras/COLLADA_DOM/src/dae/daeSIDResolver.cpp
Normal file
364
Extras/COLLADA_DOM/src/dae/daeSIDResolver.cpp
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include <dae/daeSIDResolver.h>
|
||||
#include <dae/daeIDRef.h>
|
||||
#include <dae/daeAtomicType.h>
|
||||
#include <dae/daeMetaAttribute.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
#include <dae/daeURI.h>
|
||||
|
||||
daeSIDResolver::daeSIDResolver( daeElement *container, daeString target, daeString profile )
|
||||
{
|
||||
this->container = container;
|
||||
if ( target != NULL ) {
|
||||
this->target = new char[ strlen( target ) +1 ];
|
||||
strcpy( (char*)this->target, target );
|
||||
state = target_loaded;
|
||||
}
|
||||
else {
|
||||
this->target = NULL;
|
||||
state = target_empty;
|
||||
}
|
||||
if ( profile != NULL ) {
|
||||
this->profile = new char[ strlen( profile ) +1 ];
|
||||
strcpy( (char*)this->profile, profile );
|
||||
}
|
||||
else {
|
||||
this->profile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
daeSIDResolver::~daeSIDResolver()
|
||||
{
|
||||
if ( target != NULL ) {
|
||||
delete[] target;
|
||||
target = NULL;
|
||||
}
|
||||
if ( profile != NULL ) {
|
||||
delete[] profile;
|
||||
profile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void daeSIDResolver::setTarget( daeString t )
|
||||
{
|
||||
if ( target != NULL ) {
|
||||
delete[] target;
|
||||
}
|
||||
if ( t != NULL ) {
|
||||
target = new char[ strlen( t ) +1 ];
|
||||
strcpy( (char*)target, t );
|
||||
state = target_loaded;
|
||||
}
|
||||
else {
|
||||
target = NULL;
|
||||
state = target_empty;
|
||||
}
|
||||
element = NULL;
|
||||
doubleArray = NULL;
|
||||
doublePtr = NULL;
|
||||
}
|
||||
|
||||
|
||||
void daeSIDResolver::setProfile( daeString p )
|
||||
{
|
||||
if ( profile != NULL ) {
|
||||
delete[] target;
|
||||
}
|
||||
if ( p != NULL ) {
|
||||
profile = new char[ strlen( p ) +1 ];
|
||||
strcpy( (char*)profile, p );
|
||||
}
|
||||
else {
|
||||
profile = NULL;
|
||||
}
|
||||
element = NULL;
|
||||
doubleArray = NULL;
|
||||
doublePtr = NULL;
|
||||
}
|
||||
|
||||
void daeSIDResolver::setContainer(daeElement* element)
|
||||
{
|
||||
if ( element != container ) {
|
||||
container = element;
|
||||
element = NULL;
|
||||
doubleArray = NULL;
|
||||
doublePtr = NULL;
|
||||
if ( target != NULL ) {
|
||||
state = target_loaded;
|
||||
}
|
||||
else {
|
||||
state = state = target_empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
daeElementRef daeSIDResolver::getElement()
|
||||
{
|
||||
if ( state == target_loaded ) {
|
||||
resolve();
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
daeDoubleArray *daeSIDResolver::getDoubleArray()
|
||||
{
|
||||
if ( state == target_loaded ) {
|
||||
resolve();
|
||||
}
|
||||
return doubleArray;
|
||||
}
|
||||
|
||||
daeDouble *daeSIDResolver::getDouble()
|
||||
{
|
||||
if ( state == target_loaded ) {
|
||||
resolve();
|
||||
}
|
||||
return doublePtr;
|
||||
}
|
||||
|
||||
void daeSIDResolver::resolve()
|
||||
{
|
||||
char * str = (char *)target;
|
||||
char * pos = strchr( str, '/');
|
||||
char * id;
|
||||
if ( pos == NULL ) {
|
||||
pos = strchr( str, '.' );
|
||||
}
|
||||
if ( pos == NULL ) {
|
||||
pos = strchr( str, '(' );
|
||||
}
|
||||
if ( pos != NULL ) {
|
||||
id = new char[ pos - str + 1 ];
|
||||
strncpy( id, str, pos - str );
|
||||
id[ pos - str ] = 0;
|
||||
str = pos;
|
||||
}
|
||||
else {
|
||||
id = new char[ strlen( str ) + 1 ];
|
||||
strcpy( id, str );
|
||||
str = str + strlen( str );
|
||||
}
|
||||
if ( strcmp( id, "." ) == 0 ) {
|
||||
element = container;
|
||||
state = sid_success_element;
|
||||
}
|
||||
else {
|
||||
daeIDRef idref( id );
|
||||
idref.setContainer( container );
|
||||
idref.resolveElement();
|
||||
if ( idref.getState() != daeIDRef::id_success ) {
|
||||
state = sid_failed_not_found;
|
||||
delete[] id;
|
||||
return;
|
||||
}
|
||||
element = idref.getElement();
|
||||
state = sid_success_element;
|
||||
}
|
||||
|
||||
char * next = NULL;
|
||||
while ( *str != '.' && *str != '(' && *str != 0 ) {
|
||||
if ( *str == '/' ) {
|
||||
str++;
|
||||
}
|
||||
if ( next != NULL ) {
|
||||
delete[] next;
|
||||
next = NULL;
|
||||
}
|
||||
pos = strchr( str, '/');
|
||||
if ( pos == NULL ) {
|
||||
pos = strchr( str, '.' );
|
||||
}
|
||||
if ( pos == NULL ) {
|
||||
pos = strchr( str, '(' );
|
||||
}
|
||||
if ( pos != NULL ) {
|
||||
next = new char[ pos - str + 1 ];
|
||||
strncpy( next, str, pos - str );
|
||||
next[ pos - str ] = 0;
|
||||
str = pos;
|
||||
}
|
||||
else {
|
||||
next = new char[ strlen( str ) + 1 ];
|
||||
strcpy( next, str );
|
||||
str = str + strlen( str );
|
||||
}
|
||||
//find the child element with SID of next
|
||||
daeElement *el = findSID( element, next );
|
||||
element = el;
|
||||
if ( element == NULL ) {
|
||||
//failed
|
||||
state = sid_failed_not_found;
|
||||
if ( id != NULL ) {
|
||||
delete[] id;
|
||||
}
|
||||
if ( next != NULL ) {
|
||||
delete[] next;
|
||||
next = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
//check for the double array
|
||||
if ( strcmp( element->getTypeName(), "source" ) == 0 ) {
|
||||
daeElementRefArray children;
|
||||
element->getChildren( children );
|
||||
size_t cnt = children.getCount();
|
||||
|
||||
for ( size_t x = 0; x < cnt; x++ ) {
|
||||
if ( strcmp( children[x]->getTypeName(), "float_array" ) == 0 ) {
|
||||
doubleArray = (daeDoubleArray*)children[x]->getMeta()->getValueAttribute()->getWritableMemory( children[x] );
|
||||
state = sid_success_array;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
daeMetaAttribute *ma = element->getMeta()->getValueAttribute();
|
||||
if ( ma != NULL ) {
|
||||
if ( ma->isArrayAttribute() && ma->getType()->getTypeEnum() == daeAtomicType::DoubleType ) {
|
||||
doubleArray = (daeDoubleArray*)ma->getWritableMemory( element );
|
||||
state = sid_success_array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( state == sid_success_array ) {
|
||||
//found the double array
|
||||
if ( *str == '.' ) {
|
||||
//do the double lookup stuff based on COMMON profile offset
|
||||
str++;
|
||||
if ( strcmp( str, "ANGLE" ) == 0 ) {
|
||||
doublePtr = &(doubleArray->get(3));
|
||||
state = sid_success_double;
|
||||
}
|
||||
else if ( strlen( str ) == 1 ) {
|
||||
switch ( *str ) {
|
||||
case 'X':
|
||||
case 'R':
|
||||
case 'U':
|
||||
case 'S':
|
||||
doublePtr = &(doubleArray->get(0));
|
||||
state = sid_success_double;
|
||||
break;
|
||||
case 'Y':
|
||||
case 'G':
|
||||
case 'V':
|
||||
case 'T':
|
||||
doublePtr = &(doubleArray->get(1));
|
||||
state = sid_success_double;
|
||||
break;
|
||||
case 'Z':
|
||||
case 'B':
|
||||
case 'P':
|
||||
doublePtr = &(doubleArray->get(2));
|
||||
state = sid_success_double;
|
||||
break;
|
||||
case 'W':
|
||||
case 'A':
|
||||
case 'Q':
|
||||
doublePtr = &(doubleArray->get(3));
|
||||
state = sid_success_double;
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
else if ( *str == '(' ) {
|
||||
//do the double lookup stuff based on the offset given
|
||||
str++;
|
||||
pos = strchr( str, '(' );
|
||||
daeInt i = atoi( str );
|
||||
if ( pos != NULL && doubleArray->getCount() == 16 ) {
|
||||
//we are doing a matrix lookup
|
||||
pos++;
|
||||
daeInt j = atoi( pos );
|
||||
doublePtr = &(doubleArray->get( i*4 + j ));
|
||||
state = sid_success_double;
|
||||
}
|
||||
else {
|
||||
//vector lookup
|
||||
if ( (daeInt)doubleArray->getCount() > i ) {
|
||||
doublePtr = &(doubleArray->get(i));
|
||||
state = sid_success_double;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( id != NULL ) {
|
||||
delete[] id;
|
||||
}
|
||||
if ( next != NULL ) {
|
||||
delete[] next;
|
||||
}
|
||||
}
|
||||
|
||||
daeElement *daeSIDResolver::findSID( daeElement *el, daeString sid ) {
|
||||
//first check yourself
|
||||
daeString *s = (daeString*)el->getAttributeValue( "sid" );
|
||||
if ( s != NULL && *s != NULL && strcmp( *s, sid ) == 0 ) {
|
||||
//found it
|
||||
return el;
|
||||
}
|
||||
//and if you are a instance_* then check what you point to
|
||||
daeString nm = el->getElementName();
|
||||
if ( nm == NULL ) {
|
||||
nm = el->getTypeName();
|
||||
}
|
||||
if ( strncmp( nm, "instance_", 9 ) == 0 ) {
|
||||
daeURI *uri = (daeURI*)el->getAttributeValue("url");
|
||||
if ( uri != NULL && uri->getElement() != NULL ) {
|
||||
daeElement *e = findSID( uri->getElement(), sid );
|
||||
if ( e != NULL ) {
|
||||
//found it
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
daeElementRefArray children;
|
||||
el->getChildren( children );
|
||||
size_t cnt = children.getCount();
|
||||
for ( size_t x = 0; x < cnt; x++ ) {
|
||||
//examine the children
|
||||
//char s[56];
|
||||
//daeAtomicType::get( "token" )->memoryToString( children[x]->getAttributeValue( "sid" ), s, 56 );
|
||||
daeString *s = (daeString*)children[x]->getAttributeValue( "sid" );
|
||||
if ( s != NULL && *s != NULL && strcmp( *s, sid ) == 0 ) {
|
||||
//found it
|
||||
return children[x];
|
||||
}
|
||||
}
|
||||
for ( size_t x = 0; x < cnt; x++ ) {
|
||||
//if not found look for it in each child
|
||||
if ( profile != NULL && strcmp( children[x]->getTypeName(), "technique_COMMON" ) == 0 ) {
|
||||
//not looking for common profile
|
||||
continue;
|
||||
}
|
||||
else if ( strcmp( children[x]->getTypeName(), "technique" ) == 0 && children[x]->hasAttribute( "profile" ) ) {
|
||||
if ( profile == NULL || strcmp( profile, children[x]->getAttributeValue( "profile" ) ) != 0 ) {
|
||||
//not looking for this technique profile
|
||||
continue;
|
||||
}
|
||||
}
|
||||
daeElement *e = findSID( children[x], sid );
|
||||
if ( e != NULL ) {
|
||||
//found it
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include <dae/daeStringTable.h>
|
||||
|
||||
daeStringTable::daeStringTable(int stringBufferSize):_stringBufferSize(stringBufferSize)
|
||||
daeStringTable::daeStringTable(int stringBufferSize):_stringBufferSize(stringBufferSize), _empty( "" )
|
||||
{
|
||||
//allocate initial buffer
|
||||
allocateBuffer();
|
||||
@@ -29,6 +29,7 @@ daeString daeStringTable::allocateBuffer()
|
||||
|
||||
daeString daeStringTable::allocString(daeString string)
|
||||
{
|
||||
if ( string == NULL ) return _empty;
|
||||
size_t stringSize = strlen(string) + 1;
|
||||
size_t sizeLeft = _stringBufferSize - _stringBufferIndex;
|
||||
daeString buf;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <dae/daeURI.h>
|
||||
#include <ctype.h>
|
||||
#include <dae/daeDocument.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h> // for getcwd (windows)
|
||||
@@ -28,7 +29,6 @@ daeString findCharacterReverse(daeString string, daeChar stopChar);
|
||||
daeURIResolverPtrArray daeURIResolver::_KnownResolvers;
|
||||
|
||||
static daeURI ApplicationURI(1);
|
||||
daeString empty = "";
|
||||
|
||||
void
|
||||
daeURI::setBaseURI(daeURI& uri)
|
||||
@@ -48,14 +48,14 @@ daeURI::initialize()
|
||||
{
|
||||
// Initialize a URI to it's empty state, same as daeURI::reset but also clears out "container"
|
||||
|
||||
uriString = empty;
|
||||
originalURIString = empty;
|
||||
protocol = empty;
|
||||
authority = empty;
|
||||
filepath = empty;
|
||||
file = empty;
|
||||
id = empty;
|
||||
extension = empty;
|
||||
uriString = NULL;
|
||||
originalURIString = NULL;
|
||||
protocol = NULL;
|
||||
authority = NULL;
|
||||
filepath = NULL;
|
||||
file = NULL;
|
||||
id = NULL;
|
||||
extension = NULL;
|
||||
state = uri_empty;
|
||||
element = NULL;
|
||||
container = NULL;
|
||||
@@ -187,14 +187,14 @@ daeURI::reset()
|
||||
|
||||
// Set everything to the empty string
|
||||
|
||||
uriString = empty;
|
||||
originalURIString = empty;
|
||||
protocol = empty;
|
||||
authority = empty;
|
||||
filepath = empty;
|
||||
file = empty;
|
||||
id = empty;
|
||||
extension = empty;
|
||||
uriString = NULL;
|
||||
originalURIString = NULL;
|
||||
protocol = NULL;
|
||||
authority = NULL;
|
||||
filepath = NULL;
|
||||
file = NULL;
|
||||
id = NULL;
|
||||
extension = NULL;
|
||||
|
||||
state = uri_empty;
|
||||
element = NULL;
|
||||
@@ -232,20 +232,20 @@ findCharacter(daeString string, daeChar stopChar)
|
||||
daeString safeCreate(daeString src)
|
||||
{
|
||||
if (src == NULL)
|
||||
return empty;
|
||||
return NULL;
|
||||
daeChar* ret = (daeChar*)daeMemorySystem::malloc("uri",strlen(src)+1);
|
||||
if (ret == NULL)
|
||||
return empty;
|
||||
return NULL;
|
||||
strcpy(ret,src);
|
||||
|
||||
return ret;
|
||||
}
|
||||
void safeDelete(daeString src)
|
||||
{
|
||||
if(src != empty)
|
||||
if(src != NULL)
|
||||
{
|
||||
daeMemorySystem::free("uri",(void*)src);
|
||||
src = empty;
|
||||
src = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -286,7 +286,7 @@ daeURI::internalSetURI(daeString _URIString)
|
||||
|
||||
// Store the originalURI so you can fix it post Reset
|
||||
daeString oURI = originalURIString;
|
||||
originalURIString = empty;
|
||||
originalURIString = NULL;
|
||||
|
||||
// Reset everything
|
||||
reset();
|
||||
@@ -297,7 +297,7 @@ daeURI::internalSetURI(daeString _URIString)
|
||||
uriString = safeCreate(_URIString);
|
||||
|
||||
tmp = (daeChar*)daeMemorySystem::malloc("tmp",strlen(_URIString)+1);
|
||||
if ((uriString == empty)||(tmp == NULL))
|
||||
if ((uriString == NULL)||(tmp == NULL))
|
||||
return;
|
||||
strcpy(tmp,uriString);
|
||||
|
||||
@@ -403,7 +403,7 @@ daeURI::internalSetURI(daeString _URIString)
|
||||
isAbsolute = true;
|
||||
}
|
||||
else {
|
||||
protocol = empty;
|
||||
protocol = NULL;
|
||||
isAbsolute = false;
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ daeURI::internalSetURI(daeString _URIString)
|
||||
int dirLen = (int)strlen(filepath);
|
||||
|
||||
// append a '/'
|
||||
if ((filepath != empty) && (dirLen > 0) &&
|
||||
if ((filepath != NULL) && (dirLen > 0) &&
|
||||
(filepath[dirLen-1] != '/')) {
|
||||
daeMemorySystem::free("uri",(void*)filepath);
|
||||
filepath = (daeString)daeMemorySystem::malloc("uri", dirLen+2);
|
||||
@@ -566,10 +566,19 @@ daeURI::validate(daeURI* baseURI)
|
||||
}
|
||||
else
|
||||
{
|
||||
newPath = (daeChar*)daeMemorySystem::malloc("uri", strlen(baseURI->filepath) + strlen(filepath) + 1);
|
||||
size_t l = 0;
|
||||
if ( filepath != NULL ) {
|
||||
l = strlen(filepath);
|
||||
}
|
||||
newPath = (daeChar*)daeMemorySystem::malloc("uri", strlen(baseURI->filepath) + l + 1);
|
||||
*newPath = 0;
|
||||
strcat(newPath,baseURI->filepath);
|
||||
strcat(newPath,filepath);
|
||||
if ( filepath != NULL ) {
|
||||
strcat(newPath,filepath);
|
||||
}
|
||||
else {
|
||||
strcat(newPath,"");
|
||||
}
|
||||
}
|
||||
//T.path = remove_dot_segments(T.path);
|
||||
normalizeURIPath(newPath);
|
||||
@@ -589,18 +598,27 @@ daeURI::validate(daeURI* baseURI)
|
||||
// T.fragment = R.fragment;
|
||||
|
||||
// Now for the purpose of maintaining the class members, we reassemble all this into a string version of the URI
|
||||
size_t len = 0;
|
||||
if ( protocol != NULL ) {
|
||||
len += strlen(protocol);
|
||||
}
|
||||
if ( authority != NULL ) {
|
||||
len += strlen(authority);
|
||||
}
|
||||
if ( filepath != NULL ) {
|
||||
len += strlen(filepath);
|
||||
}
|
||||
if ( file != NULL ) {
|
||||
len += strlen(file);
|
||||
}
|
||||
if ( queryString != NULL ) {
|
||||
len += strlen(queryString);
|
||||
}
|
||||
if ( id != NULL ) {
|
||||
len += strlen(id);
|
||||
}
|
||||
daeChar* newURI = (daeChar*)
|
||||
daeMemorySystem::malloc(
|
||||
"uri",
|
||||
strlen(protocol) + // really scheme
|
||||
1 + // space for ":"
|
||||
strlen(authority) + // really authority
|
||||
2 + // space for "//"
|
||||
strlen(filepath) + // path without the filename
|
||||
strlen(file) + // filename part of the path
|
||||
strlen(queryString) + // "#"
|
||||
strlen(id) + // really fragment
|
||||
1); // terminating zero
|
||||
daeMemorySystem::malloc("uri", len + 4 );
|
||||
*newURI = 0;
|
||||
|
||||
if(protocol != NULL && *protocol != 0)
|
||||
@@ -852,19 +870,22 @@ daeURI::resolveURI()
|
||||
daeBool daeURI::getPath(daeChar *dest, daeInt size)
|
||||
{
|
||||
|
||||
if(filepath==0 || file==0)
|
||||
if( file == NULL )
|
||||
{
|
||||
//printf("****** %s : %s\n", uriString, originalURIString);
|
||||
return false;
|
||||
}
|
||||
|
||||
int lenPath = (int)strlen(filepath);
|
||||
*dest = 0;
|
||||
int lenPath = 0;
|
||||
if ( filepath != NULL ) lenPath = (int)strlen(filepath);
|
||||
int lenFile = (int)strlen(file);
|
||||
|
||||
int length = lenPath + lenFile;
|
||||
if (length < size)
|
||||
int len = lenPath + lenFile;
|
||||
if (len < size)
|
||||
{
|
||||
strcpy(dest,filepath);
|
||||
if ( filepath != NULL ) {
|
||||
strcpy(dest,filepath);
|
||||
}
|
||||
strcat(dest,file);
|
||||
return true;
|
||||
}
|
||||
@@ -900,23 +921,25 @@ daeURIResolver::attemptResolveURI(daeURI& uri)
|
||||
return;
|
||||
}
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
fprintf(stderr,
|
||||
"daeURIResolver::attemptResolveURI(%s) - failed\n",
|
||||
uri.getURI());
|
||||
char msg[256];
|
||||
sprintf(msg,"daeURIResolver::attemptResolveURI(%s) - failed\n", uri.getURI());
|
||||
daeErrorHandler::get()->handleWarning( msg );
|
||||
#endif
|
||||
|
||||
if (!foundProtocol) {
|
||||
uri.setState(daeURI::uri_failed_unsupported_protocol);
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
fprintf(stderr,"**protocol '%s' is not supported**\n",uri.getProtocol());
|
||||
fflush(stderr);
|
||||
char msg[128];
|
||||
sprintf(msg,"**protocol '%s' is not supported**\n",uri.getProtocol());
|
||||
daeErrorHandler::get()->handleWarning( msg );
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
fprintf(stderr,"**file(%s/%s) or id(%s) failed to resolve\n",
|
||||
char msg[256];
|
||||
sprintf(msg,"**file(%s/%s) or id(%s) failed to resolve\n",
|
||||
uri.getFilepath(),uri.getFile(),uri.getID());
|
||||
fflush(stderr);
|
||||
daeErrorHandler::get()->handleWarning( msg );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1117,10 +1140,23 @@ void daeURI::normalizeURIPath(char *path)
|
||||
// another existing URI. The new URI is stored in the "originalURI"
|
||||
int daeURI::makeRelativeTo(daeURI* relativeToURI)
|
||||
{
|
||||
// !!!GAC for some reason, relativeToURI is in pending and not success state, why??
|
||||
// Can't do this function unless both URIs have already been successfully resolved
|
||||
if(getState() != uri_success /*|| relativeToURI->getState() != uri_success*/ )
|
||||
return(DAE_ERR_INVALID_CALL); // !!!GAC Need to assign a real error code to this
|
||||
if( getState() == uri_empty || relativeToURI->getState() == uri_empty )
|
||||
return(DAE_ERR_INVALID_CALL);
|
||||
if( getState() == uri_loaded )
|
||||
{
|
||||
if (container != NULL)
|
||||
validate(container->getDocumentURI());
|
||||
else
|
||||
validate();
|
||||
}
|
||||
if( relativeToURI->getState() == uri_loaded )
|
||||
{
|
||||
if (relativeToURI->getContainer() != NULL)
|
||||
relativeToURI->validate(relativeToURI->getContainer()->getDocumentURI());
|
||||
else
|
||||
relativeToURI->validate();
|
||||
}
|
||||
|
||||
|
||||
// Can only do this function if both URIs have the same scheme and authority
|
||||
|
||||
@@ -1158,7 +1194,15 @@ int daeURI::makeRelativeTo(daeURI* relativeToURI)
|
||||
// Delete old URI string
|
||||
safeDelete(originalURIString);
|
||||
// Allocate memory for a new "originalURI" and free the old one
|
||||
char *newRelativeURI = (char*) daeMemorySystem::malloc("uri",strlen(relativeTo_slash)+ strlen(file)+(segment_count*3)+strlen(getID())+2);
|
||||
char *newRelativeURI;
|
||||
if ( getID() == NULL )
|
||||
{
|
||||
newRelativeURI = (char*) daeMemorySystem::malloc("uri",strlen(this_slash)+ strlen(file)+(segment_count*3)+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
newRelativeURI = (char*) daeMemorySystem::malloc("uri",strlen(this_slash)+ strlen(file)+(segment_count*3)+strlen(id)+2);
|
||||
}
|
||||
char *temp = newRelativeURI;
|
||||
for(int i = 0; i < segment_count; i++)
|
||||
{
|
||||
@@ -1167,7 +1211,7 @@ int daeURI::makeRelativeTo(daeURI* relativeToURI)
|
||||
}
|
||||
strcpy(temp,this_slash);
|
||||
strcat(temp,file);
|
||||
if(id!=empty && strlen(getID()) != 0)
|
||||
if(id!=NULL && strlen(getID()) != 0)
|
||||
{
|
||||
strcat(temp,"#");
|
||||
strcat(temp,getID());
|
||||
|
||||
@@ -13,6 +13,14 @@
|
||||
|
||||
#include <dae/daeDom.h>
|
||||
#include <dae/domAny.h>
|
||||
#include <dae/daeMetaAttribute.h>
|
||||
#include <dae/daeMetaCMPolicy.h>
|
||||
#include <dae/daeMetaSequence.h>
|
||||
#include <dae/daeMetaChoice.h>
|
||||
#include <dae/daeMetaGroup.h>
|
||||
#include <dae/daeMetaAny.h>
|
||||
#include <dae/daeMetaElementAttribute.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
|
||||
daeElementRef
|
||||
domAny::create(daeInt bytes)
|
||||
@@ -30,9 +38,17 @@ domAny::registerElement()
|
||||
_Meta->setName( "any" );
|
||||
//_Meta->setStaticPointerAddress(&domAny::_Meta);
|
||||
_Meta->registerConstructor(domAny::create);
|
||||
daeMetaCMPolicy *cm = NULL;
|
||||
cm = new daeMetaSequence( _Meta, cm, 0, 1, 1 );
|
||||
|
||||
cm = new daeMetaAny( _Meta, cm, 0, 0, -1 );
|
||||
|
||||
cm->setMaxOrdinal( 0 );
|
||||
_Meta->setCMRoot( cm );
|
||||
_Meta->setAllowsAny( true );
|
||||
|
||||
_Meta->addContents(daeOffsetOf(domAny,_contents));
|
||||
_Meta->addContentsOrder(daeOffsetOf(domAny,_contentsOrder));
|
||||
|
||||
//VALUE
|
||||
{
|
||||
@@ -65,15 +81,14 @@ daeBool domAny::setAttribute(daeString attrName, daeString attrValue) {
|
||||
if ((metaAttrs[i]->getName() != NULL) && (strcmp(metaAttrs[i]->getName(),attrName)==0)) {
|
||||
if (metaAttrs[i]->getType() != NULL) {
|
||||
metaAttrs[i]->set(this,attrValue);
|
||||
_validAttributeArray[i] = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//else register it and then set it.
|
||||
if ( n >= MAX_ATTRIBUTES ) {
|
||||
fprintf(stderr, "daeAny::setAttribute() - too many attributes on this domAny. The maximum number of attributes allowed is %d",
|
||||
MAX_ATTRIBUTES );
|
||||
fflush(stderr);
|
||||
daeErrorHandler::get()->handleWarning( "domAny::setAttribute() - too many attributes on this domAny. The maximum number of attributes allowed is MAX_ATTRIBUTES" );
|
||||
return false;
|
||||
}
|
||||
daeMetaAttribute *ma = new daeMetaAttribute;
|
||||
@@ -82,6 +97,7 @@ daeBool domAny::setAttribute(daeString attrName, daeString attrValue) {
|
||||
ma->setOffset( (daeInt)daeOffsetOf( domAny , attrs[n] ));
|
||||
ma->setContainer( _meta );
|
||||
_meta->appendAttribute(ma);
|
||||
_validAttributeArray.append( true );
|
||||
if (metaAttrs[i]->getType() != NULL) {
|
||||
metaAttrs[i]->set(this,attrValue);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user