diff --git a/src/serialbox-c/FortranWrapper.cpp b/src/serialbox-c/FortranWrapper.cpp index f05a3ae1..c385a756 100644 --- a/src/serialbox-c/FortranWrapper.cpp +++ b/src/serialbox-c/FortranWrapper.cpp @@ -260,41 +260,21 @@ void serialboxFortranSerializerAddMetainfoString(void* serializer, const char* k } } -void serialboxFortranSerializerGetMetainfoBoolean(const void* serializer, const char* key, int* value) { - const Serializer* ser = toConstSerializer(static_cast(serializer)); - try { - *value = (int) ser->template getGlobalMetainfoAs(key); - } catch(std::exception& e) { - serialboxFatalError(e.what()); +#define SERIALBOX_FORTRAN_SERIALIZER_GET_METAINFO(name, CXXType) \ + void serialboxFortranSerializerGetMetainfo##name(const void* serializer, const char* key, CXXType* value) { \ + const serialboxSerializer_t* ser = static_cast(serializer); \ + serialboxMetainfo_t* metainfo = serialboxSerializerGetGlobalMetainfo(ser); \ + *value = serialboxMetainfoGet##name(metainfo, key); \ } -} -void serialboxFortranSerializerGetMetainfoInt32(const void* serializer, const char* key, int* value) { - const Serializer* ser = toConstSerializer(static_cast(serializer)); - try { - *value = ser->template getGlobalMetainfoAs(key); - } catch(std::exception& e) { - serialboxFatalError(e.what()); - } -} +SERIALBOX_FORTRAN_SERIALIZER_GET_METAINFO(Boolean, bool); +SERIALBOX_FORTRAN_SERIALIZER_GET_METAINFO(Int32, int); +SERIALBOX_FORTRAN_SERIALIZER_GET_METAINFO(Float32, float); +SERIALBOX_FORTRAN_SERIALIZER_GET_METAINFO(Float64, double); +SERIALBOX_FORTRAN_SERIALIZER_GET_METAINFO(String, const char*); -void serialboxFortranSerializerGetMetainfoFloat32(const void* serializer, const char* key, float* value) { - const Serializer* ser = toConstSerializer(static_cast(serializer)); - try { - *value = ser->template getGlobalMetainfoAs(key); - } catch(std::exception& e) { - serialboxFatalError(e.what()); - } -} +#undef SERIALBOX_FORTRAN_SAVEPOINT_GET_METAINFO -void serialboxFortranSerializerGetMetainfoFloat64(const void* serializer, const char* key, double* value) { - const Serializer* ser = toConstSerializer(static_cast(serializer)); - try { - *value = ser->template getGlobalMetainfoAs(key); - } catch(std::exception& e) { - serialboxFatalError(e.what()); - } -} void serialboxFortranSerializerRegisterField(void* serializer, const char* name, int type, int bytesPerElement, int iSize, int jSize, int kSize, diff --git a/src/serialbox-c/Serializer.cpp b/src/serialbox-c/Serializer.cpp index 67274f3e..64418cd1 100644 --- a/src/serialbox-c/Serializer.cpp +++ b/src/serialbox-c/Serializer.cpp @@ -141,8 +141,8 @@ char* serialboxSerializerToString(const serialboxSerializer_t* serializer) { * Global Meta-information \*===------------------------------------------------------------------------------------------===*/ -serialboxMetainfo_t* serialboxSerializerGetGlobalMetainfo(serialboxSerializer_t* serializer) { - Serializer* ser = toSerializer(serializer); +serialboxMetainfo_t* serialboxSerializerGetGlobalMetainfo(const serialboxSerializer_t* serializer) { + const Serializer* ser = toConstSerializer(serializer); serialboxMetainfo_t* metaInfo = allocate(); metaInfo->impl = ser->globalMetainfoPtr().get(); metaInfo->ownsData = 0; diff --git a/src/serialbox-c/Serializer.h b/src/serialbox-c/Serializer.h index a4b1c178..4360486e 100644 --- a/src/serialbox-c/Serializer.h +++ b/src/serialbox-c/Serializer.h @@ -133,7 +133,7 @@ SERIALBOX_API char* serialboxSerializerToString(const serialboxSerializer_t* ser * \return global meta-information of the serializer */ SERIALBOX_API serialboxMetainfo_t* -serialboxSerializerGetGlobalMetainfo(serialboxSerializer_t* serializer); +serialboxSerializerGetGlobalMetainfo(const serialboxSerializer_t* serializer); /*===------------------------------------------------------------------------------------------===*\ * Register and Query Savepoints