|
@@ -45,10 +45,116 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
#ifndef __AI_METADATA_H_INC__
|
|
#ifndef __AI_METADATA_H_INC__
|
|
#define __AI_METADATA_H_INC__
|
|
#define __AI_METADATA_H_INC__
|
|
|
|
|
|
|
|
+#include <stdint.h>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// -------------------------------------------------------------------------------
|
|
|
|
+/**
|
|
|
|
+ * Enum used to distinguish data types
|
|
|
|
+ */
|
|
|
|
+ // -------------------------------------------------------------------------------
|
|
|
|
+enum aiType
|
|
|
|
+{
|
|
|
|
+ AI_BOOL = 0,
|
|
|
|
+ AI_INT = 1,
|
|
|
|
+ AI_UINT64 = 2,
|
|
|
|
+ AI_FLOAT = 3,
|
|
|
|
+ AI_AISTRING = 4,
|
|
|
|
+ AI_AIVECTOR3D = 5,
|
|
|
|
+
|
|
|
|
+ FORCE_32BIT = INT_MAX
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// -------------------------------------------------------------------------------
|
|
|
|
+/**
|
|
|
|
+ * Metadata entry
|
|
|
|
+ *
|
|
|
|
+ * The type field uniquely identifies the underlying type of the data field
|
|
|
|
+ */
|
|
|
|
+ // -------------------------------------------------------------------------------
|
|
|
|
+struct aiMetaDataEntry
|
|
|
|
+{
|
|
|
|
+ aiType type;
|
|
|
|
+ void* data;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
#ifdef __cplusplus
|
|
#ifdef __cplusplus
|
|
-extern "C" {
|
|
|
|
|
|
+
|
|
|
|
+// -------------------------------------------------------------------------------
|
|
|
|
+/**
|
|
|
|
+ * Helper functions to get the aiType enum entry for a type
|
|
|
|
+ */
|
|
|
|
+ // -------------------------------------------------------------------------------
|
|
|
|
+inline aiType GetAiType( bool ) { return aiType::AI_BOOL; }
|
|
|
|
+inline aiType GetAiType( int ) { return aiType::AI_INT; }
|
|
|
|
+inline aiType GetAiType( uint64_t ) { return aiType::AI_UINT64; }
|
|
|
|
+inline aiType GetAiType( float ) { return aiType::AI_FLOAT; }
|
|
|
|
+inline aiType GetAiType( aiString ) { return aiType::AI_AISTRING; }
|
|
|
|
+inline aiType GetAiType( aiVector3D ) { return aiType::AI_AIVECTOR3D; }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// -------------------------------------------------------------------------------
|
|
|
|
+/**
|
|
|
|
+ * Transform
|
|
|
|
+ *
|
|
|
|
+ * Applies the callable, c, to the given data of the given type.
|
|
|
|
+ * The callable, c, is expected to have the following interface
|
|
|
|
+ *
|
|
|
|
+ * c( T* data )
|
|
|
|
+ *
|
|
|
|
+ * where T can be any type with a corresponding entry in the aiType enum.
|
|
|
|
+ */
|
|
|
|
+ // -------------------------------------------------------------------------------
|
|
|
|
+template<typename callable>
|
|
|
|
+inline void transform( aiType type, void* data, callable c )
|
|
|
|
+{
|
|
|
|
+ switch (type)
|
|
|
|
+ {
|
|
|
|
+ case aiType::AI_BOOL:
|
|
|
|
+ callable(static_cast<bool*>(data));
|
|
|
|
+ break;
|
|
|
|
+ case aiType::AI_INT:
|
|
|
|
+ callable(static_cast<int*>(data));
|
|
|
|
+ break;
|
|
|
|
+ case aiType::AI_UINT64:
|
|
|
|
+ callable(static_cast<uint64_t*>(data));
|
|
|
|
+ break;
|
|
|
|
+ case aiType::AI_FLOAT:
|
|
|
|
+ callable(static_cast<float*>(data));
|
|
|
|
+ break;
|
|
|
|
+ case aiType::AI_AISTRING:
|
|
|
|
+ callable(static_cast<aiString*>(data));
|
|
|
|
+ break;
|
|
|
|
+ case aiType::AI_AIVECTOR3D:
|
|
|
|
+ callable(static_cast<aiVector3D*>(data));
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ assert(false);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// -------------------------------------------------------------------------------
|
|
|
|
+/**
|
|
|
|
+ * Transform.
|
|
|
|
+ *
|
|
|
|
+ * This is a convenience overload for aiMetaDataEntry's.
|
|
|
|
+ */
|
|
|
|
+ // -------------------------------------------------------------------------------
|
|
|
|
+template<typename callable>
|
|
|
|
+inline void transform( aiMetaDataEntry entry, callable c )
|
|
|
|
+{ transform(entry.type, entry.data, c); }
|
|
|
|
+
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// -------------------------------------------------------------------------------
|
|
// -------------------------------------------------------------------------------
|
|
/**
|
|
/**
|
|
* Container for holding metadata.
|
|
* Container for holding metadata.
|
|
@@ -66,18 +172,17 @@ struct aiMetadata
|
|
|
|
|
|
/** Arrays of values, may not be NULL. Entries in this array may be NULL if the
|
|
/** Arrays of values, may not be NULL. Entries in this array may be NULL if the
|
|
* corresponding property key has no assigned value. */
|
|
* corresponding property key has no assigned value. */
|
|
- C_STRUCT aiString* mValues;
|
|
|
|
|
|
+ C_STRUCT aiMetaDataEntry* mValues;
|
|
|
|
|
|
#ifdef __cplusplus
|
|
#ifdef __cplusplus
|
|
|
|
|
|
/** Constructor */
|
|
/** Constructor */
|
|
aiMetadata()
|
|
aiMetadata()
|
|
- {
|
|
|
|
// set all members to zero by default
|
|
// set all members to zero by default
|
|
- mKeys = NULL;
|
|
|
|
- mValues = NULL;
|
|
|
|
- mNumProperties = 0;
|
|
|
|
- }
|
|
|
|
|
|
+ : mKeys(NULL)
|
|
|
|
+ , mValues(NULL)
|
|
|
|
+ , mNumProperties(0)
|
|
|
|
+ {}
|
|
|
|
|
|
|
|
|
|
/** Destructor */
|
|
/** Destructor */
|
|
@@ -86,27 +191,60 @@ struct aiMetadata
|
|
if (mKeys)
|
|
if (mKeys)
|
|
delete [] mKeys;
|
|
delete [] mKeys;
|
|
if (mValues)
|
|
if (mValues)
|
|
|
|
+ {
|
|
|
|
+ // Delete each metadata entry
|
|
|
|
+ for (unsigned i=0; i<mNumProperties; ++i)
|
|
|
|
+ transform(mValues[i], (void (*)(void*))(operator delete));
|
|
|
|
+ // Delete the metadata array
|
|
delete [] mValues;
|
|
delete [] mValues;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- inline bool Get(const aiString& key, aiString& value)
|
|
|
|
|
|
+
|
|
|
|
+ template<typename T>
|
|
|
|
+ inline void Set( unsigned index, const std::string& key, const T& value )
|
|
{
|
|
{
|
|
- for (unsigned i=0; i<mNumProperties; ++i) {
|
|
|
|
- if (mKeys[i]==key) {
|
|
|
|
- value=mValues[i];
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // In range assertion
|
|
|
|
+ assert(index < mNumProperties);
|
|
|
|
+
|
|
|
|
+ // Set metadata key
|
|
|
|
+ mKeys[index] = key;
|
|
|
|
+
|
|
|
|
+ // Set metadata type
|
|
|
|
+ mValues[index].type = GetAiType(value);
|
|
|
|
+ // Copy the given value to the dynamic storage
|
|
|
|
+ mValues[index].data = new T(value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ template<typename T>
|
|
|
|
+ inline bool Get( unsigned index, T& value )
|
|
|
|
+ {
|
|
|
|
+ // Return false if the output data type does
|
|
|
|
+ // not match the found value's data type
|
|
|
|
+ if (GetAiType(value) != mValues[index].type)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ // Otherwise, output the found value and
|
|
|
|
+ // return true
|
|
|
|
+ value = *static_cast<T*>(mValues[index].data);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ template<typename T>
|
|
|
|
+ inline bool Get( const aiString& key, T& value )
|
|
|
|
+ {
|
|
|
|
+ // Search for the given key
|
|
|
|
+ for (unsigned i=0; i<mNumProperties; ++i)
|
|
|
|
+ if (mKeys[i]==key)
|
|
|
|
+ return Get(i, value);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
#endif // __cplusplus
|
|
#endif // __cplusplus
|
|
};
|
|
};
|
|
|
|
|
|
-#ifdef __cplusplus
|
|
|
|
-} //extern "C" {
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
#endif // __AI_METADATA_H_INC__
|
|
#endif // __AI_METADATA_H_INC__
|
|
|
|
|
|
|
|
|