From 58f99165451e39bab63f5d98177276d1e15e787c Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 23 Oct 2023 11:44:51 -0400 Subject: [PATCH] Simply attribute getters for complex values --- include/openPMD/binding/c/backend/Attributable.h | 9 +++------ src/binding/c/backend/Attributable.c | 12 +++--------- src/binding/c/backend/Attributable.cpp | 7 +++---- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/openPMD/binding/c/backend/Attributable.h b/include/openPMD/binding/c/backend/Attributable.h index dc7260efb2..6d8fb0b562 100644 --- a/include/openPMD/binding/c/backend/Attributable.h +++ b/include/openPMD/binding/c/backend/Attributable.h @@ -147,18 +147,15 @@ extern "C" bool openPMD_Attributable_getAttribute_cfloat2( const openPMD_Attributable *attributable, const char *key, - float *value_re, - float *value_im); + float *value); bool openPMD_Attributable_getAttribute_cdouble2( const openPMD_Attributable *attributable, const char *key, - double *value_re, - double *value_im); + double *value); bool openPMD_Attributable_getAttribute_clong_double2( const openPMD_Attributable *attributable, const char *key, - long double *value_re, - long double *value_im); + long double *value); #ifndef __cplusplus bool openPMD_Attributable_getAttribute_cfloat( const openPMD_Attributable *attributable, diff --git a/src/binding/c/backend/Attributable.c b/src/binding/c/backend/Attributable.c index c44f9c1503..c0beb3dfd7 100644 --- a/src/binding/c/backend/Attributable.c +++ b/src/binding/c/backend/Attributable.c @@ -29,7 +29,7 @@ bool openPMD_Attributable_getAttribute_cfloat( complex float *value) { return openPMD_Attributable_getAttribute_cfloat2( - attributable, key, (float *)(void *)value, (float *)(void *)value + 1); + attributable, key, (float *)value); } bool openPMD_Attributable_getAttribute_cdouble( @@ -38,10 +38,7 @@ bool openPMD_Attributable_getAttribute_cdouble( complex double *value) { return openPMD_Attributable_getAttribute_cdouble2( - attributable, - key, - (double *)(void *)value, - (double *)(void *)value + 1); + attributable, key, (double *)value); } bool openPMD_Attributable_getAttribute_clong_double( @@ -50,8 +47,5 @@ bool openPMD_Attributable_getAttribute_clong_double( complex long double *value) { return openPMD_Attributable_getAttribute_clong_double2( - attributable, - key, - (long double *)(void *)value, - (long double *)(void *)value + 1); + attributable, key, (long double *)value); } diff --git a/src/binding/c/backend/Attributable.cpp b/src/binding/c/backend/Attributable.cpp index 4391a108c3..b913a7ae5d 100644 --- a/src/binding/c/backend/Attributable.cpp +++ b/src/binding/c/backend/Attributable.cpp @@ -91,8 +91,7 @@ openPMD_Datatype openPMD_Attributable_attributeDatatype( bool openPMD_Attributable_getAttribute_##NAME##2( \ const openPMD_Attributable *attributable, \ const char *key, \ - TYPE *value_re, \ - TYPE *value_im) \ + TYPE *value) \ { \ const auto cxx_attributable = \ (const openPMD::Attributable *)attributable; \ @@ -102,8 +101,8 @@ openPMD_Datatype openPMD_Attributable_attributeDatatype( cxx_attribute.getOptional>(); \ if (!cxx_value) \ return false; \ - *value_re = cxx_value->real(); \ - *value_im = cxx_value->imag(); \ + value[0] = cxx_value->real(); \ + value[1] = cxx_value->imag(); \ return true; \ }