added limited support for COLLADA_DOM. Will need to add jam/msvcgen build support.

This commit is contained in:
ejcoumans
2006-06-18 05:31:52 +00:00
parent 1a0f411f92
commit 6fc2e100f5
388 changed files with 129147 additions and 8 deletions

View File

@@ -0,0 +1,320 @@
/*
* 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.
*/
#ifndef __DAE_ARRAY_H__
#define __DAE_ARRAY_H__
#include <dae/daeMemorySystem.h>
class daeAtomicType;
/**
* COLLADA C++ class that implements storage for resizable array containers.
*/
class daeArray
{
protected:
size_t _count;
size_t _capacity;
daeMemoryRef _data;
size_t _elementSize;
daeAtomicType* _type;
public:
/**
* Constructor
*/
daeArray();
/**
* Copy Constructor
*/
daeArray( const daeArray &cpy ): _count(cpy._count), _capacity(cpy._capacity), _data(0),
_elementSize( cpy._elementSize), _type( cpy._type ) {
grow(_capacity);
memcpy( _data, cpy._data, _elementSize * _count );
}
/**
* Destructor
*/
virtual ~daeArray();
/**
* Clears the contents of the array. Do not use this function if the array contains @c daeSmartRef objects and the
* @c dom* class the array belongs to has a @c _contents member.
*
* Many @c dom* objects have a @c _contents member that stores the original creation order of the @c daeElements
* that are their children. If you use @c clear() on a @c daeArray of @c daeSmartRef derived objects, these
* objects will not be removed from @c _contents, which can cause problems when you
* save the data. We recommended that @c clear() not be used on arrays that are part of a @c dom* object.
*/
virtual void clear();
/**
* Sets the size of an element in the array when creating a @c daeArray of a specific type.
* @param elementSize Size of an element in the array.
*/
void setElementSize(size_t elementSize) {_elementSize = elementSize;}
/**
* Grows the array to the specified size and sets the @c daeArray to that size.
* @param cnt Size to grow the array to.
*/
inline void setRawCount(size_t cnt) {grow(cnt);_count = cnt;}
/**
* Gets the current capacity of the array, the biggest it can get without incurring a realloc.
* @return Returns the capacity of the array.
*/
inline size_t getCapacity() const {return _capacity;}
/**
* Gets the number of items stored in this @c daeArray.
* @return Returns the number of items stored in this @c daeArray.
*/
inline size_t getCount() const {return _count;}
/**
* Gets the size of an element in this array.
* @return Returns the size of an element in this array.
*/
inline size_t getElementSize() const {return _elementSize;}
/**
* Gets a pointer to the memory where the raw data for this @c daeArray is stored.
* @return Returns a pointer to the memory for the raw data.
*/
inline daeMemoryRef getRawData() const {return _data;}
/**
* Increases the size of the @c daeArray.
* @param sz Size to grow the array to.
*/
void grow(size_t sz);
/**
* Removes an item at a specific index in the @c daeArray.
* @param index Index number of the item to delete.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
* @note The @c daeElement objects sometimes list
* objects in two places, the class member and the <i> @c _contents </i> array, when you remove something from the
* dom, you must remove it from both places.
*/
virtual daeInt removeIndex(size_t index);
};
/**
* COLLADA C++ templated version of @c daeArray for storing items of various types.
*/
template <class T>
class daeTArray : public daeArray
{
public:
/**
* Constructor.
*/
daeTArray() {
// _type = daeAtomicType::getType("" T "");
_elementSize = sizeof( T );
}
/**
* Copy Constructor
*/
daeTArray( const daeTArray<T> &cpy ) : daeArray() {
_count = cpy._count;
_capacity = cpy._capacity;
_data = NULL;
_elementSize = cpy._elementSize;
_type = cpy._type;
grow(_capacity);
for(size_t i=0;i<_count;i++)
set( i, cpy[i] );
}
/**
* Destructor.
*/
virtual ~daeTArray() {
clear();
}
/**
* Frees the memory in this array and resets it to it's initial state.
*/
virtual void clear()
{
size_t i;
for(i=0;i<_count;i++)
((T*)_data + i)->~T();
daeArray::clear();
}
/**
* Removes an item at a specific index in the @c daeArray.
* @param index Index number of the item to delete.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
* @note The @c daeElement objects sometimes list
* objects in two places, the class member and the <i> @c _contents </i> array, when you remove something from the
* dom, you must remove it from both places.
*/
virtual daeInt removeIndex(size_t index)
{
if ((index >= _count)||(_count < 1))
return(DAE_ERR_INVALID_CALL);
((T*)_data + index)->~T();
return(daeArray::removeIndex(index));
}
/**
* Resets the count of items in a daeArray to an absolute value, if necessary the array
* storage will grow to the requested size and new elements will be initialized to zero
* @param nElements The new size of the array.
* @note Shrinking the array does NOT free up memory.
*/
inline void setCount(size_t nElements)
{
grow(nElements);
if(nElements < _count)
{
// If the array shrank, destruct the elements
size_t i;
for(i=_count-1; i>= nElements; i--)
{
((T*)_data + i)->~T();
memset(_data+i*_elementSize,0,_elementSize);
}
}
_count = nElements;
}
/**
* Sets a specific index in the @c daeArray, growing the array if necessary.
* @param index Index of the object to set, asserts if the index is out of bounds.
* @param value Value to store at index in the array.
*/
inline void set(size_t index, const T& value) {
if (index >= _capacity)
grow(index);
((T*)_data)[index] = value; }
/**
* Gets the object at a specific index in the @c daeArray.
* @param index Index of the object to get, asserts if the index is out of bounds.
* @return Returns the object at index.
*/
inline T& get(size_t index) const {
assert(index < _count);
return ((T*)_data)[index]; }
/**
* Appends a new object to the end of the @c daeArray.
* @param value Value of the object to append.
* @return Returns the index of the new object.
*/
inline size_t append(const T& value) {
set(_count, value);
_count++;
return _count-1;
}
/**
* Appends a unique object to the end of the @c daeArray.
* Functions the same as @c append(), but does nothing if the value is already in the @c daeArray.
* @param value Value of the object to append.
* @return Returns the index where this value was appended. If the value already exists in the array,
* returns the index in this array where the value was found.
*/
inline size_t appendUnique(const T& value) {
size_t ret;
if (find(value,ret) != DAE_OK)
return append(value);
else
return ret;
}
/**
* Removes an item from the @c daeArray.
* @param value A reference to the item to delete.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
* @note The @c daeElement objects sometimes list
* objects in two places, the class member and the <i> @c _contents </i> array, when you remove something from the
* do, you must remove it from both places.
*/
inline daeInt remove(const T& value)
{
size_t index;
if(find(value,index) == DAE_OK)
{
return(removeIndex( index ));
}
else
{
return(DAE_ERR_INVALID_CALL);
}
}
/**
* Finds an item from the @c daeArray.
* @param value A reference to the item to find.
* @param index If the function returns DAE_OK, this is set to the index where the value appears in the array.
* @return Returns DAE_OK if no error or DAE_ERR_QUERY_NO_MATCH if the value was not found.
*/
inline daeInt find(const T& value, size_t &index) const
{
size_t i;
for(i=0;i<_count;i++)
{
if (((T*)_data)[i] == value)
{
index = i;
return DAE_OK;
}
}
return DAE_ERR_QUERY_NO_MATCH;
}
/**
* Gets the object at a specific index in the @c daeArray.
* @param index Index of the object to get, asserts if the index is out of bounds.
* @return Returns the object at @c index.
*/
inline T& operator[](size_t index) const {
assert(index < _count);
return ((T*)_data)[index]; }
/**
* Inserts an object at a specific index in the daeArray, growing the array if neccessary
* @param index Index into the array for where to place the object, asserts if the index is out of bounds
* @param value of the object to append
*/
inline void insertAt(size_t index, const T& value) {
assert(index <= _capacity);
if ( _count == _capacity ) {
grow( _count +1 );
}
//memmove( &(((T*)_data)[index+1]), &(((T*)_data)[index]), (_count - index)*_elementSize );
for (size_t i = _count; i > index; i-- ) {
set( i, ((T*)_data)[i-1] );
}
set( index, value );
_count++;
}
/**
* Overloaded assignment operator.
* @param other A reference to the array to copy
* @return A reference to this object.
*/
inline daeTArray<T> &operator=( const daeTArray<T> &other ) {
clear();
_count = other._count;
_capacity = other._capacity;
grow(_capacity);
for(size_t i=0;i<_count;i++)
set( i, other[i] );
return *this;
}
};
#endif //__DAE_ARRAY_H__

View File

@@ -0,0 +1,30 @@
/*
* 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.
*/
#ifndef __DAE_ARRAY_TYPES_H__
#define __DAE_ARRAY_TYPES_H__
#include <dae/daeTypes.h>
#include <dae/daeArray.h>
typedef daeTArray<daeInt> daeIntArray;
typedef daeTArray<daeUInt> daeUIntArray;
typedef daeTArray<daeFloat> daeFloatArray;
typedef daeTArray<daeEnum> daeEnumArray;
typedef daeTArray<daeString> daeStringArray;
typedef daeTArray<daeChar> daeCharArray;
typedef daeTArray<daeBool> daeBoolArray;
typedef daeTArray<daeDouble> daeDoubleArray;
typedef daeTArray<daeLong> daeLongArray;
typedef daeTArray<daeShort> daeShortArray;
#endif //__DAE_ARRAY_TYPES_H__

View File

@@ -0,0 +1,720 @@
/*
* 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.
*/
#ifndef __DAE_ATOMIC_TYPE_H__
#define __DAE_ATOMIC_TYPE_H__
#include <dae/daeTypes.h>
#include <dae/daeStringRef.h>
#include <dae/daeArray.h>
#include <dae/daeElement.h>
#ifndef _WIN32
#include <stdint.h>
#endif
class daeAtomicType;
class daeMetaElement;
typedef daeTArray<daeAtomicType*> daeAtomicTypeArray;
class daeMetaAttribute;
typedef daeSmartRef<daeMetaAttribute> daeMetaAttributeRef;
/**
* The @c daeAtomicType class implements a standard interface for
* data elements in the reflective object system.
*
* @c daeAtomicType provides a central virtual interface that can be
* used by the rest of the reflective object system.
*
* The atomic type system if very useful for file IO and building
* automatic tools for data inspection and manipulation,
* such as hierarchy examiners and object editors.
*
* Types provide the following symantic operations:
* - @c print()
* - @c memoryToString()
* - @c stringToMemory()
* - @c resolve()
*
* Types are also able to align data pointers appropriately.
*/
class daeAtomicType
{
public:
/**
* destructor
*/
virtual ~daeAtomicType() {}
/**
* constructor
*/
daeAtomicType();
public:
/**
* Prints an atomic typed element into a destination string.
* @param src Source of the raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
/**
* Reads an atomic typed item into the destination runtime memory.
* @param src Source string.
* @param dst Raw binary location to store the resulting value.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
/**
* Resolves a reference, if indeed this type is a reference type.
* @param element The containing element.
* @param ma The @c deaMetaAttribute where the resolved reference
* should be placed.
*/
virtual void resolve(daeElementRef element, daeMetaAttributeRef ma);
/**
* Determines if this atomic type requires a special string-based
* parse state.
* @return Returns true if this type requires string contents parsing, false if not.
*/
virtual daeBool getUsesStrings() { return false; }
/**
* Gets the array of strings as name bindings for this type.
* @return Returns the array of strings.
*/
daeStringRefArray& getNameBindings() { return _nameBindings; }
/**
* Gets the enum associated with this atomic type. This is not scalable and only
* works for base types, otherwise 'extension' is used.
* @return Returns the enum associated with this atomic type.
*/
daeEnum getTypeEnum() { return _typeEnum; }
/**
* Gets the size in bytes for this atomic type.
* @return Returns the size of the atomic type in bytes.
*/
daeInt getSize() { return _size; }
/**
* Gets the scanf format used for this type.
* @return Returns the scanf format.
* @note
* Warning - this field is only for convenience and may not always work.
* It is used only when the read functions are left to the base
* implementation.
*/
daeStringRef getScanFormat() { return _scanFormat; }
/**
* Gets the printf format used for this type.
* @return Returns the printf format.
* @note
* Warning - this field is only for convenience and may not always work.
* It is used only when the print functions are left to the base
* implementation.
*/
daeStringRef getPrintFormat() { return _printFormat; }
/**
* Gets the alignment in bytes necessary for this type on this
* platform.
* @return Returns the alignment in bytes.
*/
daeInt getAlignment() { return _alignment; }
/**
* Gets the string associated with this type.
* @return Returns the string associated with this type.
*/
daeStringRef getTypeString() { return _typeString; }
/**
* Performs an alignment based on the alignment for this type.
* @param ptr Pointer to be aligned.
* @return Returns the aligned pointer computed via
* <tt> (ptr+alignment-1)&(~(alignment-1). </tt>
*
*/
daeChar* align(daeChar* ptr) {
return (daeChar*)(((intptr_t)(ptr+_alignment-1))&(~(_alignment - 1))); }
protected:
daeInt _size;
daeInt _alignment;
daeEnum _typeEnum;
daeStringRef _typeString;
daeStringRef _printFormat;
daeStringRef _scanFormat;
//daeStringRefArray _nameBindings;
daeInt _maxStringLength;
public:
/**
* An array of strings as name bindings for this type.
*/
daeStringRefArray _nameBindings;
private: // Static Members
static daeAtomicTypeArray* _Types;
static daeBool _TypesInitialized;
public: // Static Interface
/** An enum for identifying the different atomic types */
enum daeAtomicTypes {
/** bool atomic type */
BoolType,
/** enum atomic type */
EnumType,
/** character atomic type */
CharType,
/** short integer atomic type */
ShortType,
/** integer atomic type */
IntType,
/** unsigned integer atomic type */
UIntType,
/** long integer atomic type */
LongType,
/** unsigned long integer atomic type */
ULongType,
/** floating point atomic type */
FloatType,
/** double precision floating point atomic type */
DoubleType,
/** string reference atomic type */
StringRefType,
/** element reference atomic type */
ElementRefType,
/** memory reference atomic type */
MemoryRefType,
/** void reference atomic type */
RawRefType,
/** resolver atomic type */
ResolverType,
/** ID resolver atomic type */
IDResolverType,
/** string token atomic type */
TokenType,
/** extension atomic type */
ExtensionType
};
public: // STATIC INTERFACE
/**
* Appends a new type to the global list of types.
* @param t Type to append.
* @return Returns the index of the type in the list of types.
*/
static daeInt append(daeAtomicType* t);
/**
* Performs a static initialization of all known atomic types.
*/
static void initializeKnownTypes();
/**
* Performs an uninitialization for all known types, freeing associated memory.
*/
static void uninitializeKnownTypes();
/**
* Performs a static initialization of all known base atomic types.
*/
static void initializeKnownBaseTypes();
/**
* Gets a type from the list of types, based on its index.
* @param index Index of the type to retrieve.
* @return Returns the @c daeAtomicType indicated by index.
*/
static const daeAtomicType* getByIndex(daeInt index);
/**
* Gets the number of known atomic types.
* @return Returns the number of known atomic types.
*/
static daeInt getCount();
/**
* Finds a type by its string name.
* @param type String name of the type.
* @return Returns the type with the corresponding name.
*/
static daeAtomicType* get(daeStringRef type);
/**
* Finds a type by its enum.
* @param type Enum representing the desired type.
* @return Returns the type with the corresponding enum.
*/
static daeAtomicType* get(daeEnum type);
};
/**
* The @c daeBoolType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeBool.
*/
class daeBoolType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeBoolType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
/**
* Overrides the base class @c stringToMemoryFunction().
* Reads an atomic typed item into the destination runtime memory.
* @param src Source string.
* @param dst Raw binary to store the resulting value.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
};
/**
* The @c daeIntType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeInt.
*/
class daeIntType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeIntType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeLongType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeLong.
*/
class daeLongType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeLongType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeUIntType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeUInt.
*/
class daeUIntType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeUIntType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeUIntType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeUInt.
*/
class daeULongType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeULongType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeShortType is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeShort.
*/
class daeShortType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeShortType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeFloatType is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeFloat.
*/
class daeFloatType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeFloatType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeDoubleType is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeDouble.
*/
class daeDoubleType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeDoubleType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeStringRefType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeStringRef.
*/
class daeStringRefType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeStringRefType();
public:
/**
* Override base class function.
* Determines if this atomic type requires a special string-based
* parse state.
* @return Returns true if this type requires string contents parsing, false if not.
*/
virtual daeBool getUsesStrings();
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
/**
* Overrides the base class @c stringToMemoryFunction().
* Reads an atomic typed item into the destination runtime memory.
* @param src Source string.
* @param dst Raw binary to store the resulting value.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
};
/**
* The @c daeTokenType class is derived from @c daeStringRefType, and implements
* the reflective system for objects of type daeStringRef, with specialized
* treatment from the parser.
*/
class daeTokenType : public daeStringRefType
{
public:
/**
* Constructor
*/
daeTokenType();
public:
/**
* Override base class function.
* Determines if this atomic type requires a special string-based
* parse state.
* @return Returns true if this type requires string contents parsing, false if not.
*/
virtual daeBool getUsesStrings();
};
/**
* The @c daeElementRefType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeElementRef.
*/
class daeElementRefType : public daeAtomicType
{
public:
/**
* The @c daeMetaElement for the type this @c daeElementRefType represents.
*/
daeMetaElement* _elementType;
public:
/**
* Constructor
*/
daeElementRefType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeEnumType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type daeEnum.
*/
class daeEnumType: public daeAtomicType
{
public:
/**
* The array which contains the values used in this enum.
*/
daeEnumArray* _values;
/**
* The array which contains the strings to associate with the values used in this enum.
*/
daeStringRefArray* _strings;
public:
/**
* Constructor
*/
daeEnumType();
/**
* Destructor
*/
~daeEnumType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
/**
* Overrides the base class @c stringToMemoryFunction().
* Reads an atomic typed item into the destination runtime memory.
* @param src Source string.
* @param dst Raw binary to store the resulting value.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
};
/**
* The @c daeRawRefType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeRawRef.
*/
class daeRawRefType: public daeAtomicType
{
public:
/**
* Constructor.
*/
daeRawRefType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
};
/**
* The @c daeResolverType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeResolver.
*/
class daeResolverType : public daeAtomicType
{
public:
/**
* Constructor.
*/
daeResolverType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
/**
* Overrides the base class @c stringToMemoryFunction().
* Reads an atomic typed item into the destination runtime memory.
* @param src Source string.
* @param dst Raw binary to store the resulting value.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
/**
* Overrides the base class @c resolve() function
* Resolves a reference, if indeed this type is a reference type
* @param element The containing element.
* @param ma The @c deaMetaAttribute where the resolved reference
* should be placed.
*/
virtual void resolve(daeElementRef element, daeMetaAttributeRef ma);
/**
* Override base class function.
* Determines if this atomic type requires a special string-based
* parse state.
* @return Returns true if this type requires string contents parsing, false if not.
*/
virtual daeBool getUsesStrings() { return true; }
};
/**
* The @c daeIDResolverType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeIDResolver.
*/
class daeIDResolverType : public daeAtomicType
{
public:
/**
* Constructor.
*/
daeIDResolverType();
public:
/**
* Overrides the base class memory to string conversion function.
* @param src Raw data from which to get the typed items.
* @param dst Destination to output the string version of the elements to.
* @param dstSize Number of bytes available in the destination memory.
* @return Returns true if the operation was successful,
* false if the operation would cause the destination buffer to overflow.
*/
virtual daeBool memoryToString(daeChar* src, daeChar* dst, daeInt dstSize);
/**
* Overrides the base class @c stringToMemoryFunction().
* Reads an atomic typed item into the destination runtime memory.
* @param src Source string.
* @param dst Raw binary to store the resulting value.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
/**
* Overrides the base class @c resolve() function
* Resolves a reference, if indeed this type is a reference type.
* @param element The containing element.
* @param ma The @c deaMetaAttribute where the resolved reference
* should be placed.
*/
virtual void resolve(daeElementRef element, daeMetaAttributeRef ma);
};
#endif // __DAE_ATOMIC_TYPE_H__

View File

@@ -0,0 +1,265 @@
/*
* 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.
*/
#ifndef __DAE_DATABASE__
#define __DAE_DATABASE__
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
#include <dae/daeURI.h>
#include <dae/daeDocument.h>
/**
* The @c daeDatabase class defines the COLLADA runtime database interface.
*/
class daeDatabase
{
public:
/**
* Destructor.
*/
virtual ~daeDatabase() {}
/** @name Documents */
//@{
/**
* Creates a new document, defining its root as the <tt><i>dom</i></tt> object; returns an error if the document name already exists.
* @param name Name of the new document, must be a valid URI.
* @param dom Existing @c domCOLLADA root element of the document
* @param document Pointer to a @c daeDocument pointer that receives the document created
* @return Returns @c DAE_OK if the document was created successfully, otherwise returns a negative value as defined in daeError.h.
* @note The @c daeElement passed in as <tt><i>dom</i></tt> should always be a @c domCOLLADA object, the API may enforce this in the future.
* @deprecated This function will be removed in future versions. Please use createDocument.
*/
virtual daeInt insertDocument(daeString name, daeElement* dom, daeDocument** document = NULL) = 0;
/**
* Creates a new @c domCOLLADA root element and a new document; returns an error if the document name already exists.
* @param name Name of the new document, must be a valid URI.
* @param document Pointer to a @c daeDocument pointer that receives the document created
* @return Returns DAE_OK if the document was created successfully, otherwise returns a negative value as defined in daeError.h.
* @deprecated This function will be removed in future versions. Please use createDocument.
*/
virtual daeInt insertDocument(daeString name, daeDocument** document = NULL) = 0;
/**
* Creates a new document, defining its root as the <tt><i>dom</i></tt> object; returns an error if the document name already exists.
* @param name Name of the new document, must be a valid URI.
* @param dom Existing @c domCOLLADA root element of the document
* @param document Pointer to a @c daeDocument pointer that receives the document created
* @return Returns @c DAE_OK if the document was created successfully, otherwise returns a negative value as defined in daeError.h.
* @note The @c daeElement passed in as <tt><i>dom</i></tt> should always be a @c domCOLLADA object, the API may enforce this in the future.
*/
virtual daeInt createDocument(daeString name, daeElement* dom, daeDocument** document = NULL) = 0;
/**
* Creates a new @c domCOLLADA root element and a new document; returns an error if the document name already exists.
* @param name Name of the new document, must be a valid URI.
* @param document Pointer to a @c daeDocument pointer that receives the document created
* @return Returns DAE_OK if the document was created successfully, otherwise returns a negative value as defined in daeError.h.
*/
virtual daeInt createDocument(daeString name, daeDocument** document = NULL) = 0;
/**
* Inserts an already existing document into the database.
* @param c The document to insert.
* @return Returns DAE_OK if the document was inserted successfully, otherwise returns a negative value as defined in daeError.h.
*/
virtual daeInt insertDocument( daeDocument *c ) = 0;
/**
* Removes a document from the database.
* @param document Document to remove from the database
* @return Returns DAE_OK if the document was successfully removed, otherwise returns a negative value as defined in daeError.h.
*/
virtual daeInt removeDocument(daeDocument* document) = 0;
/**
* Gets the number of documents.
* @return Returns the number of documents.
*/
virtual daeUInt getDocumentCount() = 0;
/**
* Gets a document based on the document index.
* @param index Index of the document to get.
* @return Returns a pointer on the document, or NULL if not found.
*/
virtual daeDocument* getDocument(daeUInt index) = 0;
/**
* Gets a document based on the document name.
* @param name The name of the document as a URI.
* @return Returns a pointer to the document, or NULL if not found.
* @note If the URI contains a fragment, the fragment is stripped off.
*/
virtual daeDocument* getDocument(daeString name) = 0;
/**
* Gets a document name.
* @param index Index of the document to get.
* @return Returns the name of the document at the given index.
*/
virtual daeString getDocumentName(daeUInt index) = 0;
/**
* Indicates if a document is loaded or not.
* @param name Name of the document as a URI.
* @return Returns true if the document is loaded, false otherwise.
* @note If the URI contains a fragment, the fragment is stripped off.
*/
virtual daeBool isDocumentLoaded(daeString name) = 0;
//@}
/** @name Elements */
//@{
/**
* Gets the number of types in the database.
* @return Returns the number of different types of objects inserted in the database.
*/
virtual daeUInt getTypeCount() = 0;
/**
* Retrieves the name of a type of object inserted in the database.
* @param index Index of the type; must be between 0 and <tt> daeDatabase::getTypeCount()-1 </tt>
* @return Returns the name of the type, NULL if the index is invalid.
*/
virtual daeString getTypeName(daeUInt index) = 0;
/**
* Inserts a @c daeElement into the runtime database.
* @param document Document in which the @c daeElement lives.
* @param element @c daeElement to insert in the database
* @return Returns @c DAE_OK if element successfully inserted, otherwise returns a negative value as defined in daeError.h.
*/
virtual daeInt insertElement(daeDocument* document,
daeElement* element) = 0;
/**
* Removes a @c daeElement from the runtime database; not implemented in the reference STL implementation.
* @param document Document in which the @c daeElement lives.
* @param element Element to remove.
* @return Returns @c DAE_OK if element successfully removed, otherwise returns a negative value as defined in daeError.h.
* @note This function is not implemented in the reference STL implementation.
*/
virtual daeInt removeElement(daeDocument* document,
daeElement* element) = 0;
/**
* Unloads all of the documents of the runtime database.
* This function frees all the @c dom* objects and integration objects created so far,
* except any objects on which you still have a smart pointer reference (@c daeSmartRef).
* @return Returns @c DAE_OK if all documents successfully unloaded, otherwise returns a negative value as defined in daeError.h.
*/
virtual daeInt clear() = 0;
/**
* Optimizes the database.
* This function takes time; it is called by the interface at the end of a load operation.
* Some databases cannot be queried when items are being inserted; for instance, they may
* need to be sorted. All database search functions call @c validate(); you should not need to
* call this function directly.
*/
virtual void validate() = 0;
//@}
/** @name Queries */
//@{
/**
* Gets the number of daeElement objects that match the search criteria
* Any combination of search criteria can be NULL, if a criterion is NULL all
* the parameters will match for this criterion.
* Hence @c getElementCount() called without parameters returns the total number of @c daeElement objects in the database.
* Criteria can not be specified with wildcards, either a criterion is set and it will have
* to match, or it is not set and all @c daeElements match for this criterion.
* @param name Name or id of the @c daeElement, for example, "mycube1", can be NULL
* @param type Type of @c daeElement to find, this can be any COLLADA tag such as <geometry> or <library>, can be NULL
* @param file Name of the document or file, for example, "myDocument.xml", can be NULL
* @return Returns the number of elements matching this query.
*/
virtual daeUInt getElementCount(daeString name = NULL,
daeString type = NULL,
daeString file = NULL) = 0;
/**
* Returns the @c daeElement which matches the search criteria.
* Any combination of search criteria can be NULL, if a criterion is NULL all
* the parameters will match for this criterion.
* The function operates on the set of assets that match the <tt><i>name, type</i></tt> and <tt><i>file</i></tt> search criteria,
* with the <tt><i>index</i></tt> parameter indicating which asset within the set is returned.
* Calling @c daeElement(&pElement,index) without search criteria returns the @c daeElement number <tt><i>index</i></tt> in the database without
* any consideration of name, type or document.
* Criteria can not be specified with wildcards, either a criterion is set and it will have
* to match, or it is not set and all @c daeElements match for this criterion.
* The default database search is roughly in log2(n). Maximum performance is obtained when querying
* by type and a name. Any other combination results in a slight overhead, but the overall search time
* remains around log2(n).
* @param pElement Pointer of a @c daeElement* which receives the found @c daeElement if the search succeeds
* @param index Index within the set of @c daeElements that match the search criteria
* @param name Name or id of the @c daeElement, for example "mycube1", can be NULL
* @param type Type of the @c daeElement to get, this can be any COLLADA tag such as <geometry> or <library>, can be NULL
* @param file Name of the document or file, for example, "myDocument.xml", can be NULL
* @return Returns DAE_OK upon success, returns DAE_ERR_QUERY_NO_MATCH if there is no match, otherwise, returns a negative value as defined in daeError.h.
*/
virtual daeInt getElement(daeElement** pElement,
daeInt index,
daeString name = NULL,
daeString type = NULL,
daeString file = NULL ) = 0;
/**
* Returns the @c daeElement which matches the <tt><i>genericQuery</i></tt> parameter; not implemented.
* @param pElement Element to return.
* @param genericQuery Generic query
* @return Returns DAE_OK if it succeeds, returns DAE_ERR_QUERY_NO_MATCH if there is no match, otherwise returns a negative value as defined in daeError.h.
* @note This function is not implemented.
*/
virtual daeInt queryElement(daeElement** pElement, daeString genericQuery) = 0;
//@}
/**
* Sets the top meta object.
* Called by @c dae::setDatabase() when the database changes. It passes to this function the
* top meta object, which is the root of a
* hierarchy of @c daeMetaElement objects. This top meta object is capable of creating
* any of the root objects in the DOM tree.
* @param _topMeta Top meta object to use to create objects to fill the database.
* @return Returns DAE_OK if successful, otherwise returns a negative value defined in daeError.h.
*/
virtual daeInt setMeta(daeMetaElement *_topMeta) = 0;
public: //Depricated methods
inline daeInt insertCollection(daeString name, daeElement* dom, daeDocument** document = NULL) {
return insertDocument( name, dom, document );
}
inline daeInt insertCollection(daeString name, daeDocument** document = NULL) {
return insertDocument( name, document );
}
inline daeInt createCollection(daeString name, daeElement* dom, daeDocument** document = NULL) {
return createDocument( name, dom, document );
}
inline daeInt createCollection(daeString name, daeDocument** document = NULL) {
return createDocument( name, document );
}
inline daeInt insertCollection( daeDocument *c ) {
return insertDocument( c );
}
inline daeInt removeCollection(daeDocument* document) {
return removeDocument( document );
}
inline daeUInt getCollectionCount() {
return getDocumentCount();
}
inline daeDocument* getCollection(daeUInt index) {
return getDocument( index );
}
inline daeDocument* getCollection(daeString name) {
return getDocument( name );
}
inline daeString getCollectionName(daeUInt index) {
return getDocumentName( index );
}
inline daeBool isCollectionLoaded(daeString name) {
return isDocumentLoaded( name );
}
};
#endif //__DAE_DATABASE__

View File

@@ -0,0 +1,149 @@
/*
* 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.
*/
#ifndef __DAE_DOCUMENT__
#define __DAE_DOCUMENT__
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
#include <dae/daeURI.h>
#include <dae/daeStringRef.h>
/**
* The @c daeDocument class implements a COLLADA runtime database entry.
*/
class daeDocument
{
public:
/**
* Accessor to get the @c domCollada associated with this document.
* @return A @c daeElementRef for the @c domCollada that is the root of this document.
* @note This function should really return a domColladaRef,
* but we're trying to avoid having @c dae classes depend on generated dom classes.
*/
daeElement* getDomRoot() const {return(dom);}
/**
* Accessor to set the domCollada associated with this document
* @param domRoot the domCollada that is the root of this document
* @remarks Should really require a domColladaRef but we're trying to avoid having dae classes depend on generated dom classes.
*/
void setDomRoot(daeElement* domRoot) {dom = domRoot;}
/**
* Accessor to get the URI associated with the document in this document;
* this is currently set to the URI from which the document was loaded, but
* is blank if the document was created with @c insertDocument().
* @return Returns a pointer to the URI for this document.
* @note This is the full URI of the document and not the document base URI.
*/
daeURI* getDocumentURI() {return (&uri);}
/**
* Const accessor to get the URI associated with the document in this collection;
* this is currently set to the URI from which the collection was loaded, but
* is blank if the collection was created with @c insertCollection().
* @return Returns a pointer to the URI for this collection.
* @note This is the full URI of the document and not the document base URI.
*/
const daeURI* getDocumentURI() const {return (&uri);}
/**
* Accessor to get if this document has been modified since the last time the database was validated.
* @return Returns true if the document was modified, false otherwise.
*/
daeBool getModified() const {return modified;}
/**
* Sets if this document has been modified since the last time the database was validated.
* @param A boolean value specifying if the document was modified.
*/
void setModified( daeBool mod ) { if (!mod) { insertedElements.clear(); removedElements.clear(); } modified = mod;}
/**
* This function is used to track how a document gets modified. It gets called internally.
* @param element The element that was added to this document.
* @note This function is called internally and not meant to be called by the client application.
* Calling this function from the client application may result in unexpected behavior.
*/
void insertElement( daeElementRef element ) { insertedElements.append( element ); }
/**
* This function is used to track how a document gets modified. It gets called internally.
* @param element The element that was removed from this document.
* @note This function is called internally and not meant to be called by the client application.
* Calling this function from the client application may result in unexpected behavior.
*/
void removeElement( daeElementRef element ) { removedElements.append( element ); }
/**
* This function is used to track how a document gets modified. It gets called internally.
* @return Returns an array of elements that have been added since the last database update.
*/
const daeElementRefArray &getInsertedArray() const { return insertedElements; }
/**
* This function is used to track how a document gets modified. It gets called internally.
* @return Returns an array of elements that have been removed since the last database update.
*/
const daeElementRefArray &getRemovedArray() const { return removedElements; }
/**
* Adds a URI to the list of external references in this document.
* @param uri The URI that is the external reference.
* @note This function gets called internally from daeURI upon trying to resolve an element.
* Calling this function in your client code my result in unexpected behavior.
*/
void addExternalReference( daeURI &uri );
/**
* Removes a URI to the list of external references in this document.
* @param uri The URI that was the external reference.
* @note This function gets called internally from daeURI upon trying to resolve an element.
* Calling this function in your client code my result in unexpected behavior.
*/
void removeExternalReference( daeURI &uri );
/**
* Gets a list of all the documents that are referenced from URI contained within this document.
* @return Returns a list of URI strings, each being a URI which is referenced from within this document.
*/
const daeStringRefArray &getReferencedDocuments() const { return referencedDocuments; }
/**
* Resolves the URIs that reference the document specified by docURI.
* @param docURI The URI string of the document that you want to resolve against.
* @note This function is called internally whenever a new document is loaded.
*/
void resolveExternals( daeString docURI);
private:
/**
* Top Level element for of the document, always a domCollada
* @remarks This member will eventually be taken private, use getDomRoot() to access it.
*/
daeElementRef dom;
/**
* The URI of the document, may be blank if the document wasn't loaded from a URI
* @remarks This member will eventually be taken private, use getDocumentURI() to access it.
*/
daeURI uri;
/**
* A flag that indicates if this document has been modified.
*/
daeBool modified;
daeElementRefArray insertedElements;
daeElementRefArray removedElements;
daeStringRefArray referencedDocuments;
daeTArray< daeTArray<daeURI*>* > externalURIs;
};
typedef daeDocument daeCollection;
#endif

View File

@@ -0,0 +1,21 @@
/*
* 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.
*/
#ifndef __DAE_DOM__
#define __DAE_DOM__
class daeMetaElement;
daeMetaElement* initializeDomMeta();
#endif //__DAE_DOM__

View File

@@ -0,0 +1,68 @@
/*
* 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.
*/
#ifndef __DAE_DOM_TYPES__
#define __DAE_DOM_TYPES__
#include <dae/daeElement.h>
#include <dae/daeMetaElement.h>
#include <dae/daeArray.h>
#include <dae/daeURI.h>
#include <dae/daeIDRef.h>
//This line is used as a workaround because the array types enum is invalid when autogenerated
//typedef daeString domArrayTypes; // ENUM
typedef daeElement domElement;
typedef daeURI xsAnyURI;
typedef daeString xsDateTime;
typedef daeString xsID;
typedef daeIDRef xsIDREF;
typedef daeTArray<daeIDRef> xsIDREFS;
typedef daeString xsNCName;
typedef daeString xsNMTOKEN;
typedef daeString xsName;
typedef daeString xsToken;
typedef daeString xsString;
typedef daeBool xsBoolean;
typedef daeShort xsShort;
typedef daeInt xsInt;
typedef daeLong xsInteger;
typedef daeUInt xsNonNegativeInteger;
typedef daeLong xsLong;
typedef daeFloat xsFloat;
typedef daeDouble xsDouble;
typedef daeDouble xsDecimal;
typedef daeCharArray xsHexBinaryArray;
typedef daeBoolArray xsBooleanArray;
typedef daeFloatArray xsFloatArray;
typedef daeDoubleArray xsDoubleArray;
typedef daeShortArray xsShortArray;
typedef daeIntArray xsIntegerArray;
typedef daeLongArray xsLongArray;
typedef daeStringRefArray xsNameArray;
typedef daeStringRefArray xsNCNameArray;
typedef daeStringRefArray xsTokenArray;
typedef daeChar xsByte;
typedef daeUChar xsUnsignedByte;
typedef daeUInt xsUnsignedInt;
typedef daeUInt xsPositiveInteger;
typedef daeULong xsUnsignedLong;
#define daeTSmartRef daeSmartRef
#endif //__DAE_DOM_TYPES__

View File

@@ -0,0 +1,387 @@
/*
* 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.
*/
#ifndef __DAE_ELEMENT_H__
#define __DAE_ELEMENT_H__
#include <dae/daeTypes.h>
#include <dae/daeMemorySystem.h>
#include <wchar.h>
#include <dae/daeArray.h>
//#ifndef NO_MALLOC_HEADER
//#include <malloc.h>
//#endif
class daeMetaElement;
class daeIntegrationObject;
class daeDocument;
class daeURI;
template <typename T> class daeSmartRef;
/**
* The @c daeElement class represents an instance of a COLLADA "Element";
* it is the main base class for the COLLADA Dom.
* Features of this class include:
* - Uses factory concepts defined via daeMetaElement
* - Composed of attributes, content elements and content values
* - Reference counted via daeSmartRef
* - Contains information for XML base URI, and XML containing element
*/
class daeElement
{
public:
/**
* Macro that defines new and delete overrides for this class
*/
DAE_ALLOC;
private:
mutable daeInt _refCount;
daeIntegrationObject* _intObject;
daeElement* _parent;
daeDocument* _document;
protected:
daeMetaElement* _meta;
daeString _elementName;
public:
/** An enum that describes the state of user integration with this object */
enum IntegrationState {
/** The user integration is not initialized */
int_uninitialized,
/** The user integration object has been created */
int_created,
/** The user integration object has been converted */
int_converted,
/** The user integration object is completed */
int_finished
};
protected:
daeElement( const daeElement &cpy ) { (void)cpy; };
virtual daeElement &operator=( const daeElement &cpy ) { (void)cpy; return *this; }
public:
/**
* Element Constructor.
* @note This should not be used externally.
* Use factories to create elements
*/
daeElement();
/**
* Element Destructor.
* @note This should not be used externally,
* if daeSmartRefs are being used.
*/
virtual ~daeElement();
/**
* Decrements the reference count and deletes the object if reference count is zero.
* @note Should not be used externally if daeSmartRefs are being used, they call it
* automatically.
*/
void release() const;
/**
* Increments the reference count of this element.
* @note Should not be used externally if daeSmartRefs are being used, they call it
* automatically.
*/
inline void ref() const {_refCount++;}
/**
* Resolves all fields of type daeURI.
* This is done via database query of the URI.
*/
void resolve();
/**
* Sets up a @c daeElement. Called on all @c daeElements as part of their initialization.
* @param meta Meta element to use to configure this element.
* @note Should not be called externally.
*/
void setup(daeMetaElement* meta);
/**
* Places an element as a child of @c this element.
* This function searches through the list of potential child element
* fields in @c this element, checking for a matching element type where the new element can be added.
* If a match of type is found, the element* is assigned or appended to
* that field, based on whether it is a single child or an array of
* children. This automatically adds the new element to the <tt><i> _contents </i></tt> of its parent, if the parent has one.
*
* @param element Element to be placed in the @c this container.
* @return Returns true if the element was successfully placed, false otherwise.
*/
daeBool placeElement(daeElement* element);
/**
* This function searches through the list of potential child elements
* (fields) checking for a matching element type where this element can be added.
* If a match of type is found, the element* is assigned or appended to
* that field (based on whether it is a single child or an array of
* children.
* If the parent element contains a _contents array, element will be placed at the specified index,
* otherwise element gets placed among elements of the same type.
*
* @param index is the place in the _contents array to insert element.
* @param element is the element to be placed in the 'this' container.
* @return return whether or not the element was successfully placed.
*/
daeBool placeElementAt(daeInt index, daeElement* element);
/**
* Places an element as a child of @c this element.
* This function inserts the new element before the element specified as marker.
* This automatically adds the new element to the <tt><i> _contents </i></tt> of its parent, if the parent has one.
* @param marker The daeElement used to determine where the new child will be placed.
* @param element Element to be placed in the @c this container.
* @return Returns true if the element was successfully placed, false otherwise.
*/
daeBool placeElementBefore( daeElement* marker, daeElement *element );
/**
* Places an element as a child of @c this element.
* This function inserts the new element After the element specified as marker.
* This automatically adds the new element to the <tt><i> _contents </i></tt> of its parent, if the parent has one.
* @param marker The daeElement used to determine where the new child will be placed.
* @param element Element to be placed in the @c this container.
* @return Returns true if the element was successfully placed, false otherwise.
*/
daeBool placeElementAfter( daeElement* marker, daeElement *element );
/**
* Finds the last index into the array of children of the type specified.
* @param elementName The name to look for.
* @return Returns the index into the children array of the last element of type typeName. -1 if
* there are no children of type typeName.
*/
daeInt findLastIndexOf( daeString elementName );
/**
* Removes the specified element from it parent, the @c this element.
* This function is the opposite of @c placeElement(). It removes the specified
* element from the <tt><i> _contents </i></tt> array, and from wherever else it appears
* inside of the @c this element. Use this function instead of @c clear(), @c remove() or @c delete()
* if you want to keep the <tt><i> _contents </i></tt> field up-to-date.
*
* @param element Element to be removed in the @c this container.
* @return Returns true if the element was successfully removed, false otherwise.
*/
daeBool removeChildElement(daeElement* element);
/**
* Removes the specified element from its parent element.
* This function is the opposite of @c placeElement(). It removes the specified
* element from both the <tt><i> _contents </i></tt> array and from wherever else it appears
* inside of its parent. The function itself finds the parent, and is defined as a static method,
* since removing the element from its parent may result in the deletion of the element.
* If the element has no parent, nothing is done.
*
* Use this function instead of @c clear(), @c remove() or @c delete()
* if you want to keep <tt><i> _contents </i></tt> up-to-date.
*
* @param element Element to remove from its parent container, the function finds the parent element.
* @return Returns true if the element was successfully removed, false otherwise.
*/
static daeBool removeFromParent(daeElement* element)
{
if(element != NULL && element->_parent != NULL)
return(element->_parent->removeChildElement(element));
return false;
};
/**
* Looks up an attribute field via its meta name and assign its value
* as the <tt><i> attrValue </i></tt> String.
* @param attrName Attribute to set.
* @param attrValue String-based value to apply to the attribute.
* @return Returns true if the attribute was found and the value was set, false otherwise.
*/
virtual daeBool setAttribute(daeString attrName, daeString attrValue);
/**
* Finds the database document associated with @c this element.
* @return Returns the @c daeDocument representing the containing file or database
* group.
*/
daeDocument* getDocument() const { return _document; }
/**
* Deprecated.
*/
daeDocument* getCollection() const { return _document; }
/**
* Sets the database document associated with this element.
* @param c The daeDocument to associate with this element.
*/
void setDocument(daeDocument* c );
/**
* Deprecated.
*/
void setCollection(daeDocument* c );
/**
* Gets the URI of the document containing this element, note that this is NOT the URI of the element.
* @return Returns a pointer to the daeURI of the document containing this element.
*/
daeURI* getDocumentURI() const;
/**
* Creates an element via the element factory system. This creation
* is based @em only on potential child elements of this element.
* @param className Class name of the subelement to create.
* @return Returns the created @c daeElement, if it was successfully created.
*/
daeSmartRef<daeElement> createElement(daeString className);
/**
* Creates a subelement via @c createElement() and places it via @c placeElement().
* Automatically adds the new element to the <tt><i> _contents </i></tt> of its parent, if the parent has one.
* This is the primary method used to construct the COLLADA dom hierarchy.
* @param className - Class name of the subelement to create.
* @return Returns the created @c daeElement, if it was successfully created.
*/
daeElement* createAndPlace(daeString className);
//!!!ACL
/**
* Create a sub-element via #createElement and place it via #placeElementAt
* This also automatically inserts the new element at the specified index in the _contents of it's
* parent, if the parent has one.
* This is useful when constructing the COLLADA dom hierarchy
* @param index the position in the _contents array the newly created element is to be placed at
* @param className - the className of the sub-element to be created
* @return the created element if it was in fact successfully created.
*/
daeElement* createAndPlaceAt(daeInt index, daeString className);
/**
* Gets the container element for @c this element.
* If @c createAndPlace() was used to create the element, its parent is the the caller of @c createAndPlace().
* @return Returns the parent element, if @c this is not the top level element.
*/
daeElement* getXMLParentElement() { return _parent;}
/**
* Gets the associated Meta information for this element. This
* Meta also acts as a factory. See @c daeMetaElement documentation for more
* information.
* @return Returns the associated meta information.
*/
inline daeMetaElement* getMeta() { return _meta; }
/**
* Gets the integration object associated with this @c daeElement object.
* See @c daeIntegrationObject for more details.
* Integration Objects can be automatically created and associated
* with the COLLADA dom via the meta-factory mechanism and
* can be very useful for using the API to integrate with COLLADA.
* @param from_state Specifies where in the conversion process from COLLADA you are interested. A full conversion is the default.
* @param to_state Specifies where in the conversion process to COLLADA you are interested. No conversion is the default.
* @return Returns the @c daeIntegrationObject associated with this COLLADA element
* instance.
*/
daeIntegrationObject* getIntObject( IntegrationState from_state = int_converted, IntegrationState to_state = int_uninitialized );
/**
* Gets the element type name for this element.
* @return Returns the string for the type name.
*/
daeString getTypeName() const;
/**
* Gets this element's name.
* @return Returns the string for the name.
* @remarks This function returns NULL if the element's name is identical to it's type's name.
*/
daeString getElementName() const;
/**
* Sets this element's name.
* @param nm Specifies the string to use as the element's name.
* @remarks Use caution when using this function since you can easily create invalid COLLADA documents.
*/
void setElementName( daeString nm );
/**
* Gets the element ID if it exists.
* @return Returns the value of the ID attribute, if there is such
* an attribute on this element type.
* @return the string for the element ID if it exists.
*/
daeString getID() const;
//!!! ACL
/**
* Gets the children/sub-elements of this element.
* This is a helper function used to easily access an element's children without the use of the
* _meta objects. This function adds the convenience of the _contents array to elements that do
* not contain a _contents array.
* @param array The return value. An elementref array to append this element's children to.
*/
//void getChildren( daeElementRefArray &array );
void getChildren( daeTArray<daeSmartRef<daeElement> > &array );
/**
* Clones/deep copies this @c daeElement and all of it's subtree.
* @param idSuffix A string to append to the copied element's ID, if one exists.
* Default is no ID mangling.
* @param nameSuffix A string to append to the copied element's name, if one exists.
* Default is no name mangling.
* @return Returns a @c daeElement smartref of the copy of this element.
*/
daeSmartRef<daeElement> clone( daeString idSuffix = NULL, daeString nameSuffix = NULL );
public:
/**
* Resolves all @c daeURIs yet to be resolved in all @c daeElements that have been
* created.
* This is used as part of post-parsing process of a COLLADA instance document,
* which results in a new document in the database.
*/
static void resolveAll();
public:
/**
* Releases the element passed in. This function is a static wrapper that invokes
* <tt> elem->release() </tt> on the passed in element,
* if it is not NULL.
* @param elem Element to call @c release() for, if the element exists.
*/
static void release(const daeElement* elem) {if (elem != NULL) elem->release();}
/**
* Increments the reference counter for the element passed in. This function is a static wrapper
* that invokes <tt> elem->ref() </tt> on the passed in element,
* if it is not NULL.
* @param elem Element to call @c ref() for, if the element exists.
*/
static void ref(const daeElement* elem) { if (elem != NULL) elem->ref(); }
/**
* Appends the passed in element to the list of elements that need to be resolved.
* The elements in this list will be resolved during @c resolveAll().
* @param elem Element to add to the list of elements
* waiting for their @c daeURIs to be resolved.
*/
static void appendResolveElement(daeElement* elem);
};
#include <dae/daeSmartRef.h>
typedef daeSmartRef<daeElement> daeElementRef;
typedef daeSmartRef<const daeElement> daeElementConstRef;
//#include <dae/daeArray.h>
typedef daeTArray<daeElementRef> daeElementRefArray;
extern daeElementRef DAECreateElement(int nbytes);
#endif //__DAE_ELEMENT_H__

View File

@@ -0,0 +1,46 @@
/*
* 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.
*/
#ifndef __DAE__ERROR__
#define __DAE__ERROR__
/** Success */
#define DAE_OK 0
/** Fatal Error, should never be returned unless there is a bug in the library. */
#define DAE_ERR_FATAL -1
/** Call invalid, the combination of parameters given is invalid. */
#define DAE_ERR_INVALID_CALL -2
/** IO error, the file hasn't been found or there is a problem with the IO plugin. */
#define DAE_ERR_BACKEND_IO -100
/** The IOPlugin backend wasn't able to successfully validate the data. */
#define DAE_ERR_BACKEND_VALIDATION -101
/** The IOPlugin tried to write to a file that already exists and the "replace" parameter was set to false */
#define DAE_ERR_BACKEND_FILE_EXISTS -102
/** Error in the syntax of the query. */
#define DAE_ERR_QUERY_SYNTAX -200
/** No match to the search criteria. */
#define DAE_ERR_QUERY_NO_MATCH -201
/** A document with that name already exists. */
#define DAE_ERR_COLLECTION_ALREADY_EXISTS -202
/** A document with that name does not exist. */
#define DAE_ERR_COLLECTION_DOES_NOT_EXIST -203
/** Function is not implemented. */
#define DAE_ERR_NOT_IMPLEMENTED -1000
/** Gets the ASCII error string.
* @param errorCode Error code returned by a function of the API.
* @return Returns an English string describing the error.
*/
const char *daeErrorString(int errorCode);
#endif //__DAE__ERROR__

View File

@@ -0,0 +1,65 @@
/*
* 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.
*/
#ifndef _DAE_ERROR_HANDLER_
#define _DAE_ERROR_HANDLER_
#include <dae/daeTypes.h>
/**
* The @c daeErrorHandler class is a plugin that allows the use to overwrite how error and warning
* messages get handled in the client application. An example of this would be a class that reports
* the message to a gui front end instead of just printing on stdout.
*/
class daeErrorHandler {
public:
/**
* Constructor.
*/
daeErrorHandler();
/**
* Destructor.
*/
virtual ~daeErrorHandler();
/**
* This function is called when there is an error and a string needs to be sent to the user.
* You must overwrite this function in your plugin.
* @param msg Error message.
*/
virtual void handleError( daeString msg ) = 0;
/**
* This function is called when there is a warning and a string needs to be sent to the user.
* You must overwrite this function in your plugin.
* @param msg Warning message.
*/
virtual void handleWarning( daeString msg ) = 0;
/**
* Sets the daeErrorHandler to the one specified.
* @param eh The new daeErrorHandler to use. Passing in NULL results in the default plugin being used.
*/
static void setErrorHandler( daeErrorHandler *eh );
/**
* Returns the current daeErrorHandlerPlugin. DaeErrorHandler implements a singleton design pattern
* so you can get the current daeErrorHandler statically.
* @return The current daeErrorHandler.
*/
static daeErrorHandler *get();
private:
static daeErrorHandler *_instance;
static daeBool _default;
};
#endif

View File

@@ -0,0 +1,31 @@
/*
* 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.
*/
#ifndef __DAE_WIN32_PLATFORM_H__
#define __DAE_WIN32_PLATFORM_H__
#define PLATFORM_INT8 char
#define PLATFORM_INT16 short
#define PLATFORM_INT32 int
#define PLATFORM_INT64 long
#define PLATFORM_INT128 long long
#define PLATFORM_UINT8 unsigned char
#define PLATFORM_UINT16 unsigned short
#define PLATFORM_UINT32 unsigned int
#define PLATFORM_UINT64 unsigned long
#define PLATFORM_UINT128 unsigned long long
#define PLATFORM_FLOAT32 float
#define PLATFORM_FLOAT64 double
#endif

View File

@@ -0,0 +1,315 @@
/*
* 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.
*/
#ifndef __DAE_IDREF_H__
#define __DAE_IDREF_H__
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
/**
* The @c daeIDRef is a simple class designed to aid in the parsing and resolution of
* ID references inside of COLLADA elements.
* A @c daeIDRef is created for every IDREF data type in the COLLADA schema.
* It also has the capability to attempt to resolve this reference
* into a @c daeElement. If a @c daeIDRef is stored within a @c daeElement it fills
* in its container field to point to the containing element.
*
* The main API is the @c daeIDRef::resolveElement() will use a @c daeIDRefResolver
* to search for the @c daeElement inside of a @c daeDatabase.
*
*/
class daeIDRef
{
public:
/**
* An enum describing the status of the ID resolution process.
*/
enum ResolveState{
/** No ID specified */
id_empty,
/** ID specified but not resolved */
id_loaded,
/** ID resolution pending */
id_pending,
/** ID resolved correctly */
id_success,
/** Resolution failed because ID was not found */
id_failed_id_not_found,
/** Resolution failed because ID was invalid */
id_failed_invalid_id,
/** Resoltion failed due to invalid reference */
id_failed_invalid_reference,
/** Resolution failed due to an external error */
id_failed_externalization
};
private:
/** Id used to refer to another element */
daeString id;
/** Reference to the actual element the ID refers to */
daeElementRef element;
/** Element that owns this ID (if any) */
daeElement* container;
/** Current state of this id's resolution */
ResolveState state;
public:
/**
* Gets the element that this URI resolves to in memory.
* @return Returns a ref to the element.
*/
inline daeElementRef getElement(){return(element);};
/**
* Gets the element that this URI resolves to in memory.
* @return Returns a ref to the element.
*/
inline daeElementConstRef getElement() const {return(element);};
/**
* Sets the element that this URI resolves to in memory.
* @param newref A ref to the element.
*/
inline void setElement(daeElementRef newref){element=newref;};
/**
* Gets the resolve state of the URI.
* @return Returns the current state.
* @note This will be removed when daeURI starts managing its state internally.
*/
inline ResolveState getState() const {return(state);};
/**
* Sets the resolve state of the URI.
* @param newState The new state.
* @note This will be removed when daeURI starts managing its state internally.
*/
inline void setState(ResolveState newState){state=newState;};
/**
* Gets a pointer to the @c daeElement that contains this URI.
* @return Returns the pointer to the containing daeElmement.
*/
inline daeElement* getContainer() const {return(container);};
/**
* Sets the pointer to the @c daeElement that contains this URI.
* @param element Pointer to the containing @c daeElmement.
*/
inline void setContainer(daeElement* element){container=element;};
public:
/**
* Simple Constructor
*/
daeIDRef();
/**
* Destructor
*/
~daeIDRef();
/**
* Constructs an id reference via a string, using @c setID(); loads the status.
* @param id ID to construct a reference for, passed to @c setID() automatically.
*/
daeIDRef(daeString id);
/**
* Constructs a new id reference by copying an existing one.
* @param constructFromIDRef @c daeIDRef to copy into this one.
*/
daeIDRef(daeIDRef& constructFromIDRef);
/**
* Copies <tt><i>ID</i></tt> into the <tt><i>id </i></tt> data member.
* After the call to @c setID(), the <tt><i>state</i></tt> is set to @c id_loaded
* @param ID String to use to configure this @c daeIDRef.
*/
void setID(daeString ID);
/**
* Gets the ID string
* @return Returns the full ID string from <tt><i>id.</i></tt>
*/
daeString getID() const;
/**
* Uses the @c daeIDRefResolver static API to try to resolve this ID
* into a @c daeElement reference.
* This function can effectively force a load of a file, perform
* a database query, et cetera based on the @c daeIDRefResolver plugins
* implemented.
*/
void resolveElement( daeString typeNameHint = NULL );
/**
* Configures the <tt><i>id</i></tt> string of this @c daeIDRef based on the element set its <tt><i>element</i></tt> data member.
* Uses @c daeElement::getID() to get the element's ID information to configure
* the <tt><i>id</i></tt> string.
*/
void resolveID();
/**
* Sets the <tt><i>state</i></tt> of this @c daeIDRef to @c id_pending, as it is awaiting a call to
* @c resolveElement().
*/
void validate();
/**
* Copies <tt><i>from</i></tt> into <tt><i>this.</i></tt>
* The function does a simple copy, and not "base validation".
* @param from @c daeIDRef to copy from.
*/
void copyFrom(daeIDRef& from);
/**
* Outputs all components of this @c daeIDRef to stderr.
*/
void print();
/**
* Resets this @c daeIDRef; frees all string references
* and returns <tt><i>state</i></tt> to @c empty.
*/
void reset();
/**
* Initializes the @c daeIDREf, setting <tt><i>id, element,</i></tt> and <tt><i>container</i></tt> to NULL.
*/
void initialize();
};
class daeIDRefResolver;
typedef daeTArray<daeIDRefResolver*> daeIDRefResolverPtrArray;
/**
* The @c daeIDRefResolver class is the plugin point for @c daeIDRef resolution.
* This class is an abstract base class that defines an interface for
* resolving @c daeIDRefs.
* All instances of @c daeIDRefResolvers are tracked centrally.
* Every @c daeIDRef is passed through this list of @c aeIDRefResolvers for resolution.
* The list is ordered on a first come, first serve basis, and resolution
* terminates after any resolver instance is able to resolve the ID.
*/
class daeIDRefResolver
{
public:
/**
* Constructor; base constructor appends @c this to <tt><i>_KnownResolvers</i></tt> list.
*/
daeIDRefResolver();
/**
* Destructor
*/
virtual ~daeIDRefResolver();
protected:
static daeIDRefResolverPtrArray _KnownResolvers;
public:
/**
* Iterates through known resolvers
* calling @c resolveElement().
* @param id @c daeIDRef to resolve.
*/
static void attemptResolveElement(daeIDRef &id, daeString typeNameHint = NULL );
/**
* attemptResolveID iterates through known resolvers
* calling resolveID().
* @param id @c daeIDRef to resolve.
*/
static void attemptResolveID(daeIDRef &id);
public: // Abstract Interface
/**
* Provides an abstract interface to convert a @c daeIDRef into a @c daeElement.
* @param IDRef @c daeIDRef to resolve.
* @return Returns true if the @c daeIDRefResolver successfully resolved the IDRef,
* returns false otherwise.
*/
virtual daeBool resolveElement(daeIDRef& IDRef, daeString typeNameHint = NULL ) = 0;
/**
* Provides an abstract interface to convert a @c daeElement into a @c daeIDRef.
* @param IDRef @c daeIDRef to resolve.
* @return Returns true if the @c daeIDRefResolver successfully resolved the element
* into a @c daeIDRef, returns false otherwise.
*/
virtual daeBool resolveID(daeIDRef& IDRef) = 0;
/**
* Gets the name of this resolver.
* @return Returns the string name.
*/
virtual daeString getName() = 0;
};
class daeDatabase;
/**
* The @c daeDefaultIDRefResolver resolves a @c daeIDRef by checking with a database.
* It is a concrete implementation for @c daeIDRefResolver.
*/
class daeDefaultIDRefResolver : public daeIDRefResolver
{
public:
/**
* Constructor
* @param database @c daeDatabase for this implementation.
*/
daeDefaultIDRefResolver(daeDatabase* database);
/**
* Destructor
*/
~daeDefaultIDRefResolver();
protected:
daeDatabase* _database;
public: // Abstract Interface
/*
* Implements base class abstract routine from @c daeIDRefResolver.
*/
virtual daeBool resolveElement(daeIDRef& id, daeString typeNameHint = NULL );
/*
* Implements base class abstract routine from @c daeIDRefResolver.
*/
virtual daeBool resolveID(daeIDRef& id);
/*
* Implements base class abstract routine from @c daeIDRefResolver.
*/
virtual daeString getName();
};
#endif //__DAE_IDREF_H__

View File

@@ -0,0 +1,112 @@
/*
* 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.
*/
#ifndef __DAE_IOPLUGIN__
#define __DAE_IOPLUGIN__
#include <dae/daeTypes.h>
class daeDatabase;
class daeMetaElement;
class daeURI;
class daeDocument;
/**
* The @c daeIOPlugin class provides the input/output plugin interface, which is
* the interface between the COLLADA runtime and the backend storage. A native
* COLLADA XML plugin implementation is provided along with this interface.
*/
class daeIOPlugin
{
public:
/**
* Destructor
*/
virtual ~daeIOPlugin() {}
/**
* Sets the top meta object.
* Called by @c dae::setIOPlugin() when the IO plugin changes. It passes to this function the
* top meta object, which is the root of a
* hierarchy of @c daeMetaElement objects. This top meta object is capable of creating
* any of the root objects in the DOM tree.
* @param topMeta Top meta object to use to create objects to fill the database.
* @return Returns DAE_OK if successful, otherwise returns a negative value defined in daeError.h.
*/
virtual daeInt setMeta(daeMetaElement *topMeta) = 0;
/** @name Database setup */
//@{
/**
* Sets the database to use.
* All @c daeIOPlugins use the same interface to the @c daeDatabase,
* @c setDatabase() tells the @c daeIOPlugin which @c daeDatabase object it should use
* for storage and queries.
* @param database Database to set.
*/
virtual void setDatabase(daeDatabase* database) = 0;
//@}
/** @name Operations */
//@{
/**
* Imports content into the database from an input.
* The input can be a file, a database or another runtime.
* @param uri the URI of the COLLADA document to load, not all plugins accept all types of URIs,
* check the documentation for the IO plugin you are using.
* @param docBuffer A string containing the text of the document to load. This is an optional attribute
* and should only be used if the document has already been loaded into memory.
* @return Returns DAE_OK if successfully loaded, otherwise returns a negative value defined in daeError.h.
* @see @c daeInterface::load().
*/
virtual daeInt read(daeURI& uri, daeString docBuffer) = 0;
/** @name Operations */
//@{
/**
* Writes a specific document to an output.
* @param name URI to write the document to, not all IO plugins support all types of URIs
* check the documentation for the IO plugin you are using.
* @param document Pointer to the document that we're going to write out.
* @param replace True if write should overwrite an existing file. False otherwise.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
* @see @c daeInterface::saveAS()
*/
virtual daeInt write(daeURI *name, daeDocument *document, daeBool replace) = 0;
//@}
/** @name Load/Save Progress */
//@{
/**
* Gets the progress of @c load() operation.
* This function can be used from another thread to check the progress of a @c load()
* operation. The user can update a progress bar <tt> bytesParsed/totalBytes </tt> gives the
* percentage of progress of the operation.
* @param bytesParsed Pointer to an integer that receives the number of bytes already
* consumed from the file, can be NULL if the user don't want to retrieve this information.
* @param lineNumber Pointer to an integer that receives the number of lines read so far,
* can be NULL.
* @param totalBytes Pointer to an integer that receives the total number of bytes in the
* file currently beeing loaded, can be NULL.
* @param reset Indicates whether to reset the counters. A value of false is the default behaviour
* that fits most usage. Set it to true to reset
* the <tt><i> bytesParsed </i></tt> and <tt><i> lineNumber </i></tt> counters. The system resets the counter at the beginning of
* each file.
*/
virtual void getProgress(daeInt* bytesParsed,
daeInt* lineNumber,
daeInt* totalBytes,
daeBool reset = false ) = 0;
//@}
};
#endif // __DAE_IOPLUGIN__

View File

@@ -0,0 +1,179 @@
/*
* 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.
*/
#ifndef __DAE_INTEGRATION_OBJECT_H__
#define __DAE_INTEGRATION_OBJECT_H__
#include <dae/daeElement.h>
class daeIntegrationObject;
typedef daeSmartRef<daeIntegrationObject> daeIntegrationObjectRef;
/**
* The @c daeIntegrationObject class provides methods to translate COLLADA
* objects to and from application objects.
*/
class daeIntegrationObject : public daeElement
{
public:
/**
* Constructor.
*/
daeIntegrationObject() { _element = NULL; _object = NULL; _from_state = int_uninitialized; _to_state = int_uninitialized; }
/**
* Destructor.
*/
virtual ~daeIntegrationObject() {}
public:
/** A smartRef to the element associated with this integration object. */
daeElementRef _element;
/** A pointer at which to store the user object associated with this element. */
void* _object;
/** An enum describing the state of the conversion from COLLADA. */
IntegrationState _from_state;
/** An enum describing the state of the conversion to COLLADA. */
IntegrationState _to_state;
public:
/**
* Sets the element associated with this integration object.
* @param element A daeSmartRef to the element for this integration object.
*/
void setElement(daeElementRef element) { _element = element; }
/**
* Gets the element associated with this integration object.
* @return The element associated with this integration object.
*/
daeElementRef getElement() { return _element; }
/**
* Sets the user object associated with this integration object.
* @param object A void * to the user object to be associated with this integration object.
*/
void setObject(void* object) { _object = object; }
/**
* Gets the user object associated with this integration object.
* @return The user object associated with this integration object.
*/
void* getObject() { return _object; }
public: // Do not implement these by default
virtual daeElementRef lookupElement(daeString s) { (void)s; return NULL;}
virtual daeIntegrationObjectRef lookup(daeString s) { (void)s; return NULL;}
protected:
/**
* Defines the code to create the application-specific data structure associated with the DOM class
* for this integration template. This method sets up the integration object for the DOM class.
* @param element A daeSmartRef to the element to convert into the user's structure.
*/
virtual void createFrom(daeElementRef element) = 0;
/**
* Defines the code to convert the COLLADA Object Model data structure into your application-specific
* data structure.
*/
virtual void fromCOLLADA() = 0;
/**
* Defines any postprocessing code that must execute after the basic conversion.
*/
virtual void fromCOLLADAPostProcess() = 0;
/**
* Defines code to create the COLLADA Object Model data structure associated with the DOM class for
* this template.
* @param userData A pointer to the application-specific data structure to convert to the DOM structure.
*/
virtual void createTo(void *userData) = 0;
/**
* Defines the code to convert your application's data structures back into COLLADA Object Model data
* structures.
*/
virtual void toCOLLADA() = 0;
/**
* Defines any postprocessing code that must execute after the basic conversion.
*/
virtual void toCOLLADAPostProcess() = 0;
public:
/**
* Defines the code to create the application-specific data structure associated with the DOM class
* for this integration template. This method sets up the integration object for the DOM class. This
* method checks and updates the conversion state stored in _from_state and converts only if
* necessary.
* @param element A daeSmartRef to the element to convert into the user's structure.
*/
void createFromChecked(daeElementRef element) {
if ( _from_state >= int_created ) {
return;
}
createFrom(element);
_from_state = int_created;
};
/**
* Defines the code to convert the COLLADA Object Model data structure into your application-specific
* data structure. This method checks and updates the conversion state stored in _from_state and
* converts only if necessary.
*/
void fromCOLLADAChecked() {
if ( _from_state >= int_converted ) {
return;
}
fromCOLLADA();
_from_state = int_converted;
};
/**
* Defines any postprocessing code that must execute after the basic conversion. This method
* checks and updates the conversion state stored in _from_state and converts only if necessary.
*/
void fromCOLLADAPostProcessChecked() {
if ( _from_state >= int_finished) {
return;
}
fromCOLLADAPostProcess();
_from_state = int_finished;
};
/**
* Defines code to create the COLLADA Object Model data structure associated with the DOM class for
* this template. This method checks and updates the conversion state stored in _to_state and
* converts only if necessary.
* @param userData A pointer to the application-specific data structure to convert to the DOM structure.
*/
void createToChecked(void *userData) {
if ( _to_state >= int_created ) {
return;
}
createTo(userData);
_to_state = int_created;
};
/**
* Defines the code to convert your application's data structures back into COLLADA Object Model data
* structures. This method checks and updates the conversion state stored in _to_state and
* converts only if necessary.
*/
void toCOLLADAChecked() {
if ( _to_state >= int_converted ) {
return;
}
toCOLLADA();
_to_state = int_converted;
};
/**
* Defines any postprocessing code that must execute after the basic conversion. This method
* checks and updates the conversion state stored in _to_state and converts only if necessary.
*/
void toCOLLADAPostProcessChecked() {
if ( _to_state >= int_finished) {
return;
}
toCOLLADAPostProcess();
_to_state = int_finished;
};
};
#endif

View File

@@ -0,0 +1,231 @@
/*
* Copyright 2006 Sony Computer Entertainment Inc.
*
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://research.scea.com/scea_shared_source_license.html
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
#ifndef __DAE_INTERFACE__
#define __DAE_INTERFACE__
#include <dae/daeTypes.h>
class daeElement;
class daeDatabase;
class daeIOPlugin;
class domCOLLADA;
/**
* Integration library meta register function.
*
* Such a function (@c intRegisterElements() )is autogenerated by the COLLADA code generator
* and can be modified if necessary to register the meta of the
* integration library objects.
*/
typedef void (*daeIntegrationLibraryFunc)();
/**
* The @c daeInterface class provides an interface with the COLLADA runtime database.
*/
class daeInterface
{
public:
/**
* Destructor.
*/
virtual ~daeInterface() {}
/** @name Database setup
* management of the database that stores the COLLADA elements.
*/
//@{
/**
* Gets the COLLADA runtime database currently being used.
* @return Returns the database currently being used.
*/
virtual daeDatabase* getDatabase() = 0;
/**
* Sets the COLLADA runtime database to use.
* @param database Database that stores the COLLADA data,
* if set to NULL a default database is set.
* @return Returns @c DAE_OK if success, otherwise, returns a negative error value as defined in daeError.h.
*/
virtual daeInt setDatabase(daeDatabase* database) = 0;
//@}
/** @name IOPlugin setup
* handle the backend, which can import or export the COLLADA
* database to a file system, to a runtime or to any other storage system.
*/
//@{
/**
* Gets the @c daeIOPlugin currently set.
* @return Returns the @c daeIOPlugin currently set on the interface.
*/
virtual daeIOPlugin* getIOPlugin() = 0;
/**
* Sets the plugin which will be the interface between the COLLADA runtime database
* and the rest of the system.
* It can be used to read or write from a native XML file, to convert, or to store
* in a more complex structure like a storage database.
* @param plugin Plugin to use, if set to NULL a default plugin is set.
* @return Returns @c DAE_OK if success, otherwise, returns a negative error value as defined in daeError.h.
*/
virtual daeInt setIOPlugin(daeIOPlugin* plugin) = 0;
//@}
/** @name Integration Library Setup
* definition of an integration library to use when processing COLLADA file.
* It defines a framework for a user to insert a source code that will be called
* in the context of an import or export. Hence, it's the preferred way of
* accessing COLLADA runtime structure and convert between COLLADA and the user's
* runtime.
*/
//@{
/**
* Gets the integration library register function currently being used.
* @return Returns the integration library register function currently being used.
*/
virtual daeIntegrationLibraryFunc getIntegrationLibrary() = 0;
/**
* Sets the integration library register function.
* @param regFunc Integration library register function to use.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
*/
virtual daeInt setIntegrationLibrary(daeIntegrationLibraryFunc regFunc)=0;
//@}
/** @name Batch import/export operations
* import or export a COLLADA database by using the daeIOPlugin currently set.
*/
//@{
/**
* Loads a COLLADA document into the runtime database
* @param name the document to load. The format for this is defined by the IO plugin
* being used, in most cases this will be an rfc 2396 compliant relative or absolute URI. Please check
* the class documentation for the IO plugin you are using for specific restrictions. Not all IO plugins
* support all types of URIs.
* @param docBuffer A string containing the text of the document to load. This is an optional attribute
* and should only be used if the document has already been loaded into memory.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
*/
virtual daeInt load(daeString name, daeString docBuffer = NULL) = 0;
/**
* Saves a single document/document back to the location it was loaded from.
* @param documentName the name of the loaded document to be saved, in most cases this will be an rfc 2396 compliant
* URI but some IO plugins may work differently. Please check the class documentation for the IO plugin you are using for specific restrictions.
* @param replace If set to false, save won't save over top of an existing document and will return a DAE_ERR_BACKEND_FILE_EXISTS
* error.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
*/
virtual daeInt save(daeString documentName, daeBool replace=true) = 0;
/**
* Saves a single document/document back to the location it was loaded from.
* @param documentIndex the index of a loaded document to be saved.
* @param replace If set to false, save won't save over top of an existing document and will return a DAE_ERR_BACKEND_FILE_EXISTS
* error.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
*/
virtual daeInt save(daeUInt documentIndex=0, daeBool replace=true) = 0;
/**
* Saves a single document/document from the runtime database by name.
* @param name the name to save the document to. The format for this is defined by the IO plugin
* being used, in most cases this will be an rfc 2396 compliant relative or absolute URI. Please check
* the class documentation for the IO plugin you are using for specific restrictions. Not all IO plugins
* support all types of URIs.
* @param documentName the name of the document/document to save. This is also defined by the IO plugin, in
* most cases this will be the URI of where the document was loaded from.
* @param replace If set to false, saveAs won't save over top of an existing document and will return a DAE_ERR_BACKEND_FILE_EXISTS
* error.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
*/
virtual daeInt saveAs(daeString name, daeString documentName, daeBool replace=true) = 0;
/**
* Saves a single document/document from the runtime database by index.
* @param name the name to save the document to. The format for this is defined by the IO plugin
* being used, in most cases this will be an rfc 2396 compliant relative or absolute URI. Please check
* the class documentation for the IO plugin you are using for specific restrictions. Not all IO plugins
* support all types of URIs.
* @param documentIndex the index of the document/document to save, 0 is the first document loaded...etc.
* Defaults to saving the first document loaded
* @param replace If set to false, saveAs won't save over top of an existing document and will return a DAE_ERR_BACKEND_FILE_EXISTS
* error.
* @return Returns DAE_OK if success, a negative value defined in daeError.h otherwise.
*/
virtual daeInt saveAs(daeString name, daeUInt documentIndex=0, daeBool replace=true) = 0;
/**
* Unloads a specific document from the runtime database.
* @param name Name of the document to remove.
* @return Returns DAE_OK if unloaded successfully, otherwise returns a negative value as defined in daeError.h.
* @note This function is not currently implemented.
*/
virtual daeInt unload(daeString name) = 0;
/**
* Unloads all the documents of the runtime database.
* This function frees all the @c dom* objects and integration objects created so far,
* except the object on which the user still has a smart pointer reference.
* @return Returns DAE_OK if all documents unloaded successfully, otherwise returns a negative value as defined in daeError.h.
*/
virtual daeInt clear() = 0;
//@}
/** @name Import/export progress
*/
//@{
/**
* Gets the progress of @c load() operation.
* This function can be used from another thread to check the progress of a @c load()
* operation. The user can update a progress bar <tt> bytesParsed/totalBytes </tt> gives the
* percentage of progress of the operation.
* @param bytesParsed Pointer to an integer that receives the number of bytes already
* consumed from the file, can be NULL if the user don't want to retrieve this information.
* @param lineNumber Pointer to an integer that receives the number of lines read so far,
* can be NULL.
* @param totalBytes Pointer to an integer that receives the total number of bytes in the
* file currently being loaded, can be NULL.
* @param reset Indicates whether to reset the counters. A value of false is the default behavior
* that fits most usage. Set it to true to reset
* the <tt><i> bytesParsed </i></tt> and <tt><i> lineNumber </i></tt> counters. The system resets the counter at the beginning of
* each file.
*/
virtual void getProgress(daeInt* bytesParsed,
daeInt* lineNumber,
daeInt* totalBytes,
daeBool reset = false )=0;
//@}
/** @name Main DOM Query
*/
//@{
/**
* Gets the COLLADA tree root of a given document.
* @param name Document name, for the file @c daeIOPlugin, this will be the filename for a file.
* @return Returns the @c domCOLLADA root object of the document, or NULL if the document is not found.
*/
virtual domCOLLADA* getDom(daeString name) = 0;
/**
* Gets the COLLADA schema version that was used to build the DOM classes
* @return a text string with the version number in it (ie: 1.3.1)
*/
virtual daeString getDomVersion() = 0;
/**
* Sets or inserts a COLLADA tree into the database.
* The system creates a default database if none is set and then creates a document
* if the document doesn't already exist. The document keeps a reference on the
* @c daeElement, so you can then delete your own reference to the object safely.
* @param name the document name, may be an absolute or relative URI. The URI will be resolved to an absolute version
* and then compared with the absolute version of the document's URI. If the URI contains a fragment, it is stripped out.
* @param dom Root tree.
* @return Returns DAE_OK if success, otherwise returns a negative value as defined in daeError.h.
*/
virtual daeInt setDom(daeString name, domCOLLADA* dom) = 0;
//@}
};
#endif // __DAE_INTERFACE__

View File

@@ -0,0 +1,63 @@
/*
* 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.
*/
#ifndef __DAE_MEMORY_SYSTEM_H__
#define __DAE_MEMORY_SYSTEM_H__
#include <dae/daeTypes.h>
/**
* The @c daeMemorySystem class is a simple wrapper for memory operations.
* Every allocation passes a string pool name such that
* in the future different pools can be used based on allocation type.
* Currently the system is just a pass-through to system @c malloc.
*/
class daeMemorySystem
{
public:
/**
* Provides a wrapper malloc with pool field.
* @param pool String name of the pool to use for this allocation.
* @param n Number of bytes to allocate.
* @return Returns the memory allocated if successful, or NULL if not.
*/
static daeRawRef malloc(daeString pool, size_t n);
/**
* Provides a wrapper free with pool argument.
* @param pool Pool the memory should be freed from.
* @param mem Memory to be freed.
*/
static void free(daeString pool, daeRawRef mem);
};
// Shorthand for defining new and delete overrides for classes, bad use of macros!
#define DAE_ALLOC \
inline void* operator new(size_t n) { \
return daeMemorySystem::malloc("meta",n); \
} \
inline void* operator new(size_t , size_t runtimeSize) { \
return daeMemorySystem::malloc("meta",runtimeSize); \
} \
inline void operator delete(void* p) { \
daeMemorySystem::free("meta",p); \
} \
inline void operator delete(void* p, size_t runtimeSize) { \
(void)runtimeSize; \
daeMemorySystem::free("meta",p); \
}
#endif // __DAE_MEMORY_H__

View File

@@ -0,0 +1,483 @@
/*
* 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.
*/
#ifndef __DAE_META_ATTRIBUTE_H__
#define __DAE_META_ATTRIBUTE_H__
#include <dae/daeTypes.h>
#include <dae/daeStringRef.h>
#include <dae/daeAtomicType.h>
#include <dae/daeElement.h>
#include <dae/daeArray.h>
class daeElement;
class daeMetaElement;
class daeMetaAttribute;
class daeMetaElementAttribute;
typedef daeSmartRef<daeMetaElementAttribute> daeMetaElementAttributeRef;
typedef daeSmartRef<daeMetaElement> daeMetaElementRef;
typedef daeSmartRef<daeMetaAttribute> daeMetaAttributeRef;
typedef daeTArray<daeMetaAttributeRef> daeMetaAttributeRefArray;
typedef daeTArray<daeMetaAttribute*> daeMetaAttributePtrArray;
typedef daeTArray<daeMetaElementAttributeRef> daeMetaElementAttributeRefArray;
/**
* The @c daeMetaAttribute class describes one attribute in a C++ COLLADA dom element.
*
* In the case of the C++ object model a conceptual attribute can be
* either a dom attribute, a dom element, or a dom value.
* Essentially, the meta attribute describes fields on the C++ class.
* However these attributes are stored separately in the containing meta
* @c daeMetaElement.
* @c daeMetaAttributes always exist inside of @c daeMetaElements.
* Each @c daeMetaAttribute has certain symantic operations it is capable of
* including @c set(), @c get(), @c print(), and @c resolve().
* @c daeMetaAttributes use the @c daeAtomicType system as their underlying semantic
* implementation, but contain additional information about the packaging
* of the atomic types into the C++ dom classes such as offset, and
* array information.
*/
class daeMetaAttribute : public daeElement
{
protected:
daeStringRef _name;
daeInt _offset;
daeAtomicType* _type;
daeMetaElement* _container;
daeString _default;
daeBool _isValid;
daeBool _isRequired;
public:
/**
* Constructor
*/
daeMetaAttribute();
/**
* Destructor
*/
~daeMetaAttribute() {}
public:
/**
* Determines if the value of this attribute was ever set.
* This will be the case if @c setDefault() was
* called or if the attribute was assigned a value by the input file. If you set the value yourself,
* you need to call @c setIsValid() to set this flag.
* @return Returns true if the value in this attribute is valid.
*/
daeBool getIsValid() {return _isValid; }
/**
* Sets the value that indicates if this attribute contains a valid value.
* If you don't set this on an optional
* attribute, that attribute will not be written.
* @param isValid Indicates if the value in this attribute valid, true if it is, false if not.
*/
void setIsValid(daeBool isValid) {_isValid = isValid;}
/**
* Determines if the schema indicates that this is a required attribute.
* @return Returns true if this is a required attribute, false if not.
*/
daeBool getIsRequired() {return _isRequired; }
/**
* Sets the value that indicates that this attribute is required by the schema. If set, the attribute
* will always be exported by the API regardless of its value.
* @param isRequired Indicates if the schema says this attribute is required, true if it is, false if not.
*/
void setIsRequired(daeBool isRequired) {_isRequired = isRequired;}
/**
* Sets the byte offset (from @c this) where this attribute's storage is
* found in its container element class.
* @param offset Integer byte offset from @c this pointer.
*/
void setOffset(daeInt offset) { _offset = offset; }
/**
* Gets the byte offset (from @ this) where this attribute's storage is
* found in its container element class.
* @return Returns the integer byte offset from @c this pointer for this attribute.
*/
daeInt getOffset() { return _offset; }
/**
* Sets the name of the attribute.
* @param name @c daeString that is directly stored as a pointer
* without being copied.
*/
void setName(daeString name) { _name = name; }
/**
* Gets the name of this attribute.
* @return Returnsthe name of this attribute.
*/
daeStringRef getName() { return _name; }
/**
* Sets the type of the attribute.
* @param type @c daeAtomicType to use for interacting with this
* attribute in a containing @c daeElement.
*/
void setType(daeAtomicType* type) { _type = type; }
/**
* Gets the @c daeAtomicType used by this attribute.
* @return Returns the @c daeAtomicType that this attribute uses for its
* implementation.
*/
daeAtomicType* getType() { return _type; }
/**
* Sets the default for this attribute via a string. The attribute's
* type is used to convert the string into a binary value
* inside of an element.
* @param defaultVal @c daeString representing the default value.
*/
void setDefault(daeString defaultVal) { _default = defaultVal; }
/**
* Gets the default for this attribute via a string. The attribute's
* type is used to convert the string into a binary value
* inside of an element.
* @return Returns a @c daeString representing the default value.
*/
daeString getDefault() { return _default; }
/**
* Sets the containing @c daeMetaElement for this attribute.
* @param container Element on which this @c daeMetaAttribute belongs.
*/
void setContainer(daeMetaElement* container) { _container = container; }
/**
* Gets the containing @c daeMetaElement for this attribute.
* @return Returns the @c daeMetaElement to which this @c daeAttribute belongs.
*/
daeMetaElement* getContainer() { return _container; }
/**
* Gets the number of particles associated with this attribute in instance <tt><i>e.</i></tt>
* @param e Containing element to run the operation on.
* @return Returns the number of particles associated with this attribute
* in instance <tt><i>e.</i></tt>
*/
virtual daeInt getCount(daeElement* e);
/**
* Gets a particle from containing element <tt><i>e</i></tt> based on <tt><i>index.</i></tt>
* @param e Containing element from which to get the element.
* @param index Index of the particle to retrieve if indeed
* there is an array of elements rather than a singleton.
* @return Returns the associated particle out of parent element e, based on index, if necessary.
*/
virtual daeMemoryRef get(daeElement* e, daeInt index);
public: // STATIC MEMBERS
/**
* Lists the type names that can be created by factories and indicates which _FactoryTemplates to use for each type.
*/
static daeStringRefArrayArray _NameBindings;
/**
* Points to the factory objects used to construct various types of attributes, _NameBindings specifies which type names are bound to which factories.
*/
static daeMetaAttributeRefArray _FactoryTemplates;
public: //STATIC INTERFACE
/**
* Obsolete
*/
static daeMetaAttributeRef Factory(daeStringRef xmlTypeName);
/**
* Obsolete
*/
static void InitializeKnownTypes();
public:
/**
* Clones the @c daeMetaAttribute.
* @return Returns a duplicate of this @c daeMetaAttribute.
* @note Not Implemented.
*/
virtual daeMetaAttributeRef clone();
/**
* Resolves a reference (if there is one) in the attribute type;
* only useful for reference types.
* @param elem Containing element on which this attribute
* should be resolved.
*/
virtual void resolve(daeElementRef elem);
/**
* Gets the number of bytes for this attribute.
* @return Returns the number of bytes in the C++ COLLADA dom element for this
* attribute.
*/
virtual daeInt getSize();
/**
* Gets the alignment in bytes on the class of this meta attribute type.
* @return Returns the alignment in bytes.
*/
virtual daeInt getAlignment();
/**
* Sets the value of this attribute on <tt><i>element</i></tt> by converting string <tt><i>s</i></tt>
* to a binary value and assigning it via the underlying @c daeAtomicType
* system.
* @param element Element on which to set this attribute.
* @param s String containing the value to be converted via the
* atomic type system.
*/
virtual void set(daeElement* element, daeString s);
/**
* Copys the value of this attribute from fromElement into toElement.
* @param toElement Pointer to a @c daeElement to copy this attribute to.
* @param fromElement Pointer to a @c daeElement to copy this attribute from.
*/
virtual void copy(daeElement* toElement, daeElement* fromElement);
public:
/**
* Gets the storage inside of <tt><i>e</i></tt> associated with
* this attribute. It is very useful for performing generic processing
* on elements and attributes from external tools regardless of element
* and attribute type.
* @param e Element from which to apply this attributes offset.
* @return Returns the storage associate with this attribute in <tt><i>e.</i></tt>
*/
daeChar* getWritableMemory(daeElement* e) {
return (daeChar*)e+_offset; }
};
/**
* The @c daeMetaElementAttribute class represents a single attribute whose value is an element.
*/
class daeMetaElementAttribute : public daeMetaAttribute
{
public:
/** Minimum number of times this meta element can occur. */
daeInt _minOccurs;
/** Maximum number of times this meta element can occur. */
daeInt _maxOccurs;
/** If this element is found in a choice group in the schema */
daeBool _isInChoice;
/** If this element is found in a sequence group in the schema */
daeBool _isInSequence;
/** The element found before this one in the sequence group in the schema */
daeMetaElement* _previousInSequence;
/** The metaElement that describes the element type of this attribute */
daeMetaElement* _elementType;
public:
/**
* Constructor
*/
daeMetaElementAttribute();
/**
* Destructor
*/
~daeMetaElementAttribute() {}
public:
/**
* Sets the element type for the element that this attribute points to.
* @param elementType @c daeMetaElement representing the type.
*/
void setElementType(daeMetaElement *elementType) {
_elementType = elementType; }
/**
* Gets the element type for the element that this attribute points to.
* @return Returns the @c daeMetaElement representing the type.
*/
daeMetaElement* getElementType() { return _elementType; }
/**
* Defines the override version of base method.
* @see daeMetaAttribute::clone()
*/
virtual daeMetaAttributeRef clone();
/**
* Places element <tt><i>child</i></tt> in element <tt><i>parent</i></tt> using @c this element attribute.
* @param parent The Element in which to place child.
* @param child The Element to place in parent.
*/
virtual void placeElement(daeElement* parent, daeElement* child);
/**
* Removes element <tt><i>child</i></tt> from element <tt><i>parent</i></tt> using @c this element attribute.
* @param parent The Element in which to remove child.
* @param child The Element to remove from parent.
*/
virtual void removeElement(daeElement* parent, daeElement* child);
/**
* Sets the database document associated with this element.
* @param parent The daeElement to set the document.
* @param c The @c daeDocument to associate with this element.
*/
virtual void setDocument(daeElement *parent, daeDocument* c );
inline void setCollection(daeElement *parent, daeDocument* c ) {
setDocument( parent, c );
}
/**
* Gets the number of elements associated with this attribute in instance <tt><i>e.</i></tt>
* @param e Containing element to run the operation on.
* @return Returns the number of elements associated with this attribute
* in instance <tt><i>e.</i></tt>
*/
virtual daeInt getCount(daeElement* e);
/**
* Gets an element from containing element <tt><i>e</i></tt> based on <tt><i>index.</i></tt>
* @param e Containing element from which to get the element.
* @param index Index of the element to retrieve if indeed
* there is an array of elements rather than a singleton.
* @return Returns the associated element out of parent element e, based on index, if necessary.
*/
virtual daeMemoryRef get(daeElement* e, daeInt index);
/**
* Defines the override version of base method.
* @param element Element on which to set this attribute.
* @param s String containing the value to be converted via the
* atomic type system.
*/
virtual void set(daeElement* element, daeString s);
/**
* Defines the override version of base method.
* @param toElement Pointer to a @c daeElement to copy this attribute to.
* @param fromElement Pointer to a @c daeElement to copy this attribute from.
*/
virtual void copy(daeElement* toElement, daeElement* fromElement);
};
typedef daeSmartRef<daeMetaElementAttribute> daeMetaElementAttributeRef;
typedef daeTArray<daeMetaElementAttributeRef> daeMetaElementAttributeArray;
/**
* The @c daeMetaElementArrayAttribute class is similar to daeMetaElementAttribute
* except that this meta attribute
* describes an array of elements rather than a singleton.
*/
class daeMetaElementArrayAttribute : public daeMetaElementAttribute
{
public:
/**
* Constructor
*/
daeMetaElementArrayAttribute();
public:
/**
* Defines the override version of this method from @c daeMetaElement.
* @return Returns a duplicate of this @c daeMetaAttribute.
* @note Not Implemented.
*/
virtual daeMetaAttributeRef clone();
/**
* Defines the override version of this method from @c daeMetaElement.
*/
virtual void placeElement(daeElement* parent, daeElement* child);
/**
* Defines the override version of this method from @c daeMetaElement.
*/
virtual void removeElement(daeElement* parent, daeElement* child);
/**
* Sets the database document associated with this element.
* @param c The @c daeDocument to associate with this element.
*/
virtual void setDocument(daeElement *parent, daeDocument* c );
inline void setCollection(daeElement *parent, daeDocument* c ) {
setDocument( parent, c );
}
/**
* Defines the override version of this method from @c daeMetaElement.
* @param e Containing element to run the operation on.
* @return Returns the number of particles associated with this attribute
* in instance <tt><i>e.</i></tt>
*/
virtual daeInt getCount(daeElement* e);
/**
* Defines the override version of this method from @c daeMetaElement.
* @param e Containing element from which to get the element.
* @param index Index of the particle to retrieve if indeed
* there is an array of elements rather than a singleton.
* @return Returns the associated particle out of parent element e, based on index, if necessary.
*/
virtual daeMemoryRef get(daeElement* e, daeInt index);
/**
* Defines the override version of this method from @c daeMetaElement.
* @param toElement Pointer to a @c daeElement to copy this attribute to.
* @param fromElement Pointer to a @c daeElement to copy this attribute from.
*/
virtual void copy(daeElement* toElement, daeElement* fromElement);
};
typedef daeSmartRef<daeMetaElementArrayAttribute> daeMetaElementArrayAttributeRef;
typedef daeTArray<daeMetaElementArrayAttributeRef> daeMetaElementArrayAttributeArray;
/**
* The @c daeMetaArrayAttribute class is simple a wrapper that implements
* an array of atomic types rather than a singleton.
* The corresponding storage is an array
* and the corresponding operations are implemented on the array
* data structure rather than on inlined storage in elements.
*/
class daeMetaArrayAttribute : public daeMetaAttribute
{
daeMetaAttributeRef arrayType;
public:
/**
* Defines the override version of this method from @c daeMetaAttribute.
* @return Returns a duplicate of this @c daeMetaAttribute.
* @note Not Implemented.
*/
virtual daeMetaAttributeRef clone();
/**
* Defines the override version of this method from @c daeMetaAttribute.
* @param element Element on which to set this attribute.
* @param s String containing the value to be converted via the
* atomic type system.
*/
virtual void set(daeElement* element, daeString s);
/**
* Defines the override version of this method from @c daeMetaAttribute.
* @param toElement Pointer to a @c daeElement to copy this attribute to.
* @param fromElement Pointer to a @c daeElement to copy this attribute from.
*/
virtual void copy(daeElement* toElement, daeElement* fromElement);
/**
* Defines the override version of this method from @c daeMetaElement.
* @param e Containing element to run the operation on.
* @return Returns the number of particles associated with this attribute
* in instance <tt><i>e.</i></tt>
*/
virtual daeInt getCount(daeElement* e);
/**
* Defines the override version of this method from @c daeMetaElement.
* @param e Containing element from which to get the element.
* @param index Index of the particle to retrieve if indeed
* there is an array of elements rather than a singleton.
* @return Returns the associated particle out of parent element e, based on index, if necessary.
*/
virtual daeMemoryRef get(daeElement* e, daeInt index);
};
#endif //__DAE_META_ATTRIBUTE_H__

View File

@@ -0,0 +1,462 @@
/*
* 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.
*/
#ifndef __DAE_META_ELEMENT_H__
#define __DAE_META_ELEMENT_H__
#include <dae/daeTypes.h>
#include <dae/daeArrayTypes.h>
#include <dae/daeElement.h>
#include <dae/daeMetaAttribute.h>
typedef daeElementRef (*daeElementConstructFunctionPtr)(daeInt bytes);
class daeMetaElement;
typedef daeSmartRef<daeMetaElement> daeMetaElementRef;
typedef daeTArray<daeMetaElementRef> daeMetaElementRefArray;
/**
* Each instance of the @c daeMetaElement class describes a C++ COLLADA dom
* element type.
* @par
* The meta information in @c daeMetaElement is a combination of the information
* required to create and maintain C++ object instances and
* the information necessary to parse and construct a hierarchy of COLLADA
* elements.
* @par
* @c daeMetaElement objects also act as factories for C++ COLLADA dom classes where
* each @c daeElement is capable of creating an instance of the class it describes.
* Further, each @c daeMetaElement contains references to other @c daeMetaElements
* for potential XML children elements. This enables this system to easily
* create @c daeElements of the appropriate type while navigating through XML
* recursive parse.
* @par
* See @c daeElement for information about the functionality that every @c daeElement implements.
*/
class daeMetaElement : public daeElement
{
protected:
daeStringRef _name;
daeElementConstructFunctionPtr _createFunc;
daeInt _minOccurs;
daeInt _maxOccurs;
daeStringRef _ref;
daeBool _isSequence;
daeBool _isChoice;
daeBool _needsResolve;
daeInt _elementSize;
daeMetaElementAttributeArray _metaElements;
daeMetaAttributeRefArray _metaAttributes;
daeMetaAttributeRef _metaValue;
daeMetaElementArrayAttribute* _metaContents;
daeMetaElement * _metaIntegration;
daeMetaAttributeRef _metaID;
daeMetaElement* _parent;
daeMetaElement** _staticPointerAddress;
daeMetaAttributePtrArray _resolvers;
daeBool _isTrackableForQueries;
daeBool _usesStringContents;
daeBool _isTransparent;
daeBool _isAbstract;
daeBool _allowsAny;
static daeMetaElementRefArray _metas;
daeStringArray _otherChildren;
daeStringArray _otherChildrenTypes;
daeTArray<daeMetaElementAttribute*> _otherChildrenContainer;
public:
/**
* Constructor
*/
daeMetaElement();
/**
* Destructor
*/
~daeMetaElement();
public: // public accessors
/**
* Gets the number of possible children of elements of this type that don't actually
* belong to this type.
* @return Returns the number of other possible children.
*/
size_t getPossibleChildrenCount() { return _otherChildren.getCount(); }
/**
* Gets the name of the possible child specified.
* @param index Index into the _otherChildren array.
* @return Returns the name of the possible child specified.
*/
daeString getPossibleChildName(daeInt index) { return _otherChildren.get(index); }
/**
* Gets the containing element for the possible child specified.
* @param index Index into the _otherChildrenContainer array.
* @return Returns the containing element for the possible child specified.
*/
daeMetaElementAttribute* getPossibleChildContainer(daeInt index) { return _otherChildrenContainer.get(index); }
/**
* Gets the type of the possible child specified.
* @param index Index into the _otherChildren array.
* @return Returns a string of the type of the possible child specified.
*/
daeString getPossibleChildType(daeInt index) { return _otherChildrenTypes.get(index); }
/**
* Determines if elements of this type can be placed in the object model.
* @return Returns true if this element type is abstract, false otherwise.
*/
daeBool getIsAbstract() { return _isAbstract; }
/**
* Determines if elements of this type should have an element tag printed when saving.
* @return Returns true if this element type should not have a tag, false otherwise.
*/
daeBool getIsTransparent() { return _isTransparent; }
/**
* Sets if elements of this type are abstract.
* @param abstract True if this type is abstract.
*/
void setIsAbstract( daeBool abstract ) { _isAbstract = abstract; }
/**
* Sets whether or not elements of this type should have an element tag printed when saving.
* @param transparent True if this type is transparent.
*/
void setIsTransparent( daeBool transparent ) { _isTransparent = transparent; }
/**
* Determines if elements of this type should be tracked
* for daeDatabase queries.
* @return Returns true if this element type should be tracked
*/
daeBool getIsTrackableForQueries() { return _isTrackableForQueries; }
/**
* Gets whether elements of this type have "string" based
* contents; this is necessary to change the parsing mode for strings.
* @return Returns true if this element type has string contents, false if not.
*/
daeBool getUsesStringContents() { return _usesStringContents; }
/**
* Sets whether elements of this type should be tracked
* for @c daeDatabase queries.
* @param trackable Indicates whether this element should be tracked.
* A value of true indicates this element type should be tracked and be available for
* database queries.
*/
void setIsTrackableForQueries(daeBool trackable) {
_isTrackableForQueries = trackable; }
/**
* Determines if elements of this type allow for any element as a child.
* @return Returns true if this element can have any child element, false otherwise.
*/
daeBool getAllowsAny() { return _allowsAny; }
/**
* Sets if elements of this type allow for any element as a child.
* @param allows True if this element allows for any child element, false otherwise.
*/
void setAllowsAny( daeBool allows ) { _allowsAny = allows; }
/**
* Gets the @c daeMetaElement for the corresponding integration object
* associated with this COLLADA element (if any).
* @return Returns the @c daeMetaElement for the integration object; this can
* be used as a factory.
*/
daeMetaElement* getMetaIntegration() { return _metaIntegration; }
/**
* Sets the @c daeMetaElement for the corresponding integration object
* associated with this COLLADA element (if any).
* @param mI @c daeMetaElement for the integration object; this is
* used as a factory to automatically create this integration object
* whenever an instance of this element is created.
*/
void setMetaIntegration(daeMetaElement* mI) { _metaIntegration = mI; }
/**
* Gets the @c daeMetaAttribute for the non-element contents of a @c daeElement.
* This corresponds to a @c daeMetaFloatAttribute, @c daeMetaFloatArrayAttribute,
* et cetera.
* @return Returns the @c daeMetaAttribute pointer for the non-element contents of
* this element type.
*/
daeMetaAttribute* getValueAttribute() { return _metaValue; }
/**
* Gets the @c daeMetaAttribute for the ID attribute of a @c daeElement.
* @return Returns the ID @c daeMetaAttribute, or NULL if the element type
* does not have an ID attribute.
*/
daeMetaAttribute* getIDAttribute() { return _metaID; }
/**
* Gets the @c daeMetaElement associated with a child element of a given
* element type.
* @param elementName Name of the element to find as a child of @c this.
* @return Returns the @c daeMetaElement describing the potential child element, or
* NULL if no such child type exists in the context of this element.
*/
daeMetaElement* findChild(daeString elementName);
/**
* Gets the container of this element type as defined by the COLLADA's XML
* schema. This parent type controls where this element
* can be directly inlined inside of another element.
* Although an element can be referred to in multiple places, it is only
* included in one; thus a single parent.
* @return Returns the parent @c daeMetaElement.
*/
daeMetaElement* getParent() { return _parent; }
/**
* Gets the name of this element type.
* @return Returns the name of this element type.
*/
daeStringRef getName() { return _name; }
/**
* Sets the name of this element type.
* @param s String name to set.
*/
void setName(daeString s) { _name = s; }
/**
* Gets the array of element attributes associated with this element type.
* @return Returns the array of potential child elements in the XML COLLADA
* hierarchy.
*/
daeMetaElementAttributeArray& getMetaElements() {
return _metaElements; }
/**
* Gets the array of attributes that represent URI fields that need
* to be "resolved" after the database is completely read in.
* @return Returns the array of @c daeMetaAttribute*'s with all of the relevant
* attributes.
*/
daeMetaAttributePtrArray& getMetaResolvers() {
return _resolvers; }
/**
* Gets the array of all known attributes on this element type.
* This includes all meta attributes except those describing child
* elements. It does include the value element.
* @return Returns the array of @c daeMetaAttributeRefs.
*/
daeMetaAttributeRefArray& getMetaAttributes() {
return _metaAttributes; }
/**
* Gets the array of element attributes associated with this element type.
* @returns Returns the array of potential child elements in the XML COLLADA
* hierarchy.
*/
daeMetaElementAttributeArray& getMetaElementArray() {
return _metaElements; }
/**
* Gets the attribute which has a name as provided by the <tt><i>s</i></tt> parameter.
* @param s String containing the desired attribute's name.
* @return Returns the corresponding @c daeMetaAttribute, or NULL if none found.
*/
daeMetaAttribute* getMetaAttribute(daeString s);
/**
* Sets the size in bytes of each instance of this element type.
* Used for factory element creation.
* @param size Number of bytes for each C++ element instance.
*/
void setElementSize(daeInt size) {_elementSize = size;}
/**
* Gets the size in bytes of each instance of this element type.
* Used for factory element creation.
* @return Returns the number of bytes for each C++ element instance.
*/
daeInt getElementSize() { return _elementSize;}
public:
/**
* Resisters with the reflective object system that the dom class described by this @c daeMetaElement
* contains a <tt><i>_contents</i></tt> array. This method is @em only for @c daeMetaElement contstuction, and
* should only be called by the system as it sets up the Reflective Object System.
* @param offset Byte offset for the contents field in the C++
* element class.
*/
void addContents(daeInt offset);
/**
* Gets the attribute associated with the contents meta information.
* @see @c addContents()
* @return Returns the @c daeMetaElementArrayAttribute.
*/
daeMetaElementArrayAttribute* getContents() { return _metaContents; }
/**
* Appends another element type to be a potential child
* element of this element type.
* @param metaElement @c daeMetaElement of the potential child element.
* @param offset Byte offset where the corresponding C++ field lives
* in each c++ class instance for this element type.
* @param name The name for this attribute if the type is complex, if none is
* specified, the name of the @c daeMetaElement will be used.
*/
void appendElement(daeMetaElement* metaElement, daeInt offset, daeString name=NULL);
/**
* Appends the potential child element
* as a list of potential child elements rather than as a singleton.
* @param metaElement @c daeMetaElement of the potential child element.
* @param offset Byte offset where the corresponding C++ field lives
* in each C++ class instance for this element type. In this case the
* C++ field will be an array of elements rather than merely a pointer to
* one.
* @param name The name for this attribute if the type is complex, if none is
* specified, the name of the metaElement will be used.
* @note This function is the same as @c appendElement(), except that it appends the potential child element
* as a list of potential child elements rather than as a singleton.
*/
void appendArrayElement(daeMetaElement* metaElement, daeInt offset, daeString name=NULL);
/**
* Appends a @c daeMetaAttribute that represents a field corresponding to an
* XML attribute to the C++ version of this element type.
* @param attr Attribute to append to this element types list
* of potential attributes.
*/
void appendAttribute(daeMetaAttribute* attr);
/**
* Appends a possible child and maps the name to the actual container.
* @param name The name of the child element.
* @param cont Pointer to the @c daeMetaElementAttribute which contains the element.
* @param type The type name of the possible child.
*/
void appendPossibleChild( daeString name, daeMetaElementAttribute* cont, daeString type = NULL );
/**
* Sets the address where the static pointer lives for this element type's
* @c daeMetaElement. For instance, <tt> daeNode::_Meta </tt> will point to its
* corresponding @c daeMetaElement.
* If the @c daeMetaElement is deleted independently, this pointer is automatically set to NULL.
* @param addr Address of the storage for the pointer to the @c daeMetaElement.
*/
void setStaticPointerAddress(daeMetaElement** addr) {
_staticPointerAddress = addr; }
/**
* Gets the address where the static pointer lives for this element type's
* @c daeMetaElement. For instance, <tt> daeNode::_Meta </tt> will point to its
* corresponding @c daeMetaElement.
* If the @c daeMetaElement is deleted independently, this pointer is automatically set to NULL.
* @return Returns the address of the storage for the pointer to the @c daeMetaElement.
*/
daeMetaElement** getStaticPointerAddress() { return _staticPointerAddress;}
/**
* Registers the function that can construct a C++ instance
* of this class. Necessary for the factory system such that C++
* can still call @c new and the @c vptr will still be initialized even when
* constructed via the factory system.
* @param func Pointer to a function that does object construction.
*/
void registerConstructor(daeElementConstructFunctionPtr func) {
_createFunc = func; }
/**
* Determines if this element contains attributes
* of type @c daeURI which need to be resolved after they are read
* or setup.
* @return Returns true if this element type requires resolving, false if not.
*/
daeBool needsResolve() { return _needsResolve; }
/**
* Validates this class to be used by the runtime c++ object model
* including factory creation.
*/
void validate();
/**
* Places a child element into the <tt><i>parent</i></tt> element where the
* calling object is the @c daeMetaElement for the parent element.
* @param parent Element to act as the container.
* @param child Child element to place in the parent.
* @return Returns true if the operation was successful, false otherwise.
*/
daeBool place(daeElementRef parent, daeElementRef child);
/**
* Invokes the factory element creation routine set by @c registerConstructor()
* to return a C++ COLLADA Object Model instance of this element type.
* @return Returns a created @c daeElement of appropriate type via the
* object creation function and the <tt> daeElement::setup() </tt> function.
*/
daeElementRef create();
/**
* Looks through the list of potential child elements
* for this element type finding the corresponding element type; if a corresponding element type
* is found, use that type as a factory and return an instance of that
* child type. Typically @c place() is called after @c create(childelementname)
* @param childElementTypeName Type name to create.
* @return Returns the created element if the type was found as a potential child element.
*/
daeElementRef create(daeString childElementTypeName);
/**
* Gets the meta information for a given subelement
* @param s Name of the child element type to look up.
* @return Returns the meta information for a given subelement.
*/
daeMetaElement* getChildMetaElement(daeString s);
/**
* Gets the meta information for a given subelement
* @param s Name of the child element type to look up.
* @return Returns the meta information for a given subelement.
*/
daeMetaElementAttribute* getChildMetaElementAttribute(daeString s);
public:
/**
* Unused
*/
static daeMetaElement* _Schema;
public:
/**
* Empty no-op function.
*/
static void initializeSchemaMeta();
/**
* Releases all of the meta information contained in @c daeMetaElements.
*/
static void releaseMetas();
};
#endif //__DAE_META_ELEMENT_H__

View File

@@ -0,0 +1,156 @@
/*
* 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.
*/
#ifndef __DAE_SMARTREF_H__
#define __DAE_SMARTREF_H__
#include <dae/daeElement.h>
#include <assert.h>
template<class T> class daeElementWrapper {};
/**
* The @c daeSmartRef template class automates reference counting for
* objects derived from @c daeElement.
*/
template<class T> class daeSmartRef
{
public:
/**
* Constructor
*/
inline daeSmartRef() : _ptr((T*) NULL){}
/**
* Destructor
*/
inline ~daeSmartRef() {
daeElement::release((daeElement*)_ptr); }
/**
* Constructor that will convert from one template to the other.
* unimplemented.
* @param
*/
template<class U>
inline daeSmartRef(const daeElementWrapper<U>&) : _ptr(U::instance()) {}
/**
* Copy Constructor that will convert from one template to the other.
* @param smartRef a daeSmartRef to the object to copy from.
*/
template<class U>
inline daeSmartRef(const daeSmartRef<U>& smartRef) : _ptr(smartRef.cast()){
daeElement::ref((const daeElement*)_ptr); }
/**
* Function that returns a pointer to object being reference counted.
* @return the object being reference counted.
*/
inline T* cast() const { return _ptr; }
/**
* Copy Constructor.
* @param smartRef a daeSmartRef of the same template type to copy from
*/
inline daeSmartRef(const daeSmartRef<T>& smartRef) : _ptr(smartRef._ptr){
daeElement::ref((const daeElement*)_ptr); }
/**
* Constructor
* @param ptr a pointer to an object of the same template type.
*/
inline daeSmartRef(T* ptr) : _ptr(ptr) {
daeElement::ref((const daeElement*)_ptr); }
/**
* Overloaded assignment operator which will convert between template types.
* @return Returns a reference to this object.
* @note Unimplemented
*/
template<class U>
inline const daeSmartRef<T>& operator=(const daeElementWrapper<U>&){
daeElement::release((const daeElement*)_ptr);
_ptr = U::instance();
return *this; }
/**
* Overloaded assignment operator which will convert between template types.
* @param smartRef a daeSmartRef to the object to copy from.
* @return Returns a reference to this object.
*/
template<class U>
inline const daeSmartRef<T>& operator=(const daeSmartRef<U>& smartRef) {
T* ptr = smartRef.cast();
daeElement::ref((const daeElement*)ptr);
daeElement::release((const daeElement*)_ptr);
_ptr = ptr;
return *this; }
/**
* Overloaded assignment operator.
* @param other a daeSmartRef to the object to copy from. Must be of the same template type.
* @return Returns a reference to this object.
*/
inline const daeSmartRef<T>& operator=(const daeSmartRef<T>& other) {
T* ptr = other._ptr;
daeElement::ref((const daeElement*)ptr);
daeElement::release((const daeElement *)_ptr);
_ptr = ptr;
return *this; }
/**
* Overloaded assignment operator.
* @param ptr a pointer to the object to copy from. Must be of the same template type.
* @return Returns a reference to this object.
*/
inline const daeSmartRef<T>& operator=(T* ptr) {
daeElement::ref((const daeElement*)ptr);
daeElement::release((const daeElement*)_ptr);
_ptr = ptr;
return *this; }
/**
* Overloaded member selection operator.
* @return a pointer of the template class to the object.
*/
inline T* operator->() const {
assert (_ptr != (T*)NULL); return _ptr; }
/**
* Overloaded cast operator.
* @return a pointer of the template class to the object.
*/
inline operator T*() const {
return _ptr; }
/**
* Static cast function.
* @param smartRef a smartRef to cast from
* @return a pointer to an object of this template class
*/
template<class U>
inline static T* staticCast(const daeSmartRef<U>& smartRef) {
return static_cast<T*>(smartRef.cast()); }
private:
/* The pointer to the element which is being reference counted */
T* _ptr;
};
#endif // __DAE_SMARTREF_H__

View File

@@ -0,0 +1,101 @@
/*
* 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.
*/
#ifndef __DAE_STRING_REF_H__
#define __DAE_STRING_REF_H__
#include <dae/daeMemorySystem.h>
#include <dae/daeStringTable.h>
/**
*Defines the @c daeStringRef class.
*/
class daeStringRef
{
public:
/**
* Macro that defines new and delete overrides for this class
*/
DAE_ALLOC;
private:
daeString _string;
static daeStringTable _stringTable;
public:
/**
* Destructor
*/
inline ~daeStringRef() { _string = NULL; }
/**
* Constructor
*/
inline daeStringRef() { _string = NULL; }
/**
* Constructor that copies from another @c daeStringRef.
* @param other Reference to copy from.
*/
inline daeStringRef(const daeStringRef& other) {
_string = other._string; }
/**
* Constructor that creates from a <tt>const char *.</tt>
* @param string External string to create from.
*/
daeStringRef(daeString string);
/**
* Assignment operator.
* @param other The daeStringRef to copy.
* @return A reference to this object.
*/
inline const daeStringRef& operator= (const daeStringRef& other) {
_string = other._string;
return *this;
}
/**
* Sets a string from an external <tt>const char *.</tt>
* @param string The daeString to copy.
* @return A reference to this object.
*/
const daeStringRef& set(daeString string);
/**
* Assignment operator from an external <tt>const char *.</tt>
* @param string The daeString to copy.
* @return A reference to this object.
*/
const daeStringRef& operator= (daeString string);
/**
* Cast operator that returns a <tt>const char *.</tt>
*/
inline operator daeString() const { return _string; }
/**
* Comparison operator, the comparison is done via pointers as both
* strings will have same pointer if they are the same address
* @param other The daeStringRef to compare
* @return True if strings are equal. False otherwise.
*/
inline bool operator==(const daeStringRef& other) const{
//return (other._string == _string); }
return (!strcmp(other._string, _string)); }
};
typedef daeTArray<daeStringRef> daeStringRefArray;
typedef daeTArray<daeStringRefArray> daeStringRefArrayArray;
#endif //__DAE_STRING_REF_H__

View File

@@ -0,0 +1,62 @@
/*
* 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.
*/
#ifndef __DAE_STRING_TABLE_H__
#define __DAE_STRING_TABLE_H__
#include <dae/daeTypes.h>
#include <dae/daeMemorySystem.h>
/**
* The @c daeStringTable is a simple string table class to hold a float list of strings
* without a lot of allocations.
*/
class daeStringTable
{
public: // allocate/construct/destruct/deallocate
/**
* Macro that defines new and delete overrides for this class
*/
DAE_ALLOC;
/**
* Constructor which specifies fixed buffer size.
* @param stringBufferSize The size of the buffer to create for string allocation.
*/
daeStringTable(int stringBufferSize = 1024*1024);
/**
* Destructor.
*/
~daeStringTable() { clear(); }
public: // INTERFACE
/**
* Allocates a string from the table.
* @param string <tt> const char * </tt> to copy into the table.
* @return Returns an allocated string.
*/
daeString allocString(daeString string);
/**
* Clears the storage.
*/
void clear();
private: // MEMBERS
size_t _stringBufferSize;
size_t _stringBufferIndex;
daeStringArray _stringBuffersList;
daeString allocateBuffer();
};
#endif //__DAE_STRING_TABLE_H__

View 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.
*/
#ifndef __DAE_TYPES_H__
#define __DAE_TYPES_H__
#ifdef WIN32
#include <dae/daeWin32Platform.h>
#else
#include <dae/daeGenericPlatform.h>
#endif
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <wchar.h>
#include <string.h>
#include <dae/daeError.h>
#define daeOffsetOf(class, member) \
((size_t)&(((class*)0x0100)->member) - (size_t)0x0100)
typedef PLATFORM_INT8 daeChar;
typedef PLATFORM_INT16 daeShort;
typedef PLATFORM_INT32 daeInt;
typedef PLATFORM_INT64 daeLong;
typedef PLATFORM_UINT8 daeUChar;
typedef PLATFORM_UINT16 daeUShort;
typedef PLATFORM_UINT32 daeUInt;
typedef PLATFORM_UINT64 daeULong;
typedef PLATFORM_FLOAT32 daeFloat;
typedef PLATFORM_FLOAT64 daeDouble;
// base types
typedef const char* daeString;
typedef bool daeBool;
typedef const void* daeConstRawRef;
typedef void* daeRawRef;
typedef daeInt daeEnum;
typedef daeChar* daeMemoryRef;
typedef daeChar daeFixedName[512];
#include <dae/daeArray.h>
#include <dae/daeArrayTypes.h>
#endif //__DAE_TYPES_H__

View File

@@ -0,0 +1,487 @@
/*
* 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.
*/
#ifndef __DAE_URI_H__
#define __DAE_URI_H__
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
/**
* The @c daeURI is a simple class designed to aid in the parsing and resolution
* of URI references inside COLLADA elements.
* A @c daeURI is created for every @c anyURL and @c IDREF in the COLLADA schema.
* For example, the <instance> element has the url= attribute of type @c anyURL, and the
* <controller> element has the target= attribute of type @c IDREF.
* The @c daeURI class contains a URI string; the @c setURI() method breaks the string into
* its components including protocol, authority, path (directory), and ID.
* It also has the capability to attempt to resolve this reference
* into a @c daeElement, through the method @c resolveElement().
* If a @c daeURI is stored within a @c daeElement, it fills
* its container field to point to the containing element.
*
* The main API on the @c daeURI, @c resolveElement(), uses a @c daeURIResolver
* to search for the @c daeElement inside a @c daeDatabase.
*
* URIs are resolved hierarchically, where each URI is resolved based on
* the following criteria via itself and its element's base URI, which represents the
* URI of the document that contains the element, retrieved by
* <tt>daeElement::getBaseURI().</tt>
* If no base URI is provided, then the application URI
* is used as a base.
*
* The URI resolution order for the COLLADA DOM is as follows:
* - Absolute URI is specified (see definition below):
* The URI ignores its parent/base URI when validating.
* - Relative URI is specified:
* The URI uses the base URI to provide the protocol, authority, and base path.
* This URI's path is appended to the path given the the base URI.
* This URI's file and ID are used.
* - Each level of URI is resolved in this way against the base URI of the
* containing file until the top level is reached. Then the application URI
* is used as the default.
*
* <b>Definition of Absolute URI:</b>
* For the purposes of the COLLADA DOM, a URI is considered absolute
* if it starts by specifying a protocol.
* For example,
* - file://c:/data/foo.dae#myScene is an absolute URI.
* - foo.dae#myScene is relative.
* - foo.dae is a top-level file reference and is relative.
* If the URI does not include a pound sign (#), the <tt><i>id</i></tt> is empty.
*/
class daeURI
{
private:
void internalSetURI(daeString uri);
public:
/**
* An enum describing the status of the URI resolution process.
*/
enum ResolveState{
/** No URI specified */
uri_empty,
/** URI specified but unresolved */
uri_loaded,
/** Resolution pending */
uri_pending,
/** Resolution successful */
uri_success,
/** Failure due to unsupported URI scheme */
uri_failed_unsupported_protocol,
/** Failure because the file was not found */
uri_failed_file_not_found,
/** Failure because the ID was not found */
uri_failed_id_not_found,
/** Failure due to an invalid ID */
uri_failed_invalid_id,
/** A flag specifying that the URI should be resolved locally to its own document */
uri_resolve_local,
/** A flag specifying that the URI should be resolved using this relative URI */
uri_resolve_relative,
/** A flag specifying that the URI should be resolved using this absolute URI */
uri_resolve_absolute,
/** Failure due to an invalid reference */
uri_failed_invalid_reference,
/** Failure due to an external error */
uri_failed_externalization,
/** Failure due to missing document */
uri_failed_missing_container,
/** Failure because autmoatic loading of a document is turned off */
uri_failed_external_document
};
private:
/** Resolved version of the URI */
daeString uriString;
/** Original URI before resolution */
daeString originalURIString;
// Parceled out of storage as const char*'s
/** Protocol substring parsed from the URI */
daeString protocol;
/** authority substring parsed from the URI */
daeString authority;
/** Path substring parsed from the URI */
daeString filepath;
/** File name substring parsed from the URI */
daeString file;
/** Id substring parsed from the URI */
daeString id;
/** Extension parsed from the filename in the URI */
daeString extension;
/** Reference to the element that the URI resolves to in memory */
daeElementRef element;
/** Pointer to the element that owns this URI */
daeElement* container;
/** Current resolver state of the URI */
ResolveState state;
/** Flag for if this URI references an external element. */
daeBool external;
public:
/**
* Constructs a daeURI object that contains no URI reference.
*/
daeURI();
/**
* Destructor
*/
~daeURI();
/**
* Constructs a daeURI object that points to the application's current working
* directory.
* @param dummy An integer value that has no meaning.
* @note This is used only to initialize the Application URI. It's a simple
* workaround to insure that the ApplicationURI is initialized only once and before the user can call
* daeURI::setBaseURI() (so when we initialize ApplicationURI there is no chance of wiping out a user value).
*/
daeURI(int dummy);
/**
* Constructs a daeURI object from a URI passed in as a string.
* @param URIString Passed to setURI() automatically.
* @param nofrag If true, the fragment part of the URI is stripped off before construction.
*/
daeURI(daeString URIString, daeBool nofrag = false);
/**
* Constructs a daeURI object using a <tt><i>baseURI</i></tt> and a <tt><i>uriString.</i></tt>
* Calls setURI(URIString), and @c validate(baseURI).
* @param baseURI Base URI to resolve against.
* @param URIString String designating this URI.
*/
daeURI(daeURI& baseURI, daeString URIString);
/**
* Constructs a daeURI object based on a simple copy from an existing @c daeURI.
* @param constructFromURI URI to copy into this one.
*/
daeURI(daeURI& constructFromURI);
/**
* Gets the ID string parsed from the URI.
* @return Returns a pointer to the string.
*/
inline daeString getID(){return(id);};
/**
* Gets the file string parsed from the URI.
* @return Returns a pointer to the string.
*/
inline daeString getFile(){return(file);};
/**
* Gets the path string to the file, without the path name, parsed from the URI.
* @return Returns a pointer to the string.
*/
inline daeString getFilepath(){return(filepath);};
/**
* Gets the protocol string parsed from the URI.
* @return Returns a pointer to the string.
*/
inline daeString getProtocol(){return(protocol);};
/**
* Gets the authority string parsed from the URI.
* @return Returns a pointer to the string.
*/
inline daeString getAuthority(){return(authority);};
/**
* Gets the extension string parsed from the URI.
* @return Returns a pointer to the string.
*/
inline daeString getExtension(){return(extension);};
/**
* Gets the element that this URI resolves to in memory.
* @return Returns a ref to the element.
*/
inline daeElementRef getElement(){return(element);};
/**
* Gets the element that this URI resolves to in memory.
* @return Returns a ref to the element.
*/
inline daeElementConstRef getElement() const {return(element);};
/**
* Sets the element that this URI resolves to in memory.
* @param newref A ref to the element.
*/
inline void setElement(daeElementRef newref){element=newref;};
/**
* Gets the resolve state of the URI.
* @return Returns the current state.
* @note This will be removed when daeURI starts managing its state internally.
*/
inline ResolveState getState() const {return(state);};
/**
* Sets the resolve state of the URI.
* @param newState The new state.
* @note This will be removed when daeURI starts managing its state internally.
*/
inline void setState(ResolveState newState){state=newState;};
/**
* Gets a pointer to the @c daeElement that contains this URI.
* @return Returns the pointer to the containing daeElmement.
*/
inline daeElement* getContainer() const {return(container);};
/**
* Sets the pointer to the @c daeElement that contains this URI.
* @param element Pointer to the containing @c daeElmement.
*/
inline void setContainer(daeElement* element){container=element;};
/**
* Copies parameter <tt><i>uri</i></tt> into data member <tt><i>uriString,</i></tt> and then decomposes each of
* <tt><i>protocol, authority, filepath, file,</i></tt> and <tt><i>id.</i></tt>
* After @c setURI(), the <tt><i>state</i></tt> is set to @c uri_loaded.
* @param uri String to use to configure this URI.
*/
void setURI(daeString uri);
/**
* Gets the URI stored in the daeURI.
* @return Returns the full URI String, from <tt><i>uriString.</i></tt>
*/
daeString getURI() const;
/**
* Gets the original URI String as originally set, not flattened against the base URI.
* @return Returns the original URI String as originally set, not flattened against the base URI.
*/
daeString getOriginalURI() const;
/**
* Gets if this URI resolves to an element that is not contained in the same document as the URI.
* @return Returns true if the URI references an external element. False otherwise.
*/
daeBool isExternalReference() const { return external; }
/**
* Uses the @c daeURIResolver static API to try to resolve this URI
* into a @c daeElement reference, placing the resolved element into <tt><i>element.</i></tt>
* This function can effectively force a load of a file, perform
* a database query, and so on, based on the @c daeURIResolver plugins implemented.
*/
void resolveElement(daeString typeNameHint = NULL);
/**
* Configures the <tt><i>uriString</i></tt> for this @c daeURI based on the element set in <tt><i>element.</i></tt>
* Uses the element's base URI and ID information to configure
* the URI string.
*/
void resolveURI();
/**
* Flattens this URI with base URI to obtain a useable
* complete URI for resolution.
* @param baseURI Base URI to flatten against if this URI is
* relative.
* @note After @c validate(), state is @c uri_pending as it is awaiting a call to
* @c resolveElement().
*/
void validate(daeURI* baseURI = NULL);
/**
* Copies the URI specified in <tt><i>from</i></tt> into @c this.
* Performs a simple copy without validating the URI.
* @param from URI to copy from.
*/
void copyFrom(daeURI& from);
/**
* Outputs all components of this URI to stderr.
* Useful for debugging URIs, this outputs each part of the URI separately.
*/
void print();
/**
* Makes the "originalURI" in this URI relative to some other uri
* @param uri the URI to make "this" relative to.
* @note this is experimental and not fully tested, please don't use in critical code yet.
*/
int daeURI::makeRelativeTo(daeURI* uri);
/**
* Comparison operator.
* @return Returns true if URI's are equal.
*/
inline bool operator==(const daeURI& other) const{
return (!strcmp(other.getURI(), getURI())); }
private:
/**
* Resets this URI; frees all string references
* and returns <tt><i>state</i></tt> to @c empty.
*/
void reset();
/**
* Provides a shared initialization for all constructors
*/
void initialize();
public:
/**
* Gets the path part of the URI, including everything from immediately after the authority up to and
* including the file name, but not the query or fragment.
* @param dest The user allocated buffer that will receive the path.
* @param size The size of the buffer.
* @return Returns true for success, false if the path exceeded the size of the user provided buffer.
*/
daeBool getPath(daeChar *dest, daeInt size);
public:
/**
* Sets the application's default base URI. This is effectively the default protocol,
* authority, and path in the case of top-level relative URIs.
* @param uri Base URI to use as the default application URI.
*/
static void setBaseURI(daeURI& uri);
/**
* Gets the application's default base URI.
* @return Returns the base URI used in the case of top-level relative URIs.
*/
static daeURI* getBaseURI();
/**
* Performs RFC2396 path normalization.
* @param path Path to be normalized.
*/
static void normalizeURIPath(char *path);
};
class daeURIResolver;
typedef daeTArray<daeURIResolver*> daeURIResolverPtrArray;
/**
* The @c daeURIResolver class is the plugin point for URI resolution.
* This class is an abstract base class that defines an interface for
* resolving URIs.
* All instances of @c daeURIResolvers are tracked centrally.
* Every URI is passed through this list of @c daeURIResolvers for resolution.
* Before a @c daeURIResolver receives a URI, the API checks whether it supports
* the protocol.
* The list is ordered on a first come, first serve basis, and resolution
* terminates after any resolver instance resolves the URI.
*/
class daeURIResolver
{
public:
/**
* This base constructor appends @c this to KnownResolvers list.
*/
daeURIResolver();
/**
* Destructor
*/
virtual ~daeURIResolver();
protected:
static daeURIResolverPtrArray _KnownResolvers;
static daeBool _loadExternalDocuments;
public:
/**
* Iterates through known resolvers
* calling @c isProtocolSupported() and, if it is supported, calling
* @c resolveElement().
* @param uri @c daeURI to resolve.
*/
static void attemptResolveElement(daeURI &uri, daeString typeNameHint = NULL);
/**
* Iterates through known resolvers
* calling @c isProtocolSupported() and, if it is supported, calling
* @c resolveURI().
* @param uri @c daeURI to resolve.
*/
static void attemptResolveURI(daeURI &uri);
/**
* Sets a flag that tells the URI resolver whether or not to load a separate document if a URI
* being resolved points to one.
* @param load Set to true if you want the URI Resolver to automatically load other documents to
* resolve URIs.
*/
static void setAutoLoadExternalDocuments( daeBool load ) { _loadExternalDocuments = load; }
/**
* Gets a flag that tells if the URI resolver is set to load an external document if a URI
* being resolved points to one.
* @return Returns true if the resolver will automatically load documents to resolve a URI.
* False otherwise.
*/
static daeBool getAutoLoadExternalDocuments() { return _loadExternalDocuments; }
public: // Abstract Interface
/**
* Provides an abstract interface for converting a @c daeURI into a @c daeElement
* @param uri @c daeURI to resolve.
* @return Returns true if the @c daeURIResolver successfully resolved the URI,
* returns false otherwise.
*/
virtual daeBool resolveElement(daeURI& uri, daeString typeNameHint = NULL) = 0;
/**
* Provides an abstract interface for converting a @c daeElement into a @c daeURI
* @param uri @c daeURI to resolve.
* @return Returns true if the @c daeURIResolver successfully resolved the element
* into a URI, returns false otherwise.
*/
virtual daeBool resolveURI(daeURI& uri) = 0;
/**
* Gets the name of this resolver.
* @return Returns the resolver name as a string.
*/
virtual daeString getName() = 0;
/**
* Determines whether this resolver supports a particular protocol
* for resolution.
* @param protocol Determine whether the resolver supports this protocol.
* @return Returns true if this @c daeURIResolver understands how to resolve using this protocol, returns
* false otherwise
*/
virtual daeBool isProtocolSupported(daeString protocol) = 0;
/**
* Determines whether this resolver supports the given extension.
* This keeps parsers from trying to process incompatible
* file formats.
* @param extension Extension string found after the '.' in the file name.
* @return Returns true if the given extension is supported, returns false otherwise.
*/
virtual daeBool isExtensionSupported(daeString extension) = 0;
};
#endif //__DAE_URI_H__

View File

@@ -0,0 +1,32 @@
/*
* 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.
*/
#ifndef __DAE_WIN32_PLATFORM_H__
#define __DAE_WIN32_PLATFORM_H__
#define PLATFORM_INT8 char
#define PLATFORM_INT16 short
#define PLATFORM_INT32 int
#define PLATFORM_INT64 long
#define PLATFORM_UINT8 unsigned char
#define PLATFORM_UINT16 unsigned short
#define PLATFORM_UINT32 unsigned int
#define PLATFORM_UINT64 unsigned long
#define PLATFORM_FLOAT32 float
#define PLATFORM_FLOAT64 double
#if _MSC_VER <= 1200
typedef int intptr_t;
#endif
#endif

View File

@@ -0,0 +1,135 @@
/*
* 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.
*/
#ifndef __domAny_h__
#define __domAny_h__
#include <dae/daeElement.h>
#include <dae/daeMetaElement.h>
#include <dae/daeArray.h>
#include <dae/daeURI.h>
#include <dae/daeIDRef.h>
#define MAX_ATTRIBUTES 32
/**
* The domAny class allows for weakly typed xml elements. This class is used anywhere in the
* COLLADA schema where an xs:any element appears. The content and type information for a domAny
* object is generated at runtime.
*/
class domAny : public daeElement
{
protected: // Attribute
/**
* The array of daeStrings to hold attribute data for this element.
*/
daeString attrs[MAX_ATTRIBUTES];
/**
* The domString value of the text data of this element.
*/
daeString _value;
/**
* Used to preserve order in elements that do not specify strict sequencing of sub-elements.
*/
daeElementRefArray _contents;
public:
/**
* Gets the _contents array.
* @return Returns a reference to the _contents element array.
*/
daeElementRefArray &getContents() { return _contents; }
/**
* Gets the _contents array.
* @return Returns a constant reference to the _contents element array.
*/
const daeElementRefArray &getContents() const { return _contents; }
/**
* Gets the number of attributes this element has.
* @return Returns the number of attributes on this element.
*/
daeUInt getAttributeCount() const { return (daeUInt)_meta->getMetaAttributes().getCount(); }
/**
* Gets an attribute's name.
* @param index The index into the attribute list.
* @return Returns the attribute's name.
*/
daeString getAttributeName( daeUInt index ) const { return _meta->getMetaAttributes()[index]->getName(); }
/**
* Gets an attribute's value.
* @param index The index into the attribute list.
* @return Returns the attribute's value as a string.
*/
daeString getAttributeValue( daeUInt index ) const { return attrs[ index ]; }
/**
* Gets the value of this element.
* @return Returns a daeString of the value.
*/
daeString getValue() const { return _value; }
/**
* Sets the _value of this element.
* @param val The new value for this element.
*/
void setValue( daeString val ) { _value = val; }
protected:
/**
* Constructor
*/
domAny() : _value() {}
/**
* Destructor
*/
virtual ~domAny() {}
/**
* Copy Constructor
*/
domAny( const domAny &cpy ) : daeElement() { (void)cpy; }
/**
* Overloaded assignment operator
*/
virtual domAny &operator=( const domAny &cpy ) { (void)cpy; return *this; }
public: //METHODS
/**
* Override of the Base class method. Creates and registers an attribute field with its meta
* and assigns its value as the <tt><i> attrValue </i></tt> String.
* @param attrName Attribute to set.
* @param attrValue String-based value to apply to the attribute.
* @return Returns true if the attribute was created and the value was set, false otherwise.
*/
virtual daeBool setAttribute(daeString attrName, daeString attrValue);
public: // STATIC METHODS
/**
* Creates an instance of this class and returns a daeElementRef referencing it.
* @param bytes The size allocated for this instance.
* @return a daeElementRef referencing an instance of this object.
*/
static daeElementRef create(daeInt bytes);
/**
* Creates a daeMetaElement object that describes this element in the meta object reflection framework.
* @return A daeMetaElement describing this COLLADA element.
* @remarks Unlike other dom* elements, domAny will always create a new daeMetaElement when this
* function is called.
*/
static daeMetaElement* registerElement();
};
typedef daeSmartRef<domAny> domAnyRef;
typedef daeTArray<domAnyRef> domAny_Array;
#endif