From 8457425787a620a8c3b95ba36c3c25c265742090 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:42:58 -0500 Subject: [PATCH] cxx11/Variable: use regular templates --- bindings/CXX11/cxx11/Variable.cpp | 209 +----------------------------- bindings/CXX11/cxx11/Variable.tcc | 192 +++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 206 deletions(-) diff --git a/bindings/CXX11/cxx11/Variable.cpp b/bindings/CXX11/cxx11/Variable.cpp index bfebb9c0ac..fa48a0e839 100644 --- a/bindings/CXX11/cxx11/Variable.cpp +++ b/bindings/CXX11/cxx11/Variable.cpp @@ -17,211 +17,8 @@ namespace adios2 { -#define declare_type(T) \ - \ - template <> \ - Variable::Variable(core::Variable *variable) \ - : m_Variable(variable) \ - { \ - } \ - \ - template <> \ - Variable::operator bool() const noexcept \ - { \ - return (m_Variable == nullptr) ? false : true; \ - } \ - \ - template <> \ - void Variable::SetShape(const Dims &shape) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetShape"); \ - m_Variable->SetShape(shape); \ - } \ - \ - template <> \ - void Variable::SetBlockSelection(const size_t blockID) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetBlockSelection"); \ - m_Variable->SetBlockSelection(blockID); \ - } \ - \ - template <> \ - void Variable::SetSelection(const Box &selection) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetSelection"); \ - m_Variable->SetSelection(selection); \ - } \ - \ - template <> \ - void Variable::SetMemorySelection(const Box &memorySelection) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetMemorySelection"); \ - m_Variable->SetMemorySelection(memorySelection); \ - } \ - \ - template <> \ - void Variable::SetStepSelection(const Box &stepSelection) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetStepSelection"); \ - m_Variable->SetStepSelection(stepSelection); \ - } \ - \ - template <> \ - size_t Variable::SelectionSize() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SelectionSize"); \ - return m_Variable->SelectionSize(); \ - } \ - \ - template <> \ - std::string Variable::Name() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Name"); \ - return m_Variable->m_Name; \ - } \ - \ - template <> \ - std::string Variable::Type() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Type"); \ - return m_Variable->m_Type; \ - } \ - template <> \ - size_t Variable::Sizeof() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Sizeof"); \ - return m_Variable->m_ElementSize; \ - } \ - \ - template <> \ - adios2::ShapeID Variable::ShapeID() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::ShapeID"); \ - return m_Variable->m_ShapeID; \ - } \ - \ - template <> \ - Dims Variable::Shape(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Shape"); \ - return m_Variable->Shape(step); \ - } \ - \ - template <> \ - Dims Variable::Start() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Start"); \ - return m_Variable->m_Start; \ - } \ - \ - template <> \ - Dims Variable::Count() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Count"); \ - return m_Variable->m_Count; \ - } \ - \ - template <> \ - size_t Variable::Steps() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Steps"); \ - return m_Variable->m_AvailableStepsCount; \ - } \ - \ - template <> \ - size_t Variable::StepsStart() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::StepsStart"); \ - return m_Variable->m_AvailableStepsStart; \ - } \ - \ - template <> \ - size_t Variable::BlockID() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::BlockID"); \ - return m_Variable->m_BlockID; \ - } \ - \ - template <> \ - size_t Variable::AddOperation(const Operator op, \ - const Params ¶meters) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::AddOperator"); \ - if (!op) \ - { \ - throw std::invalid_argument("ERROR: invalid operator, in call to " \ - "Variable::AddOperator"); \ - } \ - return m_Variable->AddOperation(*op.m_Operator, parameters); \ - } \ - \ - template <> \ - std::vector::Operation> Variable::Operations() \ - const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::Operations"); \ - std::vector operations; \ - operations.reserve(m_Variable->m_Operations.size()); \ - \ - for (const auto &op : m_Variable->m_Operations) \ - { \ - operations.push_back( \ - Operation{Operator(op.Op), op.Parameters, op.Info}); \ - } \ - return operations; \ - } \ - \ - template <> \ - std::pair Variable::MinMax(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::MinMax"); \ - return m_Variable->MinMax(step); \ - } \ - \ - template <> \ - T Variable::Min(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Min"); \ - return m_Variable->Min(step); \ - } \ - \ - template <> \ - T Variable::Max(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Max"); \ - return m_Variable->Max(step); \ - } \ - \ - template <> \ - std::vector::Info>> \ - Variable::AllStepsBlocksInfo() \ - { \ - return DoAllStepsBlocksInfo(); \ - } \ - \ - template <> \ - const T *Variable::Info::Data() const \ - { \ - const core::Variable::Info *coreInfo = \ - reinterpret_cast::Info *>(m_Info); \ - \ - return m_Info ? (coreInfo->BufferP ? coreInfo->BufferP \ - : coreInfo->BufferV.data()) \ - : nullptr; \ - } - -ADIOS2_FOREACH_TYPE_1ARG(declare_type) -#undef declare_type +#define declare_template_instantiation(T) template class Variable; +ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) +#undef declare_template_instantiation } // end namespace adios2 diff --git a/bindings/CXX11/cxx11/Variable.tcc b/bindings/CXX11/cxx11/Variable.tcc index a6319a55f4..23f892c1e1 100644 --- a/bindings/CXX11/cxx11/Variable.tcc +++ b/bindings/CXX11/cxx11/Variable.tcc @@ -18,6 +18,198 @@ namespace adios2 { +template +Variable::Variable(core::Variable *variable) : m_Variable(variable) +{ +} + +template +Variable::operator bool() const noexcept +{ + return (m_Variable == nullptr) ? false : true; +} + +template +void Variable::SetShape(const Dims &shape) +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::SetShape"); + m_Variable->SetShape(shape); +} + +template +void Variable::SetBlockSelection(const size_t blockID) +{ + helper::CheckForNullptr(m_Variable, + "in call to Variable::SetBlockSelection"); + m_Variable->SetBlockSelection(blockID); +} + +template +void Variable::SetSelection(const Box &selection) +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::SetSelection"); + m_Variable->SetSelection(selection); +} + +template +void Variable::SetMemorySelection(const Box &memorySelection) +{ + helper::CheckForNullptr(m_Variable, + "in call to Variable::SetMemorySelection"); + m_Variable->SetMemorySelection(memorySelection); +} + +template +void Variable::SetStepSelection(const Box &stepSelection) +{ + helper::CheckForNullptr(m_Variable, + "in call to Variable::SetStepSelection"); + m_Variable->SetStepSelection(stepSelection); +} + +template +size_t Variable::SelectionSize() const +{ + helper::CheckForNullptr(m_Variable, + "in call to Variable::SelectionSize"); + return m_Variable->SelectionSize(); +} + +template +std::string Variable::Name() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Name"); + return m_Variable->m_Name; +} + +template +std::string Variable::Type() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Type"); + return m_Variable->m_Type; +} +template +size_t Variable::Sizeof() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Sizeof"); + return m_Variable->m_ElementSize; +} + +template +adios2::ShapeID Variable::ShapeID() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::ShapeID"); + return m_Variable->m_ShapeID; +} + +template +Dims Variable::Shape(const size_t step) const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Shape"); + return m_Variable->Shape(step); +} + +template +Dims Variable::Start() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Start"); + return m_Variable->m_Start; +} + +template +Dims Variable::Count() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Count"); + return m_Variable->m_Count; +} + +template +size_t Variable::Steps() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Steps"); + return m_Variable->m_AvailableStepsCount; +} + +template +size_t Variable::StepsStart() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::StepsStart"); + return m_Variable->m_AvailableStepsStart; +} + +template +size_t Variable::BlockID() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::BlockID"); + return m_Variable->m_BlockID; +} + +template +size_t Variable::AddOperation(const Operator op, const Params ¶meters) +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::AddOperator"); + if (!op) + { + throw std::invalid_argument("ERROR: invalid operator, in call to " + "Variable::AddOperator"); + } + return m_Variable->AddOperation(*op.m_Operator, parameters); +} + +template +std::vector::Operation> Variable::Operations() const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Operations"); + std::vector operations; + operations.reserve(m_Variable->m_Operations.size()); + + for (const auto &op : m_Variable->m_Operations) + { + operations.push_back( + Operation{Operator(op.Op), op.Parameters, op.Info}); + } + return operations; +} + +template +std::pair Variable::MinMax(const size_t step) const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::MinMax"); + return m_Variable->MinMax(step); +} + +template +T Variable::Min(const size_t step) const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Min"); + return m_Variable->Min(step); +} + +template +T Variable::Max(const size_t step) const +{ + helper::CheckForNullptr(m_Variable, "in call to Variable::Max"); + return m_Variable->Max(step); +} + +template +std::vector::Info>> +Variable::AllStepsBlocksInfo() +{ + return DoAllStepsBlocksInfo(); +} + +template +const T *Variable::Info::Data() const +{ + auto coreInfo = + reinterpret_cast::Info *>(m_Info); + + return m_Info ? (coreInfo->BufferP ? coreInfo->BufferP + : coreInfo->BufferV.data()) + : nullptr; +} + namespace {