Engine directory for ticket #1

This commit is contained in:
DavidWyand-GG 2012-09-19 11:15:01 -04:00
parent 352279af7a
commit 7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions

View file

@ -0,0 +1,706 @@
/*
* 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 <new>
#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
*/
DLLSPEC daeArray();
/**
* Destructor
*/
virtual DLLSPEC ~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 DLLSPEC void clear() = 0;
/**
* Sets the size of an element in the array. This clears and reinitializes the array.
* @param elementSize Size of an element in the array.
*/
DLLSPEC void setElementSize(size_t elementSize);
/**
* Gets the size of an element in this array.
* @return Returns the size of an element in this array.
*/
size_t getElementSize() const {return _elementSize;}
/**
* Grows the array to the specified size and sets the @c daeArray to that size.
* @param cnt Size to grow the array to.
*/
virtual void setCount(size_t cnt) = 0;
/**
* Gets the number of items stored in this @c daeArray.
* @return Returns the number of items stored in this @c daeArray.
*/
size_t getCount() const {return _count;}
/**
* Increases the capacity of the @c daeArray.
* @param minCapacity The minimum array capacity (the actual resulting capacity may be higher).
*/
virtual void grow(size_t minCapacity) = 0;
/**
* Gets the current capacity of the array, the biggest it can get without incurring a realloc.
* @return Returns the capacity of the array.
*/
size_t getCapacity() const {return _capacity;}
/**
* Gets a pointer to the raw memory of a particular element.
* @return Returns a pointer to the memory for the raw data.
*/
daeMemoryRef getRaw(size_t index) const {return _data + index*_elementSize;}
/**
* 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) = 0;
// Provided for backward compatibility only. Don't use these.
void setRawCount(size_t cnt) { setCount(cnt); } // Use setCount instead
daeMemoryRef getRawData() const {return _data;} // Use getRaw instead
};
/**
* COLLADA C++ templated version of @c daeArray for storing items of various types.
*/
template <class T>
class daeTArray : public daeArray
{
protected:
T* prototype;
public:
/**
* Constructor.
*/
daeTArray() {
_elementSize = sizeof( T );
prototype = NULL;
}
/**
* Constructor.
*/
explicit daeTArray(T* prototype) : prototype(prototype) {
_elementSize = sizeof( T );
}
/**
* Copy Constructor
*/
daeTArray( const daeTArray<T> &cpy ) : daeArray() {
prototype = NULL;
*this = cpy;
}
/**
* Constructor that takes one element and turns into an array
*/
explicit daeTArray( const T &el ) {
_elementSize = sizeof(T);
prototype = NULL;
append( el );
}
/**
* Destructor.
*/
virtual ~daeTArray() {
clear();
delete prototype;
}
/**
* Frees the memory in this array and resets it to it's initial state.
*/
virtual void clear()
{
for(size_t i=0;i<_count;i++)
((T*)_data + i)->~T();
free(_data);
_count = 0;
_capacity = 0;
_data = NULL;
}
/**
* Increases the capacity of the @c daeArray.
* @param minCapacity The minimum array capacity (the actual resulting capacity may be higher).
*/
void grow(size_t minCapacity) {
if (minCapacity <= _capacity)
return;
size_t newCapacity = _capacity == 0 ? 1 : _capacity;
while(newCapacity < minCapacity)
newCapacity *= 2;
T* newData = (T*)malloc(newCapacity*_elementSize);
for (size_t i = 0; i < _count; i++) {
new (&newData[i]) T(get(i));
((T*)_data + i)->~T();
}
if (_data != NULL)
free(_data);
_data = (daeMemoryRef)newData;
_capacity = newCapacity;
}
/**
* 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)
return(DAE_ERR_INVALID_CALL);
for (size_t i = index; i < _count-1; i++)
*((T*)_data+i) = *((T*)_data+i+1);
((T*)_data+(_count-1))->~T();
_count--;
return DAE_OK;
}
/**
* Resets the number of elements in the array. If the array increases in size, the new
* elements will be initialized to the specified value.
* @param nElements The new size of the array.
* @param value The value new elements will be initialized to.
* @note Shrinking the array does NOT free up memory.
*/
void setCount(size_t nElements, const T& value)
{
grow(nElements);
// Destruct the elements that are being chopped off
for (size_t i = nElements; i < _count; i++)
((T*)_data+i)->~T();
// Use value to initialize the new elements
for (size_t i = _count; i < nElements; i++)
new ((void*)((T*)_data+i)) T(value);
_count = nElements;
}
/**
* Resets the number of elements in the array. If the array increases in size, the new
* elements will be initialized with a default constructor.
* @param nElements The new size of the array.
* @note Shrinking the array does NOT free up memory.
*/
virtual void setCount(size_t nElements) {
if (prototype)
setCount(nElements, *prototype);
else
setCount(nElements, T());
}
/**
* 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.
*/
void set(size_t index, const T& value) {
if (index >= _count)
setCount(index+1);
((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.
*/
T& get(size_t index) {
assert(index < _count);
return ((T*)_data)[index]; }
/**
* 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.
*/
const 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.
*/
size_t append(const T& value) {
set(_count, value);
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.
*/
size_t appendUnique(const T& value) {
size_t ret;
if (find(value,ret) != DAE_OK)
return append(value);
else
return ret;
}
/**
* Adds a new item to the front of the @c daeArray.
* @param value Item to be added.
*/
void prepend(const T& value) {
insertAt(0, value);
}
/**
* 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.
*/
daeInt remove(const T& value, size_t *idx = NULL )
{
size_t index;
if(find(value,index) == DAE_OK)
{
if ( idx != NULL ) {
*idx = index;
}
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.
*/
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;
}
/**
* Just like the previous function, but has a more reasonable interface.
* @param value The value to find.
* @return Returns a pointer to the value if found, null otherwise.
*/
T* find(const T& value) const {
size_t i;
if (find(value, i) == DAE_OK)
return get(i);
return NULL;
}
/**
* 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.
*/
T& operator[](size_t index) {
assert(index < _count);
return ((T*)_data)[index]; }
/**
* 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.
*/
const T& operator[](size_t index) const {
assert(index < _count);
return ((T*)_data)[index]; }
/**
* Inserts the specified number of elements at a specific location in the array.
* @param index Index into the array where the elements will be inserted
* @param n The number of elements to insert
* @param val The value to insert
*/
void insert(size_t index, size_t n, const T& val = T()) {
if (index >= _count) {
// Append to the end of the array
size_t oldCount = _count;
setCount(index + n);
for (size_t i = oldCount; i < _count; i++)
get(i) = val;
}
else {
setCount(_count + n);
for (size_t i = _count-1; i >= index+n; i--)
get(i) = get(i-n);
for (size_t i = index; i < index+n; i++)
get(i) = val;
}
}
/**
* 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
* @param value The object to append
*/
void insertAt(size_t index, const T& value) {
insert(index, 1);
get(index) = value;
}
/**
* Overloaded assignment operator.
* @param other A reference to the array to copy
* @return A reference to this object.
*/
daeTArray<T> &operator=( const daeTArray<T> &other ) {
if (this != &other) {
clear();
_elementSize = other._elementSize;
_type = other._type;
grow(other._count);
for(size_t i=0;i<other._count;i++)
append(other[i]);
}
return *this;
}
/**
* Overloaded equality operator
* @param other A reference to the other array.
* @return true if the arrays are equal, false otherwise.
*/
bool operator==(const daeTArray<T>& other) {
if (getCount() != other.getCount())
return false;
for (size_t i = 0; i < getCount(); i++)
if (get(i) != other.get(i))
return false;
return true;
}
//some helpers
/**
* Sets the array to the contain the two values specified.
* @param one The first value.
* @param two The second value.
*/
void set2( const T &one, const T &two )
{
setCount( 2 );
set( 0, one );
set( 1, two );
}
/**
* Sets the array to the contain the three values specified.
* @param one The first value.
* @param two The second value.
* @param three The third value.
*/
void set3( const T &one, const T &two, const T &three )
{
setCount( 3 );
set( 0, one );
set( 1, two );
set( 2, three );
}
/**
* Sets the array to the contain the four values specified.
* @param one The first value.
* @param two The second value.
* @param three The third value.
* @param four The fourth value.
*/
void set4( const T &one, const T &two, const T &three, const T &four )
{
setCount( 4 );
set( 0, one );
set( 1, two );
set( 2, three );
set( 3, four );
}
/**
* Sets the values in the array at the specified location to the contain the two
* values specified. This function will grow the array if needed.
* @param index The position in the array to start setting.
* @param one The first value.
* @param two The second value.
*/
void set2at( size_t index, const T &one, const T &two )
{
set( index, one );
set( index+1, two );
}
/**
* Sets the values in the array at the specified location to the contain the three
* values specified. This function will grow the array if needed.
* @param index The position in the array to start setting.
* @param one The first value.
* @param two The second value.
* @param three The third value.
*/
void set3at( size_t index, const T &one, const T &two, const T &three )
{
set( index, one );
set( index+1, two );
set( index+2, three );
}
/**
* Sets the values in the array at the specified location to the contain the four
* values specified. This function will grow the array if needed.
* @param index The position in the array to start setting.
* @param one The first value.
* @param two The second value.
* @param three The third value.
* @param four The fourth value.
*/
void set4at( size_t index, const T &one, const T &two, const T &three, const T &four )
{
set( index, one );
set( index+1, two );
set( index+2, three );
set( index+3, four );
}
/**
* Appends two values to the array.
* @param one The first value.
* @param two The second value.
*/
void append2( const T &one, const T &two )
{
append( one );
append( two );
}
/**
* Appends three values to the array.
* @param one The first value.
* @param two The second value.
* @param three The third value.
*/
void append3( const T &one, const T &two, const T &three )
{
append( one );
append( two );
append( three );
}
/**
* Appends four values to the array.
* @param one The first value.
* @param two The second value.
* @param three The third value.
* @param four The fourth value.
*/
void append4( const T &one, const T &two, const T &three, const T &four )
{
append( one );
append( two );
append( three );
append( four );
}
/**
* Inserts two values into the array at the specified location.
* @param index The position in the array to start inserting.
* @param one The first value.
* @param two The second value.
*/
void insert2at( size_t index, const T &one, const T &two )
{
insert(index, 2);
set(index, one);
set(index+1, two);
}
/**
* Inserts three values into the array at the specified location.
* @param index The position in the array to start inserting.
* @param one The first value.
* @param two The second value.
* @param three The third value.
*/
void insert3at( size_t index, const T &one, const T &two, const T &three )
{
insert(index, 3);
set( index, one );
set( index+1, two );
set( index+2, three );
}
/**
* Inserts four values into the array at the specified location.
* @param index The position in the array to start inserting.
* @param one The first value.
* @param two The second value.
* @param three The third value.
* @param four The fourth value.
*/
void insert4at( size_t index, const T &one, const T &two, const T &three, const T &four )
{
insert(index, 4);
set( index, one );
set( index+1, two );
set( index+2, three );
set( index+4, four );
}
/**
* Gets two values from the array at the specified location.
* @param index The position in the array to start getting.
* @param one Variable to store the first value.
* @param two Variable to store the second value.
* @return Returns The number of elements retrieved.
*/
daeInt get2at( size_t index, T &one, T &two )
{
daeInt retVal = 0;
if ( index < _count )
{
one = get(index);
retVal++;
}
if ( index+1 < _count )
{
two = get(index+1);
retVal++;
}
return retVal;
}
/**
* Gets three values from the array at the specified location.
* @param index The position in the array to start getting.
* @param one Variable to store the first value.
* @param two Variable to store the second value.
* @param three Variable to store the third value.
* @return Returns The number of elements retrieved.
*/
daeInt get3at( size_t index, T &one, T &two, T &three )
{
daeInt retVal = 0;
if ( index < _count )
{
one = get(index);
retVal++;
}
if ( index+1 < _count )
{
two = get(index+1);
retVal++;
}
if ( index+2 < _count )
{
three = get(index+2);
retVal++;
}
return retVal;
}
/**
* Gets four values from the array at the specified location.
* @param index The position in the array to start getting.
* @param one Variable to store the first value.
* @param two Variable to store the second value.
* @param three Variable to store the third value.
* @param four Variable to store the fourth value.
* @return Returns The number of elements retrieved.
*/
daeInt get4at( size_t index, T &one, T &two, T &three, T &four )
{
daeInt retVal = 0;
if ( index < _count )
{
one = get(index);
retVal++;
}
if ( index+1 < _count )
{
two = get(index+1);
retVal++;
}
if ( index+2 < _count )
{
three = get(index+2);
retVal++;
}
if ( index+3 < _count )
{
four = get(index+3);
retVal++;
}
return retVal;
}
/**
* Appends a number of elements to this array from a C native array.
* @param num The number of elements to append.
* @param array The C native array that contains the values to append.
*/
void appendArray( size_t num, T *array )
{
if ( array == NULL )
return;
for ( size_t i = 0; i < num; i++ )
append( array[i] );
}
/**
* Appends a number of elements to this array from another daeTArray.
* @param array The daeTArray that contains the values to append.
*/
void appendArray( const daeTArray<T> &array ){
size_t num = array.getCount();
for ( size_t i = 0; i < num; i++ )
append( array[i] );
}
};
#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,731 @@
/*
* 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 <sstream>
#include <dae/daeTypes.h>
#include <dae/daeStringRef.h>
#include <dae/daeArray.h>
#include <dae/daeElement.h>
#ifndef _WIN32
#include <stdint.h>
#endif
class DAE;
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()
*
* Types are also able to align data pointers appropriately.
*/
class DLLSPEC daeAtomicType
{
public:
/**
* destructor
*/
virtual ~daeAtomicType() {}
/**
* constructor
*/
daeAtomicType(DAE& dae);
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.
* @return Returns true if the operation was successful, false if not successful.
*/
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst) = 0;
/**
* 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);
/**
* Converts an array of atomic items into a whitespace separated string.
* @param array The array of data.
* @param buffer The buffer to write into.
*/
virtual void arrayToString(daeArray& array, std::ostringstream& buffer);
/**
* Reads a whitespace separated list of atomic items into an array. The array is
* cleared before writing into it.
* @param src Whitespace separated list of items.
* @param array The output array of data.
* @return Returns true if the operation was successful, false otherwise.
*/
virtual daeBool stringToArray(daeChar* src, daeArray& array);
/**
* Creates a new object of the appropriate type for this daeAtomicType and returns it
* as a pointer. The return value must be freed by calling destroy.
* @return Returns a pointer to a new value. The memory must be freed by calling destroy.
*/
virtual daeMemoryRef create() = 0;
/**
* Deletes an object previously allocated with create.
* @param obj The object previously allocated with create.
*/
virtual void destroy(daeMemoryRef obj) = 0;
/**
* Creates a daeTArray of the appropriate type (e.g. daeTArray<int>, daeTArray<daeIDRef>)
* and returns it as a daeArray*.
* @return Returns a daeArray*. This array should be freed by the caller with
* operator delete.
*/
virtual daeArray* createArray() = 0;
/**
* Performs a virtual comparison operation between two values of the same atomic type.
* @param value1 Memory location of the first value.
* @param value2 Memory location of the second value.
* @return Returns a positive integer if value1 > value2, a negative integer if
* value1 < value2, and 0 if value1 == value2.
*/
virtual daeInt compare(daeChar* value1, daeChar* value2);
/**
* Array version of the compare function.
* @param value1 First array to compare.
* @param value2 Second array to compare.
* @return Returns a positive integer if value1 > value2, a negative integer if
* value1 < value2, and 0 if value1 == value2.
*/
virtual daeInt compareArray(daeArray& value1, daeArray& value2);
/**
* Performs a virtual copy operation.
* @param src Memory location of the value to copy from.
* @param dst Memory location of the value to copy to.
*/
virtual void copy(daeChar* src, daeChar* dst) = 0;
/**
* Array version of the copy function.
* @param src Array to copy from.
* @param dst Array to copy to.
*/
virtual void copyArray(daeArray& src, daeArray& dst);
/**
* 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))); }
/**
* Notifies an object when the containing document changes.
* @param value Memory location of the atomic type value.
* @param doc The new document.
*/
virtual void setDocument(daeChar* value, daeDocument* doc) { }
/**
* Same as the previous method, but works on an array of objects.
* @param values Array of the atomic type values.
* @param doc The new document.
*/
virtual void setDocument(daeArray& array, daeDocument* doc) { }
protected:
DAE* _dae;
daeInt _size;
daeInt _alignment;
daeEnum _typeEnum;
daeStringRef _typeString;
daeStringRef _printFormat;
daeStringRef _scanFormat;
daeInt _maxStringLength;
public:
/**
* An array of strings as name bindings for this type.
*/
daeStringRefArray _nameBindings;
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
};
};
// This is a container class for storing a modifiable list of daeAtomicType objects.
class DLLSPEC daeAtomicTypeList {
public:
daeAtomicTypeList(DAE& dae);
~daeAtomicTypeList();
/**
* Appends a new type to the list.
* @param t Type to append.
* @return Returns the index of the type in the list.
*/
daeInt append(daeAtomicType* t);
/**
* 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.
*/
const daeAtomicType* getByIndex(daeInt index);
/**
* Gets the number of atomic types in the list.
* @return Returns the number of atomic types in the list.
*/
daeInt getCount();
/**
* Finds a type by its string name.
* @param type String name of the type.
* @return Returns the type with the corresponding name.
*/
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.
*/
daeAtomicType* get(daeEnum type);
private:
daeAtomicTypeArray types;
};
/**
* The @c daeBoolType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeBool.
*/
class DLLSPEC daeBoolType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeBoolType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeIntType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeInt.
*/
class DLLSPEC daeIntType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeIntType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeLongType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeLong.
*/
class DLLSPEC daeLongType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeLongType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeUIntType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeUInt.
*/
class DLLSPEC daeUIntType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeUIntType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeUIntType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeUInt.
*/
class DLLSPEC daeULongType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeULongType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeShortType is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeShort.
*/
class DLLSPEC daeShortType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeShortType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeFloatType is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeFloat.
*/
class DLLSPEC daeFloatType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeFloatType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeDoubleType is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeDouble.
*/
class DLLSPEC daeDoubleType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeDoubleType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeStringRefType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeStringRef.
*/
class DLLSPEC daeStringRefType : public daeAtomicType
{
public:
/**
* Constructor
*/
daeStringRefType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeInt compare(daeChar* value1, daeChar* value2);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* 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 DLLSPEC daeTokenType : public daeStringRefType
{
public:
/**
* Constructor
*/
daeTokenType(DAE& dae);
public:
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeElementRefType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeElementRef.
*/
class DLLSPEC daeElementRefType : public daeAtomicType
{
public:
/**
* The @c daeMetaElement for the type this @c daeElementRefType represents.
*/
daeMetaElement* _elementType;
public:
/**
* Constructor
*/
daeElementRefType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeEnumType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type daeEnum.
*/
class DLLSPEC 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(DAE& dae);
/**
* Destructor
*/
~daeEnumType();
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeRawRefType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeRawRef.
*/
class DLLSPEC daeRawRefType: public daeAtomicType
{
public:
/**
* Constructor.
*/
daeRawRefType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
/**
* The @c daeResolverType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeResolver.
*/
class DLLSPEC daeResolverType : public daeAtomicType
{
public:
/**
* Constructor.
*/
daeResolverType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeInt compare(daeChar* value1, daeChar* value2);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
virtual void setDocument(daeChar* value, daeDocument* doc);
virtual void setDocument(daeArray& array, daeDocument* doc);
};
/**
* The @c daeIDResolverType class is derived from @c daeAtomicType, and implements
* the reflective system for objects of type @c daeIDResolver.
*/
class DLLSPEC daeIDResolverType : public daeAtomicType
{
public:
/**
* Constructor.
*/
daeIDResolverType(DAE& dae);
public:
virtual daeBool memoryToString(daeChar* src, std::ostringstream& dst);
virtual daeBool stringToMemory(daeChar* src, daeChar* dst);
virtual daeInt compare(daeChar* value1, daeChar* value2);
virtual daeMemoryRef create();
virtual void destroy(daeMemoryRef obj);
virtual void copy(daeChar* src, daeChar* dst);
virtual daeArray* createArray();
};
#endif // __DAE_ATOMIC_TYPE_H__

View file

@ -0,0 +1,334 @@
/*
* 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 <vector>
#include <dae.h>
#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 DLLSPEC daeDatabase
{
public:
/**
* Constructor
*/
daeDatabase(DAE& dae);
/**
* Destructor
*/
virtual ~daeDatabase() {}
/**
* Get the associated DAE object.
* @return The associated DAE object.
*/
virtual DAE* getDAE();
/**
* 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 index.
* @param index Index of the document to get.
* @return Returns a pointer on the document, or NULL if not found.
*/
daeDocument* getDoc(daeUInt index);
/**
* Gets a document based on the document name.
* @param name The name of the document as a URI.
* @param skipUriNormalization Use the document name as is; don't normalize it first.
* This is mostly for improved performance.
* @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, bool skipUriNormalization = false) = 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;
/**
* 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.
*/
virtual daeInt removeElement(daeDocument* document,
daeElement* element) = 0;
/**
* Updates the database to reflect a change to the ID of a @c daeElement.
* @param element @c daeElement whose ID is going to change.
* @param newID The ID that will be assigned to the element.
* @return Returns @c DAE_OK if the database was successfully updated, otherwise returns a negative value as defined in daeError.h.
* @note The database doesn't actually change the ID of the element, it
* merely updates its internal structures to reflect the change. It's
* expected that the ID will be assigned to the element by someone else.
*/
virtual daeInt changeElementID(daeElement* element,
daeString newID) = 0;
/**
* Updates the database to reflect a change to the sid of a @c daeElement.
* @param element @c daeElement whose sid is going to change.
* @param newSID The sid that will be assigned to the element.
* @return Returns @c DAE_OK if the database was successfully updated, otherwise returns a negative value as defined in daeError.h.
* @note The database doesn't actually change the sid of the element, it
* merely updates its internal structures to reflect the change. It's
* expected that the sid will be assigned to the element by someone else.
* Note - This function currently isn't implemented in the default database.
*/
virtual daeInt changeElementSID(daeElement* element,
daeString newSID) = 0;
/**
* Unloads all of the documents of the runtime database.
* This function frees all the @c dom* 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;
/**
* Lookup elements by ID, searching through all documents.
* @param id The ID to match on.
* @return The array of matching elements.
*/
virtual std::vector<daeElement*> idLookup(const std::string& id) = 0;
/**
* Find an element with the given ID in a specific document.
* @param id The ID to match on.
* @param doc The document to search in.
* @return The matching element if one is found, NULL otherwise.
*/
daeElement* idLookup(const std::string& id, daeDocument* doc);
/**
* Lookup elements by type ID.
* @param typeID The type to match on, e.g. domNode::ID().
* @param doc The document to search in, or NULL to search in all documents.
* @return The array of matching elements.
*/
std::vector<daeElement*> typeLookup(daeInt typeID, daeDocument* doc = NULL);
/**
* Same as the previous method, but returns the array of matching elements via a
* reference parameter for additional efficiency.
* @param typeID The type to match on, e.g. domNode::ID().
* @param matchingElements The array of matching elements.
* @param doc The document to search in, or NULL to search in all documents.
*/
virtual void typeLookup(daeInt typeID,
std::vector<daeElement*>& matchingElements,
daeDocument* doc = NULL) = 0;
/**
* Lookup elements by type ID.
* @param doc The document to search in, or NULL to search in all documents.
* @return The array of matching elements.
*/
template<typename T>
std::vector<T*> typeLookup(daeDocument* doc = NULL) {
std::vector<T*> result;
typeLookup(result, doc);
return result;
}
/**
* Same as the previous method, but returns the array of matching elements via a
* reference parameter for additional efficiency.
* @param matchingElements The array of matching elements.
* @param doc The document to search in, or NULL to search in all documents.
*/
template<typename T> void
typeLookup(std::vector<T*>& matchingElements, daeDocument* doc = NULL) {
std::vector<daeElement*> elts;
typeLookup(T::ID(), elts, doc);
matchingElements.clear();
matchingElements.reserve(elts.size());
for (size_t i = 0; i < elts.size(); i++)
matchingElements.push_back((T*)elts[i]);
}
/**
* Lookup elements by sid.
* @param sid The sid to match on.
* @param doc The document to search in, or NULL to search in all documents.
* @return The array of matching elements.
* Note - This function currently isn't implemented in the default database.
*/
std::vector<daeElement*> sidLookup(const std::string& sid, daeDocument* doc = NULL);
/**
* Same as the previous method, but the results are returned via a parameter instead
* of a return value, for extra efficiency.
* @param sid The sid to match on.
* @param matchingElements The array of matching elements.
* @param doc The document to search in, or NULL to search in all documents.
* Note - This function currently isn't implemented in the default database.
*/
virtual void sidLookup(const std::string& sid,
std::vector<daeElement*>& matchingElements,
daeDocument* doc = NULL) = 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:
// The following methods are deprecated, and it's recommended that you don't use them.
// Where appropriate, alternative methods are specified.
virtual daeUInt getTypeCount() = 0;
virtual daeString getTypeName(daeUInt index) = 0;
// Instead of the following two methods, use idLookup or typeLookup.
virtual daeUInt getElementCount(daeString name = NULL,
daeString type = NULL,
daeString file = NULL) = 0;
virtual daeInt getElement(daeElement** pElement,
daeInt index,
daeString name = NULL,
daeString type = NULL,
daeString file = NULL ) = 0;
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 );
}
protected:
DAE& dae;
};
#endif //__DAE_DATABASE__

View file

@ -0,0 +1,153 @@
/*
* 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>
class DAE;
class daeDatabase;
/**
* The @c daeDocument class implements a COLLADA runtime database entry.
*/
class DLLSPEC daeDocument
{
public:
/**
* Constructor
* @param dae The dae that owns this document.
*/
daeDocument(DAE& dae);
/**
* Destructor
*/
~daeDocument();
/**
* 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; domRoot->setDocument(this); }
/**
* 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 the DAE that owns this document.
* @return Returns the DAE that owns this document.
*/
DAE* getDAE();
/**
* Accessor to get the database associated with this document.
* @return Returns the database associated with this document.
*/
daeDatabase* getDatabase();
/**
* 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 );
/**
* 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 );
/**
* This function is used to track how a document gets modified. It gets called internally.
* @param element The element whose ID is about to be changed.
* @param newID The ID that is going to be assigned to the element.
* @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 changeElementID( daeElementRef element, daeString newID );
/**
* This function is just like changeElementID, except it keeps track of sids instead of IDs.
* @param element The element whose sid is about to be changed.
* @param newSID The sid that is going to be assigned to the element.
* @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 changeElementSID( daeElementRef element, daeString newSID );
/**
* 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 );
/**
* 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; }
private:
/**
* The DAE that owns this document. The DAE's database is notified by the document when
* elements are inserted, removed, or have their ID changed.
*/
DAE* dae;
/**
* 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;
daeStringRefArray referencedDocuments;
};
typedef daeDocument daeCollection;
#endif

View file

@ -0,0 +1,22 @@
/*
* Copyright 2006 Sony Computer Entertainment Inc.
*
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://research.scea.com/scea_shared_source_license.html
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
#ifndef __DAE_DOM__
#define __DAE_DOM__
class daeMetaElement;
class DAE;
daeMetaElement* initializeDomMeta(DAE& dae);
#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,556 @@
/*
* 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 <string>
#include <dae/daeTypes.h>
#include <dae/daeMemorySystem.h>
#include <wchar.h>
#include <dae/daeArray.h>
#include <dae/daeRefCountedObj.h>
#include <dae/daeSmartRef.h>
//#ifndef NO_MALLOC_HEADER
//#include <malloc.h>
//#endif
namespace COLLADA_TYPE
{
typedef int TypeEnum;
}
class DAE;
class daeMetaElement;
class daeMetaAttribute;
class daeDocument;
class daeURI;
/**
* 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 DLLSPEC daeElement : public daeRefCountedObj
{
public:
/**
* Macro that defines new and delete overrides for this class
*/
DAE_ALLOC
protected:
daeElement* _parent;
daeDocument* _document;
daeMetaElement* _meta;
daeString _elementName;
daeBoolArray _validAttributeArray;
void* _userData;
protected:
daeElement( const daeElement &cpy ) : daeRefCountedObj() { (void)cpy; };
virtual daeElement &operator=( const daeElement &cpy ) { (void)cpy; return *this; }
void init();
// These functions are called internally.
void setDocument( daeDocument* c, bool notifyDocument );
daeElement* simpleAdd(daeString name, int index = -1);
public:
/**
* Element Constructor.
* @note This should not be used externally.
* Use factories to create elements
*/
daeElement();
/**
* Element Constructor.
* @note This should not be used externally.
* Use factories to create elements
*/
daeElement(DAE& dae);
/**
* Element Destructor.
* @note This should not be used externally,
* if daeSmartRefs are being used.
*/
virtual ~daeElement();
/**
* 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);
// These functions are for adding child elements. They return null if adding
// the element failed.
daeElement* add(daeString name, int index = -1);
daeElement* add(daeElement* elt, int index = -1);
daeElement* addBefore(daeElement* elt, daeElement* index);
daeElement* addAfter(daeElement* elt, daeElement* index);
// These functions are deprecated. Use 'add' instead.
daeElement* createAndPlace(daeString elementName);
daeElement* createAndPlaceAt(daeInt index, daeString elementName);
daeBool placeElement(daeElement* element);
daeBool placeElementAt(daeInt index, daeElement* element);
daeBool placeElementBefore( daeElement* marker, daeElement *element );
daeBool placeElementAfter( daeElement* marker, daeElement *element );
/**
* Finds the last index into the array of children of the name specified.
* @param elementName The name to look for.
* @return Returns the index into the children array of the last element with name elementName. -1 if
* there are no children of name elementName.
*/
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;
};
/**
* Returns the number of attributes in this element.
* @return The number of attributes this element has.
*/
size_t getAttributeCount();
/**
* Returns the daeMetaAttribute object corresponding to the attribute specified.
* @param name The name of the attribute to find.
* @return Returns the corresponding daeMetaAttribute object or NULL if this element
* doesn't have the specified attribute.
*/
daeMetaAttribute* getAttributeObject(daeString name);
/**
* Returns the daeMetaAttribute object corresponding to attribute i.
* @param i The index of the attribute to find.
* @return Returns the corresponding daeMetaAttribute object
*/
daeMetaAttribute* getAttributeObject(size_t i);
/**
* Returns the name of the attribute at the specified index.
* @param i The index of the attribute whose name should be retrieved.
* @return Returns the name of the attribute, or "" if the index is out of range.
*/
std::string getAttributeName(size_t i);
/**
* Checks if this element can have the attribute specified.
* @param name The name of the attribute to look for.
* @return Returns true is this element can have an attribute with the name specified. False otherwise.
*/
daeBool hasAttribute(daeString name);
/**
* Checks if an attribute has been set either by being loaded from the COLLADA document or set
* programmatically.
* @param name The name of the attribute to check.
* @return Returns true if the attribute has been set. False if the attribute hasn't been set
* or doesn't exist for this element.
*/
daeBool isAttributeSet(daeString name);
/**
* Gets an attribute's value as a string.
* @param name The name of the attribute.
* @return The value of the attribute. Returns an empty string if this element doesn't
* have the specified attribute.
*/
std::string getAttribute(daeString name);
/**
* Just like the previous method, this method gets an attribute's value as a string. It
* takes the string as a reference parameter instead of returning it, for extra efficiency.
* @param name The name of the attribute.
* @param A string in which to store the value of the attribute. This will be set to an empty
* string if this element doesn't have the specified attribute.
*/
void getAttribute(daeString name, std::string& value);
/**
* Gets an attribute's value as a string.
* @param i The index of the attribute to retrieve.
* @return The value of the attribute.
*/
std::string getAttribute(size_t i);
/**
* Just like the previous method, this method gets an attribute's value as a string. It
* takes the string as a reference parameter instead of returning it, for extra efficiency.
* @param i The index of the attribute to retrieve.
* @param A string in which to store the value of the attribute.
*/
void getAttribute(size_t i, std::string& value);
struct DLLSPEC attr {
attr();
attr(const std::string& name, const std::string& value);
std::string name;
std::string value;
};
/**
* Returns an array containing all the attributes of this element.
* @return A daeArray of attr objects.
*/
daeTArray<attr> getAttributes();
/**
* Just like the previous method, this method returns an array containing all the attributes
* of this element. It returns the result via a reference parameter for extra efficiency.
* @param attrs The array of attr objects to return.
*/
void getAttributes(daeTArray<attr>& attrs);
/**
* Sets the attribute to the specified value.
* @param name Attribute to set.
* @param value 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 name, daeString value);
/**
* Sets the attribute at the specified index to the given value.
* @param i Index of the attribute to set.
* @param value Value to apply to the attribute.
* @return Returns true if the attribute was found and the value was set, false otherwise.
*/
virtual daeBool setAttribute(size_t i, daeString value);
/**
* Returns the daeMetaAttribute object corresponding to the character data for this element.
* @return Returns a daeMetaAttribute object or NULL if this element doesn't have
* character data.
*/
daeMetaAttribute* getCharDataObject();
/**
* Checks if this element can have character data.
* @return Returns true if this element can have character data, false otherwise.
*/
daeBool hasCharData();
/**
* Returns this element's character data as a string.
* @return A string containing this element's character data, or an empty string
* if this element can't have character data.
*/
std::string getCharData();
/**
* Similar to the previous method, but fills a string passed in by the user for efficiency.
* @param data The string to be filled with this element's character content. The
* string is set to an empty string if this element can't have character data.
*/
void getCharData(std::string& data);
/**
* Sets this element's character data.
* @param data The new character data of this element.
* @return Returns true if this element can have character data and the character data
* was successfully changed, false otherwise.
*/
daeBool setCharData(const std::string& data);
// These functions are deprecated.
daeMemoryRef getAttributeValue(daeString name); // Use getAttribute or getAttributeObject instead.
daeBool hasValue(); // Use hasCharData instead.
daeMemoryRef getValuePointer(); // Use getCharData or getCharDataObject instead.
/**
* 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; }
/**
* Get the associated DAE object.
* @return The associated DAE object.
*/
DAE* getDAE();
/**
* Sets the database document associated with this element.
* @param c The daeDocument to associate with this element.
*/
void setDocument(daeDocument* c) { setDocument( c, true ); }
/**
* 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 elementName Class name of the subelement to create.
* @return Returns the created @c daeElement, if it was successfully created.
*/
daeSmartRef<daeElement> createElement(daeString elementName);
/**
* 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* getParentElement() { return _parent;}
/**
* Deprecated. Use getParentElement()
* @deprecated
*/
daeElement* getXMLParentElement() { return _parent;}
/**
* Sets the parent element for this element.
* @param newParent The element which is the new parent element for this element.
* @note This function is called internally and not meant to be called form the client application.
*/
void setParentElement( daeElement *parent ) { _parent = parent; }
// These are helper structures to let the xml hierarchy search functions know when we've
// found a match. You can implement a custom matcher by inheriting from this structure,
// just like matchName and matchType.
struct DLLSPEC matchElement {
virtual bool operator()(daeElement* elt) const = 0;
virtual ~matchElement() { };
};
// Matches an element by name
struct DLLSPEC matchName : public matchElement {
matchName(daeString name);
virtual bool operator()(daeElement* elt) const;
std::string name;
};
// Matches an element by schema type
struct DLLSPEC matchType : public matchElement {
matchType(daeInt typeID);
virtual bool operator()(daeElement* elt) const;
daeInt typeID;
};
// Returns a matching child element. By "child", I mean one hierarchy level beneath the
// current element. This function is basically the same as getDescendant, except that it
// only goes one level deep.
daeElement* getChild(const matchElement& matcher);
// Performs a breadth-first search and returns a matching descendant element. A "descendant
// element" is an element beneath the current element in the xml hierarchy.
daeElement* getDescendant(const matchElement& matcher);
// Returns the parent element.
daeElement* getParent();
// Searches up through the xml hiearchy and returns a matching element.
daeElement* getAncestor(const matchElement& matcher);
// These functions perform the same as the functions above, except that they take the element
// name to match as a string. This makes these functions a little simpler to use if you're
// matching based on element name, which is assumed to be the most common case. Instead of
// "getChild(matchName(eltName))", you can just write "getChild(eltName)".
daeElement* getChild(daeString eltName);
daeElement* getDescendant(daeString eltName);
daeElement* getAncestor(daeString eltName);
/**
* 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; }
// These functions are deprecated. Use typeID instead.
virtual COLLADA_TYPE::TypeEnum getElementType() const { return (COLLADA_TYPE::TypeEnum)0; }
daeString getTypeName() const;
/**
* Returns this element's type ID. Every element is an instance of a type specified in
* the Collada schema, and every schema type has a unique ID.
* @return The element's type ID.
*/
virtual daeInt typeID() const = 0;
/**
* 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;
/**
* 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.
* @return The return value. An elementref array to append this element's children to.
*/
daeTArray< daeSmartRef<daeElement> > getChildren();
/**
* Same as the previous function, but returns the result via a parameter instead
* of a return value, for extra efficiency.
* @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 );
/**
* Gets all the children of a particular type.
* @return An array containing the matching child elements.
*/
template<typename T>
daeTArray< daeSmartRef<T> > getChildrenByType() {
daeTArray< daeSmartRef<T> > result;
getChildrenByType(result);
return result;
}
/**
* Same as the previous function, but returns the result via a parameter instead
* of a return value, for extra efficiency.
* @return An array containing the matching child elements.
*/
template<typename T>
void getChildrenByType(daeTArray< daeSmartRef<T> >& matchingChildren) {
matchingChildren.setCount(0);
daeTArray< daeSmartRef<daeElement> > children;
getChildren(children);
for (size_t i = 0; i < children.getCount(); i++)
if (children[i]->typeID() == T::ID())
matchingChildren.append((T*)children[i].cast());
}
/**
* 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 );
// Class for reporting info about element comparisons
struct DLLSPEC compareResult {
int compareValue; // > 0 if elt1 > elt2,
// < 0 if elt1 < elt2,
// = 0 if elt1 = elt2
daeElement* elt1;
daeElement* elt2;
bool nameMismatch; // true if the names didn't match
std::string attrMismatch; // The name of the mismatched attribute, or "" if there was no attr mismatch
bool charDataMismatch; // true if the char data didn't match
bool childCountMismatch; // true if the number of children didn't match
compareResult();
std::string format(); // Write to a string
};
// Function for doing a generic, recursive comparison of two xml elements. It
// also provides a full element ordering, so that you could store elements in
// a map or a set. Return val is > 0 if elt1 > elt2, < 0 if elt1 < elt2, and 0
// if elt1 == elt2.
static int compare(daeElement& elt1, daeElement& elt2);
// Same as the previous function, but returns a full compareResult object.
static compareResult compareWithFullResult(daeElement& elt1, daeElement& elt2);
/**
* Sets the user data pointer attached to this element.
* @param data User's custom data to store.
*/
void setUserData(void* data);
/**
* Gets the user data pointer attached to this element.
* @return User data pointer previously set with setUserData.
*/
void* getUserData();
public:
// This function is called internally
static void deleteCMDataArray(daeTArray<daeCharArray*>& cmData);
};
#include <dae/daeSmartRef.h>
typedef daeSmartRef<daeElement> daeElementRef;
typedef daeSmartRef<const daeElement> daeElementConstRef;
//#include <dae/daeArray.h>
typedef daeTArray<daeElementRef> daeElementRefArray;
#endif //__DAE_ELEMENT_H__

View file

@ -0,0 +1,51 @@
/*
* 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__
#include <dae/daePlatform.h>
/** 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
/** Generic error */
#define DAE_ERROR -3
/** 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.
*/
DLLSPEC const char *daeErrorString(int errorCode);
#endif //__DAE__ERROR__

View file

@ -0,0 +1,66 @@
/*
* 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 <memory>
#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 DLLSPEC 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. A program has one globally-accessible
* daeErrorHandler active at a time.
* @return The current daeErrorHandler.
*/
static daeErrorHandler *get();
private:
static daeErrorHandler *_instance;
static std::auto_ptr<daeErrorHandler> _defaultInstance;
};
#endif

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_GCC_PLATFORM_H__
#define __DAE_GCC_PLATFORM_H__
#define PLATFORM_INT8 char
#define PLATFORM_INT16 short
#define PLATFORM_INT32 int
#define PLATFORM_INT64 long long
#define PLATFORM_UINT8 unsigned char
#define PLATFORM_UINT16 unsigned short
#define PLATFORM_UINT32 unsigned int
#define PLATFORM_UINT64 unsigned long long
#define PLATFORM_FLOAT32 float
#define PLATFORM_FLOAT64 double
#define DLLSPEC
#endif

View file

@ -0,0 +1,235 @@
/*
* 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 <string>
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
class DAE;
/**
* 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 DLLSPEC 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,
/** Resolution failed because we don't have a document in which to search for the element.
This means you probably forgot to set a container element. */
id_failed_no_document
};
private:
/** ID used to refer to another element */
std::string id;
/** Element that owns this ID (if any) */
daeElement* container;
public:
/**
* Simple Constructor
*/
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(const daeIDRef& constructFromIDRef);
/**
* Constructs an id reference with a container element
* @param container The container element.
*/
daeIDRef(daeElement& container);
/**
* Gets the ID string
* @return Returns the full ID string from <tt><i>id.</i></tt>
*/
daeString getID() const;
/**
* 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 element that this URI resolves to in memory.
* @return Returns a ref to the element.
*/
daeElement* getElement() const;
/**
* Gets a pointer to the @c daeElement that contains this URI.
* @return Returns the pointer to the containing daeElmement.
*/
daeElement* getContainer() const;
/**
* Sets the pointer to the @c daeElement that contains this URI.
* @param cont Pointer to the containing @c daeElmement.
*/
void setContainer(daeElement* cont);
/**
* 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();
/**
* Comparison operator.
* @return Returns true if URI's are equal.
*/
bool operator==(const daeIDRef& other) const;
/**
* Assignment operator.
* @return Returns a reference to this object.
*/
daeIDRef &operator=( const daeIDRef& other);
// These methods are only provided for backwards compatibility. Use the listed alternatives.
daeIDRef &get( daeUInt idx ); // Never should have existed. No alternative.
size_t getCount() const; // Never should have existed. No alternative.
daeIDRef& operator[](size_t index); // Never should have existed. No alternative.
void resolveElement( daeString typeNameHint = NULL ); // Call getElement. No separate "resolve" step needed.
void resolveID(); // Never should have existed. No alternative.
void validate(); // Never should have existed. No alternative.
void copyFrom(const daeIDRef& from); // Use the assignment operator instead.
ResolveState getState() const; // Never should have existed. No alternative.
};
/**
* 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.
*/
class DLLSPEC daeIDRefResolver
{
public:
/**
* Constructor
*/
daeIDRefResolver(DAE& dae);
/**
* Destructor
*/
virtual ~daeIDRefResolver();
/**
* Provides an abstract interface to convert a @c daeIDRef into a @c daeElement.
* @param id The ID of the element to find.
* @param doc The document containing the element.
* @return Returns a daeElement with matching ID, if one is found.
*/
virtual daeElement* resolveElement(const std::string& id, daeDocument* doc) = 0;
/**
* Gets the name of this resolver.
* @return Returns the string name.
*/
virtual daeString getName() = 0;
protected:
DAE* dae;
};
/**
* The @c daeDefaultIDRefResolver resolves a @c daeIDRef by checking with a database.
* It is a concrete implementation for @c daeIDRefResolver.
*/
class DLLSPEC daeDefaultIDRefResolver : public daeIDRefResolver
{
public:
daeDefaultIDRefResolver(DAE& dae);
~daeDefaultIDRefResolver();
virtual daeElement* resolveElement(const std::string& id, daeDocument* doc);
virtual daeString getName();
};
// This is a container class for storing a modifiable list of daeIDRefResolver objects.
class DLLSPEC daeIDRefResolverList {
public:
daeIDRefResolverList();
~daeIDRefResolverList();
void addResolver(daeIDRefResolver* resolver);
void removeResolver(daeIDRefResolver* resolver);
daeElement* resolveElement(const std::string& id, daeDocument* doc);
private:
// Disabled copy constructor/assignment operator
daeIDRefResolverList(const daeIDRefResolverList& resolverList) { };
daeIDRefResolverList& operator=(const daeIDRefResolverList& resolverList) { return *this; };
daeTArray<daeIDRefResolver*> resolvers;
};
#endif //__DAE_IDREF_H__

View file

@ -0,0 +1,133 @@
/*
* 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 <string>
#include <vector>
#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 DLLSPEC 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 DAE::load().
*/
virtual daeInt read(const 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 DAE::saveAs()
*/
virtual daeInt write(const daeURI& name, daeDocument *document, daeBool replace) = 0;
//@}
/**
* Returns a list of the URI protocols that this plugin supports.
* @return Returns a daeArray containing the supported protocols.
*/
virtual const std::vector<std::string>& getSupportedProtocols() {
return supportedProtocols;
}
/**
* setOption allows you to set options for this IOPlugin. Which options a plugin supports is
* dependent on the plugin itself. There is currently no list of options that plugins are
* suggested to implement.
* @param option The option to set.
* @param value The value to set the option.
* @return Returns DAE_OK upon success.
*/
virtual daeInt setOption( daeString option, daeString value ) = 0;
/**
* getOption retrieves the value of an option from this IOPlugin. Which options a plugin supports is
* dependent on the plugin itself.
* @param option The option to get.
* @return Returns the string value of the option or NULL if option is not valid.
*/
virtual daeString getOption( daeString option ) = 0;
protected:
// This is an array of the URI protocols supported by this plugin, e.g. "http", "file",
// etc. Each plugin should initialize this variable in the constructor.
std::vector<std::string> supportedProtocols;
};
class DLLSPEC daeIOEmpty : public daeIOPlugin {
public:
virtual daeInt setMeta(daeMetaElement *topMeta) { return DAE_ERROR; }
virtual void setDatabase(daeDatabase* database) { }
virtual daeInt read(const daeURI& uri, daeString docBuffer) { return DAE_ERROR; }
virtual daeInt write(const daeURI& name, daeDocument *document, daeBool replace) { return DAE_ERROR; }
virtual daeInt setOption( daeString option, daeString value ) { return DAE_ERROR; }
virtual daeString getOption( daeString option ) { return ""; }
};
#endif // __DAE_IOPLUGIN__

View file

@ -0,0 +1,68 @@
/*
* Copyright 2007 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_IO_PLUGIN_COMMON__
#define __DAE_IO_PLUGIN_COMMON__
#include <vector>
#include <dae/daeElement.h>
#include <dae/daeURI.h>
#include <dae/daeMetaAttribute.h>
#include <dae/daeIOPlugin.h>
class daeMetaElement;
class daeDocument;
/**
* The @c daeIOPluginCommon class was created to serve as a base class for the common functionality
* between the daeLIBXMLPlugin and daeTinyXMLPlugin classes.
*/
class DLLSPEC daeIOPluginCommon : public daeIOPlugin {
public:
/**
* Constructor.
*/
daeIOPluginCommon();
/**
* Destructor.
*/
virtual ~daeIOPluginCommon();
virtual daeInt setMeta(daeMetaElement *topMeta);
// Database setup
virtual void setDatabase(daeDatabase* database);
// Operations
virtual daeInt read(const daeURI& uri, daeString docBuffer);
protected:
daeDatabase* database;
// On failure, these functions return NULL
virtual daeElementRef readFromFile(const daeURI& uri) = 0;
virtual daeElementRef readFromMemory(daeString buffer, const daeURI& baseUri) = 0;
// Reading support for subclasses
typedef std::pair<daeString, daeString> attrPair;
daeElementRef beginReadElement(daeElement* parentElement,
daeString elementName,
const std::vector<attrPair>& attributes,
daeInt lineNumber);
bool readElementText(daeElement* element, daeString text, daeInt elementLineNumber);
private:
daeMetaElement* topMeta;
};
#endif //__DAE_IO_PLUGIN_COMMON__

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_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 DLLSPEC daeRawRef alloc(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 DLLSPEC void dealloc(daeString pool, daeRawRef mem);
};
// (steveT) These new/delete overrides aren't complete. What about new[] and delete[]?
// Standard new should throw a bad_alloc exception, and a nothrow new should be provided
// that returns null instead of throwing bad_alloc. Because of these problems, plus the
// fact that we currently don't benefit in any way from overriding new and delete, this
// code is currently disabled.
#if 0
#define DAE_ALLOC \
/* Standard new/delete */ \
inline void* operator new(size_t size) { return daeMemorySystem::alloc("meta", size); } \
inline void operator delete(void* p) { daeMemorySystem::dealloc("meta", p); } \
/* Placement new/delete */ \
inline void* operator new(size_t, void* p) { return p; } \
inline void operator delete(void*, void*) { }
#endif
#define DAE_ALLOC
#endif // __DAE_MEMORY_H__

View file

@ -0,0 +1,44 @@
/*
* 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_ANY_H__
#define __DAE_META_ANY_H__
#include <dae/daeMetaCMPolicy.h>
/**
* The daeMetaAny class defines the behavior of an xs:any content model in the COLLADA Schema.
*/
class daeMetaAny : public daeMetaCMPolicy
{
public:
/**
* Constructor.
* @param container The daeMetaElement that this policy object belongs to.
* @param parent The daeMetaCMPolicy parent of this policy object.
* @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
* correct order of child elements.
* @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
* @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
*/
daeMetaAny( daeMetaElement *container, daeMetaCMPolicy *parent = NULL, daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1 );
~daeMetaAny();
daeElement *placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL );
daeBool removeElement(daeElement* parent, daeElement* child);
daeMetaElement *findChild( daeString elementName );
void getChildren( daeElement* parent, daeElementRefArray &array );
};
#endif

View file

@ -0,0 +1,325 @@
/*
* 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 <string>
#include <sstream>
#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;
/**
* 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 semantic operations it is capable of
* including @c set(), @c get(), and @c print().
* @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 DLLSPEC daeMetaAttribute : public daeRefCountedObj
{
protected:
daeStringRef _name;
daeInt _offset;
daeAtomicType* _type;
daeMetaElement* _container;
std::string _defaultString;
daeMemoryRef _defaultValue;
daeBool _isRequired;
public:
/**
* Constructor
*/
daeMetaAttribute();
/**
* Destructor
*/
virtual ~daeMetaAttribute();
public:
/**
* 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.
* @param defaultVal @c daeString representing the default value.
*/
virtual void setDefaultString(daeString defaultVal);
/**
* Sets the default for this attribute via a memory pointer.
* @param defaultVal @c daeMemoryRef representing the default value.
*/
virtual void setDefaultValue(daeMemoryRef defaultVal);
/**
* Gets the default for this attribute as a string.
* @return Returns a @c daeString representing the default value.
*/
daeString getDefaultString();
/**
* Gets the default for this attribute as a memory value.
* @return Returns a @c daeMemoryRef representing the default value.
*/
daeMemoryRef getDefaultValue();
/**
* 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; }
/**
* Notifies an attribute when the containing document changes.
*/
virtual void setDocument(daeElement* e, daeDocument* doc);
/**
* Converts an element's attribute value to a string.
*/
virtual void memoryToString(daeElement* e, std::ostringstream& buffer);
/**
* Converts a string to a memory value in the specified element.
*/
virtual void stringToMemory(daeElement* e, daeString s);
/**
* Gets the attribute's memory pointer from containing element <tt><i>e</i></tt>.
* @param e Containing element from which to get the value.
* @return Returns the memory pointer corresponding to this attribute out of parent element e.
*/
virtual daeMemoryRef get(daeElement* e);
/**
* Gets if this attribute is an array attribute.
* @return Returns true if this attribute is an array type.
*/
virtual daeBool isArrayAttribute() { return false; }
public:
/**
* 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();
/**
* Copies 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);
/**
* Copies the default value of this attribute to the element
* @param element Pointer to a @c daeElement to copy the default value to.
*/
virtual void copyDefault(daeElement* element);
/**
* Compares the value of this attribute in the given elements.
* @param elt1 The first element whose attribute value should be compared.
* @param elt2 The second element whose attribute value should be compared.
* @return Returns a positive integer if value1 > value2, a negative integer if
* value1 < value2, and 0 if value1 == value2.
*/
virtual daeInt compare(daeElement* elt1, daeElement* elt2);
/**
* Compares the value of this attribute from the given element to the default value
* of this attribute (if one exists).
* @param e The element whose value should be compared to the default value.
* @return Returns a positive integer if value > default, a negative integer if
* value < default, and 0 if value == default.
*/
virtual daeInt compareToDefault(daeElement* e);
public:
// These methods are deprecated.
virtual daeChar* getWritableMemory(daeElement* e); // Use get instead.
virtual void set(daeElement* element, daeString s); // Use stringToMemory instead.
};
/**
* 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 DLLSPEC daeMetaArrayAttribute : public daeMetaAttribute
{
public:
virtual ~daeMetaArrayAttribute();
/**
* 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);
/**
* Copies the default value of this attribute to the element
* @param element Pointer to a @c daeElement to copy the default value to.
*/
virtual void copyDefault(daeElement* element);
/**
* Compares the value of this attribute in the given elements.
* @param elt1 The first element whose attribute value should be compared.
* @param elt2 The second element whose attribute value should be compared.
* @return Returns a positive integer if value1 > value2, a negative integer if
* value1 < value2, and 0 if value1 == value2.
*/
virtual daeInt compare(daeElement* elt1, daeElement* elt2);
/**
* Compares the value of this attribute from the given element to the default value
* of this attribute (if one exists).
* @param e The element whose value should be compared to the default value.
* @return Returns a positive integer if value > default, a negative integer if
* value < default, and 0 if value == default.
*/
virtual daeInt compareToDefault(daeElement* e);
/**
* Converts an element's attribute value to a string.
*/
virtual void memoryToString(daeElement* e, std::ostringstream& buffer);
/**
* Converts a string to a memory value in the specified element.
*/
virtual void stringToMemory(daeElement* e, daeString s);
/**
* Sets the default for this attribute via a string.
* @param defaultVal @c daeString representing the default value.
*/
virtual void setDefaultString(daeString defaultVal);
/**
* Sets the default for this attribute via a memory pointer.
* @param defaultVal @c daeMemoryRef representing the default value.
*/
virtual void setDefaultValue(daeMemoryRef defaultVal);
/**
* Gets if this attribute is an array attribute.
* @return Returns true if this attribute is an array type.
*/
virtual daeBool isArrayAttribute() { return true; }
/**
* Notifies an attribute when the containing document changes.
*/
virtual void setDocument(daeElement* e, daeDocument* doc);
};
typedef daeSmartRef<daeMetaAttribute> daeMetaAttributeRef;
typedef daeTArray<daeMetaAttributeRef> daeMetaAttributeRefArray;
typedef daeTArray<daeMetaAttribute*> daeMetaAttributePtrArray;
#endif //__DAE_META_ATTRIBUTE_H__

View file

@ -0,0 +1,120 @@
/*
* 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_CM_POLICY_H__
#define __DAE_META_CM_POLICY_H__
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
//class daeElement;
class daeMetaElement;
/**
* The daeMetaCMPolicy class is the base class for the content model policy classes which are used to
* describe the availability and ordering of an element's children.
*/
class daeMetaCMPolicy
{
public:
/**
* Places an element into the parent element based on this content model policy object.
* @param parent The parent element for which the child element will be placed.
* @param child The new child element.
* @param ordinal A reference to a daeUInt which holds the ordinal return value for a placed child. Used
* to maintain proper ording of child elements.
* @param offset The offset to used when attempting to place this element. Affects comparison against
* minOccurs and maxOccurs.
* @param before The element that the child should appear before. Optional.
* @param after The element that the child should appear after. Optional.
* @return Returns The child element that was placed within this content model object or any of its
* children. NULL if placement failed.
*/
virtual daeElement *placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL ) = 0;
/**
* Removes an element from the parent based on this content model object.
* @param parent The parent element for which child you want to remove.
* @param child The child that will be removed from the parent.
* @return Returns true if the child was successfully removed from this content model object or any of
* its children. False otherwise.
*/
virtual daeBool removeElement(daeElement* parent, daeElement* child ) = 0;
/**
* Gets the daeMetaElement of an acceptable child of this content model object.
* @param elementName The name of the element whos metaElement information you are interested in.
* @return Returns a pointer to a daeMetaElement class that describes the element interested in.
* Returns NULL if the element is not valid in this content model.
*/
virtual daeMetaElement *findChild( daeString elementName ) = 0;
/**
* Populates an array with the children of parent based on this content model object.
* @param parent The parent element whos children you want.
* @param array The array where you the children will be appended to.
*/
virtual void getChildren( daeElement* parent, daeElementRefArray &array ) = 0;
/**
* Adds a child to this content model object.
* @param p The child content model policy object.
*/
void appendChild( daeMetaCMPolicy *p ) { _children.append( p ); }
/**
* Gets the parent of this content model policy object.
* @return Returns a pointer to the parent node.
*/
daeMetaCMPolicy *getParent() { return _parent; }
/**
* Sets the maximum ordinal value of this policy objects children. Used to keep proper ordering for
* cm objects that may appear multiple times.
* @param ord The maximum ordinal value for this content model object.
*/
void setMaxOrdinal( daeUInt ord ) { _maxOrdinal = ord; }
protected:
/**
* Constructor.
* @param container The daeMetaElement that this policy object belongs to.
* @param parent The daeMetaCMPolicy parent of this policy object.
* @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
* correct order of child elements.
* @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
* @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
*/
daeMetaCMPolicy( daeMetaElement *container ,daeMetaCMPolicy *parent, daeUInt ordinal,
daeInt minO, daeInt maxO ) : _container( container ), _parent( parent ), _minOccurs( minO ),
_maxOccurs( maxO ), _maxOrdinal( 0 ), _ordinalOffset( ordinal ) {}
public:
/**
* Destructor.
*/
virtual ~daeMetaCMPolicy();
protected:
daeMetaElement * _container;
daeMetaCMPolicy * _parent;
daeTArray<daeMetaCMPolicy*> _children;
/** Minimum number of times this meta element can occur. */
daeInt _minOccurs;
/** Maximum number of times this meta element can occur. -1 for unbounded */
daeInt _maxOccurs;
daeUInt _maxOrdinal;
daeUInt _ordinalOffset;
};
#endif

View file

@ -0,0 +1,48 @@
/*
* 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_CHOICE_H__
#define __DAE_META_CHOICE_H__
#include <dae/daeMetaCMPolicy.h>
/**
* The daeMetaChoice class defines the behavior of an xs:choice content model in the COLLADA Schema.
*/
class daeMetaChoice : public daeMetaCMPolicy
{
public:
/**
* Constructor.
* @param container The daeMetaElement that this policy object belongs to.
* @param parent The daeMetaCMPolicy parent of this policy object.
* @param choiceNum An unsigned integer that represents which index in an element's CMData array coresponds to this choice's data.
* @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
* correct order of child elements.
* @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
* @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
*/
daeMetaChoice( daeMetaElement *container, daeMetaCMPolicy *parent = NULL, daeUInt choiceNum = 0, daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1 );
~daeMetaChoice();
daeElement *placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL );
daeBool removeElement(daeElement* parent, daeElement* child);
daeMetaElement *findChild( daeString elementName );
void getChildren( daeElement* parent, daeElementRefArray &array );
private:
daeUInt _choiceNum;
};
#endif

View file

@ -0,0 +1,368 @@
/*
* 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>
#include <dae/daeRefCountedObj.h>
class DAE;
class daeMetaCMPolicy;
class daeMetaElementArrayAttribute;
typedef daeElementRef (*daeElementConstructFunctionPtr)(DAE& dae);
/**
* 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 daeRefCountedObj
{
protected:
daeStringRef _name;
daeElementConstructFunctionPtr _createFunc;
daeInt _elementSize;
daeMetaAttributeRefArray _metaAttributes;
daeMetaAttributeRef _metaValue;
daeMetaElementArrayAttribute* _metaContents;
daeMetaArrayAttribute* _metaContentsOrder;
daeMetaAttributeRef _metaID;
daeBool _isTrackableForQueries;
daeBool _usesStringContents;
daeBool _isTransparent;
daeBool _isAbstract;
daeBool _allowsAny;
daeBool _innerClass;
daeMetaCMPolicy* _contentModel;
daeMetaArrayAttribute* _metaCMData;
daeUInt _numMetaChoices;
DAE& dae;
public:
/**
* Constructor
*/
DLLSPEC daeMetaElement(DAE& dae);
/**
* Destructor
*/
DLLSPEC ~daeMetaElement();
public: // public accessors
/**
* Gets the DAE object that owns this daeMetaElement.
* @return Returns the owning DAE.
*/
DAE* getDAE();
/**
* Determines if elements of this type is an inner class.
* @return Returns true if this element type is an inner class.
*/
daeBool getIsInnerClass() { return _innerClass; }
/**
* Sets if elements of this type are inner classes.
* @param abstract True if this type is an inner class.
*/
void setIsInnerClass( daeBool ic ) { _innerClass = ic; }
/**
* 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; }
/**
* 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 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 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 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 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.
*/
DLLSPEC 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:
/**
* Registers 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.
*/
DLLSPEC void addContents(daeInt offset);
/**
* Registers with the reflective object system the array that stores the _contents ordering. 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 order array in the C++ element class.
*/
DLLSPEC void addContentsOrder( daeInt offset );
/**
* Registers with the reflective object system that the dom class described by this @c daeMetaElement
* contains at least one choice group in the content model for this element. 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.
* @param numChoices The number of choice content model blocks there are for this element type.
*/
DLLSPEC void addCMDataArray( daeInt offset, daeUInt numChoices );
/**
* Gets the attribute associated with the contents meta information.
* @see @c addContents()
* @return Returns the @c daeMetaElementArrayAttribute.
*/
daeMetaElementArrayAttribute* getContents() { return _metaContents; }
/**
* Gets the attribute associated with the CMData array meta information.
* @see @c addCMDataArray()
* @return Returns the @c daeMetaArrayAttribute for the CMData of an element.
*/
daeMetaArrayAttribute* getMetaCMData() { return _metaCMData; }
/**
* Gets the number of choice content model blocks there are for this element type.
* @return Returns the number of daeMetaChoice's there are in the content model.
*/
daeUInt getNumChoices() const { return _numMetaChoices; }
/**
* 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.
*/
DLLSPEC void appendAttribute(daeMetaAttribute* attr);
/**
* 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 registerClass(daeElementConstructFunctionPtr func) {
_createFunc = func; }
/**
* Validates this class to be used by the runtime c++ object model
* including factory creation.
*/
DLLSPEC 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.
*/
DLLSPEC daeBool place(daeElement *parent, daeElement *child, daeUInt *ordinal = NULL);
/**
* Places a child element into the <tt><i>parent</i></tt> element at a specific location
* where the calling object is the @c daeMetaElement for the parent element.
* @param index The location in the contents array to insert.
* @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.
* @note This should only be called on elements that have a _contents array. Elements without
* a _contents array will be placed normally.
*/
DLLSPEC daeBool placeAt( daeInt index, daeElement *parent, daeElement *child );
/**
* Places a child element into the <tt><i>parent</i></tt> element at a specific location which is right
* before the marker element.
* @param marker The element location in the contents array to insert before.
* @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.
*/
DLLSPEC daeBool placeBefore( daeElement* marker, daeElement *parent, daeElement *child, daeUInt *ordinal = NULL );
/**
* Places a child element into the <tt><i>parent</i></tt> element at a specific location which is right
* after the marker element.
* @param marker The element location in the contents array to insert after.
* @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.
*/
DLLSPEC daeBool placeAfter( daeElement* marker, daeElement *parent, daeElement *child, daeUInt *ordinal = NULL );
/**
* Removes a child element from its parent element.
* @param parent Element That is the parent.
* @param child Child element to remove.
* @return Returns true if the operation was successful, false otherwise.
*/
DLLSPEC daeBool remove( daeElement *parent, daeElement *child );
/**
* Gets all of the children from an element of this type.
* @param parent The element that you want to get the children from.
* @param array The return value. An elementref array to append this element's children to.
*/
DLLSPEC void getChildren( daeElement* parent, daeElementRefArray &array );
/**
* 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.
*/
DLLSPEC 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.
*/
DLLSPEC daeElementRef create(daeString childElementTypeName);
/**
* Gets the root of the content model policy tree.
* @return Returns the root element of the tree of content model policy elements.
*/
daeMetaCMPolicy *getCMRoot() { return _contentModel; }
/**
* Sets the root of the content model policy tree.
* @param cm The root element of the tree of content model policy elements.
*/
DLLSPEC void setCMRoot( daeMetaCMPolicy *cm );
};
typedef daeSmartRef<daeMetaElement> daeMetaElementRef;
typedef daeTArray<daeMetaElementRef> daeMetaElementRefArray;
#endif //__DAE_META_ELEMENT_H__

View file

@ -0,0 +1,189 @@
/*
* 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_ATTRIBUTE_H__
#define __DAE_META_ELEMENT_ATTRIBUTE_H__
#include <dae/daeTypes.h>
#include <dae/daeMetaAttribute.h>
#include <dae/daeMetaCMPolicy.h>
class daeMetaElement;
class daeElement;
class daeDocument;
/**
* The @c daeMetaElementAttribute class represents a content model object that is an element.
*/
class daeMetaElementAttribute : public daeMetaAttribute, public daeMetaCMPolicy
{
public:
/** The metaElement that describes the element type of this attribute */
daeMetaElement* _elementType;
public:
/**
* Constructor.
* @param container The daeMetaElement that this policy object belongs to.
* @param parent The daeMetaCMPolicy parent of this policy object.
* @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
* correct order of child elements.
* @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
* @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
*/
daeMetaElementAttribute( daeMetaElement *container, daeMetaCMPolicy *parent = NULL, daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1);
/**
* Destructor
*/
virtual ~daeMetaElementAttribute();
public:
virtual daeElement *placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL);
virtual daeBool removeElement(daeElement* parent, daeElement* child);
daeMetaElement *findChild( daeString elementName );
virtual void getChildren( daeElement* parent, daeElementRefArray &array );
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; }
/**
* 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);
/**
* Gets if this attribute is an array attribute.
* @return Returns true if this attribute is an array type.
*/
virtual daeBool isArrayAttribute() { return false; }
};
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.
* @param container The daeMetaElement that this policy object belongs to.
* @param parent The daeMetaCMPolicy parent of this policy object.
* @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
* correct order of child elements.
* @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
* @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
*/
daeMetaElementArrayAttribute(daeMetaElement *container, daeMetaCMPolicy *parent = NULL, daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1);
~daeMetaElementArrayAttribute();
public:
virtual daeElement *placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL);
virtual daeBool removeElement(daeElement* parent, daeElement* child);
void getChildren( daeElement* parent, daeElementRefArray &array );
/**
* 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);
/**
* Gets if this attribute is an array attribute.
* @return Returns true if this attribute is an array type.
*/
virtual daeBool isArrayAttribute() { return true; }
};
typedef daeSmartRef<daeMetaElementArrayAttribute> daeMetaElementArrayAttributeRef;
typedef daeTArray<daeMetaElementArrayAttributeRef> daeMetaElementArrayAttributeArray;
#endif

View file

@ -0,0 +1,55 @@
/*
* 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_GROUP_H__
#define __DAE_META_GROUP_H__
#include <dae/daeMetaCMPolicy.h>
class daeMetaElementAttribute;
/**
* The daeMetaGroup class defines the behavior of an xs:group ref content model from the COLLADA Schema.
*/
class daeMetaGroup : public daeMetaCMPolicy
{
public:
/**
* Constructor.
* @param econ The daeMetaElementAttribute that represents the group element in the parent.
* @param container The daeMetaElement that this policy object belongs to.
* @param parent The daeMetaCMPolicy parent of this policy object.
* @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
* correct order of child elements.
* @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
* @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
*/
daeMetaGroup( daeMetaElementAttribute *econ, daeMetaElement *container, daeMetaCMPolicy *parent = NULL,
daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1 );
/**
* Destructor.
*/
~daeMetaGroup();
daeElement *placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL );
daeBool removeElement(daeElement* parent, daeElement* child);
daeMetaElement *findChild( daeString elementName );
void getChildren( daeElement* parent, daeElementRefArray &array );
protected:
daeMetaElementAttribute *_elementContainer;
};
#endif

View file

@ -0,0 +1,51 @@
/*
* 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_SEQUENCE_H__
#define __DAE_META_SEQUENCE_H__
#include <dae/daeMetaCMPolicy.h>
/**
* The daeMetaSequence class defines the behavior of an xs:sequence content model in the COLLADA Schema.
*/
class daeMetaSequence : public daeMetaCMPolicy
{
public:
/**
* Constructor.
* @param container The daeMetaElement that this policy object belongs to.
* @param parent The daeMetaCMPolicy parent of this policy object.
* @param odinal The ordinal value offset of this specific policy object. Used for maintaining the
* correct order of child elements.
* @param minO The minimum number of times this CMPolicy object must appear. This value comes from the COLLADA schema.
* @param maxO The maximum number of times this CMPolicy object may appear. This value comes from the COLLADA schema.
*/
daeMetaSequence( daeMetaElement *container, daeMetaCMPolicy *parent = NULL, daeUInt ordinal = 0, daeInt minO = 1, daeInt maxO = 1 );
/**
* Destructor.
*/
~daeMetaSequence();
daeElement *placeElement( daeElement *parent, daeElement *child, daeUInt &ordinal, daeInt offset = 0, daeElement* before = NULL, daeElement *after = NULL );
daeBool removeElement(daeElement* parent, daeElement* child);
daeMetaElement *findChild( daeString elementName );
void getChildren( daeElement* parent, daeElementRefArray &array );
};
#endif

View file

@ -0,0 +1,39 @@
/*
* 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_PLATFORM_H__
#define __DAE_PLATFORM_H__
#ifdef WIN32
#include <dae/daeWin32Platform.h>
#elif defined( __GCC__ )
#include <dae/daeGCCPlatform.h>
#else
// Use some generic settings
#include <limits.h>
#define PLATFORM_INT8 char
#define PLATFORM_INT16 short
#define PLATFORM_INT32 int
#define PLATFORM_INT64 long long
#define PLATFORM_UINT8 unsigned char
#define PLATFORM_UINT16 unsigned short
#define PLATFORM_UINT32 unsigned int
#define PLATFORM_UINT64 unsigned long long
#define PLATFORM_FLOAT32 float
#define PLATFORM_FLOAT64 double
#define DLLSPEC
#endif
#endif

View file

@ -0,0 +1,57 @@
/*
* 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_RAWRESOLVER_H__
#define __DAE_RAWRESOLVER_H__
#include <string>
#include <map>
#include <dae/daeURI.h>
class DAE;
/**
* The @c daeRawResolver class derives from @c daeURIResolver and implements
* the .raw backend resolver for raw binary data.
*/
class DLLSPEC daeRawResolver : public daeURIResolver
{
public:
/**
* Constructor.
*/
daeRawResolver(DAE& dae);
/**
* Destructor.
*/
~daeRawResolver();
public: // Abstract Interface
virtual daeElement* resolveElement(const daeURI& uri);
virtual daeString getName();
};
// A simple class to make speed up the process of resolving a .raw URI.
// The result of the resolve is cached for future use.
// This is meant for DOM internal use only.
class DLLSPEC daeRawRefCache {
public:
daeElement* lookup(const daeURI& uri);
void add(const daeURI& uri, daeElement* elt);
void remove(const daeURI& uri);
void clear();
private:
std::map<std::string, daeElement*> lookupTable;
};
#endif

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 daeRefCountedObj_h
#define daeRefCountedObj_h
#include <dae/daeTypes.h>
#include <dae/daePlatform.h>
class DLLSPEC daeRefCountedObj {
protected:
mutable daeInt _refCount;
public:
daeRefCountedObj();
virtual ~daeRefCountedObj();
/**
* 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.
*/
void ref() const;
};
void DLLSPEC checkedRelease(const daeRefCountedObj* obj);
void DLLSPEC checkedRef(const daeRefCountedObj* obj);
#endif

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_SIDRESOLVER_H__
#define __DAE_SIDRESOLVER_H__
#include <string>
#include <map>
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
// This is an alternative to the daeSIDResolver class. It's recommended you use
// this class instead. Typical usage: get the element a sid ref points to. For
// example, if you want to find the element with sid 'sampler' using a
// daeElement pointer named 'effect', that would look like this:
// daeElement* elt = daeSidRef("sampler", effect).resolve().elt
struct DLLSPEC daeSidRef {
// A helper class for returning all the data retrieved when a sid is resolved.
struct DLLSPEC resolveData {
resolveData();
resolveData(daeElement* elt, daeDoubleArray* array, daeDouble* scalar);
daeElement* elt;
daeDoubleArray* array;
daeDouble* scalar;
};
daeSidRef();
daeSidRef(const std::string& sidRef, daeElement* referenceElt, const std::string& profile = "");
bool operator<(const daeSidRef& other) const;
resolveData resolve();
std::string sidRef;
daeElement* refElt;
std::string profile;
};
/**
* The daeSIDResolver class is designed to resolve sid references within a COLLADA document.
* The rules for sid resolution are set forth by the Addressing Syntax section in Chapter 3 of the
* COLLADA specification which can be found at https://www.khronos.org/collada .
* This resolver always attempts to resolve to the daeElement which is referenced. If the element contains
* a daeDoubleArray (domFloatArray) value, the resolver will set the pointer to that array. The
* resolver will also do this if the sid target points to a <source> element which has a <float_array> as
* a child. If the sid target specifies a value, i.e. blah.X or blah(6), the resolver will attempt to
* get a pointer to that specific value. The resolver only attempts to resolve to that level for values which
* are defined in the COMMON profile glossary of the COLLADA specification, or values reference with the (#)
* syntax. You can check the return value from getState() to see which level of resolution is possible.
*/
class DLLSPEC daeSIDResolver
{
public:
/**
* An enum describing the status of the SID resolution process.
*/
enum ResolveState{
/** No target specified */
target_empty,
/** target specified but not resolved */
target_loaded,
/** Resolution failed because target was not found */
sid_failed_not_found,
/** Resolution successful to the Element level */
sid_success_element,
/** Resolution successful to the Double Array level */
sid_success_array,
/** Resolution successful to the Double level */
sid_success_double
};
/**
* Constructor.
* @param container The element which contains the target that you want to resolve.
* @param target The target string which needs to be resolved.
* @param platform The platform name of the technique to use. A NULL value indicates the common platform.
*/
daeSIDResolver( daeElement *container, daeString target, daeString platform = NULL );
/**
* Gets the target string.
* @return Returns the target string of this SID resolver.
*/
daeString getTarget() const;
/**
* Sets the target string.
* @param t The new target string for this resolver.
*/
void setTarget( daeString t );
/**
* Gets the name of the profile to use when resolving.
* @return Returns the name of the profile or NULL for the common profile.
*/
daeString getProfile() const;
/**
* Sets the profile to use when resolving.
* @param p The profile name of the technique to use. A NULL value indicates the common profile.
*/
void setProfile( daeString p );
/**
* Gets a pointer to the @c daeElement that contains the target to resolve.
* @return Returns the pointer to the containing daeElmement.
*/
daeElement* getContainer() const;
/**
* Sets the pointer to the @c daeElement that contains the target to resolve.
* @param element Pointer to the containing @c daeElmement.
*/
void setContainer(daeElement* element);
/**
* Gets the element that this SID resolves to.
* @return Returns the element that the URI resolves to.
*/
daeElement* getElement();
/**
* Gets the value array of the element that the SID resolves to.
* @return Returns a pointer to the value array that the SID resolves to
* @note The daeSIDResolver can only resolve to this level for daeDoubleArray values.
*/
daeDoubleArray *getDoubleArray();
/**
* Gets a pointer to the particle this target resolved to.
* @return Returns a pointer to a double value which is the fully resolved target.
* @note The daeSIDResolver can only resolve to this level for domDouble values and only if the
* final symbolic name is from the COMMON profile or a cardinal value is specified.
* @note The daeSIDResolver assumes the value is a 4x4 matrix if there are 2 cardinal values specified.
*/
daeDouble *getDouble();
// This method is deprecated. Don't use it.
ResolveState getState() const;
private:
// This data is provided by the user
std::string target;
std::string profile;
daeElement* container;
};
// A class to make sid ref lookups faster. Meant for DOM internal use only.
class DLLSPEC daeSidRefCache {
public:
daeSidRefCache();
daeSidRef::resolveData lookup(const daeSidRef& sidRef);
void add(const daeSidRef& sidRef, const daeSidRef::resolveData& data);
void clear();
// For debugging/testing
bool empty();
int misses();
int hits();
private:
std::map<daeSidRef, daeSidRef::resolveData> lookupTable;
int hitCount;
int missCount;
};
#endif

View file

@ -0,0 +1,139 @@
/*
* Copyright 2006 Sony Computer Entertainment Inc.
*
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://research.scea.com/scea_shared_source_license.html
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
#ifndef __DAE_SMARTREF_H__
#define __DAE_SMARTREF_H__
#include <assert.h>
#include <dae/daeRefCountedObj.h>
/**
* The @c daeSmartRef template class automates reference counting for
* objects derived from @c daeRefCountedObj.
*/
template<class T> class daeSmartRef
{
public:
/**
* Constructor
*/
inline daeSmartRef() : _ptr(NULL) { }
/**
* Destructor
*/
inline ~daeSmartRef() {
checkedRelease(_ptr);
}
/**
* 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()) {
checkedRef(_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) {
checkedRef(_ptr);
}
/**
* Constructor
* @param ptr a pointer to an object of the same template type.
*/
inline daeSmartRef(T* ptr) : _ptr(ptr) {
checkedRef(_ptr);
}
/**
* 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();
checkedRef(ptr);
checkedRelease(_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;
checkedRef(ptr);
checkedRelease(_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) {
checkedRef(ptr);
checkedRelease(_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,44 @@
/*
* 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_STANDARD_URI_RESOLVER__
#define __DAE_STANDARD_URI_RESOVLER__
#include <string>
#include "dae/daeURI.h"
class DAE;
/**
* The @c daeStandardURIResolver class derives from @c daeURIResolver and implements
* the default XML backend resolver.
*/
class daeStandardURIResolver : public daeURIResolver
{
public:
/**
* Constructor.
* @param database The @c daeDatabase used.
* @param plugin The @c daeIOPlugin used.
*/
DLLSPEC daeStandardURIResolver(DAE& dae);
/**
* Destructor.
*/
DLLSPEC ~daeStandardURIResolver();
public: // Abstract Interface
virtual DLLSPEC daeElement* resolveElement(const daeURI& uri);
virtual DLLSPEC daeString getName();
};
#endif //__DAE_STANDARD_URI_RESOLVER__

View file

@ -0,0 +1,108 @@
/*
* 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.
*/
DLLSPEC 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.
*/
DLLSPEC 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.
*/
DLLSPEC 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)); }
//Contributed by Nus - Wed, 08 Nov 2006
/**
* Release string table...
*/
static void releaseStringTable(void);
//--------------------
};
typedef daeTArray<daeStringRef> daeStringRefArray;
typedef daeTArray<daeStringRefArray> daeStringRefArrayArray;
#endif //__DAE_STRING_REF_H__

View file

@ -0,0 +1,64 @@
/*
* 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.
*/
DLLSPEC 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.
*/
DLLSPEC daeString allocString(daeString string);
/**
* Clears the storage.
*/
DLLSPEC void clear();
private: // MEMBERS
size_t _stringBufferSize;
size_t _stringBufferIndex;
daeStringArray _stringBuffersList;
daeString allocateBuffer();
daeString _empty;
};
#endif //__DAE_STRING_TABLE_H__

View file

@ -0,0 +1,75 @@
/*
* Copyright 2007 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_TINYXMLPLUGIN__
#define __DAE_TINYXMLPLUGIN__
#include <vector>
#include <list>
#include <dae/daeElement.h>
#include <dae/daeURI.h>
#include <dae/daeIOPluginCommon.h>
class TiXmlDocument;
class TiXmlElement;
class daeTinyXMLPlugin : public daeIOPluginCommon
{
public:
// Constructor / destructor
/**
* Constructor.
*/
DLLSPEC daeTinyXMLPlugin();
/**
* Destructor.
*/
virtual DLLSPEC ~daeTinyXMLPlugin();
// Operations
virtual DLLSPEC daeInt write(const daeURI& name, daeDocument *document, daeBool replace);
/**
* setOption allows you to set options for this IOPlugin. Which options a plugin supports is
* dependent on the plugin itself. There is currently no list of options that plugins are
* suggested to implement. daeLibXML2Plugin supports only one option, "saveRawBinary". Set to
* "true" to save float_array data as a .raw binary file. The daeRawResolver will convert the
* data back into COLLADA domFloat_array elements upon load.
* @param option The option to set.
* @param value The value to set the option.
* @return Returns DAE_OK upon success.
*/
virtual DLLSPEC daeInt setOption( daeString option, daeString value );
/**
* getOption retrieves the value of an option from this IOPlugin. Which options a plugin supports is
* dependent on the plugin itself.
* @param option The option to get.
* @return Returns the string value of the option or NULL if option is not valid.
*/
virtual DLLSPEC daeString getOption( daeString option );
private:
TiXmlDocument* m_doc;
std::list<TiXmlElement*> m_elements;
virtual daeElementRef readFromFile(const daeURI& uri);
virtual daeElementRef readFromMemory(daeString buffer, const daeURI& baseUri);
daeElementRef readElement(TiXmlElement* tinyXmlElement, daeElement* parentElement);
void writeElement( daeElement* element );
void writeAttribute( daeMetaAttribute* attr, daeElement* element );
void writeValue( daeElement* element );
};
#endif //__DAE_TINYXMLPLUGIN__

View file

@ -0,0 +1,55 @@
/*
* 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__
#include <dae/daePlatform.h>
#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,498 @@
/*
* 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 <string>
#include <dae/daeTypes.h>
#include <dae/daeElement.h>
#include <dae/daeUtils.h>
class DAE;
/**
* 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 set() method breaks the string into
* its components including scheme, authority, path (directory), and fragment.
* 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 scheme, 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 scheme.
* 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>fragment</i></tt> is empty.
*/
class DLLSPEC daeURI
{
private:
daeElement* internalResolveElement() const;
public:
/**
* An enum describing the status of the URI resolution process.
* This is pretty much entirely useless now. Just use the various accessors
* to query the state of the uri.
*/
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 fragment was not found */
uri_failed_id_not_found,
/** Failure due to an invalid fragment */
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 automatic loading of a document is turned off */
uri_failed_external_document
};
private:
// All daeURIs have a pointer to a master DAE that they use to access global information.
mutable DAE* dae;
/** Resolved version of the URI */
std::string uriString;
/** Original URI before resolution */
std::string originalURIString;
/** scheme component */
std::string _scheme;
/** authority component */
std::string _authority;
/** path component */
std::string _path;
/** query component */
std::string _query;
/** fragment component */
std::string _fragment;
/** Pointer to the element that owns this URI */
daeElement* container;
public:
/**
* Constructs a daeURI object that contains no URI reference.
* @param dae The DAE associated with this daeURI.
* current working directory.
*/
daeURI(DAE& dae);
/**
* Destructor
*/
~daeURI();
/**
* Constructs a daeURI object from a URI passed in as a string.
* @param dae The DAE associated with this daeURI.
* @param URIString Passed to set() automatically.
* @param nofrag If true, the fragment part of the URI is stripped off before construction.
*/
daeURI(DAE& dae, const std::string& URIString, daeBool nofrag = false);
/**
* Constructs a daeURI object using a <tt><i>baseURI</i></tt> and a <tt><i>uriString.</i></tt>
* Calls set(URIString), and @c validate(baseURI).
* @param baseURI Base URI to resolve against.
* @param URIString String designating this URI.
*/
daeURI(const daeURI& baseURI, const std::string& URIString);
/**
* Constructs a daeURI object based on a simple copy from an existing @c daeURI.
* @param constructFromURI URI to copy into this one.
*/
daeURI(const daeURI& constructFromURI);
/**
* Constructs a daeURI given a container element and a URI string.
* @param container The container element.
* @param uriString the URI string.
*/
daeURI(daeElement& container, const std::string& uriString = "");
// This constructor is for internal DOM purposes only. For client code, use the constructor
// that takes only a daeElement instead of this one.
daeURI(DAE& dae, daeElement& container, const std::string& uriString = "");
/**
* Gets the DAE objects associated with this daeURI.
* @return Returns a pointer to the associated DAE. This will never return null.
*/
DAE* getDAE() const;
// Returns the fully resolved URI as a string
const std::string& str() const;
// Returns the URI as originally set (i.e. not resolved against the base URI)
const std::string& originalStr() const;
// Old C string versions of the previous functions
daeString getURI() const; // Alias for str()
daeString getOriginalURI() const; // Alias for originalStr();
// Setter function for setting the full uri.
void set(const std::string& uriStr, const daeURI* baseURI = NULL);
// Setter function for setting the individual uri components.
void set(const std::string& scheme,
const std::string& authority,
const std::string& path,
const std::string& query,
const std::string& fragment,
const daeURI* baseURI = NULL);
// Old C string function. Alias for set().
void setURI(daeString uriStr, const daeURI* baseURI = NULL);
// std::string based component accessors.
const std::string& scheme() const;
const std::string& authority() const;
const std::string& path() const;
const std::string& query() const;
const std::string& fragment() const;
const std::string& id() const; // Alias for fragment()
// Component setter functions. If you're going to be calling multiple setters, as in
// uri.path(path);
// uri.fragment(frag);
// it'd be more efficient to call uri.set once instead.
void scheme(const std::string& scheme);
void authority(const std::string& authority);
void path(const std::string& path);
void query(const std::string& query);
void fragment(const std::string& fragment);
void id(const std::string& id); // Alias for uri.fragment(frag)
// Retrieves the individual path components. For example, in a uri of the form
// file:/folder/file.dae, dir = /folder/, baseName = file, ext = .dae
void pathComponents(std::string& dir, std::string& baseName, std::string& ext) const;
// Individual path component accessors. If you need access to multiple path
// components, calling pathComponents() will be faster.
std::string pathDir() const; // daeURI("/folder/file.dae").pathDir() == "/folder/"
std::string pathFileBase() const; // daeURI("/folder/file.dae").pathFileBase() == "file"
std::string pathExt() const; // daeURI("/folder/file.dae").pathExt() == ".dae"
std::string pathFile() const; // daeURI("/folder/file.dae").pathFile() == "file.dae"
// Path component setter.
void path(const std::string& dir, const std::string& baseName, const std::string& ext);
// Individual path component setters. If you're going to be calling multiple setters,
// it'd be more efficient to call set() instead.
void pathDir(const std::string& dir);
void pathFileBase(const std::string& baseName);
void pathExt(const std::string& ext);
void pathFile(const std::string& file);
// The older C string accessors. Aliases for the std::string based component accessors.
daeString getScheme() const;
daeString getProtocol() const; // Alias for getScheme()
daeString getAuthority() const;
daeString getPath() const;
daeString getQuery() const;
daeString getFragment() const;
daeString getID() const; // Alias for getFragment()
// Same as getPath(), but puts the result in the destination buffer. This is only here
// for backward compatibility. Use getPath() instead.
daeBool getPath(daeChar* dest, daeInt size) const;
/**
* Gets the element that this URI resolves to in memory.
* @return Returns a ref to the element.
*/
daeElementRef getElement() const;
// Returns the document that this URI references, or null if the document
// hasn't been loaded yet.
daeDocument* getReferencedDocument() const;
/**
* 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 cont Pointer to the containing @c daeElmement.
*/
void setContainer(daeElement* container);
/**
* 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;
/**
* 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(const 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 makeRelativeTo(const daeURI* uri);
/**
* Comparison operator.
* @return Returns true if URI's are equal.
*/
inline bool operator==(const daeURI& other) const {
return uriString == other.uriString;
}
daeURI& operator=(const daeURI& other);
daeURI& operator=(const std::string& uri);
// These methods are deprecated.
void resolveElement(); // Call getElement directly.
void validate(const daeURI* baseURI = NULL); // Shouldn't ever need to call this.
ResolveState getState() const; // Call getElement to see if resolving succeeded.
void setState(ResolveState newState); // Don't call this.
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:
/**
* 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.
* Every URI is passed through this list of @c daeURIResolvers for resolution.
* The list is ordered on a first come, first serve basis, and resolution
* terminates after any resolver instance resolves the URI.
*/
class DLLSPEC daeURIResolver
{
public:
/**
* Constructor
* @param dae The associated dae object.
*/
daeURIResolver(DAE& dae);
/**
* Destructor
*/
virtual ~daeURIResolver();
/**
* 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 );
/**
* 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();
/**
* Provides an abstract interface for converting a @c daeURI into a @c daeElement
* @param uri @c daeURI to resolve.
* @return Returns the resolved element, or null if resolving failed.
* returns false otherwise.
*/
virtual daeElement* resolveElement(const daeURI& uri) = 0;
/**
* Gets the name of this resolver.
* @return Returns the resolver name as a string.
*/
virtual daeString getName() = 0;
protected:
static daeBool _loadExternalDocuments;
DAE* dae;
};
// This is a container class for storing a modifiable list of daeURIResolver objects.
class DLLSPEC daeURIResolverList {
public:
daeURIResolverList();
~daeURIResolverList();
daeTArray<daeURIResolver*>& list();
daeElement* resolveElement(const daeURI& uri);
private:
// Disabled copy constructor/assignment operator
daeURIResolverList(const daeURIResolverList& resolverList) { };
daeURIResolverList& operator=(const daeURIResolverList& resolverList) { return *this; };
daeTArray<daeURIResolver*> resolvers;
};
// Helper functions for file path <--> URI conversion
namespace cdom {
// Takes a uri reference and parses it into its components.
DLLSPEC bool parseUriRef(const std::string& uriRef,
std::string& scheme,
std::string& authority,
std::string& path,
std::string& query,
std::string& fragment);
// Takes the uri components of a uri ref and combines them.
//
// The 'forceLibxmlCompatible' param is meant to work around bugs in the file
// scheme uri handling of libxml. It causes the function to output a uri
// that's fully compatible with libxml. It only modifies file scheme uris,
// since uris with other schemes seem to work fine.
//
// The known libxml uri bugs are as follows:
// 1) libxml won't write files when given file scheme URIs with an empty
// authority, as in "file:/home".
// 2) libxml won't read or write Windows UNC paths represented with the
// machine name in the authority, as in "file://otherMachine/folder/file.dae"
// 3) On Windows, libxml won't read or write paths that don't have a drive
// letter, as in "/folder/file.dae".
DLLSPEC std::string assembleUri(const std::string& scheme,
const std::string& authority,
const std::string& path,
const std::string& query,
const std::string& fragment,
bool forceLibxmlCompatible = false);
// A wrapper function for calling assembleUri to create a URI that's compatible
// with libxml.
DLLSPEC std::string fixUriForLibxml(const std::string& uriRef);
// This function takes a file path in the OS's native format and converts it to
// a URI reference. If a relative path is given, a relative URI reference is
// returned. If an absolute path is given, a relative URI reference containing
// a fully specified path is returned. Spaces are encoded as %20. The 'type'
// parameter indicates the format of the nativePath.
//
// Examples - Windows
// nativePathToUri("C:\myFolder\myFile.dae") --> "/C:/myFolder/myFile.dae"
// nativePathToUri("\myFolder\myFile.dae") --> "/myFolder/myFile.dae"
// nativePathToUri("..\myFolder\myFile.dae") --> "../myFolder/myFile.dae"
// nativePathToUri("\\otherComputer\myFile.dae") --> "//otherComputer/myFile.dae"
//
// Examples - Linux/Mac
// nativePathToUri("/myFolder/myFile.dae") --> "/myFolder/myFile.dae"
// nativePathToUri("../myFolder/myFile.dae") --> "../myFolder/myFile.dae"
// nativePathToUri("/my folder/my file.dae") --> "/my%20folder/my%20file.dae"
DLLSPEC std::string nativePathToUri(const std::string& nativePath,
systemType type = getSystemType());
// This function takes a URI reference and converts it to an OS file path. Conversion
// can fail if the URI reference is ill-formed, or if the URI contains a scheme other
// than "file", in which case an empty string is returned. The 'type' parameter
// indicates the format of the returned native path.
//
// Examples - Windows
// uriToNativePath("../folder/file.dae") --> "..\folder\file.dae"
// uriToNativePath("/folder/file.dae") --> "\folder\file.dae"
// uriToNativePath("file:/C:/folder/file.dae") --> "C:\folder\file.dae"
// uriToNativePath("file://otherComputer/file.dae") --> "\\otherComputer\file.dae"
// uriToNativePath("http://www.slashdot.org") --> "" (it's not a file scheme URI!)
//
// Examples - Linux/Mac
// uriToNativePath("../folder/file.dae") --> "../folder/file.dae"
// uriToNativePath("file:/folder/file.dae") --> "/folder/file.dae"
// uriToNativePath("http://www.slashdot.org") --> "" (it's not a file scheme URI!)
DLLSPEC std::string uriToNativePath(const std::string& uriRef,
systemType type = getSystemType());
DLLSPEC std::string filePathToUri(const std::string& filePath); // Alias for nativePathToUri
DLLSPEC std::string uriToFilePath(const std::string& uriRef); // Alias for uriToNativePath
}
#endif //__DAE_URI_H__

View file

@ -0,0 +1,67 @@
// A home for commonly used utility functions. These are mostly for internal DOM
// use, but the automated tests use some of these functions, so we'll export
// them.
#ifndef daeUtils_h
#define daeUtils_h
#include <string>
#include <sstream>
#include <list>
#include <vector>
#include <dae/daePlatform.h>
namespace cdom {
// System type info. We only need to distinguish between Posix and Winodws for now.
enum systemType {
Posix,
Windows
};
// Get the system type at runtime.
DLLSPEC systemType getSystemType();
// String replace function. Usage: replace("abcdef", "cd", "12") --> "ab12ef".
DLLSPEC std::string replace(const std::string& s,
const std::string& replace,
const std::string& replaceWith);
// Usage:
// tokenize("this/is some#text", "/#", true) --> ("this" "/" "is some" "#" "text")
// tokenize("this is some text", " ", false) --> ("this" "is" "some" "text")
DLLSPEC std::list<std::string> tokenize(const std::string& s,
const std::string& separators,
bool separatorsInResult = false);
// Same as the previous function, but returns the result via a parameter to avoid an object copy.
DLLSPEC void tokenize(const std::string& s,
const std::string& separators,
/* out */ std::list<std::string>& tokens,
bool separatorsInResult = false);
typedef std::list<std::string>::iterator tokenIter;
DLLSPEC std::vector<std::string> makeStringArray(const char* s, ...);
DLLSPEC std::list<std::string> makeStringList(const char* s, ...);
DLLSPEC std::string getCurrentDir();
DLLSPEC std::string getCurrentDirAsUri();
DLLSPEC int strcasecmp(const char* str1, const char* str2);
DLLSPEC std::string tolower(const std::string& s);
// Disable VS warning
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4267)
#endif
template<typename T>
std::string toString(const T& val) {
std::ostringstream stream;
stream << val;
return stream.str();
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}
#endif

View file

@ -0,0 +1,58 @@
/*
* 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 __int8
#define PLATFORM_INT16 __int16
#define PLATFORM_INT32 __int32
#define PLATFORM_INT64 __int64
#define PLATFORM_UINT8 unsigned __int8
#define PLATFORM_UINT16 unsigned __int16
#define PLATFORM_UINT32 unsigned __int32
#define PLATFORM_UINT64 unsigned __int64
#define PLATFORM_FLOAT32 float
#define PLATFORM_FLOAT64 double
#if _MSC_VER <= 1200
typedef int intptr_t;
#endif
#ifdef DOM_DYNAMIC
#ifdef DOM_EXPORT
#define DLLSPEC __declspec( dllexport )
#else
#define DLLSPEC __declspec( dllimport )
#endif
#else
#define DLLSPEC
#endif
// GCC doesn't understand "#pragma warning"
#ifdef _MSC_VER
// class 'std::auto_ptr<_Ty>' needs to have dll-interface to be used by clients of class 'daeErrorHandler'
#pragma warning(disable: 4251)
// warning C4100: 'profile' : unreferenced formal parameter
#pragma warning(disable: 4100)
// warning C4355: 'this' : used in base member initializer list
#pragma warning(disable: 4355)
// warning C4512: 'daeDatabase' : assignment operator could not be generated
#pragma warning(disable: 4512)
// warning LNK4099: Missing pdb file for PCRE
#pragma warning(disable: 4099)
#endif
#endif

View file

@ -0,0 +1,146 @@
/*
* 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>
#include <dom/domTypes.h>
/**
* 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
{
friend class domAnyAttribute;
protected: // Attribute
/**
* The array of daeStrings to hold attribute data for this element.
*/
daeTArray<daeString> attrs;
/**
* 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;
/**
* Used to preserve order in elements that have a complex content model.
*/
daeUIntArray _contentsOrder;
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 ) { *(daeStringRef*)&_value = val; }
/**
* Gets the element type.
* @return Returns the COLLADA_TYPE::TypeEnum value corresponding to this element's type.
*/
virtual COLLADA_TYPE::TypeEnum getElementType() const { return COLLADA_TYPE::ANY; }
static daeInt ID() { return colladaTypeCount()-1; }
virtual daeInt typeID() const { return colladaTypeCount()-1; }
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 DLLSPEC daeBool setAttribute(daeString attrName, daeString attrValue);
public: // STATIC METHODS
/**
* Creates an instance of this class and returns a daeElementRef referencing it.
* @return a daeElementRef referencing an instance of this object.
*/
static DLLSPEC daeElementRef create(DAE& dae);
/**
* 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 DLLSPEC daeMetaElement* registerElement(DAE& dae);
};
typedef daeSmartRef<domAny> domAnyRef;
typedef daeTArray<domAnyRef> domAny_Array;
#endif