added limited support for COLLADA_DOM. Will need to add jam/msvcgen build support.
This commit is contained in:
364
Extras/COLLADA_DOM/src/dae/dae.cpp
Normal file
364
Extras/COLLADA_DOM/src/dae/dae.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.h>
|
||||
#include <dae/daeDom.h>
|
||||
#include <dae/daeIDRef.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
#include <modules/daeSTLDatabase.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
|
||||
#ifndef NO_DEFAULT_PLUGIN
|
||||
#ifndef DEFAULT_BXCEPLUGIN
|
||||
#include <modules/daeLIBXMLPlugin.h>
|
||||
#include <modules/daeLIBXMLResolver.h>
|
||||
#else
|
||||
//This plugin is not provided with the public release. If you don't know about it then you don't need
|
||||
//to worry about it.
|
||||
#include <modules/daebXCePlugin.h>
|
||||
#include <modules/daebXCeResolver.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Don't include domConstants.h because it varies depending on the dom version,
|
||||
// just extern the one thing we need (COLLADA_VERSION) which all versions of
|
||||
// domConstants.h/.cpp are required to define.
|
||||
|
||||
extern daeString COLLADA_VERSION;
|
||||
|
||||
daeInt DAEInstanceCount = 0;
|
||||
|
||||
void
|
||||
DAE::cleanup()
|
||||
{
|
||||
if (DAEInstanceCount == 0) {
|
||||
daeMetaElement::releaseMetas();
|
||||
daeAtomicType::uninitializeKnownTypes();
|
||||
}
|
||||
}
|
||||
|
||||
// constructor
|
||||
DAE::DAE() : database(NULL),
|
||||
plugin(NULL),
|
||||
resolver(NULL),
|
||||
idResolver(NULL),
|
||||
defaultDatabase(false),
|
||||
defaultPlugin(false),
|
||||
registerFunc(NULL)
|
||||
{
|
||||
topMeta = initializeDomMeta();
|
||||
DAEInstanceCount++;
|
||||
}
|
||||
|
||||
DAE::~DAE()
|
||||
{
|
||||
if (defaultDatabase)
|
||||
delete database;
|
||||
if (defaultPlugin) {
|
||||
delete plugin;
|
||||
delete resolver;
|
||||
delete idResolver;
|
||||
}
|
||||
topMeta = NULL;
|
||||
--DAEInstanceCount;
|
||||
}
|
||||
|
||||
// Database setup
|
||||
daeDatabase* DAE::getDatabase()
|
||||
{
|
||||
return database;
|
||||
}
|
||||
|
||||
daeInt DAE::setDatabase(daeDatabase* _database)
|
||||
{
|
||||
if (defaultDatabase)
|
||||
delete database;
|
||||
if (_database)
|
||||
database = _database;
|
||||
else
|
||||
{
|
||||
//create default database
|
||||
database = new daeSTLDatabase;
|
||||
defaultDatabase = true;
|
||||
}
|
||||
// !!!GAC Not sure what good the error return is, current implementations never fail, what would we do if they did?
|
||||
int res = database->setMeta(topMeta);
|
||||
(void)res;
|
||||
return DAE_OK;
|
||||
}
|
||||
|
||||
// IO Plugin setup
|
||||
daeIOPlugin* DAE::getIOPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
daeInt DAE::setIOPlugin(daeIOPlugin* _plugin)
|
||||
{
|
||||
if (defaultPlugin)
|
||||
delete plugin;
|
||||
if (_plugin)
|
||||
plugin = _plugin;
|
||||
else
|
||||
{
|
||||
//create default plugin
|
||||
#ifndef NO_DEFAULT_PLUGIN
|
||||
#ifndef DEFAULT_BXCEPLUGIN
|
||||
plugin = new daeLIBXMLPlugin;
|
||||
defaultPlugin = true;
|
||||
resolver = new daeLIBXMLResolver(database,plugin);
|
||||
#else
|
||||
plugin = new daebXCePlugin();
|
||||
defaultPlugin = true;
|
||||
resolver = new daebXCeResolver(database, plugin);
|
||||
#endif
|
||||
#else
|
||||
daeErrorHandler::get()->handleWarning( "No IOPlugin Set! NO_DEFAULT_PLUGIN is defined." );
|
||||
plugin = NULL;
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
#endif
|
||||
|
||||
// Setup the IDRef resolver
|
||||
idResolver = new daeDefaultIDRefResolver(database);
|
||||
}
|
||||
int res = plugin->setMeta(topMeta);
|
||||
if (res != DAE_OK)
|
||||
{
|
||||
if (defaultPlugin)
|
||||
{
|
||||
defaultPlugin = false;
|
||||
delete plugin;
|
||||
}
|
||||
plugin = NULL;
|
||||
return res;
|
||||
}
|
||||
return DAE_OK;
|
||||
}
|
||||
|
||||
// Integration Library Setup
|
||||
daeIntegrationLibraryFunc DAE::getIntegrationLibrary()
|
||||
{
|
||||
return registerFunc;
|
||||
}
|
||||
|
||||
daeInt DAE::setIntegrationLibrary(daeIntegrationLibraryFunc _registerFunc)
|
||||
{
|
||||
registerFunc = _registerFunc;
|
||||
return DAE_OK;
|
||||
}
|
||||
|
||||
// batch file operations
|
||||
daeInt DAE::load(daeString name, daeString docBuffer)
|
||||
{
|
||||
if (!database)
|
||||
setDatabase(NULL);
|
||||
|
||||
if (!plugin)
|
||||
setIOPlugin(NULL);
|
||||
|
||||
if (registerFunc)
|
||||
registerFunc();
|
||||
|
||||
if ( !plugin || !database ) {
|
||||
printf( "no plugin or database\n" );
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
plugin->setDatabase(database);
|
||||
|
||||
if (!name || name[0] == '\0')
|
||||
return DAE_ERR_INVALID_CALL;
|
||||
|
||||
daeURI tempURI(name);
|
||||
|
||||
return plugin->read(tempURI, docBuffer);
|
||||
}
|
||||
daeInt DAE::save(daeString documentName, daeBool replace)
|
||||
{
|
||||
if (!database)
|
||||
setDatabase(NULL);
|
||||
|
||||
if (!plugin)
|
||||
setIOPlugin(NULL);
|
||||
|
||||
if (registerFunc)
|
||||
registerFunc();
|
||||
|
||||
if ( !plugin || !database ) {
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
plugin->setDatabase(database);
|
||||
|
||||
// Find the document we want by name
|
||||
daeDocument* document = database->getDocument(documentName);
|
||||
if(document == NULL)
|
||||
return DAE_ERR_COLLECTION_DOES_NOT_EXIST;
|
||||
|
||||
// Save it out to the URI it was loaded from
|
||||
return plugin->write(document->getDocumentURI(), document, replace);
|
||||
|
||||
}
|
||||
daeInt DAE::save(daeUInt documentIndex, daeBool replace)
|
||||
{
|
||||
if (!database)
|
||||
setDatabase(NULL);
|
||||
|
||||
if (!plugin)
|
||||
setIOPlugin(NULL);
|
||||
|
||||
if (registerFunc)
|
||||
registerFunc();
|
||||
|
||||
if ( !plugin || !database ) {
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
plugin->setDatabase(database);
|
||||
|
||||
if(documentIndex >= database->getDocumentCount())
|
||||
return DAE_ERR_COLLECTION_DOES_NOT_EXIST;
|
||||
|
||||
daeDocument *document = database->getDocument(documentIndex);
|
||||
|
||||
// Save it out to the URI it was loaded from
|
||||
return plugin->write(document->getDocumentURI(), document, replace);
|
||||
}
|
||||
daeInt DAE::saveAs(daeString name, daeString documentName, daeBool replace)
|
||||
{
|
||||
if (!database)
|
||||
setDatabase(NULL);
|
||||
|
||||
if (!plugin)
|
||||
setIOPlugin(NULL);
|
||||
|
||||
if (registerFunc)
|
||||
registerFunc();
|
||||
|
||||
if ( !plugin || !database ) {
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
plugin->setDatabase(database);
|
||||
|
||||
// Find the document we want by name
|
||||
daeDocument* document = database->getDocument(documentName);
|
||||
if(document == NULL)
|
||||
return DAE_ERR_COLLECTION_DOES_NOT_EXIST;
|
||||
|
||||
// Make a URI from "name" and save to that
|
||||
|
||||
daeURI tempURI(name);
|
||||
return plugin->write(&tempURI, document, replace);
|
||||
|
||||
}
|
||||
daeInt DAE::saveAs(daeString name, daeUInt documentIndex, daeBool replace)
|
||||
{
|
||||
if (!database)
|
||||
setDatabase(NULL);
|
||||
|
||||
if (!plugin)
|
||||
setIOPlugin(NULL);
|
||||
|
||||
if (registerFunc)
|
||||
registerFunc();
|
||||
|
||||
if ( !plugin || !database ) {
|
||||
return DAE_ERR_BACKEND_IO;
|
||||
}
|
||||
|
||||
plugin->setDatabase(database);
|
||||
|
||||
if(documentIndex >= database->getDocumentCount())
|
||||
return DAE_ERR_COLLECTION_DOES_NOT_EXIST;
|
||||
|
||||
daeDocument *document = database->getDocument(documentIndex);
|
||||
|
||||
daeURI tempURI(name);
|
||||
return plugin->write(&tempURI, document, replace);
|
||||
}
|
||||
daeInt DAE::unload(daeString name)
|
||||
{
|
||||
daeDocument *col = database->getDocument( name );
|
||||
if ( col == NULL ) return DAE_ERR_COLLECTION_DOES_NOT_EXIST;
|
||||
return database->removeDocument( col );
|
||||
}
|
||||
|
||||
daeInt DAE::clear()
|
||||
{
|
||||
if (database)
|
||||
database->clear();
|
||||
return DAE_OK;
|
||||
}
|
||||
|
||||
// Load/Save Progress
|
||||
void DAE::getProgress(daeInt* bytesParsed,daeInt* lineNumber,daeInt* totalBytes,daeBool reset)
|
||||
{
|
||||
if (!database || !plugin)
|
||||
{
|
||||
if (bytesParsed)
|
||||
*bytesParsed=0;
|
||||
if (bytesParsed)
|
||||
*lineNumber=0;
|
||||
if (totalBytes)
|
||||
*totalBytes=0;
|
||||
}
|
||||
else
|
||||
plugin->getProgress(bytesParsed,lineNumber,totalBytes,reset);
|
||||
}
|
||||
|
||||
// Simple Query
|
||||
domCOLLADA* DAE::getDom(daeString name)
|
||||
{
|
||||
if (!database)
|
||||
return NULL;
|
||||
|
||||
// Find the document by name
|
||||
daeDocument *document = database->getDocument(name);
|
||||
if(document)
|
||||
{
|
||||
// Return the root domCOLLADA element
|
||||
return (domCOLLADA*)(daeElement*)document->getDomRoot();
|
||||
}
|
||||
else
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
daeInt DAE::setDom(daeString name, domCOLLADA* dom)
|
||||
{
|
||||
if (!database)
|
||||
setDatabase(NULL);
|
||||
|
||||
// Find the document by name
|
||||
|
||||
daeDocument *document = database->getDocument(name);
|
||||
|
||||
if(document)
|
||||
{
|
||||
//replace a DOM on an existing document by the one provided.
|
||||
// Note that the casts are needed because we don't want to include the full definition of domCOLLADA
|
||||
document->setDomRoot((daeElement*)dom);
|
||||
return DAE_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Document doesn't exist, make a new one
|
||||
return database->insertDocument(name,(daeElement*)dom);
|
||||
}
|
||||
}
|
||||
daeString DAE::getDomVersion()
|
||||
{
|
||||
return(COLLADA_VERSION);
|
||||
}
|
||||
84
Extras/COLLADA_DOM/src/dae/daeArray.cpp
Normal file
84
Extras/COLLADA_DOM/src/dae/daeArray.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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/daeArrayTypes.h>
|
||||
#include <dae/daeArray.h>
|
||||
|
||||
daeArray::daeArray():_count(0),_capacity(0),_data(NULL),_elementSize(4),_type(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
daeArray::~daeArray()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void
|
||||
daeArray::clear()
|
||||
{
|
||||
if (_data)
|
||||
{
|
||||
daeMemorySystem::free("array",_data);
|
||||
_capacity = 0;
|
||||
_data = NULL;
|
||||
_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeArray::removeIndex(size_t index)
|
||||
{
|
||||
if ((index >= _count)||(_count < 1)||(_data == NULL))
|
||||
return(DAE_ERR_INVALID_CALL);
|
||||
if (_count-1-index)
|
||||
memmove(_data+index*_elementSize, _data+(index+1)*_elementSize, _elementSize*(_count-1-index));
|
||||
memset(_data+(_count-1)*_elementSize,0,_elementSize);
|
||||
_count--;
|
||||
return(DAE_OK);
|
||||
}
|
||||
|
||||
void
|
||||
daeArray::grow(size_t sz)
|
||||
{
|
||||
|
||||
if (sz < _capacity)
|
||||
return;
|
||||
|
||||
size_t newSize = 4*_elementSize;
|
||||
size_t neccesarySize = (sz+1)*_elementSize;
|
||||
|
||||
while(newSize < neccesarySize) {
|
||||
if (newSize < 16384)
|
||||
newSize *= 2;
|
||||
else
|
||||
newSize += 16384;
|
||||
}
|
||||
|
||||
size_t newCapacity = newSize/_elementSize;
|
||||
daeChar* newData =
|
||||
(daeChar*)daeMemorySystem::malloc("array", newCapacity*_elementSize);
|
||||
|
||||
if (_data != NULL)
|
||||
memcpy(newData,_data,_capacity*_elementSize);
|
||||
else
|
||||
memset(newData,0,_capacity*_elementSize);
|
||||
|
||||
memset(newData+_capacity*_elementSize,0,
|
||||
(newCapacity-_capacity)*_elementSize);
|
||||
|
||||
if (_data != NULL)
|
||||
daeMemorySystem::free("array",_data);
|
||||
|
||||
_data = newData;
|
||||
_capacity = newCapacity;
|
||||
}
|
||||
668
Extras/COLLADA_DOM/src/dae/daeAtomicType.cpp
Normal file
668
Extras/COLLADA_DOM/src/dae/daeAtomicType.cpp
Normal file
@@ -0,0 +1,668 @@
|
||||
/*
|
||||
* 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/daeAtomicType.h>
|
||||
#include <dae/daeElement.h>
|
||||
#include <dae/daeURI.h>
|
||||
#include <dae/daeIDRef.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
#include <dae/daeDatabase.h>
|
||||
|
||||
daeAtomicTypeArray* daeAtomicType::_Types = NULL;
|
||||
daeBool daeAtomicType::_TypesInitialized = false;
|
||||
|
||||
void
|
||||
daeAtomicType::initializeKnownTypes()
|
||||
{
|
||||
_Types = new daeAtomicTypeArray;
|
||||
initializeKnownBaseTypes();
|
||||
//mandatory to set here, because the array types are querying the atomic types
|
||||
_TypesInitialized = true;
|
||||
}
|
||||
|
||||
void
|
||||
daeAtomicType::uninitializeKnownTypes()
|
||||
{
|
||||
_TypesInitialized = false;
|
||||
unsigned int i;
|
||||
for (i=0;i<_Types->getCount();i++)
|
||||
{
|
||||
daeAtomicType* type = _Types->get(i);
|
||||
delete type;
|
||||
}
|
||||
delete _Types;
|
||||
}
|
||||
|
||||
void
|
||||
daeAtomicType::initializeKnownBaseTypes()
|
||||
{
|
||||
_Types->append(new daeUIntType);
|
||||
_Types->append(new daeIntType);
|
||||
_Types->append(new daeLongType);
|
||||
_Types->append(new daeShortType);
|
||||
_Types->append(new daeUIntType);
|
||||
_Types->append(new daeULongType);
|
||||
_Types->append(new daeFloatType);
|
||||
_Types->append(new daeDoubleType);
|
||||
_Types->append(new daeStringRefType);
|
||||
_Types->append(new daeElementRefType);
|
||||
_Types->append(new daeEnumType);
|
||||
_Types->append(new daeRawRefType);
|
||||
_Types->append(new daeResolverType);
|
||||
_Types->append(new daeIDResolverType);
|
||||
_Types->append(new daeBoolType);
|
||||
_Types->append(new daeTokenType);
|
||||
}
|
||||
|
||||
daeAtomicType*
|
||||
daeAtomicType::get(daeStringRef typeString)
|
||||
{
|
||||
if (!_TypesInitialized)
|
||||
daeAtomicType::initializeKnownTypes();
|
||||
|
||||
int tCount = (int)_Types->getCount();
|
||||
int i;
|
||||
for(i=0; i<tCount; i++) {
|
||||
daeAtomicType* type = _Types->get(i);
|
||||
daeStringRefArray& nameBindings = type->getNameBindings();
|
||||
int count = (int)nameBindings.getCount();
|
||||
int j;
|
||||
for(j=0;j<count;j++)
|
||||
if (!strcmp(nameBindings[j],typeString))
|
||||
break;
|
||||
if (j!=count)
|
||||
return type;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
daeAtomicType::daeAtomicType()
|
||||
{
|
||||
_size = -1;
|
||||
_alignment = -1;
|
||||
_typeEnum = -1;
|
||||
_typeString = "notype";
|
||||
_printFormat = "badtype";
|
||||
_scanFormat = "";
|
||||
_maxStringLength = -1;
|
||||
}
|
||||
|
||||
daeAtomicType*
|
||||
daeAtomicType::get(daeEnum typeEnum)
|
||||
{
|
||||
if (!_TypesInitialized)
|
||||
daeAtomicType::initializeKnownTypes();
|
||||
|
||||
int tCount = (int)_Types->getCount();
|
||||
int i;
|
||||
for(i=0; i<tCount; i++) {
|
||||
daeAtomicType* type = _Types->get(i);
|
||||
if (type->getTypeEnum() == typeEnum)
|
||||
return type;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeAtomicType::stringToMemory(daeChar *src, daeChar* dstMemory)
|
||||
{
|
||||
sscanf(src, _scanFormat, dstMemory);
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeAtomicType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
// just to remove the warnings
|
||||
(void)src;
|
||||
|
||||
if (dstSize > 32)
|
||||
sprintf(dst,"unknown type string conversion\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeAtomicType::append(daeAtomicType* t) {
|
||||
if (!_TypesInitialized)
|
||||
daeAtomicType::initializeKnownTypes();
|
||||
return (daeInt)_Types->append(t);
|
||||
}
|
||||
|
||||
const daeAtomicType*
|
||||
daeAtomicType::getByIndex(daeInt index) {
|
||||
return _Types->get(index);
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeAtomicType::getCount() {
|
||||
return (daeInt)_Types->getCount();
|
||||
}
|
||||
|
||||
daeEnumType::daeEnumType()
|
||||
{
|
||||
_size = sizeof(daeEnum);
|
||||
_alignment = sizeof(daeEnum);
|
||||
_typeEnum = EnumType;
|
||||
_nameBindings.append("enum");
|
||||
_printFormat = "%s";//"%%.%ds";
|
||||
_scanFormat = "%s";
|
||||
_strings = NULL;
|
||||
_values = NULL;
|
||||
_typeString = "enum";
|
||||
}
|
||||
|
||||
daeEnumType::~daeEnumType() {
|
||||
if ( _strings ) {
|
||||
delete _strings;
|
||||
_strings = NULL;
|
||||
}
|
||||
if ( _values ) {
|
||||
delete _values;
|
||||
_values = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
daeBoolType::daeBoolType()
|
||||
{
|
||||
_size = sizeof(daeBool);
|
||||
_alignment = sizeof(daeBool);
|
||||
_typeEnum = BoolType;
|
||||
_printFormat = "%d";
|
||||
_scanFormat = "%d";
|
||||
_typeString = "bool";
|
||||
_maxStringLength = (daeInt)strlen("false")+1;
|
||||
_nameBindings.append("bool");
|
||||
//_nameBindings.append("xsBool");
|
||||
_nameBindings.append("xsBoolean");
|
||||
}
|
||||
|
||||
daeIntType::daeIntType()
|
||||
{
|
||||
_size = sizeof(daeInt);
|
||||
_alignment = sizeof(daeInt);
|
||||
_typeEnum = IntType;
|
||||
_maxStringLength = 16;
|
||||
_nameBindings.append("int");
|
||||
_nameBindings.append("xsInteger");
|
||||
_nameBindings.append("xsHexBinary");
|
||||
_nameBindings.append("xsIntegerArray");
|
||||
_nameBindings.append("xsHexBinaryArray");
|
||||
_nameBindings.append("xsByte");
|
||||
_nameBindings.append("xsInt");
|
||||
_printFormat = "%d";
|
||||
_scanFormat = "%d";
|
||||
_typeString = "int";
|
||||
}
|
||||
daeLongType::daeLongType()
|
||||
{
|
||||
_size = sizeof(daeLong);
|
||||
_alignment = sizeof(daeLong);
|
||||
_typeEnum = LongType;
|
||||
_maxStringLength = 32;
|
||||
_nameBindings.append("xsLong");
|
||||
_nameBindings.append("xsLongArray");
|
||||
_printFormat = "%ld";
|
||||
_scanFormat = "%ld";
|
||||
_typeString = "long";
|
||||
}
|
||||
daeShortType::daeShortType()
|
||||
{
|
||||
_maxStringLength = 8;
|
||||
_size = sizeof(daeShort);
|
||||
_alignment = sizeof(daeShort);
|
||||
_typeEnum = ShortType;
|
||||
_nameBindings.append("short");
|
||||
_nameBindings.append("xsShort");
|
||||
_printFormat = "%hd";
|
||||
_scanFormat = "%hd";
|
||||
_typeString = "short";
|
||||
}
|
||||
daeUIntType::daeUIntType()
|
||||
{
|
||||
_maxStringLength = 16;
|
||||
_size = sizeof(daeUInt);
|
||||
_alignment = sizeof(daeUInt);
|
||||
_typeEnum = UIntType;
|
||||
_nameBindings.append("uint");
|
||||
_nameBindings.append("xsNonNegativeInteger");
|
||||
_nameBindings.append("xsUnsignedByte");
|
||||
_nameBindings.append("xsUnsignedInt");
|
||||
_nameBindings.append("xsPositiveInteger");
|
||||
_printFormat = "%u";
|
||||
_scanFormat = "%u";
|
||||
_typeString = "uint";
|
||||
}
|
||||
daeULongType::daeULongType()
|
||||
{
|
||||
_size = sizeof(daeULong);
|
||||
_alignment = sizeof(daeULong);
|
||||
_typeEnum = ULongType;
|
||||
_maxStringLength = 32;
|
||||
_nameBindings.append("ulong");
|
||||
_nameBindings.append("xsUnsignedLong");
|
||||
_printFormat = "%lu";
|
||||
_scanFormat = "%lu";
|
||||
_typeString = "ulong";
|
||||
}
|
||||
daeFloatType::daeFloatType()
|
||||
{
|
||||
_maxStringLength = 64;
|
||||
_size = sizeof(daeFloat);
|
||||
_alignment = sizeof(daeFloat);
|
||||
_typeEnum = FloatType;
|
||||
_nameBindings.append("float");
|
||||
_nameBindings.append("xsFloat");
|
||||
_printFormat = "%g";
|
||||
_scanFormat = "%g";
|
||||
_typeString = "float";
|
||||
}
|
||||
daeDoubleType::daeDoubleType()
|
||||
{
|
||||
_size = sizeof(daeDouble);
|
||||
_alignment = sizeof(daeDouble);
|
||||
_typeEnum = DoubleType;
|
||||
_nameBindings.append("double");
|
||||
_nameBindings.append("xsDouble");
|
||||
_nameBindings.append("xsDecimal");
|
||||
_printFormat = "%lg";
|
||||
_scanFormat = "%lg";
|
||||
_typeString = "double";
|
||||
_maxStringLength = 64;
|
||||
}
|
||||
|
||||
daeStringRefType::daeStringRefType()
|
||||
{
|
||||
_size = sizeof(daeStringRef);
|
||||
_alignment = sizeof(daeStringRef);
|
||||
_typeEnum = StringRefType;
|
||||
_nameBindings.append("string");
|
||||
_nameBindings.append("xsString");
|
||||
_nameBindings.append("xsDateTime");
|
||||
_printFormat = "%s";
|
||||
_scanFormat = "%s";
|
||||
_typeString = "string";
|
||||
}
|
||||
|
||||
daeTokenType::daeTokenType()
|
||||
{
|
||||
_size = sizeof(daeStringRef);
|
||||
_alignment = sizeof(daeStringRef);
|
||||
_typeEnum = TokenType;
|
||||
_nameBindings.append("token");
|
||||
_nameBindings.append("xsID");
|
||||
_nameBindings.append("xsNCName");
|
||||
_nameBindings.append("xsNMTOKEN");
|
||||
_nameBindings.append("xsName");
|
||||
_nameBindings.append("xsToken");
|
||||
_nameBindings.append("xsNameArray");
|
||||
_nameBindings.append("xsTokenArray");
|
||||
_nameBindings.append("xsNCNameArray");
|
||||
_printFormat = "%s";
|
||||
_scanFormat = "%s";
|
||||
_typeString = "token";
|
||||
}
|
||||
|
||||
daeElementRefType::daeElementRefType()
|
||||
{
|
||||
_size = sizeof(daeElementRef);
|
||||
_alignment = sizeof(daeElementRef);
|
||||
_typeEnum = ElementRefType;
|
||||
_nameBindings.append("element");
|
||||
_nameBindings.append("Element");
|
||||
_nameBindings.append("TrackedElement");
|
||||
_printFormat = "%p";
|
||||
_scanFormat = "%p";
|
||||
_typeString = "element";
|
||||
_maxStringLength = 64;
|
||||
}
|
||||
|
||||
daeRawRefType::daeRawRefType()
|
||||
{
|
||||
_size = sizeof(daeRawRef);
|
||||
_alignment = sizeof(daeRawRef);
|
||||
_typeEnum = RawRefType;
|
||||
_nameBindings.append("raw");
|
||||
_printFormat = "%p";
|
||||
_scanFormat = "%p";
|
||||
_typeString = "raw";
|
||||
_maxStringLength = 64;
|
||||
}
|
||||
|
||||
daeResolverType::daeResolverType()
|
||||
{
|
||||
_size = sizeof(daeURI);
|
||||
_alignment = sizeof(daeURI);
|
||||
_typeEnum = ResolverType;
|
||||
_nameBindings.append("resolver");
|
||||
_nameBindings.append("xsAnyURI");
|
||||
_printFormat = "%s";
|
||||
_scanFormat = "%s";
|
||||
_typeString = "resolver";
|
||||
}
|
||||
daeIDResolverType::daeIDResolverType()
|
||||
{
|
||||
_size = sizeof(daeIDRef);
|
||||
_alignment = sizeof(daeIDRef);
|
||||
_typeEnum = IDResolverType;
|
||||
_nameBindings.append("xsIDREF");
|
||||
_nameBindings.append("xsIDREFS");
|
||||
_printFormat = "%s";
|
||||
_scanFormat = "%s";
|
||||
_typeString = "idref_resolver";
|
||||
}
|
||||
daeBool
|
||||
daeIntType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,_printFormat,*((daeInt*)src));
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeLongType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,_printFormat,*((daeLong*)src));
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeShortType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,_printFormat,*((daeShort*)src));
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeUIntType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,_printFormat,*((daeUInt*)src));
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeULongType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,_printFormat,*((daeULong*)src));
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeFloatType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,_printFormat,*((daeFloat*)src));
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeDoubleType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,_printFormat,*((daeDouble*)src));
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeRawRefType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (_maxStringLength > dstSize) return false;
|
||||
sprintf(dst,"%p",(void *)(*((daeRawRef*)src)));
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeStringRefType::getUsesStrings()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeTokenType::getUsesStrings()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
daeBool
|
||||
daeStringRefType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
daeString s = *((daeStringRef *)src);
|
||||
if (!s || strlen(s) == 0)
|
||||
dst[0] = '\0';
|
||||
else {
|
||||
char tmp[64];
|
||||
sprintf(tmp,"%%.%ds",dstSize-1);
|
||||
sprintf(dst,tmp,(const char*)s);
|
||||
|
||||
if ((daeInt)(strlen(s)+1) > dstSize)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
#if 1
|
||||
// Get the URI we are trying to write
|
||||
daeURI *thisURI = ((daeURI *)src);
|
||||
daeString s;
|
||||
|
||||
// !!!GAC We may want to re-resolve the URI before writing, if so call thisURI->resolveURI() here
|
||||
// !!!GAC if you're willing to trust that everything is properly resolved, this isn't needed
|
||||
|
||||
// Was this URI successfully resolved ? (if element or collection is null, we can't write the URI correctly)
|
||||
if(thisURI->getState() != daeURI::uri_success || !(thisURI->getElement()) || !(thisURI->getContainer()))
|
||||
{
|
||||
// This URI was never successfully resolved, so write out it's original value
|
||||
s = thisURI->getOriginalURI();
|
||||
}
|
||||
else
|
||||
{
|
||||
// This URI was successfully resolved, we need to determine if it is referencing this document (the one being written)
|
||||
// or some other document so we know what URI to write out.
|
||||
// !!!GAC this approach should be safe, if the collection pointer of our document matches the collection pointer
|
||||
// !!!GAC of the element our URI is pointing at, we are pointing at our own doc.
|
||||
if(thisURI->getElement()->getCollection() == thisURI->getContainer()->getDocument())
|
||||
{
|
||||
// we will send back the original URI if we're pointing at ourselves
|
||||
s = thisURI->getOriginalURI();
|
||||
}
|
||||
else
|
||||
{
|
||||
// !!!GAC change this to test outputting of relative URIs, NOT FULLY TESTED!!!
|
||||
#if 1
|
||||
// we will send back the full resolved URI
|
||||
s = thisURI->getURI();
|
||||
#else
|
||||
// Makes the URI relative to the document being written, EXPERIMENTAL, not fully tested!!!
|
||||
thisURI->makeRelativeTo(thisURI->getDocument()->getCollection()->getDocumentURI());
|
||||
s = thisURI->getOriginalURI();
|
||||
#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++)
|
||||
{
|
||||
// If the URI contains spaces, substitute %20
|
||||
if(*s == ' ')
|
||||
{
|
||||
if( (i+2)<dstSize)
|
||||
{
|
||||
*(d++)='%';
|
||||
*(d++)='2';
|
||||
*d = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
// not enough space to escape the string so null terminate and return error
|
||||
*d = 0;
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*d = *s;
|
||||
}
|
||||
}
|
||||
*d = 0;
|
||||
if(*s == 0)
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
#else
|
||||
// !!!GAC This is the old code which doesn't work for cross document references
|
||||
// ((daeURI*)src)->resolveURI();
|
||||
|
||||
// Get the URI String as set, not the composited one from the base
|
||||
// as per SCEA request
|
||||
daeString s = ((daeURI *)src)->getOriginalURI();
|
||||
char tmp[64];
|
||||
sprintf(tmp,"%%.%ds",dstSize-1);
|
||||
sprintf(dst,tmp,s);
|
||||
|
||||
if ((daeInt)(strlen(s)+1) > dstSize)
|
||||
return false;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
daeBool
|
||||
daeIDResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
((daeIDRef*)src)->resolveID();
|
||||
|
||||
daeString s = ((daeIDRef *)src)->getID();
|
||||
char tmp[64];
|
||||
sprintf(tmp,"%%.%ds",dstSize-1);
|
||||
sprintf(dst,tmp,s);
|
||||
|
||||
if ((daeInt)(strlen(s)+1) > dstSize)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
daeAtomicType::resolve(daeElementRef element, daeMetaAttributeRef ma)
|
||||
{
|
||||
// just to remove the warnings
|
||||
(void)element;
|
||||
(void)ma;
|
||||
}
|
||||
|
||||
void
|
||||
daeResolverType::resolve(daeElementRef element, daeMetaAttributeRef ma)
|
||||
{
|
||||
daeURI* resolver = (daeURI*)ma->getWritableMemory(element);
|
||||
resolver->setContainer(element);
|
||||
resolver->resolveElement();
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeResolverType::stringToMemory(daeChar* src, daeChar* dstMemory)
|
||||
{
|
||||
((daeURI*)dstMemory)->setURI(src);
|
||||
return true;
|
||||
}
|
||||
void
|
||||
daeIDResolverType::resolve(daeElementRef element, daeMetaAttributeRef ma)
|
||||
{
|
||||
daeIDRef* resolver = (daeIDRef*)ma->getWritableMemory(element);
|
||||
resolver->setContainer( element );
|
||||
resolver->resolveElement();
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeIDResolverType::stringToMemory(daeChar* src, daeChar* dstMemory)
|
||||
{
|
||||
((daeIDRef*)dstMemory)->setID(src);
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeStringRefType::stringToMemory(daeChar* srcChars, daeChar* dstMemory)
|
||||
{
|
||||
*((daeStringRef*)dstMemory) = srcChars;
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeEnumType::stringToMemory(daeChar* src, daeChar* dst )
|
||||
{
|
||||
size_t index;
|
||||
if ( _strings->find(src,index) == DAE_ERR_QUERY_NO_MATCH ) return false;
|
||||
daeEnum val = _values->get( index );
|
||||
*((daeEnum*)dst) = val;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeEnumType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
daeStringRef s = "unknown";
|
||||
if (_strings != NULL) {
|
||||
size_t index;
|
||||
if (_values->find(*((daeEnum*)src), index) == DAE_OK)
|
||||
s = _strings->get(index);
|
||||
}
|
||||
sprintf(dst,_printFormat,(const char*)s);
|
||||
(void)dstSize;
|
||||
return true;
|
||||
}
|
||||
daeBool
|
||||
daeBoolType::stringToMemory(daeChar* srcChars, daeChar* dstMemory)
|
||||
{
|
||||
if (strncmp(srcChars,"true",4)==0)
|
||||
*((daeBool*)dstMemory) = true;
|
||||
else
|
||||
*((daeBool*)dstMemory) = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeBoolType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
if (*((daeBool*)src)) {
|
||||
if (dstSize < 5)
|
||||
return false;
|
||||
else
|
||||
sprintf(dst,"true");
|
||||
}
|
||||
else {
|
||||
if (dstSize < 6)
|
||||
return false;
|
||||
else
|
||||
sprintf(dst,"false");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//!!!ACL added for 1.4 complex types and groups
|
||||
|
||||
//unImplemented
|
||||
daeBool
|
||||
daeElementRefType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
|
||||
{
|
||||
/*if (*((daeBool*)src)) {
|
||||
if (dstSize < 5)
|
||||
return false;
|
||||
else
|
||||
sprintf(dst,"true");
|
||||
}
|
||||
else {
|
||||
if (dstSize < 6)
|
||||
return false;
|
||||
else
|
||||
sprintf(dst,"false");
|
||||
}*/
|
||||
(void)src;
|
||||
(void)dst;
|
||||
(void)dstSize;
|
||||
return false;
|
||||
}
|
||||
|
||||
59
Extras/COLLADA_DOM/src/dae/daeDocument.cpp
Normal file
59
Extras/COLLADA_DOM/src/dae/daeDocument.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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/daeDocument.h>
|
||||
|
||||
void daeDocument::addExternalReference( daeURI &uri ) {
|
||||
if ( uri.getContainer() == NULL || uri.getContainer()->getDocument() != this ) {
|
||||
return;
|
||||
}
|
||||
size_t idx;
|
||||
daeURI tempURI( uri.getURI(), true );
|
||||
daeStringRef docURI( tempURI.getURI() );
|
||||
if ( referencedDocuments.find( docURI, idx ) == DAE_OK ) {
|
||||
externalURIs[idx]->appendUnique( &uri );
|
||||
}
|
||||
else {
|
||||
referencedDocuments.append( docURI );
|
||||
idx = externalURIs.append( new daeTArray<daeURI*> );
|
||||
externalURIs[idx]->append( &uri );
|
||||
}
|
||||
}
|
||||
|
||||
void daeDocument::removeExternalReference( daeURI &uri ) {
|
||||
for( unsigned int i = 0; i < externalURIs.getCount(); i++ ) {
|
||||
for ( unsigned int j = 0; j < externalURIs[i]->getCount(); j++ ) {
|
||||
daeURI *tempURI = externalURIs[i]->get(j);
|
||||
if ( tempURI == &uri ) {
|
||||
//found the uri. now remove it
|
||||
externalURIs[i]->removeIndex(j);
|
||||
if ( externalURIs[i]->getCount() == 0 ) {
|
||||
externalURIs.removeIndex(i);
|
||||
referencedDocuments.removeIndex(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void daeDocument::resolveExternals( daeString docURI ) {
|
||||
size_t idx;
|
||||
if ( referencedDocuments.find( docURI, idx ) == DAE_OK ) {
|
||||
for ( unsigned int j = 0; j < externalURIs[idx]->getCount(); j++ ) {
|
||||
daeURI *tempURI = externalURIs[idx]->get(j);
|
||||
tempURI->resolveElement();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
24
Extras/COLLADA_DOM/src/dae/daeDom.cpp
Normal file
24
Extras/COLLADA_DOM/src/dae/daeDom.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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/daeDom.h>
|
||||
|
||||
#include <dae/daeMetaElement.h>
|
||||
|
||||
#include <dom.h>
|
||||
|
||||
daeMetaElement* initializeDomMeta()
|
||||
{
|
||||
registerDomTypes();
|
||||
|
||||
return registerDomElements();
|
||||
}
|
||||
644
Extras/COLLADA_DOM/src/dae/daeElement.cpp
Normal file
644
Extras/COLLADA_DOM/src/dae/daeElement.cpp
Normal file
@@ -0,0 +1,644 @@
|
||||
/*
|
||||
* 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/daeElement.h>
|
||||
#include <dae/daeArray.h>
|
||||
#include <dae/daeMetaAttribute.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
#include <dae/daeDatabase.h>
|
||||
#include <dae/daeErrorHandler.h>
|
||||
|
||||
#include <dae/daeIntegrationObject.h>
|
||||
#include <dae/daeURI.h>
|
||||
|
||||
void
|
||||
daeElement::release() const
|
||||
{
|
||||
if (--_refCount <= 0)
|
||||
delete this;
|
||||
}
|
||||
daeElementRef DAECreateElement(int nbytes)
|
||||
{
|
||||
return new(nbytes) daeElement;
|
||||
}
|
||||
|
||||
static daeElementRefArray resolveArray;
|
||||
//static char StaticIndentBuf[] = "";
|
||||
|
||||
daeIntegrationObject*
|
||||
daeElement::getIntObject( IntegrationState from_state, IntegrationState to_state )
|
||||
{
|
||||
if ( !_intObject ) {
|
||||
return NULL;
|
||||
}
|
||||
if ( from_state >= int_created ) {
|
||||
if ( _intObject->_from_state < int_created ) {
|
||||
daeErrorHandler::get()->handleWarning("Warning: getIntObject tries to get object that is not created (from)");
|
||||
return NULL;
|
||||
}
|
||||
if ( from_state >= int_converted ) {
|
||||
_intObject->fromCOLLADAChecked();
|
||||
if ( from_state == int_finished ) {
|
||||
_intObject->fromCOLLADAPostProcessChecked();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( to_state >= int_created ) {
|
||||
if ( _intObject->_to_state < int_created ) {
|
||||
daeErrorHandler::get()->handleWarning("Warning: getIntObject tries to get object that is not created (to)");
|
||||
return NULL;
|
||||
}
|
||||
if ( to_state >= int_converted ) {
|
||||
_intObject->toCOLLADAChecked();
|
||||
if ( to_state == int_finished ) {
|
||||
_intObject->toCOLLADAPostProcessChecked();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _intObject;
|
||||
}
|
||||
|
||||
daeElementRef
|
||||
daeElement::createElement(daeString className)
|
||||
{
|
||||
daeElementRef elem = _meta->create(className);
|
||||
// Bug #225 work around
|
||||
// if ( elem != NULL)
|
||||
// elem->ref(); // change premature delete into memory leak.
|
||||
return elem;
|
||||
}
|
||||
|
||||
daeElement*
|
||||
daeElement::createAndPlace(daeString className)
|
||||
{
|
||||
daeElementRef elem = _meta->create(className);
|
||||
daeBool place = false;
|
||||
if (elem != NULL)
|
||||
place = placeElement(elem);
|
||||
if (place)
|
||||
return elem;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeElement*
|
||||
daeElement::createAndPlaceAt(daeInt index, daeString className)
|
||||
{
|
||||
daeElementRef elem = _meta->create(className);
|
||||
daeBool place = false;
|
||||
if (elem != NULL)
|
||||
place = placeElementAt(index, elem);
|
||||
if (place)
|
||||
return elem;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
daeBool
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
daeBool daeElement::placeElementAfter( 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+1, element );
|
||||
}
|
||||
if ( strcmp( marker->getTypeName(), element->getTypeName() ) == 0 ) {
|
||||
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+1, element );
|
||||
return true;
|
||||
}
|
||||
return placeElement( element );
|
||||
}
|
||||
|
||||
daeInt daeElement::findLastIndexOf( daeString elementName ) {
|
||||
if ( _meta->getContents() != NULL ) {
|
||||
daeElementRefArray* contents =
|
||||
(daeElementRefArray*)_meta->getContents()->getWritableMemory(this);
|
||||
for ( int i = (int)contents->getCount()-1; i >= 0; --i ) {
|
||||
daeString nm = contents->get(i)->getElementName();
|
||||
if ( nm == NULL ) {
|
||||
nm = contents->get(i)->getTypeName();
|
||||
}
|
||||
if ( strcmp( nm, elementName ) == 0 ) {
|
||||
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;
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeElement::removeChildElement(daeElement* element)
|
||||
{
|
||||
// error traps
|
||||
if(element==NULL)
|
||||
return false;
|
||||
if(element->_parent != this)
|
||||
return false;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// !!!ACL Added to fix mantis issue 0000416
|
||||
void daeElement::setDocument( daeDocument *c ) {
|
||||
if( _document == c ) {
|
||||
return;
|
||||
}
|
||||
_document = c;
|
||||
|
||||
daeMetaElementAttributeArray &meas = _meta->getMetaElements();
|
||||
int cnt = (int)meas.getCount();
|
||||
for( int i = 0; i < cnt; i++) {
|
||||
meas[i]->setDocument( this, c );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeElement::setAttribute(daeString attrName, daeString attrValue)
|
||||
{
|
||||
if (_meta == NULL)
|
||||
return false;
|
||||
|
||||
daeMetaAttributeRefArray& metaAttrs = _meta->getMetaAttributes();
|
||||
int n = (int)metaAttrs.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
//fflush(stdout);
|
||||
if ((metaAttrs[i]->getName() != NULL) &&
|
||||
(strcmp(metaAttrs[i]->getName(),attrName)==0)) {
|
||||
#if 0 //debug stuff
|
||||
printf("%s(%s)->setAttr(%s,%s)\n",
|
||||
(const char*)_meta->getName(),
|
||||
metaAttrs[i]->getType()->getTypeString(),
|
||||
attrName,
|
||||
attrValue);
|
||||
#endif
|
||||
if (metaAttrs[i]->getType() != NULL)
|
||||
{
|
||||
metaAttrs[i]->set(this,attrValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
daeElement::appendResolveElement(daeElement* elem)
|
||||
{
|
||||
resolveArray.append(elem);
|
||||
}
|
||||
void
|
||||
daeElement::resolveAll()
|
||||
{
|
||||
int cnt;
|
||||
while(resolveArray.getCount()) {
|
||||
cnt = (int)resolveArray.getCount();
|
||||
daeElementRef elem = resolveArray[cnt-1];
|
||||
resolveArray.removeIndex(cnt-1);
|
||||
elem->resolve();
|
||||
}
|
||||
/*size_t cnt = resolveArray.getCount();
|
||||
for ( size_t i =0; i < cnt; i++ ) {
|
||||
resolveArray[i]->resolve();
|
||||
}
|
||||
resolveArray.clear();*/
|
||||
}
|
||||
|
||||
void
|
||||
daeElement::resolve()
|
||||
{
|
||||
if (_meta == NULL)
|
||||
return;
|
||||
|
||||
daeMetaAttributeRefArray& maa = _meta->getMetaAttributes();
|
||||
int n = (int)maa.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++)
|
||||
maa[i]->resolve(this);
|
||||
}
|
||||
|
||||
void
|
||||
daeElement::setup(daeMetaElement* meta)
|
||||
{
|
||||
if (_meta)
|
||||
return;
|
||||
_meta = meta;
|
||||
if (meta->needsResolve())
|
||||
appendResolveElement((daeElement*)this);
|
||||
daeMetaElement* intlibMeta = meta->getMetaIntegration();
|
||||
if (intlibMeta != NULL)
|
||||
{
|
||||
daeElementRef intObj = intlibMeta->create();
|
||||
intObj->ref(); //inc the ref count
|
||||
_intObject = (daeIntegrationObject*)(daeElement*)intObj;
|
||||
}
|
||||
daeMetaAttributeRefArray& attrs = meta->getMetaAttributes();
|
||||
int macnt = (int)attrs.getCount();
|
||||
|
||||
int i;
|
||||
for(i=0;i<macnt;i++)
|
||||
if (attrs[i]->getDefault() != NULL)
|
||||
attrs[i]->set(this, attrs[i]->getDefault());
|
||||
|
||||
#if 0
|
||||
// Setup resolvers to know their containers and thus their file context
|
||||
daeMetaAttributePtrArray& resolvers = meta->getMetaResolvers();
|
||||
int racnt = resolvers.getCount();
|
||||
for(i=0;i<racnt;i++)
|
||||
((daeURI*)(resolvers[i]->getWritableMemory(this)))->_container =
|
||||
this;
|
||||
#endif
|
||||
}
|
||||
|
||||
daeElement::daeElement():
|
||||
_refCount(0),
|
||||
_intObject(0),
|
||||
_parent(NULL),
|
||||
_document(NULL),
|
||||
_meta(NULL),
|
||||
_elementName(NULL)
|
||||
{}
|
||||
|
||||
daeElement::~daeElement()
|
||||
{
|
||||
if (_intObject)
|
||||
_intObject->release();
|
||||
|
||||
if (_elementName) {
|
||||
delete[] _elementName;
|
||||
_elementName = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//function used until we clarify what's a type and what's a name for an element
|
||||
daeString daeElement::getTypeName() const
|
||||
{
|
||||
return _meta->getName();
|
||||
}
|
||||
daeString daeElement::getElementName() const
|
||||
{
|
||||
return _elementName;
|
||||
}
|
||||
void daeElement::setElementName( daeString nm ) {
|
||||
if ( nm == NULL ) {
|
||||
if ( _elementName ) delete[] _elementName;
|
||||
_elementName = NULL;
|
||||
return;
|
||||
}
|
||||
if ( !_elementName ) _elementName = new daeChar[128];
|
||||
strcpy( (char*)_elementName, nm );
|
||||
}
|
||||
|
||||
daeString daeElement::getID() const
|
||||
{
|
||||
if ((_meta == NULL) || (!_meta->getIDAttribute()))
|
||||
return NULL;
|
||||
else
|
||||
return *(daeStringRef*)_meta->getIDAttribute()->getWritableMemory(const_cast<daeElement*>(this));
|
||||
}
|
||||
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
daeSmartRef<daeElement> daeElement::clone(daeString idSuffix, daeString nameSuffix) {
|
||||
//use the meta object system to create a new instance of this element
|
||||
daeElementRef ret = _meta->create();
|
||||
ret->setElementName( getElementName() );
|
||||
//use meta system to copy attributes
|
||||
daeMetaAttributeRefArray &attrs = _meta->getMetaAttributes();
|
||||
for ( unsigned int i = 0; i < attrs.getCount(); i++ ) {
|
||||
//memcpy( attrs[i]->getWritableMemory( ret ), attrs[i]->getWritableMemory( this ), attrs[i]->getSize() );
|
||||
attrs[i]->copy( ret, this );
|
||||
}
|
||||
if ( _meta->getValueAttribute() != NULL ) {
|
||||
daeMetaAttribute *val = _meta->getValueAttribute();
|
||||
//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) );
|
||||
}
|
||||
}
|
||||
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 ) {
|
||||
daeChar str[2048];
|
||||
id->getType()->memoryToString( id->getWritableMemory( ret ), str, 2048 );
|
||||
if ( strcmp( str, "" ) ) {
|
||||
strcat( str, idSuffix );
|
||||
}
|
||||
id->getType()->stringToMemory( str, id->getWritableMemory( ret ) );
|
||||
}
|
||||
//mangle the name
|
||||
daeMetaAttribute *nm = _meta->getMetaAttribute("name");
|
||||
if ( nameSuffix != NULL && nm != NULL ) {
|
||||
daeChar str[2048];
|
||||
nm->getType()->memoryToString( nm->getWritableMemory( ret ), str, 2048 );
|
||||
if ( strcmp( str, "" ) ) {
|
||||
strcat( str, nameSuffix );
|
||||
}
|
||||
nm->getType()->stringToMemory( str, nm->getWritableMemory( ret ) );
|
||||
}
|
||||
//ret->_intObject = _intObject;
|
||||
return ret;
|
||||
}
|
||||
|
||||
daeURI *daeElement::getDocumentURI() const {
|
||||
if ( _document == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
return _document->getDocumentURI();
|
||||
}
|
||||
45
Extras/COLLADA_DOM/src/dae/daeError.cpp
Normal file
45
Extras/COLLADA_DOM/src/dae/daeError.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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/daeError.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int errCode;
|
||||
const char *errString;
|
||||
} DAEERROR;
|
||||
|
||||
static DAEERROR errorsArray[] =
|
||||
{
|
||||
{ DAE_OK, "Success" },
|
||||
{ DAE_ERR_INVALID_CALL, "Invalid function call" },
|
||||
{ DAE_ERR_FATAL, "Fatal" },
|
||||
{ DAE_ERR_BACKEND_IO, "Backend IO" },
|
||||
{ DAE_ERR_BACKEND_VALIDATION, "Backend validation" },
|
||||
{ DAE_ERR_QUERY_SYNTAX, "Query syntax" },
|
||||
{ DAE_ERR_QUERY_NO_MATCH, "Query no match" },
|
||||
{ DAE_ERR_COLLECTION_ALREADY_EXISTS, "A document with the same name exists already" },
|
||||
{ DAE_ERR_COLLECTION_DOES_NOT_EXIST, "No document is loaded with that name or index" },
|
||||
{ DAE_ERR_NOT_IMPLEMENTED, "This function is not implemented in this reference implementation" },
|
||||
};
|
||||
|
||||
const char *daeErrorString(int errorCode)
|
||||
{
|
||||
int iErrorCount = (int)(sizeof(errorsArray)/sizeof(DAEERROR));
|
||||
for (int i=0;i<iErrorCount;i++)
|
||||
{
|
||||
if (errorsArray[i].errCode == errorCode)
|
||||
return errorsArray[i].errString;
|
||||
}
|
||||
return "Unknown Error code";
|
||||
}
|
||||
43
Extras/COLLADA_DOM/src/dae/daeErrorHandler.cpp
Normal file
43
Extras/COLLADA_DOM/src/dae/daeErrorHandler.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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/daeErrorHandler.h>
|
||||
#include <modules/stdErrPlugin.h>
|
||||
|
||||
daeErrorHandler *daeErrorHandler::_instance = NULL;
|
||||
daeBool daeErrorHandler::_default = false;
|
||||
|
||||
daeErrorHandler::daeErrorHandler() {
|
||||
}
|
||||
|
||||
daeErrorHandler::~daeErrorHandler() {
|
||||
if (_instance != NULL && _default ) {
|
||||
delete _instance;
|
||||
_instance = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void daeErrorHandler::setErrorHandler( daeErrorHandler *eh ) {
|
||||
if ( _instance != NULL && _default ) {
|
||||
delete _instance;
|
||||
}
|
||||
_instance = eh;
|
||||
}
|
||||
|
||||
daeErrorHandler *daeErrorHandler::get() {
|
||||
if ( _instance == NULL ) {
|
||||
_instance = new stdErrPlugin();
|
||||
_default = true;
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
228
Extras/COLLADA_DOM/src/dae/daeIDRef.cpp
Normal file
228
Extras/COLLADA_DOM/src/dae/daeIDRef.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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/daeIDRef.h>
|
||||
#include <dae/daeDatabase.h>
|
||||
daeIDRefResolverPtrArray daeIDRefResolver::_KnownResolvers;
|
||||
|
||||
void
|
||||
daeIDRef::initialize()
|
||||
{
|
||||
id = NULL;
|
||||
element = NULL;
|
||||
container = NULL;
|
||||
}
|
||||
|
||||
daeIDRef::~daeIDRef()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
daeIDRef::daeIDRef()
|
||||
{
|
||||
initialize();
|
||||
reset();
|
||||
}
|
||||
|
||||
daeIDRef::daeIDRef(daeString IDRefString)
|
||||
{
|
||||
initialize();
|
||||
setID(IDRefString);
|
||||
validate();
|
||||
}
|
||||
|
||||
daeIDRef::daeIDRef(daeIDRef& copyFrom)
|
||||
{
|
||||
initialize();
|
||||
element = copyFrom.element;
|
||||
setID(copyFrom.getID());
|
||||
state = copyFrom.state;
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRef::copyFrom(daeIDRef& copyFrom)
|
||||
{
|
||||
element = copyFrom.element;
|
||||
setID(copyFrom.getID());
|
||||
state = copyFrom.state;
|
||||
}
|
||||
|
||||
daeString emptyID = "";
|
||||
|
||||
void
|
||||
daeIDRef::reset()
|
||||
{
|
||||
if ((id != NULL) && (strcmp(id, emptyID) != 0))
|
||||
daeMemorySystem::free("idref",(void*)id);
|
||||
|
||||
id = emptyID;
|
||||
}
|
||||
|
||||
daeString safeCreateID(daeString src)
|
||||
{
|
||||
if (src == NULL)
|
||||
return emptyID;
|
||||
daeChar* ret = (daeChar*)daeMemorySystem::malloc("idref",strlen(src)+1);
|
||||
if (ret == NULL)
|
||||
return emptyID;
|
||||
strcpy(ret,src);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRef::setID(daeString _IDString)
|
||||
{
|
||||
reset();
|
||||
|
||||
id = safeCreateID(_IDString);
|
||||
|
||||
state = id_loaded;
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRef::print()
|
||||
{
|
||||
fprintf(stderr,"id = %s\n",id);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
daeString
|
||||
daeIDRef::getID() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRef::validate()
|
||||
{
|
||||
state = id_pending;
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRef::resolveElement( daeString typeNameHint )
|
||||
{
|
||||
if (state == id_empty)
|
||||
return;
|
||||
|
||||
if (state == id_loaded)
|
||||
validate();
|
||||
|
||||
daeIDRefResolver::attemptResolveElement(*((daeIDRef*)this), typeNameHint );
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRef::resolveID()
|
||||
{
|
||||
if (state == id_empty) {
|
||||
if (element != NULL)
|
||||
setID(element->getID());
|
||||
else
|
||||
state = id_failed_invalid_reference;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRefResolver::attemptResolveElement(daeIDRef& id, daeString typeNameHint)
|
||||
{
|
||||
int i;
|
||||
int cnt = (int)_KnownResolvers.getCount();
|
||||
|
||||
for(i=0;i<cnt;i++)
|
||||
if (_KnownResolvers[i]->resolveElement(id, typeNameHint))
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
daeIDRefResolver::attemptResolveID(daeIDRef& id)
|
||||
{
|
||||
int i,cnt = (int)_KnownResolvers.getCount();
|
||||
|
||||
// daeBool foundProtocol = false;
|
||||
for(i=0;i<cnt;i++)
|
||||
if (_KnownResolvers[i]->resolveID(id))
|
||||
return;
|
||||
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
fprintf(stderr,
|
||||
"daeIDRefResolver::attemptResolveID(%s) - failed\n",
|
||||
id.getID());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
daeIDRefResolver::daeIDRefResolver()
|
||||
{
|
||||
_KnownResolvers.append((daeIDRefResolver*)this);
|
||||
}
|
||||
|
||||
daeIDRefResolver::~daeIDRefResolver()
|
||||
{
|
||||
_KnownResolvers.remove((daeIDRefResolver*)this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
daeDefaultIDRefResolver::daeDefaultIDRefResolver(daeDatabase* database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
daeDefaultIDRefResolver::~daeDefaultIDRefResolver()
|
||||
{
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeDefaultIDRefResolver::resolveID(daeIDRef& id)
|
||||
{
|
||||
(void)id;
|
||||
return false;
|
||||
}
|
||||
|
||||
daeString
|
||||
daeDefaultIDRefResolver::getName()
|
||||
{
|
||||
return "DefaultIDRefResolver";
|
||||
}
|
||||
|
||||
daeBool
|
||||
daeDefaultIDRefResolver::resolveElement(daeIDRef& idref, daeString typeNameHint)
|
||||
{
|
||||
if (idref.getState() == daeIDRef::id_loaded)
|
||||
idref.validate();
|
||||
|
||||
daeElement* resolved = NULL;
|
||||
int status;
|
||||
|
||||
daeString id = idref.getID();
|
||||
|
||||
status = _database->getElement(&resolved,0,id,typeNameHint,NULL);
|
||||
|
||||
idref.setElement( resolved );
|
||||
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
||||
idref.setState( daeIDRef::id_success );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
34
Extras/COLLADA_DOM/src/dae/daeMemorySystem.cpp
Normal file
34
Extras/COLLADA_DOM/src/dae/daeMemorySystem.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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/daeMemorySystem.h>
|
||||
//#include <malloc.h>
|
||||
|
||||
daeRawRef
|
||||
daeMemorySystem::malloc(daeString pool, size_t n)
|
||||
{
|
||||
(void)pool;
|
||||
void *mem = ::malloc(n);
|
||||
// memset(mem,0,n);
|
||||
// printf("alloc[%s] - %d = 0x%x\n",pool,n,mem);
|
||||
return (daeRawRef)mem;
|
||||
}
|
||||
|
||||
void
|
||||
daeMemorySystem::free(daeString pool, daeRawRef mem)
|
||||
{
|
||||
(void)pool;
|
||||
// printf("free[%s] - 0x%x\n",pool,mem);
|
||||
::free(mem);
|
||||
}
|
||||
|
||||
361
Extras/COLLADA_DOM/src/dae/daeMetaAttribute.cpp
Normal file
361
Extras/COLLADA_DOM/src/dae/daeMetaAttribute.cpp
Normal file
@@ -0,0 +1,361 @@
|
||||
/*
|
||||
* 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/daeMetaAttribute.h>
|
||||
#include <dae/daeMetaElement.h>
|
||||
|
||||
daeStringRefArrayArray daeMetaAttribute::_NameBindings;
|
||||
daeMetaAttributeRefArray daeMetaAttribute::_FactoryTemplates;
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
_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) {
|
||||
daeChar str[4096];
|
||||
_type->memoryToString( getWritableMemory(from), str, 2048 );
|
||||
_type->stringToMemory( str, getWritableMemory( to ) );
|
||||
//memcpy( getWritableMemory( to ), getWritableMemory( from ), getSize() );
|
||||
_isValid=true;
|
||||
}
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
daeArray* array = (daeArray*)getWritableMemory(e);
|
||||
daeInt typeSize = _type->getSize();
|
||||
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) {
|
||||
daeArray* toArray = (daeArray*)getWritableMemory(to);
|
||||
daeArray* fromArray = (daeArray*)getWritableMemory(from);
|
||||
daeInt typeSize = _type->getSize();
|
||||
daeInt cnt = (daeInt)fromArray->getCount();
|
||||
toArray->setRawCount( cnt );
|
||||
//memcpy( toArray->getRawData(), fromArray->getRawData(), cnt * typeSize );
|
||||
daeChar *toData = toArray->getRawData();
|
||||
daeChar *fromData = fromArray->getRawData();
|
||||
daeChar str[4096];
|
||||
for ( int i = 0; i < cnt; i++ ) {
|
||||
_type->memoryToString( fromData+i*typeSize, str, 2048 );
|
||||
_type->stringToMemory( str, toData+i*typeSize );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
_offset = -1;
|
||||
_type = NULL;
|
||||
_container = NULL;
|
||||
_default = NULL;
|
||||
_isValid = false;
|
||||
_isRequired = false;
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaAttribute::resolve(daeElementRef element)
|
||||
{
|
||||
if (_type != NULL)
|
||||
_type->resolve(element, this);
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeMetaAttribute::getSize()
|
||||
{
|
||||
return _type->getSize();
|
||||
}
|
||||
daeInt
|
||||
daeMetaAttribute::getAlignment()
|
||||
{
|
||||
return _type->getAlignment();
|
||||
}
|
||||
|
||||
//!!!ACL 10-18
|
||||
daeInt
|
||||
daeMetaAttribute::getCount(daeElement* e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return 0;
|
||||
return (getWritableMemory(e) != NULL);
|
||||
}
|
||||
|
||||
daeMemoryRef
|
||||
daeMetaAttribute::get(daeElement *e, daeInt index)
|
||||
{
|
||||
(void)index;
|
||||
return getWritableMemory(e);
|
||||
}
|
||||
|
||||
daeInt
|
||||
daeMetaArrayAttribute::getCount(daeElement *e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return 0;
|
||||
daeArray* era = (daeArray*)getWritableMemory(e);
|
||||
if (era == NULL)
|
||||
return 0;
|
||||
return (daeInt)era->getCount();
|
||||
}
|
||||
|
||||
daeMemoryRef
|
||||
daeMetaArrayAttribute::get(daeElement* e, daeInt index)
|
||||
{
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
daeArray* era = (daeArray*)getWritableMemory(e);
|
||||
if (era == NULL || index >= (daeInt)era->getCount() )
|
||||
return NULL;
|
||||
return era->getRawData()+(index*era->getElementSize());
|
||||
}
|
||||
//******************************************************
|
||||
291
Extras/COLLADA_DOM/src/dae/daeMetaElement.cpp
Normal file
291
Extras/COLLADA_DOM/src/dae/daeMetaElement.cpp
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* 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/daeMetaElement.h>
|
||||
#include <dae/daeElement.h>
|
||||
#include <dae/domAny.h>
|
||||
|
||||
daeMetaElementRefArray daeMetaElement::_metas;
|
||||
|
||||
daeElementRef
|
||||
daeMetaElement::create()
|
||||
{
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
if (_createFunc == NULL)
|
||||
return NULL;
|
||||
#endif
|
||||
daeElementRef ret = (*_createFunc)(_elementSize);
|
||||
ret->setup(this);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
daeMetaElement*
|
||||
daeMetaElement::findChild(daeString s)
|
||||
{
|
||||
if (s != NULL) {
|
||||
if ( strcmp( _name, s) == 0 ) {
|
||||
return this;
|
||||
}
|
||||
int n = (int)_metaElements.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
daeMetaElement* me = _metaElements[i]->_elementType;
|
||||
|
||||
if ((me == NULL) || ((daeString)(me->_name) == NULL))
|
||||
continue;
|
||||
|
||||
if (strcmp(me->_name,s)==0)
|
||||
return me;
|
||||
|
||||
if (strcmp(_metaElements[i]->getName(),s)==0)
|
||||
return me;
|
||||
}
|
||||
//!!!ACL Added for testing complex types and groups
|
||||
for( i =0; i < (int)_otherChildren.getCount(); i++ ) {
|
||||
if ( strcmp( _otherChildren[i], s) == 0 ) {
|
||||
daeMetaElementAttribute *mea = _otherChildrenContainer[i];
|
||||
daeMetaElement *me = mea->getElementType();
|
||||
return me->findChild(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;
|
||||
_metas.append(this);
|
||||
}
|
||||
|
||||
daeMetaElement::~daeMetaElement()
|
||||
{
|
||||
if (_metaContents)
|
||||
delete _metaContents;
|
||||
if (_staticPointerAddress != NULL)
|
||||
*_staticPointerAddress = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElement::addContents(daeInt offset)
|
||||
{
|
||||
daeMetaElementArrayAttribute* meaa = new daeMetaElementArrayAttribute;
|
||||
meaa->setType(daeAtomicType::get("element"));
|
||||
meaa->setName("contents");
|
||||
meaa->setOffset(offset);
|
||||
meaa->setContainer( this);
|
||||
meaa->setElementType( daeElement::getMeta() );
|
||||
_metaContents = meaa;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
daeMetaElement::appendArrayElement(daeMetaElement* element, daeInt offset, daeString name)
|
||||
{
|
||||
daeMetaElementArrayAttribute* meaa = new daeMetaElementArrayAttribute;
|
||||
meaa->setType(daeAtomicType::get("element"));
|
||||
if ( name ) {
|
||||
meaa->setName(name);
|
||||
}
|
||||
else {
|
||||
meaa->setName(element->getName());
|
||||
}
|
||||
meaa->setOffset(offset);
|
||||
meaa->setContainer(this);
|
||||
meaa->setElementType( element);
|
||||
_metaElements.append(meaa);
|
||||
element->_parent = this;
|
||||
}
|
||||
void
|
||||
daeMetaElement::appendElement(daeMetaElement* element, daeInt offset, daeString name)
|
||||
{
|
||||
daeMetaElementAttribute* meaa = new daeMetaElementAttribute;
|
||||
meaa->setType(daeAtomicType::get("element"));
|
||||
if ( name ) {
|
||||
meaa->setName(name);
|
||||
}
|
||||
else {
|
||||
meaa->setName(element->getName());
|
||||
}
|
||||
meaa->setOffset( offset);
|
||||
meaa->setContainer( this );
|
||||
meaa->setElementType( element );
|
||||
_metaElements.append(meaa);
|
||||
element->_parent = this;
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElement::appendAttribute(daeMetaAttribute* attr)
|
||||
{
|
||||
if (attr == NULL)
|
||||
return;
|
||||
|
||||
if (strcmp(attr->getName(),"_value") == 0) {
|
||||
_usesStringContents = attr->getType()->getUsesStrings();
|
||||
|
||||
_metaValue = attr;
|
||||
}
|
||||
else
|
||||
_metaAttributes.append(attr);
|
||||
|
||||
if ((attr->getType() != NULL) &&
|
||||
((strcmp(attr->getType()->getTypeString(),"resolver")==0)||
|
||||
(strcmp(attr->getType()->getTypeString(),"idref_resolver")==0))) {
|
||||
_resolvers.append(attr);
|
||||
_needsResolve = true;
|
||||
}
|
||||
|
||||
if ((attr->getName() != NULL) &&
|
||||
(strcmp(attr->getName(),"id") == 0)) {
|
||||
_metaID = attr;
|
||||
_isTrackableForQueries = true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
daeMetaElement::validate()
|
||||
{
|
||||
if (_createFunc == NULL)
|
||||
_createFunc = DAECreateElement;
|
||||
if (_elementSize == 0)
|
||||
{
|
||||
daeInt place=0;
|
||||
unsigned int i;
|
||||
for(i=0;i<_metaAttributes.getCount();i++) {
|
||||
place += _metaAttributes[i]->getSize();
|
||||
int align = _metaAttributes[i]->getAlignment();
|
||||
place += align;
|
||||
place &= (~(align-1));
|
||||
}
|
||||
_elementSize = place;
|
||||
}
|
||||
}
|
||||
|
||||
daeMetaAttribute*
|
||||
daeMetaElement::getMetaAttribute(daeString s)
|
||||
{
|
||||
int cnt = (int)_metaAttributes.getCount();
|
||||
int i;
|
||||
for(i=0;i<cnt;i++)
|
||||
if (strcmp(_metaAttributes[i]->getName(),s) == 0)
|
||||
return _metaAttributes[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
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( "" );
|
||||
}
|
||||
|
||||
34
Extras/COLLADA_DOM/src/dae/daeStringRef.cpp
Normal file
34
Extras/COLLADA_DOM/src/dae/daeStringRef.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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/daeStringRef.h>
|
||||
|
||||
daeStringTable daeStringRef::_stringTable;
|
||||
|
||||
daeStringRef::daeStringRef(daeString string)
|
||||
{
|
||||
_string = _stringTable.allocString(string);
|
||||
}
|
||||
|
||||
const daeStringRef&
|
||||
daeStringRef::set(daeString string)
|
||||
{
|
||||
_string = _stringTable.allocString(string);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const daeStringRef&
|
||||
daeStringRef::operator= (daeString string)
|
||||
{
|
||||
return set(string);
|
||||
}
|
||||
76
Extras/COLLADA_DOM/src/dae/daeStringTable.cpp
Normal file
76
Extras/COLLADA_DOM/src/dae/daeStringTable.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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/daeStringTable.h>
|
||||
|
||||
daeStringTable::daeStringTable(int stringBufferSize):_stringBufferSize(stringBufferSize)
|
||||
{
|
||||
//allocate initial buffer
|
||||
allocateBuffer();
|
||||
}
|
||||
|
||||
daeString daeStringTable::allocateBuffer()
|
||||
{
|
||||
daeString buf = new daeChar[_stringBufferSize];
|
||||
_stringBuffersList.append(buf);
|
||||
_stringBufferIndex = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
daeString daeStringTable::allocString(daeString string)
|
||||
{
|
||||
size_t stringSize = strlen(string) + 1;
|
||||
size_t sizeLeft = _stringBufferSize - _stringBufferIndex;
|
||||
daeString buf;
|
||||
if (sizeLeft < stringSize)
|
||||
{
|
||||
buf = allocateBuffer();
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = _stringBuffersList.get((daeInt)_stringBuffersList.getCount()-1);
|
||||
}
|
||||
daeChar *str = (char*)buf + _stringBufferIndex;
|
||||
memcpy(str,string,stringSize);
|
||||
_stringBufferIndex += stringSize;
|
||||
|
||||
int align = sizeof(void*);
|
||||
_stringBufferIndex = (_stringBufferIndex+(align-1)) & (~(align-1));
|
||||
|
||||
//assert
|
||||
#if defined(_DEBUG) && defined(WIN32)
|
||||
if (_stringBufferIndex>_stringBufferSize)
|
||||
{
|
||||
//error the size of the buffer is not aligned,
|
||||
//or there is an internal error
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void daeStringTable::clear()
|
||||
{
|
||||
unsigned int i;
|
||||
for (i=0;i<_stringBuffersList.getCount();i++)
|
||||
#if _MSC_VER <= 1200
|
||||
delete [] (char *) _stringBuffersList[i];
|
||||
#else
|
||||
delete [] _stringBuffersList[i];
|
||||
#endif
|
||||
|
||||
_stringBuffersList.clear();
|
||||
_stringBufferIndex = 0;
|
||||
}
|
||||
1178
Extras/COLLADA_DOM/src/dae/daeURI.cpp
Normal file
1178
Extras/COLLADA_DOM/src/dae/daeURI.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
Version="8.00"
|
||||
Name="dae_vc8"
|
||||
ProjectGUID="{B70CBA1A-414C-4872-8DAF-31934BCAB568}"
|
||||
RootNamespace="dae_vc8"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
@@ -40,7 +41,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include""
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include";../../../FCollada/LibXML/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
@@ -105,7 +106,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include""
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include";../../../FCollada/LibXML/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
@@ -169,7 +170,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include""
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include";../../../FCollada/LibXML/include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
@@ -231,7 +232,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include""
|
||||
AdditionalIncludeDirectories="../../include;"../../external-libs/libxml2/win32/include";../../../FCollada/LibXML/include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
|
||||
93
Extras/COLLADA_DOM/src/dae/domAny.cpp
Normal file
93
Extras/COLLADA_DOM/src/dae/domAny.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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/daeDom.h>
|
||||
#include <dae/domAny.h>
|
||||
|
||||
daeElementRef
|
||||
domAny::create(daeInt bytes)
|
||||
{
|
||||
domAnyRef ref = new(bytes) domAny;
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
daeMetaElement *
|
||||
domAny::registerElement()
|
||||
{
|
||||
//if ( _Meta != NULL ) return _Meta;
|
||||
daeMetaElement *_Meta = new daeMetaElement;
|
||||
_Meta->setName( "any" );
|
||||
//_Meta->setStaticPointerAddress(&domAny::_Meta);
|
||||
_Meta->registerConstructor(domAny::create);
|
||||
_Meta->setAllowsAny( true );
|
||||
|
||||
_Meta->addContents(daeOffsetOf(domAny,_contents));
|
||||
|
||||
//VALUE
|
||||
{
|
||||
daeMetaAttribute *ma = new daeMetaAttribute;
|
||||
ma->setName( "_value" );
|
||||
ma->setType( daeAtomicType::get("xsString"));
|
||||
ma->setOffset( daeOffsetOf( domAny , _value ));
|
||||
ma->setContainer( _Meta );
|
||||
_Meta->appendAttribute(ma);
|
||||
}
|
||||
|
||||
_Meta->setElementSize(sizeof(domAny));
|
||||
_Meta->validate();
|
||||
|
||||
return _Meta;
|
||||
}
|
||||
|
||||
//daeMetaElement * domAny::_Meta = NULL;
|
||||
|
||||
daeBool domAny::setAttribute(daeString attrName, daeString attrValue) {
|
||||
if (_meta == NULL)
|
||||
return false;
|
||||
|
||||
//if the attribute already exists set it.
|
||||
daeMetaAttributeRefArray& metaAttrs = _meta->getMetaAttributes();
|
||||
int n = (int)metaAttrs.getCount();
|
||||
int i;
|
||||
for(i=0;i<n;i++) {
|
||||
fflush(stdout);
|
||||
if ((metaAttrs[i]->getName() != NULL) && (strcmp(metaAttrs[i]->getName(),attrName)==0)) {
|
||||
if (metaAttrs[i]->getType() != NULL) {
|
||||
metaAttrs[i]->set(this,attrValue);
|
||||
}
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
daeMetaAttribute *ma = new daeMetaAttribute;
|
||||
ma->setName( attrName );
|
||||
ma->setType( daeAtomicType::get("xsString"));
|
||||
ma->setOffset( (daeInt)daeOffsetOf( domAny , attrs[n] ));
|
||||
ma->setContainer( _meta );
|
||||
_meta->appendAttribute(ma);
|
||||
if (metaAttrs[i]->getType() != NULL) {
|
||||
metaAttrs[i]->set(this,attrValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user