Skip to content

Commit

Permalink
Rename Variadic to Variant
Browse files Browse the repository at this point in the history
  • Loading branch information
C0nsultant committed Apr 11, 2018
1 parent aea4659 commit 0ccf00b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
#pragma once

#include "openPMD/auxiliary/Variadic.hpp"
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/backend/Attribute.hpp"
#include "openPMD/backend/Writable.hpp"
#include "openPMD/Dataset.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2017 Fabian Koller
/* Copyright 2017-2018 Fabian Koller
*
* This file is part of openPMD-api.
*
Expand All @@ -22,10 +22,10 @@

#if __cplusplus >= 201703L
# include <variant>
namespace variadicSrc = std;
namespace variantSrc = std;
#else
# include <mpark/variant.hpp>
namespace variadicSrc = mpark;
namespace variantSrc = mpark;
#endif

#include <type_traits>
Expand All @@ -41,20 +41,20 @@ namespace auxiliary
* @tparam T Varaidic template argument list of datatypes to be stored.
*/
template< class T_DTYPES, typename ... T >
class Variadic
class Variant
{
static_assert(std::is_enum< T_DTYPES >::value, "Datatypes to Variadic must be supplied as enum.");
static_assert(std::is_enum< T_DTYPES >::value, "Datatypes to Variant must be supplied as enum.");

public:
using resource = variadicSrc::variant< T ... >;
using resource = variantSrc::variant< T ... >;
/** Construct a lightweight wrapper around a generic object that indicates
* the concrete datatype of the specific object stored.
*
* @note Gerneric objects can only generated implicitly if their datatype
* is contained in T_DTYPES.
* @param r Generic object to be stored.
*/
Variadic(resource r)
Variant(resource r)
: dtype{static_cast<T_DTYPES>(r.index())},
m_data{r}
{ }
Expand All @@ -68,7 +68,7 @@ class Variadic
template< typename U >
U get() const
{
return variadicSrc::get< U >(m_data);
return variantSrc::get< U >(m_data);
}

/** Retrieve the stored generic object.
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Attributable : public Writable
*
* @throw no_such_attribute_error If no Attribute is currently stored with the provided key.
* @param key Key (i.e. name) of the Attribute to retrieve value for.
* @return Stored Attribute in Variadic form.
* @return Stored Attribute in Variant form.
*/
Attribute getAttribute(std::string const& key) const;
/** Remove Attribute of provided value both logically and physically.
Expand Down
4 changes: 2 additions & 2 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
#pragma once

#include "openPMD/auxiliary/Variadic.hpp"
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/Datatype.hpp"

#include <array>
Expand All @@ -41,7 +41,7 @@ namespace openPMD
* @note Extending and/or modifying the available formats requires identical
* modifications to Datatype.
*/
using Attribute = auxiliary::Variadic< Datatype,
using Attribute = auxiliary::Variant< Datatype,
char, unsigned char,
int16_t, int32_t, int64_t,
uint16_t, uint32_t, uint64_t,
Expand Down
8 changes: 4 additions & 4 deletions include/openPMD/backend/GenericPatchData.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "openPMD/auxiliary/Variadic.hpp"
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/Datatype.hpp"

#include <cstdint>
Expand All @@ -27,12 +27,12 @@ class GenericPatchData
INT8, INT16, INT32, INT64,
BOOL,
UNDEFINED };
using variadic_t = auxiliary::Variadic< Dtype,
using variant_t = auxiliary::Variant< Dtype,
float, double,
uint8_t, uint16_t, uint32_t, uint64_t,
int8_t, int16_t, int32_t, int64_t,
bool >;
variadic_t m_data;
variant_t m_data;
}; // GenericPatchData


Expand All @@ -43,7 +43,7 @@ GenericPatchData::operator=(T t)
{
static_assert(std::is_arithmetic< T >::value, "Only arithmetic types may be saved as patch data.\n");
// Datatype d = determineDatatype< T >();
m_data = variadic_t(t);
m_data = variant_t(t);
return *this;
}

Expand Down
16 changes: 8 additions & 8 deletions test/AuxiliaryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* make Writable::parent visible for hierarchy check */
#define protected public
#include "openPMD/auxiliary/StringManip.hpp"
#include "openPMD/auxiliary/Variadic.hpp"
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/Writable.hpp"
#include "openPMD/IO/AbstractIOHandler.hpp"
Expand Down Expand Up @@ -75,7 +75,7 @@ class structure : public Attributable
int int_ = 42;
float float_ = 3.14f;

std::string text() const { return variadicSrc::get< std::string >(getAttribute("text").getResource()); }
std::string text() const { return variantSrc::get< std::string >(getAttribute("text").getResource()); }
structure& setText(std::string text) { setAttribute("text", text); return *this; }
};

Expand Down Expand Up @@ -187,17 +187,17 @@ TEST_CASE( "attributable_access_test", "[auxiliary]" )

a.setAttribute("key", std::string("value"));
REQUIRE(a.numAttributes() == 1);
REQUIRE(variadicSrc::get< std::string >(a.get("key")) == "value");
REQUIRE(variantSrc::get< std::string >(a.get("key")) == "value");

a.setAttribute("key", std::string("newValue"));
REQUIRE(a.numAttributes() == 1);
REQUIRE(variadicSrc::get< std::string >(a.get("key")) == "newValue");
REQUIRE(variantSrc::get< std::string >(a.get("key")) == "newValue");

using array_t = std::array< double, 7 >;
array_t arr{{1, 2, 3, 4, 5, 6, 7}};
a.setAttribute("array", arr);
REQUIRE(a.numAttributes() == 2);
REQUIRE(variadicSrc::get< array_t >(a.get("array")) == arr);
REQUIRE(variantSrc::get< array_t >(a.get("array")) == arr);
REQUIRE(a.deleteAttribute("nonExistentKey") == false);
REQUIRE(a.numAttributes() == 2);
REQUIRE(a.deleteAttribute("key") == true);
Expand All @@ -220,9 +220,9 @@ class Dotty : public Attributable
setAtt3("3");
}

int att1() const { return variadicSrc::get< int >(getAttribute("att1").getResource()); }
double att2() const { return variadicSrc::get< double >(getAttribute("att2").getResource()); }
std::string att3() const { return variadicSrc::get< std::string >(getAttribute("att3").getResource()); }
int att1() const { return variantSrc::get< int >(getAttribute("att1").getResource()); }
double att2() const { return variantSrc::get< double >(getAttribute("att2").getResource()); }
std::string att3() const { return variantSrc::get< std::string >(getAttribute("att3").getResource()); }
Dotty& setAtt1(int i) { setAttribute("att1", i); return *this; }
Dotty& setAtt2(double d) { setAttribute("att2", d); return *this; }
Dotty& setAtt3(std::string s) { setAttribute("att3", s); return *this; }
Expand Down

0 comments on commit 0ccf00b

Please sign in to comment.