Skip to content

Commit

Permalink
span: Define cxx11:Span<T> in .tcc
Browse files Browse the repository at this point in the history
and without the macro stuff
  • Loading branch information
germasch committed Mar 26, 2019
1 parent c448223 commit 16c9056
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 81 deletions.
53 changes: 3 additions & 50 deletions bindings/CXX11/cxx11/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,55 +224,8 @@ namespace adios2
ADIOS2_FOREACH_TYPE_1ARG(declare_type)
#undef declare_type

#define declare_type(T) \
\
template <> \
Variable<T>::Span::Span(core::Span<IOType> *coreSpan) \
: m_Span(coreSpan) \
{ \
} \
\
template <> \
size_t Variable<T>::Span::size() const noexcept \
{ \
return m_Span->Size(); \
} \
\
template <> \
T *Variable<T>::Span::data() const noexcept \
{ \
return reinterpret_cast<T *>(m_Span->Data()); \
} \
\
template <> \
T &Variable<T>::Span::at(const size_t position) \
{ \
IOType &data = m_Span->At(position); \
return reinterpret_cast<T &>(data); \
} \
\
template <> \
const T &Variable<T>::Span::at(const size_t position) const \
{ \
const IOType &data = m_Span->At(position); \
return reinterpret_cast<const T &>(data); \
} \
\
template <> \
T &Variable<T>::Span::operator[](const size_t position) \
{ \
IOType &data = m_Span->Access(position); \
return reinterpret_cast<T &>(data); \
} \
\
template <> \
const T &Variable<T>::Span::operator[](const size_t position) const \
{ \
const IOType &data = m_Span->Access(position); \
return reinterpret_cast<const T &>(data); \
}

ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_type)
#undef declare_type
#define declare_template_instantiation(T) template class Span<T>;
ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

} // end namespace adios2
67 changes: 36 additions & 31 deletions bindings/CXX11/cxx11/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ class Span; // private implementation
}
/// \endcond

template <class T>
class Span
{
using IOType = typename TypeInfo<T>::IOType;

public:
Span() = delete;
Span(const Span &) = delete;
Span(Span &&) = default;
~Span() = default;

Span &operator=(const Span &) = delete;
Span &operator=(Span &&) = default;

size_t size() const noexcept;
T *data() const noexcept;

T &at(const size_t position);
const T &at(const size_t position) const;

T &operator[](const size_t position);
const T &operator[](const size_t position) const;

// engine allowed to set m_Span
friend class Engine;

ADIOS2_CLASS_iterator;
ADIOS2_iterators_functions(data(), size());

private:
using CoreSpan = core::Span<IOType>;
Span(CoreSpan *span);
CoreSpan *m_Span = nullptr;
};

template <class T>
class Variable
{
Expand Down Expand Up @@ -268,37 +303,7 @@ class Variable
*/
std::vector<std::vector<typename Variable<T>::Info>> AllStepsBlocksInfo();

class Span
{
public:
Span() = delete;
Span(const Span &) = delete;
Span(Span &&) = default;
~Span() = default;

Span &operator=(const Span &) = delete;
Span &operator=(Span &&) = default;

size_t size() const noexcept;
T *data() const noexcept;

T &at(const size_t position);
const T &at(const size_t position) const;

T &operator[](const size_t position);
const T &operator[](const size_t position) const;

// engine allowed to set m_Span
friend class Engine;

ADIOS2_CLASS_iterator;
ADIOS2_iterators_functions(data(), size());

private:
using CoreSpan = core::Span<IOType>;
Span(CoreSpan *span);
CoreSpan *m_Span = nullptr;
};
using Span = adios2::Span<T>;

private:
Variable<T>(core::Variable<IOType> *variable);
Expand Down
47 changes: 47 additions & 0 deletions bindings/CXX11/cxx11/Variable.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,53 @@ Variable<T>::DoAllStepsBlocksInfo()
return allStepsBlocksInfo;
}

template <class T>
Span<T>::Span(core::Span<IOType> *coreSpan)
: m_Span(coreSpan)
{
}

// Span
template <class T>
size_t Span<T>::size() const noexcept
{
return m_Span->Size();
}

template <class T>
T *Span<T>::data() const noexcept
{
return reinterpret_cast<T *>(m_Span->Data());
}

template <class T>
T &Span<T>::at(const size_t position)
{
IOType &data = m_Span->At(position);
return reinterpret_cast<T &>(data);
}

template <class T>
const T &Span<T>::at(const size_t position) const
{
const IOType &data = m_Span->At(position);
return reinterpret_cast<const T &>(data);
}

template <class T>
T &Span<T>::operator[](const size_t position)
{
IOType &data = m_Span->Access(position);
return reinterpret_cast<T &>(data);
}

template <class T>
const T &Span<T>::operator[](const size_t position) const
{
const IOType &data = m_Span->Access(position);
return reinterpret_cast<const T &>(data);
}

} // end namespace adios2

#endif /* ADIOS2_BINDINGS_CXX11_CXX11_VARIABLE_TCC_ */

0 comments on commit 16c9056

Please sign in to comment.