updated COLLADA-DOM to the latest bleeding-edge (1.4.1) SVN version of today
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <libxml/xmlreader.h>
|
||||
#include <libxml/xmlmemory.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
#include <dae/daeMetaElementAttribute.h>
|
||||
|
||||
daeLIBXMLPlugin::daeLIBXMLPlugin():topMeta(NULL),database(NULL)
|
||||
{
|
||||
@@ -107,7 +108,9 @@ daeInt daeLIBXMLPlugin::read(daeURI& uri, daeString docBuffer)
|
||||
|
||||
if(!reader)
|
||||
{
|
||||
printf( "no libxml2 reader\n");
|
||||
char msg[512];
|
||||
sprintf( msg, "Failed to open %s\n", fileURI.getURI() );
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
@@ -121,12 +124,9 @@ daeInt daeLIBXMLPlugin::read(daeURI& uri, daeString docBuffer)
|
||||
|
||||
if (!domObject)
|
||||
{
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
fprintf(stderr,"daeLIBXMLPlugin::read(%s) failed - XML Parse Failed\n",
|
||||
fileURI.getFile());
|
||||
fflush(stdout);
|
||||
#endif
|
||||
printf("not able to load\n");
|
||||
char msg[512];
|
||||
sprintf(msg,"daeLIBXMLPlugin::read(%s) failed - XML Parse Failed\n",fileURI.getFile());
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
@@ -198,8 +198,8 @@ daeLIBXMLPlugin::startParse(daeMetaElement* thisMetaElement, xmlTextReaderPtr re
|
||||
daeElementRef element = thisMetaElement->create((const daeString)xmlTextReaderConstName(reader));
|
||||
if(!element)
|
||||
{
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
const xmlChar * mine =xmlTextReaderConstName(reader);
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"The DOM was unable to create an element type %s at line %d\nProbably a schema violation.\n", mine,xmlTextReaderGetParserLineNumber(reader));
|
||||
@@ -215,6 +215,7 @@ daeLIBXMLPlugin::startParse(daeMetaElement* thisMetaElement, xmlTextReaderPtr re
|
||||
//try and read attributes
|
||||
readAttributes( element, reader );
|
||||
|
||||
#if 1
|
||||
//Check COLLADA Version
|
||||
if ( strcmp( element->getTypeName(), "COLLADA" ) != 0 ) {
|
||||
//invalid root
|
||||
@@ -227,6 +228,7 @@ daeLIBXMLPlugin::startParse(daeMetaElement* thisMetaElement, xmlTextReaderPtr re
|
||||
daeErrorHandler::get()->handleError("Trying to load an invalid COLLADA version for this DOM build!");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ret = xmlTextReaderRead(reader);
|
||||
@@ -253,8 +255,8 @@ daeLIBXMLPlugin::startParse(daeMetaElement* thisMetaElement, xmlTextReaderPtr re
|
||||
// The element is a child of this one, so we recurse
|
||||
if(!element->placeElement(nextElement(element->getMeta(), reader)))
|
||||
{
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"placeElement failed at line %d\n", xmlTextReaderGetParserLineNumber(reader));
|
||||
#else
|
||||
@@ -307,8 +309,8 @@ void daeLIBXMLPlugin::readAttributes( daeElement *element, xmlTextReaderPtr read
|
||||
{
|
||||
const xmlChar * attName = xmlTextReaderConstName(reader);
|
||||
const xmlChar * attValue = xmlTextReaderConstValue(reader);
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"The DOM was unable to create an attribute %s = %s at line %d\nProbably a schema violation.\n", attName, attValue ,xmlTextReaderGetParserLineNumber(reader));
|
||||
#else
|
||||
@@ -325,8 +327,8 @@ void daeLIBXMLPlugin::readAttributes( daeElement *element, xmlTextReaderPtr read
|
||||
if ( ma == NULL ) {
|
||||
const xmlChar * attName = xmlTextReaderConstName(reader);
|
||||
const xmlChar * attValue = xmlTextReaderConstValue(reader);
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"The DOM was unable to create an attribute %s = %s at line %d\nProbably a schema violation.\n", attName, attValue ,xmlTextReaderGetParserLineNumber(reader));
|
||||
#else
|
||||
@@ -356,8 +358,8 @@ void daeLIBXMLPlugin::readAttributes( daeElement *element, xmlTextReaderPtr read
|
||||
{
|
||||
const xmlChar * attName = xmlTextReaderConstName(reader);
|
||||
const xmlChar * attValue = xmlTextReaderConstValue(reader);
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"The DOM was unable to create an attribute %s = %s at line %d\nProbably a schema violation.\n", attName, attValue ,xmlTextReaderGetParserLineNumber(reader));
|
||||
#else
|
||||
@@ -375,8 +377,8 @@ void daeLIBXMLPlugin::readAttributes( daeElement *element, xmlTextReaderPtr read
|
||||
|
||||
void daeLIBXMLPlugin::readValue( daeElement *element, xmlTextReaderPtr reader ) {
|
||||
if ( element->getMeta()->getValueAttribute() == NULL ) {
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"The DOM was unable to set a value for element of type %s at line %d\nProbably a schema violation.\n", element->getTypeName() ,xmlTextReaderGetParserLineNumber(reader));
|
||||
#else
|
||||
@@ -441,17 +443,15 @@ daeLIBXMLPlugin::nextElement(daeMetaElement* thisMetaElement, xmlTextReaderPtr r
|
||||
if(!element)
|
||||
{
|
||||
const xmlChar * mine =xmlTextReaderConstName(reader);
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"The DOM was unable to create an element type %s at line %d\nProbably a schema violation.\n", mine,xmlTextReaderGetParserLineNumber(reader));
|
||||
#else
|
||||
sprintf(err,"The DOM was unable to create an element type %s\nProbably a schema violation.\n", mine);
|
||||
#endif
|
||||
daeErrorHandler::get()->handleWarning( err );
|
||||
if ( xmlTextReaderNext(reader) == -1 ) {
|
||||
int x = 12312412;
|
||||
}
|
||||
xmlTextReaderNext(reader);
|
||||
return NULL;
|
||||
}
|
||||
int currentDepth = xmlTextReaderDepth(reader);
|
||||
@@ -481,20 +481,17 @@ daeLIBXMLPlugin::nextElement(daeMetaElement* thisMetaElement, xmlTextReaderPtr r
|
||||
else
|
||||
{
|
||||
// The element is a child of this one, so we recurse
|
||||
if(!element->placeElement(nextElement(element->getMeta(), reader)))
|
||||
daeElementRef newEl = nextElement(element->getMeta(), reader);
|
||||
if( newEl != NULL && !element->placeElement(newEl) )
|
||||
{
|
||||
char err[256];
|
||||
memset( err, 0, 256 );
|
||||
#if LIBXML_VERSION >= 20620
|
||||
sprintf(err,"placeElement failed at line %d\n", xmlTextReaderGetParserLineNumber(reader));
|
||||
#else
|
||||
sprintf(err,"placeElement failed\n");
|
||||
#endif
|
||||
daeErrorHandler::get()->handleWarning( err );
|
||||
ret = xmlTextReaderRead(reader);
|
||||
if ( ret != 1 ) {
|
||||
return element;
|
||||
}
|
||||
char err[512];
|
||||
memset( err, 0, 512 );
|
||||
sprintf(err,"placeElement failed placing element %s in element %s\n", newEl->getTypeName(), element->getTypeName() );
|
||||
daeErrorHandler::get()->handleWarning( err );
|
||||
ret = xmlTextReaderRead(reader);
|
||||
if ( ret != 1 ) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -528,7 +525,7 @@ void daeLIBXMLPlugin::postProcessDom(daeDocument *document, daeElement* element,
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
element->setDocument(document);
|
||||
//element->setDocument(document);
|
||||
// If this element has an integration object, add it to a list so we can process them all in a bunch later
|
||||
|
||||
if (element->getIntObject(daeElement::int_uninitialized))
|
||||
@@ -540,8 +537,13 @@ void daeLIBXMLPlugin::postProcessDom(daeDocument *document, daeElement* element,
|
||||
}
|
||||
|
||||
// Recursively call postProcessDom on all of this element's children
|
||||
|
||||
if (element->getMeta()->getContents() != NULL) {
|
||||
daeElementRefArray children;
|
||||
element->getChildren( children );
|
||||
for ( size_t x = 0; x < children.getCount(); x++ ) {
|
||||
postProcessDom(document, children.get(x), intItems);
|
||||
}
|
||||
|
||||
/*if (element->getMeta()->getContents() != NULL) {
|
||||
daeMetaElementArrayAttribute *contents = element->getMeta()->getContents();
|
||||
for ( int i = 0; i < contents->getCount( element ); i++ ) {
|
||||
//array.append( *(daeElementRef*)contents->get( this, i ) );
|
||||
@@ -564,8 +566,9 @@ void daeLIBXMLPlugin::postProcessDom(daeDocument *document, daeElement* element,
|
||||
postProcessDom(document,elem, intItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
daeInt daeLIBXMLPlugin::write(daeURI *name, daeDocument *document, daeBool replace)
|
||||
{
|
||||
// Make sure database and document are both set
|
||||
@@ -578,7 +581,7 @@ daeInt daeLIBXMLPlugin::write(daeURI *name, daeDocument *document, daeBool repla
|
||||
daeFixedName finalname;
|
||||
if (!name->getPath(finalname,sizeof(finalname)))
|
||||
{
|
||||
printf( "can't get path in write\n" );
|
||||
daeErrorHandler::get()->handleError( "can't get path in write\n" );
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
@@ -598,7 +601,9 @@ daeInt daeLIBXMLPlugin::write(daeURI *name, daeDocument *document, daeBool repla
|
||||
// Open the file we will write to
|
||||
writer = xmlNewTextWriterFilename(name->getURI(), 0);
|
||||
if ( !writer ) {
|
||||
printf( "no libxml2 writer\n" );
|
||||
char msg[512];
|
||||
sprintf(msg,"daeLIBXMLPlugin::write(%s) failed\n",name->getURI());
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
xmlChar indentString[10] = " ";
|
||||
@@ -636,14 +641,20 @@ void daeLIBXMLPlugin::writeElement( daeElement* element )
|
||||
int acnt = (int)attrs.getCount();
|
||||
|
||||
for(int i=0;i<acnt;i++) {
|
||||
writeAttribute( attrs[i], element);
|
||||
writeAttribute( attrs[i], element, i );
|
||||
}
|
||||
}
|
||||
daeMetaAttribute* valueAttr = _meta->getValueAttribute();
|
||||
if (valueAttr!=NULL)
|
||||
writeAttribute(valueAttr, element);
|
||||
|
||||
if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray children;
|
||||
element->getChildren( children );
|
||||
for ( size_t x = 0; x < children.getCount(); x++ ) {
|
||||
writeElement( children.get(x) );
|
||||
}
|
||||
|
||||
/*if (_meta->getContents() != NULL) {
|
||||
daeElementRefArray* era = (daeElementRefArray*)_meta->getContents()->getWritableMemory(element);
|
||||
int elemCnt = (int)era->getCount();
|
||||
for(int i = 0; i < elemCnt; i++) {
|
||||
@@ -665,7 +676,7 @@ void daeLIBXMLPlugin::writeElement( daeElement* element )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (!_meta->getIsTransparent() ) {
|
||||
xmlTextWriterEndElement(writer);
|
||||
}
|
||||
@@ -673,7 +684,7 @@ void daeLIBXMLPlugin::writeElement( daeElement* element )
|
||||
|
||||
#define TYPE_BUFFER_SIZE 4096
|
||||
|
||||
void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* element )
|
||||
void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* element, daeInt attrNum )
|
||||
{
|
||||
static daeChar atomicTypeBuf[TYPE_BUFFER_SIZE];
|
||||
|
||||
@@ -704,10 +715,11 @@ void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* elemen
|
||||
// DISABLE THIS CODE IF YOU WANT DEFAULT VALUES TO ALWAYS EXPORT
|
||||
if(typeSize >= TYPE_BUFFER_SIZE)
|
||||
{
|
||||
fprintf(stderr,
|
||||
char msg[512];
|
||||
sprintf(msg,
|
||||
"daeMetaAttribute::print() - buffer too small for default value of %s in %s\n",
|
||||
(daeString)attr->getName(),(daeString)attr->getContainer()->getName());
|
||||
fflush(stderr);
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
return;
|
||||
}
|
||||
attr->getType()->stringToMemory((daeChar*)attr->getDefault(),atomicTypeBuf);
|
||||
@@ -717,12 +729,12 @@ void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* elemen
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 1
|
||||
#if 0
|
||||
// The attribute does not have a default, suppress it if its value is all zeros (binary)
|
||||
// DISABLE THIS CODE IF YOU WANT OPTIONAL ATTRIBUTES THAT HAVE A VALUE OF ZERO TO EXPORT
|
||||
// Disabling this code may cause some unused attributes to be exported if _isValid is not
|
||||
// enabled and properly used.
|
||||
int i;
|
||||
int i;
|
||||
for(i=0; i<typeSize;i++)
|
||||
{
|
||||
if(elemMem[i] != 0)
|
||||
@@ -733,16 +745,20 @@ void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* elemen
|
||||
attr->getType()->getTypeEnum() != daeAtomicType::EnumType )
|
||||
return;
|
||||
#endif
|
||||
if ( attrNum != -1 && !element->isAttributeSet( attr->getName() ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert the attribute to a string
|
||||
|
||||
if (attr->getType()->memoryToString(elemMem, atomicTypeBuf, TYPE_BUFFER_SIZE)== false) {
|
||||
fprintf(stderr,
|
||||
char msg[512];
|
||||
sprintf(msg,
|
||||
"daeMetaAttribute::print() - buffer too small for %s in %s\n",
|
||||
(daeString)attr->getName(),(daeString)attr->getContainer()->getName());
|
||||
fflush(stderr);
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
}
|
||||
|
||||
// Suppress attributes that convert to an empty string.
|
||||
@@ -782,10 +798,11 @@ void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* elemen
|
||||
char* elemMem = attr->get(element, i);
|
||||
if (attr->getType()->memoryToString(elemMem, atomicTypeBuf, TYPE_BUFFER_SIZE)== false)
|
||||
{
|
||||
fprintf(stderr,
|
||||
char msg[512];
|
||||
sprintf(msg,
|
||||
"daeMetaArrayAttribute::print() - buffer too small for %s in %s\n",
|
||||
(daeString)attr->getName(),(daeString)attr->getContainer()->getName());
|
||||
fflush(stderr);
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
}
|
||||
xmlTextWriterWriteFormatString( writer, "%s ", (xmlChar*)atomicTypeBuf );
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <dae/daeDatabase.h>
|
||||
#include <dae/daeURI.h>
|
||||
#include <modules/daeLIBXMLPlugin.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
|
||||
daeLIBXMLResolver::daeLIBXMLResolver(daeDatabase* database,daeIOPlugin* plugin)
|
||||
{
|
||||
@@ -100,10 +101,11 @@ daeLIBXMLResolver::resolveElement(daeURI& uri, daeString typeNameHint)
|
||||
daeDocument *tempDocument;
|
||||
if ( tempElement == NULL || (tempDocument = tempElement->getDocument()) == NULL ) {
|
||||
uri.setState(daeURI::uri_failed_missing_container);
|
||||
fprintf(stderr,
|
||||
char msg[256];
|
||||
sprintf(msg,
|
||||
"daeLIBXMLResolver::resolveElement() - failed to resolve %s\n",
|
||||
uri.getURI());
|
||||
fflush(stderr);
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
return false;
|
||||
}
|
||||
//assert(tempDocument);
|
||||
@@ -119,10 +121,11 @@ daeLIBXMLResolver::resolveElement(daeURI& uri, daeString typeNameHint)
|
||||
if (status ||(resolved==NULL))
|
||||
{
|
||||
uri.setState(daeURI::uri_failed_id_not_found);
|
||||
fprintf(stderr,
|
||||
char msg[256];
|
||||
sprintf(msg,
|
||||
"daeLIBXMLResolver::resolveElement() - failed to resolve %s\n",
|
||||
uri.getURI());
|
||||
fflush(stderr);
|
||||
daeErrorHandler::get()->handleError( msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <modules/daeSTLDatabase.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
|
||||
daeSTLDatabase::daeSTLDatabase():validated(true)
|
||||
daeSTLDatabase::daeSTLDatabase()
|
||||
{}
|
||||
|
||||
daeSTLDatabase::~daeSTLDatabase()
|
||||
@@ -238,7 +238,6 @@ daeInt daeSTLDatabase::insertElement(daeDocument* document,daeElement* element)
|
||||
return DAE_OK;
|
||||
|
||||
DAE_STL_DATABASE_CELL tmp;
|
||||
validated = false;
|
||||
tmp.document = document;
|
||||
tmp.name = element->getID();
|
||||
if (tmp.name == NULL)
|
||||
@@ -248,7 +247,11 @@ daeInt daeSTLDatabase::insertElement(daeDocument* document,daeElement* element)
|
||||
|
||||
std::vector<DAE_STL_DATABASE_CELL>::iterator it = std::upper_bound(elements.begin(), elements.end(), tmp, daeSTLDatabaseLess());
|
||||
elements.insert(it, tmp);
|
||||
//elements.push_back(tmp);
|
||||
|
||||
//insert into IDMap if element has an ID. IDMap is used to speed up URI resolution
|
||||
if ( element->getID() != NULL ) {
|
||||
elementsIDMap.insert( std::make_pair( std::string( element->getID() ), tmp ) );
|
||||
}
|
||||
|
||||
return DAE_OK;
|
||||
}
|
||||
@@ -272,13 +275,24 @@ daeInt daeSTLDatabase::removeElement(daeDocument* document,daeElement* element)
|
||||
std::vector<DAE_STL_DATABASE_CELL>::iterator iter = elements.begin();
|
||||
while ( iter != elements.end() ) {
|
||||
if ( (*iter).element == element ) {
|
||||
iter = elements.erase(iter);
|
||||
elements.erase(iter);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
iter++;
|
||||
}
|
||||
|
||||
if ( element->getID() != NULL ) {
|
||||
std::pair< std::multimap<std::string, DAE_STL_DATABASE_CELL>::iterator, std::multimap<std::string, DAE_STL_DATABASE_CELL>::iterator> range;
|
||||
range = elementsIDMap.equal_range( std::string( element->getID() ) );
|
||||
std::multimap<std::string, DAE_STL_DATABASE_CELL>::iterator iter = range.first;
|
||||
while( iter != range.second ) {
|
||||
if ( (*iter).second.element == element ) {
|
||||
elementsIDMap.erase( iter );
|
||||
break;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
validated = false;
|
||||
}
|
||||
return DAE_OK;
|
||||
}
|
||||
|
||||
@@ -296,6 +310,7 @@ daeInt daeSTLDatabase::removeChildren( daeDocument *c, daeElement *element )
|
||||
daeInt daeSTLDatabase::clear()
|
||||
{
|
||||
elements.clear();
|
||||
elementsIDMap.clear();
|
||||
int i;
|
||||
for (i=0;i<(int)documents.size();i++)
|
||||
delete documents[i];
|
||||
@@ -315,6 +330,48 @@ daeUInt daeSTLDatabase::getElementCount(daeString name,daeString type,daeString
|
||||
return (daeUInt)elements.size();
|
||||
}
|
||||
|
||||
if ( name )
|
||||
{
|
||||
// name specified
|
||||
int count = 0;
|
||||
if ( file )
|
||||
{
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
// a document was specified
|
||||
std::pair< std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator, std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator> range;
|
||||
range = elementsIDMap.equal_range( std::string( name ) );
|
||||
std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = (*i).second;
|
||||
if ( col == e.document && !strcmp(name, e.name) )
|
||||
{
|
||||
count++;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
else
|
||||
{
|
||||
//no file specified
|
||||
std::pair< std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator, std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator> range;
|
||||
range = elementsIDMap.equal_range( std::string( name ) );
|
||||
std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
++i;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
std::pair< std::vector<DAE_STL_DATABASE_CELL>::iterator, std::vector<DAE_STL_DATABASE_CELL>::iterator> range;
|
||||
int sz = 0;
|
||||
// The database is sorted by type so if type was one of the keys, find the range of items with that type
|
||||
@@ -336,72 +393,28 @@ daeUInt daeSTLDatabase::getElementCount(daeString name,daeString type,daeString
|
||||
sz = (int)elements.size();
|
||||
}
|
||||
|
||||
if ( name )
|
||||
//no name specified
|
||||
if ( file )
|
||||
{
|
||||
// name specified
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
//a document was specified
|
||||
int count = 0;
|
||||
if ( file )
|
||||
{
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
// a document was specified
|
||||
//for ( int i = 0; i < sz; i++ )
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *(i);
|
||||
if( col == e.document )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *(i);
|
||||
if ( col == e.document && !strcmp(name, e.name) )
|
||||
{
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
else
|
||||
{
|
||||
//no file specified
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *(i);
|
||||
if ( !strcmp( name, e.name ) ) {
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//no name specified
|
||||
if ( file )
|
||||
{
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
//a document was specified
|
||||
int count = 0;
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *(i);
|
||||
if( col == e.document )
|
||||
{
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return count;
|
||||
++i;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
//if you get to this point only a type was specified
|
||||
return sz;
|
||||
@@ -424,7 +437,60 @@ daeInt daeSTLDatabase::getElement(daeElement** pElement,daeInt index,daeString n
|
||||
*pElement = elements[index].element;
|
||||
return DAE_OK;
|
||||
}
|
||||
|
||||
|
||||
if ( name )
|
||||
{
|
||||
//name specified
|
||||
int count = 0;
|
||||
if ( file )
|
||||
{
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
//a document was specified
|
||||
std::pair< std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator, std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator> range;
|
||||
range = elementsIDMap.equal_range( std::string( name ) );
|
||||
std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = (*i).second;
|
||||
if ( col == e.document && !strcmp(name, e.name) )
|
||||
{
|
||||
if ( count == index )
|
||||
{
|
||||
*pElement = e.element;
|
||||
return DAE_OK;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
else
|
||||
{
|
||||
//no document specified
|
||||
std::pair< std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator, std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator> range;
|
||||
range = elementsIDMap.equal_range( std::string( name ) );
|
||||
std::multimap< std::string, DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = (*i).second;
|
||||
if ( count == index )
|
||||
{
|
||||
*pElement = e.element;
|
||||
return DAE_OK;
|
||||
}
|
||||
count++;
|
||||
++i;
|
||||
}
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
}
|
||||
|
||||
std::pair< std::vector<DAE_STL_DATABASE_CELL>::iterator, std::vector<DAE_STL_DATABASE_CELL>::iterator> range;
|
||||
int sz = 0;
|
||||
if ( type )
|
||||
@@ -449,89 +515,36 @@ daeInt daeSTLDatabase::getElement(daeElement** pElement,daeInt index,daeString n
|
||||
sz = (int)elements.size();
|
||||
}
|
||||
|
||||
if ( name )
|
||||
|
||||
//no name specified
|
||||
if ( file )
|
||||
{
|
||||
//name specified
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
//a document was specified
|
||||
int count = 0;
|
||||
if ( file )
|
||||
{
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
//a document was specified
|
||||
//for ( int i = 0; i < sz; i++ )
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *(i);
|
||||
if( col == e.document )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *i;
|
||||
if ( col == e.document && !strcmp(name, e.name) )
|
||||
if( count == index )
|
||||
{
|
||||
if ( count == index )
|
||||
{
|
||||
*pElement = e.element;
|
||||
return DAE_OK;
|
||||
}
|
||||
count++;
|
||||
*pElement = e.element;
|
||||
return DAE_OK;
|
||||
}
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
else
|
||||
{
|
||||
//no document specified
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *(i);
|
||||
if ( !strcmp( name, e.name ) )
|
||||
{
|
||||
if ( count == index )
|
||||
{
|
||||
*pElement = e.element;
|
||||
return DAE_OK;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//no name specified
|
||||
if ( file )
|
||||
{
|
||||
// If a document URI was a search key (in file) resolve it to a text URI with no fragment
|
||||
daeURI tempURI(file,true);
|
||||
daeDocument *col = getDocument( tempURI.getURI() );
|
||||
if ( col == NULL ) {
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
//a document was specified
|
||||
int count = 0;
|
||||
std::vector< DAE_STL_DATABASE_CELL >::iterator i = range.first;
|
||||
while ( i != range.second )
|
||||
{
|
||||
DAE_STL_DATABASE_CELL e = *(i);
|
||||
if( col == e.document )
|
||||
{
|
||||
if( count == index )
|
||||
{
|
||||
*pElement = e.element;
|
||||
return DAE_OK;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
++i;
|
||||
}
|
||||
return DAE_ERR_QUERY_NO_MATCH;
|
||||
}
|
||||
|
||||
//if you get to this point only a type was specified
|
||||
*pElement = (*(range.first+index)).element;
|
||||
return DAE_OK;
|
||||
@@ -552,23 +565,18 @@ void daeSTLDatabase::validate()
|
||||
daeDocument *tmp = documents[i];
|
||||
//removeDocument( tmp );
|
||||
//insertDocument( tmp );
|
||||
const daeElementRefArray &iea = tmp->getInsertedArray();
|
||||
for ( unsigned int x = 0; x < iea.getCount(); x++ ) {
|
||||
insertElement( tmp, iea[x] );
|
||||
}
|
||||
const daeElementRefArray &rea = tmp->getRemovedArray();
|
||||
for ( unsigned int x = 0; x < rea.getCount(); x++ ) {
|
||||
removeElement( tmp, rea[x] );
|
||||
}
|
||||
|
||||
const daeElementRefArray &iea = tmp->getInsertedArray();
|
||||
for ( unsigned int x = 0; x < iea.getCount(); x++ ) {
|
||||
insertElement( tmp, iea[x] );
|
||||
}
|
||||
|
||||
tmp->setModified(false);
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
//if (!validated)
|
||||
//{
|
||||
// //sort the array by type then by name
|
||||
// std::sort(elements.begin(),elements.end(),daeSTLDatabaseLess());
|
||||
// validated = true;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user