Skip to content

Commit

Permalink
Merge pull request #2342 from bradking/data-type-public
Browse files Browse the repository at this point in the history
bindings: Restore public adios2::GetType function name
  • Loading branch information
Chuck Atkins authored Jun 18, 2020
2 parents c8ca6a5 + c2541a8 commit ed328d5
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 176 deletions.
8 changes: 4 additions & 4 deletions bindings/CXX11/adios2/cxx11/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,18 @@ class IO

/**
* Inspects variable type. This function can be used in conjunction with
* MACROS in an else if (type == adios2::GetDataType<T>() ) {} loop
* MACROS in an else if (type == adios2::GetType<T>() ) {} loop
* @param name unique variable name identifier in current IO
* @return type as in adios2::GetDataType<T>() (e.g. "double", "float"),
* @return type as in adios2::GetType<T>() (e.g. "double", "float"),
* empty std::string if variable not found
*/
std::string VariableType(const std::string &name) const;

/**
* Inspects attribute type. This function can be used in conjunction with
* MACROS in an else if (type == adios2::GetDataType<T>() ) {} loop
* MACROS in an else if (type == adios2::GetType<T>() ) {} loop
* @param name unique attribute name identifier in current IO
* @return type as in adios2::GetDataType<T>() (e.g. "double", "float"),
* @return type as in adios2::GetType<T>() (e.g. "double", "float"),
* empty std::string if attribute not found
*/
std::string AttributeType(const std::string &name) const;
Expand Down
2 changes: 1 addition & 1 deletion bindings/CXX11/adios2/cxx11/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace adios2
{

#define declare_template_instantiation(T) \
template std::string GetDataType<T>() noexcept;
template std::string GetType<T>() noexcept;

ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
6 changes: 3 additions & 3 deletions bindings/CXX11/adios2/cxx11/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace adios2
{

template <class T>
std::string GetDataType() noexcept;
std::string GetType() noexcept;

// LIMIT TEMPLATE TYPES FOR adios2::GetDataType
// LIMIT TEMPLATE TYPES FOR adios2::GetType
#define declare_template_instantiation(T) \
\
extern template std::string GetDataType<T>() noexcept;
extern template std::string GetType<T>() noexcept;

ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
2 changes: 1 addition & 1 deletion bindings/CXX11/adios2/cxx11/Types.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace adios2
{

template <class T>
std::string GetDataType() noexcept
std::string GetType() noexcept
{
return ToString(helper::GetDataType<typename TypeInfo<T>::IOType>());
}
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/source/advice/advice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The goal is to provide specific advice and good practices about the use of ADIOS

11. Prefer the high-level Python and C++ APIs for simple tasks that do not require performance. The more familiar Write/Read overloads for File I/O return native data constructs (``std::vector`` and ``numpy arrays``) immediately for a requested selection. ``open`` only explores the metadata index.

12. C++: prefer templates to ``void*`` to increase compile-time safety. Use ``IO::InquireVariableType("variableName")`` and ``adios2::GetDataType<T>()`` to cast upfront to a ``Variable<T>``. C++17 has ``std::any`` as an alternative to ``void*``. ADIOS 2 follows closely the STL model.
12. C++: prefer templates to ``void*`` to increase compile-time safety. Use ``IO::InquireVariableType("variableName")`` and ``adios2::GetType<T>()`` to cast upfront to a ``Variable<T>``. C++17 has ``std::any`` as an alternative to ``void*``. ADIOS 2 follows closely the STL model.

13. Understand ``Put`` and ``Get`` memory contracts from :ref:`Engine`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ProcessMetadata(int rank, const adios2::Engine &reader, adios2::IO &io,
// not supported
}
#define declare_template_instantiation(T) \
else if (type == adios2::GetDataType<T>()) \
else if (type == adios2::GetType<T>()) \
{ \
ProcessVariableMetadata<T>(rank, name, type, reader, io, varinfos); \
}
Expand Down
40 changes: 19 additions & 21 deletions testing/adios2/engine/bp/TestBPWriteAppendReadADIOS2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,121 +425,119 @@ TEST_F(BPWriteAppendReadTestADIOS2, ADIOS2BPWriteAppendRead2D2x4)
EXPECT_TRUE(attr_s1);
ASSERT_EQ(attr_s1.Name(), s1_Single);
ASSERT_EQ(attr_s1.Data().size() == 1, true);
ASSERT_EQ(attr_s1.Type(), adios2::GetDataType<std::string>());
ASSERT_EQ(attr_s1.Type(), adios2::GetType<std::string>());
ASSERT_EQ(attr_s1.Data().front(), attributeTestData.S1);

EXPECT_TRUE(attr_s1a);
ASSERT_EQ(attr_s1a.Name(), s1_Array);
ASSERT_EQ(attr_s1a.Data().size() == 1, true);
ASSERT_EQ(attr_s1a.Type(), adios2::GetDataType<std::string>());
ASSERT_EQ(attr_s1a.Type(), adios2::GetType<std::string>());
ASSERT_EQ(attr_s1a.Data()[0], attributeTestData.S1array[0]);

EXPECT_TRUE(attr_i8);
ASSERT_EQ(attr_i8.Name(), i8_Single);
ASSERT_EQ(attr_i8.Data().size() == 1, true);
ASSERT_EQ(attr_i8.Type(), adios2::GetDataType<int8_t>());
ASSERT_EQ(attr_i8.Type(), adios2::GetType<int8_t>());
ASSERT_EQ(attr_i8.Data().front(), attributeTestData.I8.front());

EXPECT_TRUE(attr_i16);
ASSERT_EQ(attr_i16.Name(), i16_Single);
ASSERT_EQ(attr_i16.Data().size() == 1, true);
ASSERT_EQ(attr_i16.Type(), adios2::GetDataType<int16_t>());
ASSERT_EQ(attr_i16.Type(), adios2::GetType<int16_t>());
ASSERT_EQ(attr_i16.Data().front(), attributeTestData.I16.front());

EXPECT_TRUE(attr_i32);
ASSERT_EQ(attr_i32.Name(), i32_Single);
ASSERT_EQ(attr_i32.Data().size() == 1, true);
ASSERT_EQ(attr_i32.Type(), adios2::GetDataType<int32_t>());
ASSERT_EQ(attr_i32.Type(), adios2::GetType<int32_t>());
ASSERT_EQ(attr_i32.Data().front(), attributeTestData.I32.front());

EXPECT_TRUE(attr_i32a);
ASSERT_EQ(attr_i32a.Name(), i32_Array);
ASSERT_EQ(attr_i32a.Data().size() == attributeTestData.I32.size(),
true);
ASSERT_EQ(attr_i32a.Type(), adios2::GetDataType<int32_t>());
ASSERT_EQ(attr_i32a.Type(), adios2::GetType<int32_t>());
ASSERT_EQ(attr_i32a.Data()[0], attributeTestData.I32[0]);

EXPECT_TRUE(attr_i64);
ASSERT_EQ(attr_i64.Name(), i64_Single);
ASSERT_EQ(attr_i64.Data().size() == 1, true);
ASSERT_EQ(attr_i64.Type(), adios2::GetDataType<int64_t>());
ASSERT_EQ(attr_i64.Type(), adios2::GetType<int64_t>());
ASSERT_EQ(attr_i64.Data().front(), attributeTestData.I64.front());

EXPECT_TRUE(attr_u8);
ASSERT_EQ(attr_u8.Name(), u8_Single);
ASSERT_EQ(attr_u8.Data().size() == 1, true);
ASSERT_EQ(attr_u8.Type(), adios2::GetDataType<uint8_t>());
ASSERT_EQ(attr_u8.Type(), adios2::GetType<uint8_t>());
ASSERT_EQ(attr_u8.Data().front(), attributeTestData.U8.front());

EXPECT_TRUE(attr_u16);
ASSERT_EQ(attr_u16.Name(), u16_Single);
ASSERT_EQ(attr_u16.Data().size() == 1, true);
ASSERT_EQ(attr_u16.Type(), adios2::GetDataType<uint16_t>());
ASSERT_EQ(attr_u16.Type(), adios2::GetType<uint16_t>());
ASSERT_EQ(attr_u16.Data().front(), attributeTestData.U16.front());

EXPECT_TRUE(attr_u32);
ASSERT_EQ(attr_u32.Name(), u32_Single);
ASSERT_EQ(attr_u32.Data().size() == 1, true);
ASSERT_EQ(attr_u32.Type(), adios2::GetDataType<uint32_t>());
ASSERT_EQ(attr_u32.Type(), adios2::GetType<uint32_t>());
ASSERT_EQ(attr_u32.Data().front(), attributeTestData.U32.front());

EXPECT_TRUE(attr_u32a);
ASSERT_EQ(attr_u32a.Name(), u32_Array);
ASSERT_EQ(attr_u32a.Data().size() == attributeTestData.U32.size(),
true);
ASSERT_EQ(attr_u32a.Type(), adios2::GetDataType<uint32_t>());
ASSERT_EQ(attr_u32a.Type(), adios2::GetType<uint32_t>());
ASSERT_EQ(attr_u32a.Data()[0], attributeTestData.U32[0]);

EXPECT_TRUE(attr_u64);
ASSERT_EQ(attr_u64.Name(), u64_Single);
ASSERT_EQ(attr_u64.Data().size() == 1, true);
ASSERT_EQ(attr_u64.Type(), adios2::GetDataType<uint64_t>());
ASSERT_EQ(attr_u64.Type(), adios2::GetType<uint64_t>());
ASSERT_EQ(attr_u64.Data().front(), attributeTestData.U64.front());

EXPECT_TRUE(attr_r32);
ASSERT_EQ(attr_r32.Name(), r32_Single);
ASSERT_EQ(attr_r32.Data().size() == 1, true);
ASSERT_EQ(attr_r32.Type(), adios2::GetDataType<float>());
ASSERT_EQ(attr_r32.Type(), adios2::GetType<float>());
ASSERT_EQ(attr_r32.Data().front(), attributeTestData.R32.front());

EXPECT_TRUE(attr_r32a);
ASSERT_EQ(attr_r32a.Name(), r32_Array);
ASSERT_EQ(attr_r32a.Data().size() == attributeTestData.R32.size(),
true);
ASSERT_EQ(attr_r32a.Type(), adios2::GetDataType<float>());
ASSERT_EQ(attr_r32a.Type(), adios2::GetType<float>());
ASSERT_EQ(attr_r32a.Data()[0], attributeTestData.R32[0]);

EXPECT_TRUE(attr_r64);
ASSERT_EQ(attr_r64.Name(), r64_Single);
ASSERT_EQ(attr_r64.Data().size() == 1, true);
ASSERT_EQ(attr_r64.Type(), adios2::GetDataType<double>());
ASSERT_EQ(attr_r64.Type(), adios2::GetType<double>());
ASSERT_EQ(attr_r64.Data().front(), attributeTestData.R64.front());

EXPECT_TRUE(attr_r128);
ASSERT_EQ(attr_r128.Name(), r128_Single);
ASSERT_EQ(attr_r128.Data().size() == 1, true);
ASSERT_EQ(attr_r128.Type(), adios2::GetDataType<long double>());
ASSERT_EQ(attr_r128.Type(), adios2::GetType<long double>());
ASSERT_EQ(attr_r128.Data().front(), attributeTestData.R128.front());

EXPECT_TRUE(attr_cr32);
ASSERT_EQ(attr_cr32.Name(), cr32_Single);
ASSERT_EQ(attr_cr32.Data().size() == 1, true);
ASSERT_EQ(attr_cr32.Type(), adios2::GetDataType<std::complex<float>>());
ASSERT_EQ(attr_cr32.Type(), adios2::GetType<std::complex<float>>());
ASSERT_EQ(attr_cr32.Data().front(), attributeTestData.CR32.front());

EXPECT_TRUE(attr_cr32a);
ASSERT_EQ(attr_cr32a.Name(), cr32_Array);
ASSERT_EQ(attr_cr32a.Data().size() == attributeTestData.CR32.size(),
true);
ASSERT_EQ(attr_cr32a.Type(),
adios2::GetDataType<std::complex<float>>());
ASSERT_EQ(attr_cr32a.Type(), adios2::GetType<std::complex<float>>());
ASSERT_EQ(attr_cr32a.Data()[0], attributeTestData.CR32[0]);

EXPECT_TRUE(attr_cr64);
ASSERT_EQ(attr_cr64.Name(), cr64_Single);
ASSERT_EQ(attr_cr64.Data().size() == 1, true);
ASSERT_EQ(attr_cr64.Type(),
adios2::GetDataType<std::complex<double>>());
ASSERT_EQ(attr_cr64.Type(), adios2::GetType<std::complex<double>>());
ASSERT_EQ(attr_cr64.Data().front(), attributeTestData.CR64.front());

EXPECT_EQ(bpReader.Steps(), 2 * NSteps);
Expand Down
Loading

0 comments on commit ed328d5

Please sign in to comment.