Skip to content

Commit

Permalink
Merge pull request #1169 from germasch/c_bindings
Browse files Browse the repository at this point in the history
C bindings fixes / updates
  • Loading branch information
williamfgc authored Feb 13, 2019
2 parents d3207cf + 52783b2 commit df98d9f
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 410 deletions.
41 changes: 15 additions & 26 deletions bindings/C/c/adios2_c_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,12 @@
#include "adios2/ADIOSMacros.h"
#include "adios2/core/AttributeBase.h"
#include "adios2/helper/adiosFunctions.h"
#include "adios2_c_internal.h"

#ifdef __cplusplus
extern "C" {
#endif

namespace
{
const std::map<std::string, std::vector<adios2_type>>
adios2_attribute_types_map = {
{"char", {adios2_type_signed_char}},
{"int", {adios2_type_int32_t}},
{"float", {adios2_type_float}},
{"double", {adios2_type_double}},
{"signed char", {adios2_type_int8_t}},
{"short", {adios2_type_int16_t}},
{"long int", {adios2_type_int64_t}},
{"long long int", {adios2_type_int64_t}},
{"string", {adios2_type_string}},
{"unsigned char", {adios2_type_uint8_t, adios2_type_unsigned_char}},
{"unsigned short", {adios2_type_uint16_t}},
{"unsigned int", {adios2_type_uint32_t}},
{"unsigned long int", {adios2_type_uint64_t}},
{"unsigned long long int", {adios2_type_uint64_t}},
};
} // end anonymous namespace

adios2_error adios2_attribute_name(char *name, size_t *size,
const adios2_attribute *attribute)
{
Expand Down Expand Up @@ -72,10 +52,19 @@ adios2_error adios2_attribute_type(adios2_type *type,
const adios2::core::AttributeBase *attributeBase =
reinterpret_cast<const adios2::core::AttributeBase *>(attribute);

auto itType = adios2_attribute_types_map.find(attributeBase->m_Type);
*type = (itType == adios2_attribute_types_map.end())
? adios2_type_unknown
: itType->second.front();
auto type_s = attributeBase->m_Type;
if (type_s == adios2::helper::GetType<std::string>())
{
*type = adios2_type_string;
}
#define make_case(T) \
else if (type_s == adios2::helper::GetType<MapAdios2Type<T>::Type>()) \
{ \
*type = T; \
}
ADIOS2_FOREACH_C_ATTRIBUTE_TYPE_1ARG(make_case)
#undef make_case
else { *type = adios2_type_unknown; }
return adios2_error_none;
}
catch (...)
Expand Down Expand Up @@ -213,7 +202,7 @@ adios2_error adios2_attribute_data(void *data, size_t *size,
*size = attributeCpp->m_Elements; \
} \
}
ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_TYPE_1ARG(
ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_STDTYPE_1ARG(
declare_template_instantiation)
#undef declare_template_instantiation

Expand Down
8 changes: 4 additions & 4 deletions bindings/C/c/adios2_c_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable,
*dynamic_cast<adios2::core::Variable<T> *>(variableBase), \
reinterpret_cast<const T *>(data), modeCpp); \
}
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

return adios2_error_none;
Expand Down Expand Up @@ -226,7 +226,7 @@ adios2_error adios2_put_by_name(adios2_engine *engine,
engineCpp.Put(variable_name, reinterpret_cast<const T *>(data), \
modeCpp); \
}
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
return adios2_error_none;
}
Expand Down Expand Up @@ -297,7 +297,7 @@ adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable,
*dynamic_cast<adios2::core::Variable<T> *>(variableBase), \
reinterpret_cast<T *>(values), modeCpp); \
}
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
return adios2_error_none;
}
Expand Down Expand Up @@ -342,7 +342,7 @@ adios2_error adios2_get_by_name(adios2_engine *engine,
{ \
engineCpp.Get(variable_name, reinterpret_cast<T *>(data), modeCpp); \
}
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
return adios2_error_none;
}
Expand Down
58 changes: 58 additions & 0 deletions bindings/C/c/adios2_c_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* adios2_c_internal.h
*
* Created on: Feb 9, 2019
* Author: Kai Germaschewski <[email protected]>
*/

#ifndef ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_H_
#define ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_H_

#include "adios2_c_types.h"

namespace
{
/**
* MapAdios2Type
* maps the C adios2_type enum to the actual C/C++ type,
* except string, which needs to be handled separately
*/
template <int adios2_type>
struct MapAdios2Type;

} // anonymous namespace

#include "adios2_c_internal.inl"

#define ADIOS2_FOREACH_C_TYPE_1ARG(MACRO) \
MACRO(adios2_type_int8_t) \
MACRO(adios2_type_int16_t) \
MACRO(adios2_type_int32_t) \
MACRO(adios2_type_int64_t) \
MACRO(adios2_type_uint8_t) \
MACRO(adios2_type_uint16_t) \
MACRO(adios2_type_uint32_t) \
MACRO(adios2_type_uint64_t) \
MACRO(adios2_type_float) \
MACRO(adios2_type_double) \
MACRO(adios2_type_float_complex) \
MACRO(adios2_type_double_complex)

// calls MACRO for all adios2_type attribute types except for adios2_type_string
#define ADIOS2_FOREACH_C_ATTRIBUTE_TYPE_1ARG(MACRO) \
MACRO(adios2_type_int8_t) \
MACRO(adios2_type_int16_t) \
MACRO(adios2_type_int32_t) \
MACRO(adios2_type_int64_t) \
MACRO(adios2_type_uint8_t) \
MACRO(adios2_type_uint16_t) \
MACRO(adios2_type_uint32_t) \
MACRO(adios2_type_uint64_t) \
MACRO(adios2_type_float) \
MACRO(adios2_type_double)

#endif /* ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_H_ */
48 changes: 48 additions & 0 deletions bindings/C/c/adios2_c_internal.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* adios2_c_internal.inl
*
* Created on: Feb 9, 2019
* Author: Kai Germaschewski <[email protected]>
*/

#ifndef ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_INL_
#define ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_INL_
#ifndef ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_H_
#error "Inline file should only be included from its header, never on its own"
#endif

namespace
{

// no default implementation, so only type below are
// supported

#define make_MapAdios2Type(adios2_type, T) \
template <> \
struct MapAdios2Type<adios2_type> \
{ \
using Type = T; \
};
/* clang-format off */
make_MapAdios2Type(adios2_type_int8_t, int8_t)
make_MapAdios2Type(adios2_type_int16_t, int16_t)
make_MapAdios2Type(adios2_type_int32_t, int32_t)
make_MapAdios2Type(adios2_type_int64_t, int64_t)
make_MapAdios2Type(adios2_type_uint8_t, uint8_t)
make_MapAdios2Type(adios2_type_uint16_t, uint16_t)
make_MapAdios2Type(adios2_type_uint32_t, uint32_t)
make_MapAdios2Type(adios2_type_uint64_t, uint64_t)
make_MapAdios2Type(adios2_type_float, float)
make_MapAdios2Type(adios2_type_double, double)
make_MapAdios2Type(adios2_type_float_complex, std::complex<float>)
make_MapAdios2Type(adios2_type_double_complex, std::complex<double>)
/* clang-format on */
#undef make_MapAdios2Type

} // namespace

#endif /* ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_INL_ */
Loading

0 comments on commit df98d9f

Please sign in to comment.