Skip to content

Commit

Permalink
[C] Reimplemented getter for global meta-info in FortranWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Hovy committed Mar 8, 2018
1 parent 19cfb46 commit dc96842
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 34 deletions.
42 changes: 11 additions & 31 deletions src/serialbox-c/FortranWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const serialboxSerializer_t*>(serializer));
try {
*value = (int) ser->template getGlobalMetainfoAs<bool, const char*&>(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<const serialboxSerializer_t*>(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<const serialboxSerializer_t*>(serializer));
try {
*value = ser->template getGlobalMetainfoAs<int, const char*&>(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<const serialboxSerializer_t*>(serializer));
try {
*value = ser->template getGlobalMetainfoAs<float, const char*&>(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<const serialboxSerializer_t*>(serializer));
try {
*value = ser->template getGlobalMetainfoAs<double, const char*&>(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,
Expand Down
4 changes: 2 additions & 2 deletions src/serialbox-c/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<serialboxMetainfo_t>();
metaInfo->impl = ser->globalMetainfoPtr().get();
metaInfo->ownsData = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/serialbox-c/Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc96842

Please sign in to comment.