From 0ccf00b5ecc7661a0c26d4db4c8c6770d772c4e3 Mon Sep 17 00:00:00 2001 From: C0nsultant Date: Wed, 11 Apr 2018 12:05:13 +0200 Subject: [PATCH] Rename Variadic to Variant --- include/openPMD/IO/IOTask.hpp | 2 +- .../auxiliary/{Variadic.hpp => Variant.hpp} | 16 ++++++++-------- include/openPMD/backend/Attributable.hpp | 2 +- include/openPMD/backend/Attribute.hpp | 4 ++-- include/openPMD/backend/GenericPatchData.hpp | 8 ++++---- test/AuxiliaryTest.cpp | 16 ++++++++-------- 6 files changed, 24 insertions(+), 24 deletions(-) rename include/openPMD/auxiliary/{Variadic.hpp => Variant.hpp} (89%) diff --git a/include/openPMD/IO/IOTask.hpp b/include/openPMD/IO/IOTask.hpp index dd58f52781..afa95c2352 100755 --- a/include/openPMD/IO/IOTask.hpp +++ b/include/openPMD/IO/IOTask.hpp @@ -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" diff --git a/include/openPMD/auxiliary/Variadic.hpp b/include/openPMD/auxiliary/Variant.hpp similarity index 89% rename from include/openPMD/auxiliary/Variadic.hpp rename to include/openPMD/auxiliary/Variant.hpp index 73e06c7128..596365e07b 100644 --- a/include/openPMD/auxiliary/Variadic.hpp +++ b/include/openPMD/auxiliary/Variant.hpp @@ -1,4 +1,4 @@ -/* Copyright 2017 Fabian Koller +/* Copyright 2017-2018 Fabian Koller * * This file is part of openPMD-api. * @@ -22,10 +22,10 @@ #if __cplusplus >= 201703L # include -namespace variadicSrc = std; +namespace variantSrc = std; #else # include -namespace variadicSrc = mpark; +namespace variantSrc = mpark; #endif #include @@ -41,12 +41,12 @@ 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. * @@ -54,7 +54,7 @@ class Variadic * is contained in T_DTYPES. * @param r Generic object to be stored. */ - Variadic(resource r) + Variant(resource r) : dtype{static_cast(r.index())}, m_data{r} { } @@ -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. diff --git a/include/openPMD/backend/Attributable.hpp b/include/openPMD/backend/Attributable.hpp index 9f4587d045..7b19bb28ce 100755 --- a/include/openPMD/backend/Attributable.hpp +++ b/include/openPMD/backend/Attributable.hpp @@ -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. diff --git a/include/openPMD/backend/Attribute.hpp b/include/openPMD/backend/Attribute.hpp index 9c994a0093..a86e629ebd 100755 --- a/include/openPMD/backend/Attribute.hpp +++ b/include/openPMD/backend/Attribute.hpp @@ -20,7 +20,7 @@ */ #pragma once -#include "openPMD/auxiliary/Variadic.hpp" +#include "openPMD/auxiliary/Variant.hpp" #include "openPMD/Datatype.hpp" #include @@ -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, diff --git a/include/openPMD/backend/GenericPatchData.hpp b/include/openPMD/backend/GenericPatchData.hpp index 6d4a7a2a1b..a12eb2b4aa 100644 --- a/include/openPMD/backend/GenericPatchData.hpp +++ b/include/openPMD/backend/GenericPatchData.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openPMD/auxiliary/Variadic.hpp" +#include "openPMD/auxiliary/Variant.hpp" #include "openPMD/Datatype.hpp" #include @@ -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 @@ -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; } diff --git a/test/AuxiliaryTest.cpp b/test/AuxiliaryTest.cpp index 8acb02a553..e140132a18 100755 --- a/test/AuxiliaryTest.cpp +++ b/test/AuxiliaryTest.cpp @@ -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" @@ -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; } }; @@ -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); @@ -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; }