-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3169 from JasonRuonanWang/datatype
move Span class to dedicated files
- Loading branch information
Showing
7 changed files
with
144 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Distributed under the OSI-approved Apache License, Version 2.0. See | ||
* accompanying file Copyright.txt for details. | ||
* | ||
* Span.cpp | ||
* | ||
* Created on: Apr 17, 2022 | ||
* Author: Jason Wang jason.ruonan.wang@gmail.com | ||
*/ | ||
|
||
#include "Span.tcc" | ||
|
||
namespace adios2 | ||
{ | ||
namespace core | ||
{ | ||
|
||
#define declare_template_instantiation(T) template class Span<T>; | ||
ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) | ||
#undef declare_type | ||
|
||
} // end namespace core | ||
} // end namespace adios2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Distributed under the OSI-approved Apache License, Version 2.0. See | ||
* accompanying file Copyright.txt for details. | ||
* | ||
* Span.h | ||
* | ||
* Created on: Apr 17, 2022 | ||
* Author: Jason Wang jason.ruonan.wang@gmail.com | ||
*/ | ||
|
||
#ifndef ADIOS2_CORE_SPAN_H_ | ||
#define ADIOS2_CORE_SPAN_H_ | ||
|
||
#include "adios2/core/VariableBase.h" | ||
|
||
namespace adios2 | ||
{ | ||
namespace core | ||
{ | ||
|
||
template <class T> | ||
class Span | ||
{ | ||
public: | ||
std::pair<size_t, size_t> m_MinMaxMetadataPositions; | ||
|
||
// internal position variables from which the engine | ||
// can return a valid pointer any time | ||
// BP5 needs two levels of reference, BP3/4 uses only one | ||
size_t m_PayloadPosition = 0; | ||
int m_BufferIdx = -1; | ||
|
||
T m_Value = T{}; | ||
|
||
Span(Engine &engine, const size_t size); | ||
~Span() = default; | ||
|
||
size_t Size() const noexcept; | ||
T *Data() const noexcept; | ||
|
||
T &At(const size_t position); | ||
|
||
T &operator[](const size_t position); | ||
|
||
private: | ||
Engine &m_Engine; | ||
size_t m_Size = 0; | ||
}; | ||
|
||
} // end namespace core | ||
} // end namespace adios2 | ||
|
||
#endif // ADIOS2_CORE_SPAN_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Distributed under the OSI-approved Apache License, Version 2.0. See | ||
* accompanying file Copyright.txt for details. | ||
* | ||
* Span.tcc | ||
* | ||
* Created on: Apr 17, 2022 | ||
* Author: Jason Wang jason.ruonan.wang@gmail.com | ||
*/ | ||
|
||
#ifndef ADIOS2_CORE_SPAN_TCC_ | ||
#define ADIOS2_CORE_SPAN_TCC_ | ||
|
||
#include "Span.h" | ||
|
||
#include "adios2/core/Engine.h" | ||
|
||
namespace adios2 | ||
{ | ||
namespace core | ||
{ | ||
|
||
template <class T> | ||
Span<T>::Span(Engine &engine, const size_t size) | ||
: m_Engine(engine), m_Size(size) | ||
{ | ||
} | ||
|
||
template <class T> | ||
size_t Span<T>::Size() const noexcept | ||
{ | ||
return m_Size; | ||
} | ||
|
||
template <class T> | ||
T *Span<T>::Data() const noexcept | ||
{ | ||
return m_Engine.BufferData<T>(m_BufferIdx, m_PayloadPosition); | ||
} | ||
|
||
template <class T> | ||
T &Span<T>::At(const size_t position) | ||
{ | ||
if (position > m_Size) | ||
{ | ||
helper::Throw<std::invalid_argument>( | ||
"Core", "Span", "At", | ||
"position " + std::to_string(position) + | ||
" is out of bounds for span of size " + std::to_string(m_Size)); | ||
} | ||
|
||
return (*this)[position]; | ||
} | ||
|
||
template <class T> | ||
T &Span<T>::operator[](const size_t position) | ||
{ | ||
T &data = *m_Engine.BufferData<T>(m_BufferIdx, | ||
m_PayloadPosition + position * sizeof(T)); | ||
return data; | ||
} | ||
|
||
} // end namespace core | ||
} // end namespace adios2 | ||
|
||
#endif // ADIOS2_CORE_SPAN_TCC_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters