Skip to content
Snippets Groups Projects
Commit f7de2550 authored by William F Godoy's avatar William F Godoy
Browse files

Initial implementation of Attributes with Tests

Refactored IO, Variable class due to common functionality
parent 857cdfc4
No related branches found
No related tags found
1 merge request!228Attribute template core class implementation
Showing
with 681 additions and 40 deletions
......@@ -4,6 +4,8 @@
#------------------------------------------------------------------------------#
add_library(adios2
core/Attribute.cpp core/Attribute.tcc
core/AttributeBase.cpp
core/ADIOS.cpp
core/Engine.cpp
core/IO.cpp core/IO.tcc
......
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Attribute.cpp : needed for template separation using Attribute.tcc
*
* Created on: Aug 3, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include "Attribute.h"
#include "Attribute.tcc"
namespace adios2
{
} // end namespace adios2
......@@ -2,7 +2,7 @@
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Attribute.h : template class
* Attribute.h : template class that defines typed attributes
*
* Created on: Aug 1, 2017
* Author: William F Godoy godoywf@ornl.gov
......@@ -45,4 +45,4 @@ public:
} // end namespace adios2
#endif /* SOURCE_ADIOS2_CORE_ATTRIBUTE_H_ */
#endif /* ADIOS2_CORE_ATTRIBUTE_H_ */
......@@ -31,7 +31,7 @@ namespace adios2
\
template <> \
Attribute<T>::Attribute(const std::string &name, const T &value) \
: AttributeBase(name, GetType<T>(), 1), m_DataValue() \
: AttributeBase(name, GetType<T>(), 1), m_DataValue(value) \
{ \
}
......@@ -39,3 +39,5 @@ ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_type)
#undef declare_type
} // end namespace adios2
#endif /* ADIOS2_CORE_ATTRIBUTE_TCC_ */
......@@ -11,6 +11,13 @@
#ifndef ADIOS2_CORE_ATTRIBUTEBASE_H_
#define ADIOS2_CORE_ATTRIBUTEBASE_H_
/// \cond EXCLUDE_FROM_DOXYGEN
#include <string>
/// \endcond
#include "adios2/ADIOSConfig.h"
#include "adios2/ADIOSTypes.h"
namespace adios2
{
......
......@@ -287,11 +287,22 @@ void IO::CheckTransportType(const std::string type) const
// Explicitly instantiate the necessary public template implementations
#define define_template_instantiation(T) \
template Variable<T> &IO::DefineVariable<T>( \
const std::string &, const Dims, const Dims, const Dims, const bool); \
template Variable<T> &IO::DefineVariable<T>(const std::string &, \
const Dims &, const Dims &, \
const Dims &, const bool); \
template Variable<T> &IO::GetVariable<T>(const std::string &);
ADIOS2_FOREACH_TYPE_1ARG(define_template_instantiation)
#undef define_template_instatiation
#define declare_template_instantiation(T) \
template Attribute<T> &IO::DefineAttribute<T>(const std::string &, \
const T *, const size_t); \
template Attribute<T> &IO::DefineAttribute<T>(const std::string &, \
const T &); \
template Attribute<T> &IO::GetAttribute(const std::string &);
ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
} // end namespace adios
......@@ -118,8 +118,8 @@ public:
* @return reference to Variable object
*/
template <class T>
Variable<T> &DefineVariable(const std::string &name, const Dims shape = {},
const Dims start = {}, const Dims count = {},
Variable<T> &DefineVariable(const std::string &name, const Dims &shape = {},
const Dims &start = {}, const Dims &count = {},
const bool constantShape = false);
/**
......@@ -136,13 +136,14 @@ public:
*/
template <class T>
VariableCompound &
DefineVariableCompound(const std::string &name, const Dims shape = Dims{},
const Dims start = Dims{}, const Dims count = Dims{},
const bool constantShape = false);
VariableCompound &DefineVariableCompound(const std::string &name,
const Dims &shape = Dims{},
const Dims &start = Dims{},
const Dims &count = Dims{},
const bool constantShape = false);
/**
* Define attribute from contiguous data array
* Define attribute from contiguous data array owned by an application
* @param name must be unique for the IO object
* @param array pointer to user data
* @param elements number of data elements
......@@ -153,7 +154,7 @@ public:
const size_t elements);
/**
* Define attribute from a single variable
* Define attribute from a single variable making a copy
* @param name must be unique for the IO object
* @param value single data value
* @return reference to internal Attribute
......@@ -340,8 +341,8 @@ private:
// Explicit declaration of the public template methods
#define declare_template_instantiation(T) \
extern template Variable<T> &IO::DefineVariable<T>( \
const std::string &name, const Dims, const Dims, const Dims, \
const bool constantShape); \
const std::string &, const Dims &, const Dims &, const Dims &, \
const bool); \
extern template Variable<T> &IO::GetVariable<T>(const std::string &name);
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
......@@ -349,14 +350,15 @@ ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#define declare_template_instantiation(T) \
extern template Attribute<T> &IO::DefineAttribute<T>( \
const std::string &name, const T *array, const size_t elements); \
extern template Attribute<T> &IO::DefineAttribute<T>( \
const std::string &name, const T &value);
const std::string &, const T *, const size_t); \
extern template Attribute<T> &IO::DefineAttribute<T>(const std::string &, \
const T &); \
extern template Attribute<T> &IO::GetAttribute(const std::string &);
ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
} // end namespace adios
} // end namespace adios2
#include "adios2/core/IO.inl"
......
......@@ -21,10 +21,10 @@ namespace adios2
{
template <class T>
VariableCompound &IO::DefineVariableCompound(const std::string &name,
const Dims shape, const Dims start,
const Dims count,
const bool constantShape)
VariableCompound &
IO::DefineVariableCompound(const std::string &name, const Dims &shape,
const Dims &start, const Dims &count,
const bool constantShape)
{
if (m_DebugMode)
{
......
......@@ -26,8 +26,8 @@ namespace adios2
{
template <class T>
Variable<T> &IO::DefineVariable(const std::string &name, const Dims shape,
const Dims start, const Dims count,
Variable<T> &IO::DefineVariable(const std::string &name, const Dims &shape,
const Dims &start, const Dims &count,
const bool constantShape)
{
if (m_DebugMode)
......
......@@ -2,7 +2,7 @@
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Variable.cpp needed for template separation using Variable.tcc
* Variable.cpp : needed for template separation using Variable.tcc
*
* Created on: Jun 8, 2017
* Author: William F Godoy godoywf@ornl.gov
......@@ -14,4 +14,4 @@
namespace adios2
{
} // end namespace adios
} // end namespace adios2
......@@ -18,8 +18,6 @@
#include <vector>
/// \endcond
#include "adios2/ADIOSMacros.h"
#include "adios2/core/Transform.h"
#include "adios2/core/VariableBase.h"
namespace adios2
......@@ -50,8 +48,8 @@ public:
* @param constantShape
* @param debugMode
*/
Variable<T>(const std::string &name, const Dims shape, const Dims start,
const Dims count, const bool constantShape,
Variable<T>(const std::string &name, const Dims &shape, const Dims &start,
const Dims &count, const bool constantShape,
const bool debugMode);
~Variable<T>() = default;
......
......@@ -22,8 +22,8 @@ namespace adios2
#define declare_type(T) \
\
template <> \
Variable<T>::Variable(const std::string &name, const Dims shape, \
const Dims start, const Dims count, \
Variable<T>::Variable(const std::string &name, const Dims &shape, \
const Dims &start, const Dims &count, \
const bool constantShape, const bool debugMode) \
: VariableBase(name, GetType<T>(), sizeof(T), shape, start, count, \
constantShape, debugMode) \
......
......@@ -21,8 +21,8 @@ namespace adios2
{
VariableBase::VariableBase(const std::string &name, const std::string type,
const size_t elementSize, const Dims shape,
const Dims start, const Dims count,
const size_t elementSize, const Dims &shape,
const Dims &start, const Dims &count,
const bool constantDims, const bool debugMode)
: m_Name(name), m_Type(type), m_ElementSize(elementSize), m_Shape(shape),
m_Start(start), m_Count(count), m_ConstantDims(constantDims),
......@@ -41,7 +41,7 @@ size_t VariableBase::TotalSize() const noexcept
return GetTotalSize(m_Count);
}
void VariableBase::SetSelection(const Dims start, const Dims count)
void VariableBase::SetSelection(const Dims &start, const Dims &count)
{
if (m_DebugMode)
{
......
......@@ -63,8 +63,8 @@ public:
unsigned int m_AvailableSteps = 1;
VariableBase(const std::string &name, const std::string type,
const size_t elementSize, const Dims shape, const Dims start,
const Dims count, const bool constantShape,
const size_t elementSize, const Dims &shape, const Dims &start,
const Dims &count, const bool constantShape,
const bool debugMode);
virtual ~VariableBase() = default;
......@@ -82,7 +82,7 @@ public:
size_t TotalSize() const noexcept;
/** Set the local dimension and global offset of the variable */
void SetSelection(const Dims start, const Dims count);
void SetSelection(const Dims &start, const Dims &count);
/** Overloaded version of SetSelection using a SelectionBoundingBox */
void SetSelection(const SelectionBoundingBox &selection);
......
......@@ -27,6 +27,13 @@ inline std::string GetType<void>() noexcept
{
return "unknown";
}
template <>
inline std::string GetType<std::string>() noexcept
{
return "string";
}
template <>
inline std::string GetType<char>() noexcept
{
......
......@@ -9,5 +9,9 @@ target_link_libraries(TestADIOSInterfaceWrite adios2 gtest gtest_main)
add_executable(TestADIOSDefineVariable TestADIOSDefineVariable.cpp)
target_link_libraries(TestADIOSDefineVariable adios2 gtest gtest_main)
add_executable(TestADIOSDefineAttribute TestADIOSDefineAttribute.cpp)
target_link_libraries(TestADIOSDefineAttribute adios2 gtest gtest_main)
gtest_add_tests(TARGET TestADIOSInterfaceWrite)
gtest_add_tests(TARGET TestADIOSDefineVariable)
\ No newline at end of file
gtest_add_tests(TARGET TestADIOSDefineVariable)
gtest_add_tests(TARGET TestADIOSDefineAttribute)
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment