Skip to content

Commit

Permalink
some steps ahead
Browse files Browse the repository at this point in the history
  • Loading branch information
ptahmose committed Oct 6, 2024
1 parent a6a6ae0 commit 67002f2
Show file tree
Hide file tree
Showing 16 changed files with 519 additions and 185 deletions.
105 changes: 56 additions & 49 deletions AppModel/include/app_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,87 +7,94 @@ extern "C" {
#include <stdint.h>
#include <stdbool.h>

typedef void* Parameter;
typedef void* Parameter;

enum AppExtensionClassId
{
AppExtensionClassId_Unknown,
AppExtensionClassId_Uint8,
AppExtensionClassId_Int8,
AppExtensionClassId_Uint16,
AppExtensionClassId_Int16,
AppExtensionClassId_Uint32,
AppExtensionClassId_Int32,
AppExtensionClassId_Uint64,
AppExtensionClassId_Int64,
AppExtensionClassId_Double,
AppExtensionClassId_Single,
};
enum AppExtensionClassId
{
AppExtensionClassId_Unknown,
AppExtensionClassId_Uint8,
AppExtensionClassId_Int8,
AppExtensionClassId_Uint16,
AppExtensionClassId_Int16,
AppExtensionClassId_Uint32,
AppExtensionClassId_Int32,
AppExtensionClassId_Uint64,
AppExtensionClassId_Int64,
AppExtensionClassId_Double,
AppExtensionClassId_Single,
AppExtensionClassId_Logical,
};

struct IAppExtensionFunctions
{
bool (*pfn_IsNanOrInfDouble)(double d);
struct IAppExtensionFunctions
{
bool (*pfn_IsNanOrInfDouble)(double d);

bool (*pfn_IsNanOrInfSingle)(float f);
bool (*pfn_IsNanOrInfSingle)(float f);

void* (*pfn_GetData)(const Parameter* parameter);
double (*pfn_GetInfDouble)(void);

uint8_t* (*pfn_GetUint8s)(const Parameter* parameter);
double (*pfn_GetNaNDouble)(void);

int8_t* (*pfn_GetInt8s)(const Parameter* parameter);
void* (*pfn_GetData)(const Parameter* parameter);

uint16_t* (*pfn_GetUint16s)(const Parameter* parameter);
uint8_t* (*pfn_GetUint8s)(const Parameter* parameter);

int16_t* (*pfn_GetInt16s)(const Parameter* parameter);
int8_t* (*pfn_GetInt8s)(const Parameter* parameter);

uint32_t* (*pfn_GetUint32s)(const Parameter* parameter);
uint16_t* (*pfn_GetUint16s)(const Parameter* parameter);

int32_t* (*pfn_GetInt32s)(const Parameter* parameter);
int16_t* (*pfn_GetInt16s)(const Parameter* parameter);

uint64_t* (*pfn_GetUint64s)(const Parameter* parameter);
uint32_t* (*pfn_GetUint32s)(const Parameter* parameter);

int64_t* (*pfn_GetInt64s)(const Parameter* parameter);
int32_t* (*pfn_GetInt32s)(const Parameter* parameter);

double* (*pfn_GetDoubles)(const Parameter* parameter);
uint64_t* (*pfn_GetUint64s)(const Parameter* parameter);

float* (*pfn_GetSingles)(const Parameter* parameter);
int64_t* (*pfn_GetInt64s)(const Parameter* parameter);

bool (*pfn_IsNumeric)(const Parameter* parameter);
double* (*pfn_GetDoubles)(const Parameter* parameter);

bool (*pfn_IsChar)(const Parameter* parameter);
float* (*pfn_GetSingles)(const Parameter* parameter);

bool (*pfn_IsSparse)(const Parameter* parameter);
bool* (*pfn_GetLogicals)(const Parameter* parameter);

bool (*pfn_IsStruct)(const Parameter* parameter);
bool (*pfn_IsNumeric)(const Parameter* parameter);

Parameter* (*pfn_CreateString)(const char* string);
bool (*pfn_IsChar)(const Parameter* parameter);

void (*pfn_ReportErrorAndRaiseSignal)(const char* identifier, const char* message);
bool (*pfn_IsSparse)(const Parameter* parameter);

char* (*pfn_StrDupHostAllocated)(const char* string);
bool (*pfn_IsStruct)(const Parameter* parameter);

Parameter* (*pfn_CreateStructArray)(size_t ndim, const size_t* dims, int nfields, const char** field_names);
Parameter* (*pfn_CreateString)(const char* string);

void (*pfn_SetFieldByNumber)(Parameter* pa, size_t i, int fieldnum, Parameter* value);
void (*pfn_ReportErrorAndRaiseSignal)(const char* identifier, const char* message);

char* (*pfn_ConvertToUTF8String)(const Parameter* parameter);
char* (*pfn_StrDupHostAllocated)(const char* string);

void (*pfn_Free)(void* ptr);
Parameter* (*pfn_CreateStructArray)(size_t ndim, const size_t* dims, int nfields, const char** field_names);

Parameter* (*pfn_CreateNumericMatrixReal)(size_t m, size_t n, enum AppExtensionClassId class_id);
void (*pfn_SetFieldByNumber)(Parameter* pa, size_t i, int fieldnum, Parameter* value);

enum AppExtensionClassId (*pfn_GetClassId)(const Parameter* parameter);
char* (*pfn_ConvertToUTF8String)(const Parameter* parameter);

size_t (*pfn_GetNumberOfElements)(const Parameter* parameter);
void (*pfn_Free)(void* ptr);

size_t(*pfn_GetNumberOfDimensions)(const Parameter* parameter);
Parameter* (*pfn_CreateNumericMatrixReal)(size_t m, size_t n, enum AppExtensionClassId class_id);

void (*pfn_GetSizeOfDimensions)(const Parameter* parameter, size_t number_of_dimension, size_t* sizes);
enum AppExtensionClassId(*pfn_GetClassId)(const Parameter* parameter);

Parameter* (*pfn_GetField)(const Parameter* parameter, const char* field_name);
size_t(*pfn_GetNumberOfElements)(const Parameter* parameter);

Parameter* (*pfn_CreateNumericArrayReal)(size_t ndim, const size_t* dims, enum AppExtensionClassId class_id);
};
size_t(*pfn_GetNumberOfDimensions)(const Parameter* parameter);

void (*pfn_GetSizeOfDimensions)(const Parameter* parameter, size_t number_of_dimension, size_t* sizes);

Parameter* (*pfn_GetField)(const Parameter* parameter, const char* field_name);

Parameter* (*pfn_CreateNumericArrayReal)(size_t ndim, const size_t* dims, enum AppExtensionClassId class_id);
};

#ifdef __cplusplus
}
Expand Down
105 changes: 78 additions & 27 deletions MatlabMex/app_api_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ bool matlabMexIsNanOrInfSingle(float value)
return mxIsNaN(value) || mxIsInf(value);
}

double matlabMaxGetInfinityDouble(void)
{
return mxGetInf();
}

double matlabMaxGetNaNDouble(void)
{
return mxGetNaN();
}

void* matlabMexGetData(const Parameter* parameter)
{
return mxGetData((const mxArray*)parameter);
Expand Down Expand Up @@ -67,6 +77,11 @@ float* matlabMexGetSingles(const Parameter* parameter)
return mxGetSingles((const mxArray*)parameter);
}

bool* matlabMexGetLogicals(const Parameter* parameter)
{
return mxGetLogicals((const mxArray*)parameter);
}

bool matlabMexIsNumeric(const Parameter* parameter)
{
return mxIsNumeric((const mxArray*)parameter);
Expand Down Expand Up @@ -126,45 +141,76 @@ void matlabFree(void* ptr)
mxFree(ptr);
}

Parameter* matlabCreateNumericMatrixReal(size_t m, size_t n, enum AppExtensionClassId class_id)
mxClassID AppExtensionClassIdToMxClassId(enum AppExtensionClassId class_id)
{
mxClassID mx_class_id;
switch (class_id)
{
case AppExtensionClassId_Uint8:
mx_class_id = mxUINT8_CLASS;
break;
return mxUINT8_CLASS;
case AppExtensionClassId_Int8:
mx_class_id = mxINT8_CLASS;
break;
return mxINT8_CLASS;
case AppExtensionClassId_Uint16:
mx_class_id = mxUINT16_CLASS;
break;
return mxUINT16_CLASS;
case AppExtensionClassId_Int16:
mx_class_id = mxINT16_CLASS;
break;
return mxINT16_CLASS;
case AppExtensionClassId_Uint32:
mx_class_id = mxUINT32_CLASS;
break;
return mxUINT32_CLASS;
case AppExtensionClassId_Int32:
mx_class_id = mxINT32_CLASS;
break;
return mxINT32_CLASS;
case AppExtensionClassId_Uint64:
mx_class_id = mxUINT64_CLASS;
break;
return mxUINT64_CLASS;
case AppExtensionClassId_Int64:
mx_class_id = mxINT64_CLASS;
break;
return mxINT64_CLASS;
case AppExtensionClassId_Double:
mx_class_id = mxDOUBLE_CLASS;
break;
return mxDOUBLE_CLASS;
case AppExtensionClassId_Single:
mx_class_id = mxSINGLE_CLASS;
break;
return mxSINGLE_CLASS;
case AppExtensionClassId_Logical:
return mxLOGICAL_CLASS;
default:
mx_class_id = mxUNKNOWN_CLASS;
break;
return mxUNKNOWN_CLASS;
}
}

Parameter* matlabCreateNumericMatrixReal(size_t m, size_t n, enum AppExtensionClassId class_id)
{
mxClassID mx_class_id = AppExtensionClassIdToMxClassId(class_id);
//switch (class_id)
//{
//case AppExtensionClassId_Uint8:
// mx_class_id = mxUINT8_CLASS;
// break;
//case AppExtensionClassId_Int8:
// mx_class_id = mxINT8_CLASS;
// break;
//case AppExtensionClassId_Uint16:
// mx_class_id = mxUINT16_CLASS;
// break;
//case AppExtensionClassId_Int16:
// mx_class_id = mxINT16_CLASS;
// break;
//case AppExtensionClassId_Uint32:
// mx_class_id = mxUINT32_CLASS;
// break;
//case AppExtensionClassId_Int32:
// mx_class_id = mxINT32_CLASS;
// break;
//case AppExtensionClassId_Uint64:
// mx_class_id = mxUINT64_CLASS;
// break;
//case AppExtensionClassId_Int64:
// mx_class_id = mxINT64_CLASS;
// break;
//case AppExtensionClassId_Double:
// mx_class_id = mxDOUBLE_CLASS;
// break;
//case AppExtensionClassId_Single:
// mx_class_id = mxSINGLE_CLASS;
// break;
//default:
// mx_class_id = mxUNKNOWN_CLASS;
// break;
//}

return (Parameter*)mxCreateNumericMatrix(m, n, mx_class_id, mxREAL);
}
Expand Down Expand Up @@ -194,6 +240,8 @@ enum AppExtensionClassId matlabGetClassId(const Parameter* parameter)
return AppExtensionClassId_Double;
case mxSINGLE_CLASS:
return AppExtensionClassId_Single;
case mxLOGICAL_CLASS:
return AppExtensionClassId_Logical;
default:
return AppExtensionClassId_Unknown;
}
Expand Down Expand Up @@ -230,8 +278,8 @@ Parameter* matlabGetField(const Parameter* parameter, const char* field_name)

Parameter* matlabCreateNumericArrayReal(size_t ndim, const size_t* dims, enum AppExtensionClassId class_id)
{
mxClassID mx_class_id;
switch (class_id)
mxClassID mx_class_id = AppExtensionClassIdToMxClassId(class_id);
/*switch (class_id)
{
case AppExtensionClassId_Uint8:
mx_class_id = mxUINT8_CLASS;
Expand Down Expand Up @@ -266,7 +314,7 @@ Parameter* matlabCreateNumericArrayReal(size_t ndim, const size_t* dims, enum Ap
default:
mx_class_id = mxUNKNOWN_CLASS;
break;
}
}*/

return (Parameter*)mxCreateNumericArray(ndim, dims, mx_class_id, mxREAL);
}
Expand All @@ -275,6 +323,8 @@ struct IAppExtensionFunctions g_appExtensionFunctions =
{
.pfn_IsNanOrInfDouble = matlabMexIsNanOrInfDouble,
.pfn_IsNanOrInfSingle = matlabMexIsNanOrInfSingle,
.pfn_GetInfDouble = matlabMaxGetInfinityDouble,
.pfn_GetNaNDouble = matlabMaxGetNaNDouble,
.pfn_GetData = matlabMexGetData,
.pfn_GetUint8s = matlabMexGetUint8s,
.pfn_GetInt8s = matlabMexGetInt8s,
Expand All @@ -286,6 +336,7 @@ struct IAppExtensionFunctions g_appExtensionFunctions =
.pfn_GetInt64s = matlabMexGetInt64s,
.pfn_GetDoubles = matlabMexGetDoubles,
.pfn_GetSingles = matlabMexGetSingles,
.pfn_GetLogicals = matlabMexGetLogicals,
.pfn_IsNumeric = matlabMexIsNumeric,
.pfn_IsChar = matlabMexIsChar,
.pfn_IsSparse = matlabMexIsSparse,
Expand Down
21 changes: 14 additions & 7 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ set (libSourceFiles
"src/implementation/CziReader.cpp"
"src/implementation/dbgprint.h"
"src/implementation/dbgprint.cpp"
"src/implementation/CziReaderSbBlkStore.cpp"
"src/implementation/CziReaderSbBlkStore.h"
"src/implementation/CziUtilities.cpp"
"src/implementation/CziUtilities.h"
"src/implementation/include_rapidjson.h"
"src/implementation/argsutils.h"
"src/implementation/CziReaderSbBlkStore.cpp"
"src/implementation/CziReaderSbBlkStore.h"
"src/implementation/CziUtilities.cpp"
"src/implementation/CziUtilities.h"
"src/implementation/include_rapidjson.h"
"src/implementation/argsutils.h"
"src/implementation/argsutils.cpp"
"src/implementation/CziWriter.cpp" "src/implementation/CziWriter.h")
"src/implementation/CziWriter.cpp"
"src/implementation/CziWriter.h"
"src/implementation/utils.cpp"
"src/implementation/utils.h"
"src/implementation/CziWriterManager.cpp"
"src/implementation/CziWriterManager.h"
"src/functions/func_open.cpp"
"src/functions/func_open.h" "src/functions/func_getsubblockbitmap.cpp" "src/functions/func_getsubblockbitmap.h")

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(lib_ENABLE_LOGGING 1)
Expand Down
Loading

0 comments on commit 67002f2

Please sign in to comment.