From 4a47a2225cb0b5e8fab212608c87869f3ecdb848 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:42:46 -0500 Subject: [PATCH 1/7] core/Variable: use regular templates only moves the code from .cpp -> .tcc and changes `template <>` to `template `, and then instantiates the whole class for each relevant type in .cpp --- source/adios2/core/Variable.cpp | 82 ++------------------------------- source/adios2/core/Variable.tcc | 75 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 79 deletions(-) diff --git a/source/adios2/core/Variable.cpp b/source/adios2/core/Variable.cpp index 44de2628b4..351126772a 100644 --- a/source/adios2/core/Variable.cpp +++ b/source/adios2/core/Variable.cpp @@ -20,85 +20,9 @@ namespace adios2 namespace core { -#define declare_type(T) \ - \ - template <> \ - Variable::Variable(const std::string &name, const Dims &shape, \ - const Dims &start, const Dims &count, \ - const bool constantDims, const bool debugMode) \ - : VariableBase(name, helper::GetType(), sizeof(T), shape, start, count, \ - constantDims, debugMode) \ - { \ - m_BlocksInfo.reserve(1); \ - } \ - \ - template <> \ - typename Variable::Info &Variable::SetBlockInfo( \ - const T *data, const size_t stepsStart, \ - const size_t stepsCount) noexcept \ - { \ - Info info; \ - info.Shape = m_Shape; \ - info.Start = m_Start; \ - info.Count = m_Count; \ - info.BlockID = m_BlockID; \ - info.Selection = m_SelectionType; \ - info.MemoryStart = m_MemoryStart; \ - info.MemoryCount = m_MemoryCount; \ - info.StepsStart = stepsStart; \ - info.StepsCount = stepsCount; \ - info.Data = const_cast(data); \ - info.BufferP = info.Data; \ - info.Operations = m_Operations; \ - m_BlocksInfo.push_back(info); \ - return m_BlocksInfo.back(); \ - } \ - \ - template <> \ - void Variable::SetData(const T *data) noexcept \ - { \ - m_Data = const_cast(data); \ - } \ - \ - template <> \ - T *Variable::GetData() const noexcept \ - { \ - return m_Data; \ - } \ - \ - template <> \ - Dims Variable::Shape(const size_t step) const \ - { \ - return DoShape(step); \ - } \ - \ - template <> \ - std::pair Variable::MinMax(const size_t step) const \ - { \ - return DoMinMax(step); \ - } \ - \ - template <> \ - T Variable::Min(const size_t step) const \ - { \ - return MinMax(step).first; \ - } \ - \ - template <> \ - T Variable::Max(const size_t step) const \ - { \ - return MinMax(step).second; \ - } \ - \ - template <> \ - std::vector::Info>> \ - Variable::AllStepsBlocksInfo() const \ - { \ - return DoAllStepsBlocksInfo(); \ - } - -ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) -#undef declare_type +#define declare_template_instantiation(T) template class Variable; +ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) +#undef declare_template_instantiation } // end namespace core } // end namespace adios2 diff --git a/source/adios2/core/Variable.tcc b/source/adios2/core/Variable.tcc index 3db34b1af9..5dd82e0335 100644 --- a/source/adios2/core/Variable.tcc +++ b/source/adios2/core/Variable.tcc @@ -171,6 +171,81 @@ Variable::DoAllStepsBlocksInfo() const return m_Engine->AllRelativeStepsBlocksInfo(*this); } +template +Variable::Variable(const std::string &name, const Dims &shape, + const Dims &start, const Dims &count, + const bool constantDims, const bool debugMode) +: VariableBase(name, helper::GetType(), sizeof(T), shape, start, count, + constantDims, debugMode) +{ + m_BlocksInfo.reserve(1); +} + +template +typename Variable::Info & +Variable::SetBlockInfo(const T *data, const size_t stepsStart, + const size_t stepsCount) noexcept +{ + Info info; + info.Shape = m_Shape; + info.Start = m_Start; + info.Count = m_Count; + info.BlockID = m_BlockID; + info.Selection = m_SelectionType; + info.MemoryStart = m_MemoryStart; + info.MemoryCount = m_MemoryCount; + info.StepsStart = stepsStart; + info.StepsCount = stepsCount; + info.Data = const_cast(data); + info.BufferP = info.Data; + info.Operations = m_Operations; + m_BlocksInfo.push_back(info); + return m_BlocksInfo.back(); +} + +template +void Variable::SetData(const T *data) noexcept +{ + m_Data = const_cast(data); +} + +template +T *Variable::GetData() const noexcept +{ + return m_Data; +} + +template +Dims Variable::Shape(const size_t step) const +{ + return DoShape(step); +} + +template +std::pair Variable::MinMax(const size_t step) const +{ + return DoMinMax(step); +} + +template +T Variable::Min(const size_t step) const +{ + return MinMax(step).first; +} + +template +T Variable::Max(const size_t step) const +{ + return MinMax(step).second; +} + +template +std::vector::Info>> +Variable::AllStepsBlocksInfo() const +{ + return DoAllStepsBlocksInfo(); +} + } // end namespace core } // end namespace adios2 From c38ba84755376c1c33d14e00875fd14d1f9c50c9 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:42:48 -0500 Subject: [PATCH 2/7] core/Variable: remove additional layer of wrapping functions which are not needed anymore --- source/adios2/core/Variable.h | 8 -------- source/adios2/core/Variable.tcc | 25 +++---------------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/source/adios2/core/Variable.h b/source/adios2/core/Variable.h index a95d146df8..3accaa9b99 100644 --- a/source/adios2/core/Variable.h +++ b/source/adios2/core/Variable.h @@ -105,14 +105,6 @@ class Variable : public VariableBase std::vector::Info>> AllStepsBlocksInfo() const; - -private: - Dims DoShape(const size_t step) const; - - std::pair DoMinMax(const size_t step) const; - - std::vector::Info>> - DoAllStepsBlocksInfo() const; }; } // end namespace core diff --git a/source/adios2/core/Variable.tcc b/source/adios2/core/Variable.tcc index 5dd82e0335..2bd853427d 100644 --- a/source/adios2/core/Variable.tcc +++ b/source/adios2/core/Variable.tcc @@ -22,7 +22,7 @@ namespace core { template -Dims Variable::DoShape(const size_t step) const +Dims Variable::Shape(const size_t step) const { if (m_DebugMode) { @@ -66,7 +66,7 @@ Dims Variable::DoShape(const size_t step) const } template -std::pair Variable::DoMinMax(const size_t step) const +std::pair Variable::MinMax(const size_t step) const { if (m_DebugMode && !m_FirstStreamingStep && step != DefaultSizeT) { @@ -146,7 +146,7 @@ std::pair Variable::DoMinMax(const size_t step) const template std::vector::Info>> -Variable::DoAllStepsBlocksInfo() const +Variable::AllStepsBlocksInfo() const { if (m_DebugMode && m_Engine == nullptr) { @@ -215,18 +215,6 @@ T *Variable::GetData() const noexcept return m_Data; } -template -Dims Variable::Shape(const size_t step) const -{ - return DoShape(step); -} - -template -std::pair Variable::MinMax(const size_t step) const -{ - return DoMinMax(step); -} - template T Variable::Min(const size_t step) const { @@ -239,13 +227,6 @@ T Variable::Max(const size_t step) const return MinMax(step).second; } -template -std::vector::Info>> -Variable::AllStepsBlocksInfo() const -{ - return DoAllStepsBlocksInfo(); -} - } // end namespace core } // end namespace adios2 From 01faadb28211d5c81cf2db9c3543332de7ed21c8 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:42:51 -0500 Subject: [PATCH 3/7] core/Variable: reorder Variable.tcc This only moves code around to have the functions in Variable.tcc appears in the order they are declared in Variable.h. --- source/adios2/core/Variable.tcc | 112 ++++++++++++++++---------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/source/adios2/core/Variable.tcc b/source/adios2/core/Variable.tcc index 2bd853427d..8cced05dd3 100644 --- a/source/adios2/core/Variable.tcc +++ b/source/adios2/core/Variable.tcc @@ -21,6 +21,50 @@ namespace adios2 namespace core { +template +Variable::Variable(const std::string &name, const Dims &shape, + const Dims &start, const Dims &count, + const bool constantDims, const bool debugMode) +: VariableBase(name, helper::GetType(), sizeof(T), shape, start, count, + constantDims, debugMode) +{ + m_BlocksInfo.reserve(1); +} + +template +typename Variable::Info & +Variable::SetBlockInfo(const T *data, const size_t stepsStart, + const size_t stepsCount) noexcept +{ + Info info; + info.Shape = m_Shape; + info.Start = m_Start; + info.Count = m_Count; + info.BlockID = m_BlockID; + info.Selection = m_SelectionType; + info.MemoryStart = m_MemoryStart; + info.MemoryCount = m_MemoryCount; + info.StepsStart = stepsStart; + info.StepsCount = stepsCount; + info.Data = const_cast(data); + info.BufferP = info.Data; + info.Operations = m_Operations; + m_BlocksInfo.push_back(info); + return m_BlocksInfo.back(); +} + +template +void Variable::SetData(const T *data) noexcept +{ + m_Data = const_cast(data); +} + +template +T *Variable::GetData() const noexcept +{ + return m_Data; +} + template Dims Variable::Shape(const size_t step) const { @@ -144,6 +188,18 @@ std::pair Variable::MinMax(const size_t step) const return minMax; } +template +T Variable::Min(const size_t step) const +{ + return MinMax(step).first; +} + +template +T Variable::Max(const size_t step) const +{ + return MinMax(step).second; +} + template std::vector::Info>> Variable::AllStepsBlocksInfo() const @@ -171,62 +227,6 @@ Variable::AllStepsBlocksInfo() const return m_Engine->AllRelativeStepsBlocksInfo(*this); } -template -Variable::Variable(const std::string &name, const Dims &shape, - const Dims &start, const Dims &count, - const bool constantDims, const bool debugMode) -: VariableBase(name, helper::GetType(), sizeof(T), shape, start, count, - constantDims, debugMode) -{ - m_BlocksInfo.reserve(1); -} - -template -typename Variable::Info & -Variable::SetBlockInfo(const T *data, const size_t stepsStart, - const size_t stepsCount) noexcept -{ - Info info; - info.Shape = m_Shape; - info.Start = m_Start; - info.Count = m_Count; - info.BlockID = m_BlockID; - info.Selection = m_SelectionType; - info.MemoryStart = m_MemoryStart; - info.MemoryCount = m_MemoryCount; - info.StepsStart = stepsStart; - info.StepsCount = stepsCount; - info.Data = const_cast(data); - info.BufferP = info.Data; - info.Operations = m_Operations; - m_BlocksInfo.push_back(info); - return m_BlocksInfo.back(); -} - -template -void Variable::SetData(const T *data) noexcept -{ - m_Data = const_cast(data); -} - -template -T *Variable::GetData() const noexcept -{ - return m_Data; -} - -template -T Variable::Min(const size_t step) const -{ - return MinMax(step).first; -} - -template -T Variable::Max(const size_t step) const -{ - return MinMax(step).second; -} - } // end namespace core } // end namespace adios2 From 3c9ad2646101e4ec8b6c1249ebbda32246796525 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:42:53 -0500 Subject: [PATCH 4/7] core/Variable: remove unused SubStreamsInfoSize --- source/adios2/core/Variable.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/adios2/core/Variable.h b/source/adios2/core/Variable.h index 3accaa9b99..9d63375f19 100644 --- a/source/adios2/core/Variable.h +++ b/source/adios2/core/Variable.h @@ -93,8 +93,6 @@ class Variable : public VariableBase T *GetData() const noexcept; - size_t SubStreamsInfoSize(); - Dims Shape(const size_t step) const; std::pair MinMax(const size_t step) const; From 34ed987fe8bd362521e16d748fad53faa4f2878b Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:42:55 -0500 Subject: [PATCH 5/7] core/Attribute: use regular templates --- source/adios2/core/Attribute.cpp | 24 ++++---------------- source/adios2/core/Attribute.tcc | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 source/adios2/core/Attribute.tcc diff --git a/source/adios2/core/Attribute.cpp b/source/adios2/core/Attribute.cpp index cdb995b7a1..ebb2d98cdf 100644 --- a/source/adios2/core/Attribute.cpp +++ b/source/adios2/core/Attribute.cpp @@ -8,34 +8,18 @@ * Author: William F Godoy godoywf@ornl.gov */ -#include "Attribute.h" +#include "Attribute.tcc" #include "adios2/ADIOSMacros.h" -#include "adios2/helper/adiosFunctions.h" //GetType namespace adios2 { namespace core { -#define declare_type(T) \ - \ - template <> \ - Attribute::Attribute(const std::string &name, const T *array, \ - const size_t elements) \ - : AttributeBase(name, helper::GetType(), elements), m_DataSingleValue() \ - { \ - m_DataArray = std::vector(array, array + elements); \ - } \ - \ - template <> \ - Attribute::Attribute(const std::string &name, const T &value) \ - : AttributeBase(name, helper::GetType()), m_DataSingleValue(value) \ - { \ - } - -ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_type) -#undef declare_type +#define declare_template_instantiation(T) template class Attribute; +ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_template_instantiation) +#undef declare_template_instantiation } // end namespace core } // end namespace adios2 diff --git a/source/adios2/core/Attribute.tcc b/source/adios2/core/Attribute.tcc new file mode 100644 index 0000000000..774f203fec --- /dev/null +++ b/source/adios2/core/Attribute.tcc @@ -0,0 +1,39 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Attribute.tcc : templated member functions for Attribute + * + * Created on: Feb 23, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#ifndef ADIOS2_CORE_ATTRIBUTE_TCC_ +#define ADIOS2_CORE_ATTRIBUTE_TCC_ + +#include "Attribute.h" + +#include "adios2/helper/adiosFunctions.h" //GetType + +namespace adios2 +{ +namespace core +{ +template +Attribute::Attribute(const std::string &name, const T *array, + const size_t elements) +: AttributeBase(name, helper::GetType(), elements), m_DataSingleValue() +{ + m_DataArray = std::vector(array, array + elements); +} + +template +Attribute::Attribute(const std::string &name, const T &value) +: AttributeBase(name, helper::GetType()), m_DataSingleValue(value) +{ +} + +} // end namespace core +} // end namespace adios2 + +#endif /* ADIOS2_CORE_ATTRIBUTE_TCC_ */ From 8457425787a620a8c3b95ba36c3c25c265742090 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:42:58 -0500 Subject: [PATCH 6/7] 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 { From b51eafe0ebb14311fe8025718c44e008f5a09c55 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Mon, 25 Feb 2019 10:43:00 -0500 Subject: [PATCH 7/7] cxx11/Attribute: use regular templates --- bindings/CXX11/cxx11/Attribute.cpp | 56 ++------------------------ bindings/CXX11/cxx11/Attribute.tcc | 64 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 52 deletions(-) create mode 100644 bindings/CXX11/cxx11/Attribute.tcc diff --git a/bindings/CXX11/cxx11/Attribute.cpp b/bindings/CXX11/cxx11/Attribute.cpp index 5791c12e7b..efd98e4286 100644 --- a/bindings/CXX11/cxx11/Attribute.cpp +++ b/bindings/CXX11/cxx11/Attribute.cpp @@ -9,62 +9,14 @@ */ #include "Attribute.h" - -#include "adios2/ADIOSMacros.h" -#include "adios2/core/Attribute.h" -#include "adios2/helper/adiosFunctions.h" +#include "Attribute.tcc" namespace adios2 { -#define declare_type(T) \ - \ - template <> \ - Attribute::Attribute(core::Attribute *attribute) \ - : m_Attribute(attribute) \ - { \ - } \ - \ - template <> \ - Attribute::operator bool() const noexcept \ - { \ - return (m_Attribute == nullptr) ? false : true; \ - } \ - \ - template <> \ - std::string Attribute::Name() const \ - { \ - helper::CheckForNullptr(m_Attribute, \ - "in call to Attribute::Name()"); \ - return m_Attribute->m_Name; \ - } \ - \ - template <> \ - std::string Attribute::Type() const \ - { \ - helper::CheckForNullptr(m_Attribute, \ - "in call to Attribute::Type()"); \ - return m_Attribute->m_Type; \ - } \ - \ - template <> \ - std::vector Attribute::Data() const \ - { \ - helper::CheckForNullptr(m_Attribute, \ - "in call to Attribute::Data()"); \ - \ - if (m_Attribute->m_IsSingleValue) \ - { \ - return std::vector{m_Attribute->m_DataSingleValue}; \ - } \ - else \ - { \ - return reinterpret_cast &>( \ - m_Attribute->m_DataArray); \ - } \ - } +#define declare_template_instantiation(T) template class Attribute; -ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_type) -#undef declare_type +ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation) +#undef declare_template_instantiation } // end namespace adios2 diff --git a/bindings/CXX11/cxx11/Attribute.tcc b/bindings/CXX11/cxx11/Attribute.tcc new file mode 100644 index 0000000000..6a0fab2f1a --- /dev/null +++ b/bindings/CXX11/cxx11/Attribute.tcc @@ -0,0 +1,64 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Attribute.tcc : + * + * Created on: Jun 4, 2018 + * Author: William F Godoy godoywf@ornl.gov + */ + +#ifndef ADIOS2_BINDINGS_CXX11_CXX11_ATTRIBUTE_TCC_ +#define ADIOS2_BINDINGS_CXX11_CXX11_ATTRIBUTE_TCC_ + +#include "Attribute.h" + +#include "adios2/helper/adiosFunctions.h" + +namespace adios2 +{ + +template +Attribute::Attribute(core::Attribute *attribute) +: m_Attribute(attribute) +{ +} + +template +Attribute::operator bool() const noexcept +{ + return (m_Attribute == nullptr) ? false : true; +} + +template +std::string Attribute::Name() const +{ + helper::CheckForNullptr(m_Attribute, "in call to Attribute::Name()"); + return m_Attribute->m_Name; +} + +template +std::string Attribute::Type() const +{ + helper::CheckForNullptr(m_Attribute, "in call to Attribute::Type()"); + return m_Attribute->m_Type; +} + +template +std::vector Attribute::Data() const +{ + helper::CheckForNullptr(m_Attribute, "in call to Attribute::Data()"); + + if (m_Attribute->m_IsSingleValue) + { + return std::vector{m_Attribute->m_DataSingleValue}; + } + else + { + return reinterpret_cast &>(m_Attribute->m_DataArray); + } +} + +} // end namespace adios2 + +#endif /* ADIOS2_BINDINGS_CXX11_CXX11_ATTRIBUTE_TCC_ */