Aufgrund einer Wartung wird GitLab am 18.05. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 18.05. between 8:00 and 9:00 am.

Commit 3614834f authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Cleaning and renaming function maps

parent 74620282
/*
* --------------------------------------------------------------------------------------------
*
* VVV VVV A
* VVV VVV AAA Virtual Acoustics
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA Virtual Acoustics (VA)
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA
* VVVVVV AAA (c) Copyright Institut fr Technische Akustik (ITA)
* VVVV AAA RWTH Aachen (http://www.akustik.rwth-aachen.de)
* VVVVVV AAA (c) Copyright Institute of Technical Acoustics (ITA), 2015-2017
* VVVV AAA RWTH Aachen University (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* File: FunctionMappings.h
*
* Purpose: Reflexion mechanisms for the Matlab extension functions
*
* Authors: Frank Wefers (Frank.Wefers@akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
* --------------------------------------------------------------------------------------------
*/
// $Id: $
#ifndef __FUNCTIONMAPPINGS_H__
#define __FUNCTIONMAPPINGS_H__
#ifndef IW_FUNCTION_MAPPINGS
#define IW_FUNCTION_MAPPINGS
#include <assert.h>
#include <algorithm>
......@@ -31,19 +22,20 @@
#include <mex.h>
typedef void (CommandFunction)(int, mxArray**, int, const mxArray**);
typedef void ( CommandFunction )( int, mxArray**, int, const mxArray** );
class FunctionMapping;
void AddFunctionMapping(FunctionMapping* pFuncMapping);
void AddFunctionMapping( FunctionMapping* pFuncMapping );
class FunctionInputArgument;
void AddFunctionInputArgument(const std::string& sFuncName, FunctionInputArgument* pArg);
void AddFunctionInputArgument( const std::string& sFuncName, FunctionInputArgument* pArg );
class FunctionOutputArgument;
void AddFunctionOutputArgument(const std::string& sFuncName, FunctionOutputArgument* pArg);
void AddFunctionOutputArgument( const std::string& sFuncName, FunctionOutputArgument* pArg );
class FunctionInputArgument {
class FunctionInputArgument
{
public:
std::string sName;
std::string sType;
......@@ -51,94 +43,87 @@ public:
bool bOptional;
std::string sDefaultValue; // Default value expression in Matlab
FunctionInputArgument(const std::string& sFunctionName,
const std::string& sArgName,
const std::string& sArgType,
const std::string& sArgDesc,
bool bArgOptional,
const std::string& sArgDefaultValue)
: sName(sArgName),
sType(sArgType),
sDesc(sArgDesc),
bOptional(bArgOptional),
sDefaultValue(sArgDefaultValue)
inline FunctionInputArgument( const std::string& sFunctionName, const std::string& sArgName, const std::string& sArgType, const std::string& sArgDesc, bool bArgOptional, const std::string& sArgDefaultValue )
: sName( sArgName )
, sType( sArgType )
, sDesc( sArgDesc )
, bOptional( bArgOptional )
, sDefaultValue( sArgDefaultValue )
{
// Self register the argument globally
AddFunctionInputArgument(sFunctionName, this);
}
AddFunctionInputArgument( sFunctionName, this );
};
};
class FunctionOutputArgument {
class FunctionOutputArgument
{
public:
std::string sName;
std::string sType;
std::string sDesc;
FunctionOutputArgument(const std::string& sFunctionName,
const std::string& sArgName,
const std::string& sArgType,
const std::string& sArgDesc)
: sName(sArgName),
sType(sArgType),
sDesc(sArgDesc)
inline FunctionOutputArgument( const std::string& sFunctionName, const std::string& sArgName, const std::string& sArgType, const std::string& sArgDesc )
: sName( sArgName )
, sType( sArgType )
, sDesc( sArgDesc )
{
// Self register the argument globally
AddFunctionOutputArgument(sFunctionName, this);
}
AddFunctionOutputArgument( sFunctionName, this );
};
};
class FunctionMapping {
class FunctionMapping
{
public:
std::string sName;
CommandFunction* pAddr;
bool bPublic;
std::string sDesc;
std::string sDoc;
std::vector<FunctionInputArgument> vInputArgs;
std::vector<FunctionOutputArgument> vOutputArgs;
FunctionMapping(const std::string& sFunctionName,
CommandFunction* pFunctionAddr,
bool bPublicFunc,
const std::string& sFunctionDesc,
const std::string& sFunctionDoc)
: sName(sFunctionName),
pAddr(pFunctionAddr),
bPublic(bPublicFunc),
sDesc(sFunctionDesc)
std::vector< FunctionInputArgument > vInputArgs;
std::vector< FunctionOutputArgument > vOutputArgs;
FunctionMapping( const std::string& sFunctionName, CommandFunction* pFunctionAddr, bool bPublicFunc, const std::string& sFunctionDesc, const std::string& sFunctionDoc )
: sName( sFunctionName )
, pAddr( pFunctionAddr )
, bPublic( bPublicFunc )
, sDesc( sFunctionDesc )
{
// Self register the function globally
AddFunctionMapping(this);
}
AddFunctionMapping( this );
};
};
// Function list (map used for O(log N) lookups via function name)
typedef std::map< std::string, FunctionMapping >::iterator FunctionMapIterator;
std::map< std::string, FunctionMapping > g_mFunctionMap;
void AddFunctionMapping(FunctionMapping* pFuncMapping) {
std::string sUpperName(pFuncMapping->sName);
std::transform(sUpperName.begin(), sUpperName.end(), sUpperName.begin(), toupper);
g_mFunctionMap.insert( std::pair< std::string, FunctionMapping >(sUpperName, *pFuncMapping));
}
void AddFunctionMapping( FunctionMapping* pFuncMapping )
{
std::string sUpperName( pFuncMapping->sName );
std::transform( sUpperName.begin(), sUpperName.end(), sUpperName.begin(), toupper );
g_mFunctionMap.insert( std::pair< std::string, FunctionMapping >( sUpperName, *pFuncMapping ) );
};
void AddFunctionInputArgument(const std::string& sFuncName, FunctionInputArgument* pArg) {
std::string sUpperName(sFuncName);
std::transform(sUpperName.begin(), sUpperName.end(), sUpperName.begin(), toupper);
void AddFunctionInputArgument( const std::string& sFuncName, FunctionInputArgument* pArg )
{
std::string sUpperName( sFuncName );
std::transform( sUpperName.begin(), sUpperName.end(), sUpperName.begin(), toupper );
FunctionMapIterator it = g_mFunctionMap.find(sUpperName);
FunctionMapIterator it = g_mFunctionMap.find( sUpperName );
assert( it != g_mFunctionMap.end() );
it->second.vInputArgs.push_back( *pArg );
}
};
void AddFunctionOutputArgument(const std::string& sFuncName, FunctionOutputArgument* pArg) {
std::string sUpperName(sFuncName);
std::transform(sUpperName.begin(), sUpperName.end(), sUpperName.begin(), toupper);
inline void AddFunctionOutputArgument( const std::string& sFuncName, FunctionOutputArgument* pArg )
{
std::string sUpperName( sFuncName );
std::transform( sUpperName.begin(), sUpperName.end(), sUpperName.begin(), toupper );
FunctionMapIterator it = g_mFunctionMap.find(sUpperName);
FunctionMapIterator it = g_mFunctionMap.find( sUpperName );
assert( it != g_mFunctionMap.end() );
it->second.vOutputArgs.push_back( *pArg );
}
};
// INFO: Forward declare the function first. Allows to put documentation above the function body...
#define REGISTER_PUBLIC_FUNCTION(NAME, DESC, DOC) void NAME(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);\
......@@ -153,34 +138,36 @@ FunctionMapping g_oFuncMapping_##NAME(#NAME, &NAME, false, "", "")
#define DECLARE_FUNCTION_OUTARG(FUNCNAME, ARGNAME, ARGTYPE, ARGDESC) FunctionOutputArgument g_oFuncOutArg_##FUNCNAME##_##ARGNAME##(#FUNCNAME, #ARGNAME, ARGTYPE, ARGDESC)
mxArray* CreateFunctionInputArgumentStruct(std::vector<FunctionInputArgument>& vInputArgs) {
inline mxArray* CreateFunctionInputArgumentStruct( std::vector<FunctionInputArgument>& vInputArgs )
{
const mwSize nFields = 5;
const char* ppszFieldNames[] = {"name", "type", "desc", "optional", "default"};
const char* ppszFieldNames[] = { "name", "type", "desc", "optional", "default" };
mxArray* pStruct = mxCreateStructMatrix( 1, int( vInputArgs.size() ), nFields, ppszFieldNames );
for (size_t i=0; i<vInputArgs.size(); i++) {
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[0], mxCreateString(vInputArgs[i].sName.c_str()));
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[1], mxCreateString(vInputArgs[i].sType.c_str()));
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[2], mxCreateString(vInputArgs[i].sDesc.c_str()));
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[3], mxCreateLogicalScalar(vInputArgs[i].bOptional));
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[4], mxCreateString(vInputArgs[i].sDefaultValue.c_str()));
for( size_t i = 0; i < vInputArgs.size(); i++ ) {
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 0 ], mxCreateString( vInputArgs[ i ].sName.c_str() ) );
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 1 ], mxCreateString( vInputArgs[ i ].sType.c_str() ) );
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 2 ], mxCreateString( vInputArgs[ i ].sDesc.c_str() ) );
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 3 ], mxCreateLogicalScalar( vInputArgs[ i ].bOptional ) );
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 4 ], mxCreateString( vInputArgs[ i ].sDefaultValue.c_str() ) );
}
return pStruct;
}
};
mxArray* CreateFunctionOutputArgumentStruct(std::vector<FunctionOutputArgument>& vOutputArgs) {
inline mxArray* CreateFunctionOutputArgumentStruct( std::vector<FunctionOutputArgument>& vOutputArgs )
{
const mwSize nFields = 3;
const char* ppszFieldNames[] = {"name", "type", "desc"};
const char* ppszFieldNames[] = { "name", "type", "desc" };
mxArray* pStruct = mxCreateStructMatrix( 1, int( vOutputArgs.size() ), nFields, ppszFieldNames );
for (size_t i=0; i<vOutputArgs.size(); i++) {
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[0], mxCreateString(vOutputArgs[i].sName.c_str()));
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[1], mxCreateString(vOutputArgs[i].sType.c_str()));
mxSetField(pStruct, (mwIndex) i, ppszFieldNames[2], mxCreateString(vOutputArgs[i].sDesc.c_str()));
for( size_t i = 0; i < vOutputArgs.size(); i++ ) {
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 0 ], mxCreateString( vOutputArgs[ i ].sName.c_str() ) );
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 1 ], mxCreateString( vOutputArgs[ i ].sType.c_str() ) );
mxSetField( pStruct, ( mwIndex ) i, ppszFieldNames[ 2 ], mxCreateString( vOutputArgs[ i ].sDesc.c_str() ) );
}
return pStruct;
}
};
#endif __FUNCTIONMAPPINGS_H__
#endif IW_FUNCTION_MAPPINGS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment