[D] Use non-templated loading code to slightly reduce binary size.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@547 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
klickverbot 2010-02-16 21:23:12 +00:00
parent 52228add3a
commit 552c64bf4d
1 changed files with 48 additions and 63 deletions

View File

@ -81,11 +81,11 @@ public:
} }
// Versioning // Versioning
bind( aiGetLegalString )( "aiGetLegalString" ); mixin( bindCode( "aiGetLegalString" ) );
bind( aiGetVersionMinor )( "aiGetVersionMinor" ); mixin( bindCode( "aiGetVersionMinor" ) );
bind( aiGetVersionMajor )( "aiGetVersionMajor" ); mixin( bindCode( "aiGetVersionMajor" ) );
bind( aiGetVersionRevision )( "aiGetVersionRevision" ); mixin( bindCode( "aiGetVersionRevision" ) );
bind( aiGetCompileFlags )( "aiGetCompileFlags" ); mixin( bindCode( "aiGetCompileFlags" ) );
// Check for version mismatch between the external, dynamically loaded // Check for version mismatch between the external, dynamically loaded
// library and the version the bindings were created against. // library and the version the bindings were created against.
@ -116,44 +116,44 @@ public:
} }
// General API // General API
bind( aiImportFile )( "aiImportFile" ); mixin( bindCode( "aiImportFile" ) );
bind( aiImportFileEx )( "aiImportFileEx" ); mixin( bindCode( "aiImportFileEx" ) );
bind( aiImportFileFromMemory )( "aiImportFileFromMemory" ); mixin( bindCode( "aiImportFileFromMemory" ) );
bind( aiApplyPostProcessing )( "aiApplyPostProcessing" ); mixin( bindCode( "aiApplyPostProcessing" ) );
bind( aiGetPredefinedLogStream )( "aiGetPredefinedLogStream" ); mixin( bindCode( "aiGetPredefinedLogStream" ) );
bind( aiAttachLogStream )( "aiAttachLogStream" ); mixin( bindCode( "aiAttachLogStream" ) );
bind( aiEnableVerboseLogging )( "aiEnableVerboseLogging" ); mixin( bindCode( "aiEnableVerboseLogging" ) );
bind( aiDetachLogStream )( "aiDetachLogStream" ); mixin( bindCode( "aiDetachLogStream" ) );
bind( aiDetachAllLogStreams )( "aiDetachAllLogStreams" ); mixin( bindCode( "aiDetachAllLogStreams" ) );
bind( aiReleaseImport )( "aiReleaseImport" ); mixin( bindCode( "aiReleaseImport" ) );
bind( aiGetErrorString )( "aiGetErrorString" ); mixin( bindCode( "aiGetErrorString" ) );
bind( aiIsExtensionSupported )( "aiIsExtensionSupported" ); mixin( bindCode( "aiIsExtensionSupported" ) );
bind( aiGetExtensionList )( "aiGetExtensionList" ); mixin( bindCode( "aiGetExtensionList" ) );
bind( aiGetMemoryRequirements )( "aiGetMemoryRequirements" ); mixin( bindCode( "aiGetMemoryRequirements" ) );
bind( aiSetImportPropertyInteger )( "aiSetImportPropertyInteger" ); mixin( bindCode( "aiSetImportPropertyInteger" ) );
bind( aiSetImportPropertyFloat )( "aiSetImportPropertyFloat" ); mixin( bindCode( "aiSetImportPropertyFloat" ) );
bind( aiSetImportPropertyString )( "aiSetImportPropertyString" ); mixin( bindCode( "aiSetImportPropertyString" ) );
// Mathematical functions // Mathematical functions
bind( aiCreateQuaternionFromMatrix )( "aiCreateQuaternionFromMatrix" ); mixin( bindCode( "aiCreateQuaternionFromMatrix" ) );
bind( aiDecomposeMatrix )( "aiDecomposeMatrix" ); mixin( bindCode( "aiDecomposeMatrix" ) );
bind( aiTransposeMatrix4 )( "aiTransposeMatrix4" ); mixin( bindCode( "aiTransposeMatrix4" ) );
bind( aiTransposeMatrix3 )( "aiTransposeMatrix3" ); mixin( bindCode( "aiTransposeMatrix3" ) );
bind( aiTransformVecByMatrix3 )( "aiTransformVecByMatrix3" ); mixin( bindCode( "aiTransformVecByMatrix3" ) );
bind( aiTransformVecByMatrix4 )( "aiTransformVecByMatrix4" ); mixin( bindCode( "aiTransformVecByMatrix4" ) );
bind( aiMultiplyMatrix4 )( "aiMultiplyMatrix4" ); mixin( bindCode( "aiMultiplyMatrix4" ) );
bind( aiMultiplyMatrix3 )( "aiMultiplyMatrix3" ); mixin( bindCode( "aiMultiplyMatrix3" ) );
bind( aiIdentityMatrix3 )( "aiIdentityMatrix3" ); mixin( bindCode( "aiIdentityMatrix3" ) );
bind( aiIdentityMatrix4 )( "aiIdentityMatrix4" ); mixin( bindCode( "aiIdentityMatrix4" ) );
// Material system // Material system
bind( aiGetMaterialProperty )( "aiGetMaterialProperty" ); mixin( bindCode( "aiGetMaterialProperty" ) );
bind( aiGetMaterialFloatArray )( "aiGetMaterialFloatArray" ); mixin( bindCode( "aiGetMaterialFloatArray" ) );
bind( aiGetMaterialIntegerArray )( "aiGetMaterialIntegerArray" ); mixin( bindCode( "aiGetMaterialIntegerArray" ) );
bind( aiGetMaterialColor )( "aiGetMaterialColor" ); mixin( bindCode( "aiGetMaterialColor" ) );
bind( aiGetMaterialString )( "aiGetMaterialString" ); mixin( bindCode( "aiGetMaterialString" ) );
bind( aiGetMaterialTextureCount )( "aiGetMaterialTextureCount" ); mixin( bindCode( "aiGetMaterialTextureCount" ) );
bind( aiGetMaterialTexture )( "aiGetMaterialTexture" ); mixin( bindCode( "aiGetMaterialTexture" ) );
} }
++m_sRefCount; ++m_sRefCount;
} }
@ -172,33 +172,18 @@ public:
} }
private: private:
// The binding magic is heavily inspired by the Derelict loading code.
struct Binder {
public:
static Binder opCall( void** functionPointerAddress ) {
Binder binder;
binder.m_functionPointerAddress = functionPointerAddress;
return binder;
}
void opCall( char* name ) {
*m_functionPointerAddress = m_sLibrary.getSymbol( name );
}
private:
void** m_functionPointerAddress;
}
template bind( Function ) {
static Binder bind( inout Function a ) {
Binder binder = Binder( cast( void** ) &a );
return binder;
}
}
/// Current number of references to the library. /// Current number of references to the library.
static uint m_sRefCount; static uint m_sRefCount;
/// Library handle. /// Library handle.
static SharedLib m_sLibrary; static SharedLib m_sLibrary;
} }
/**
* Private helper function which constructs the bind command for a symbol to
* keep the code DRY.
*/
private char[] bindCode( char[] symbol ) {
return symbol ~ " = cast( typeof( " ~ symbol ~
" ) )m_sLibrary.getSymbol( `" ~ symbol ~ "` );";
}