Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPark.Variant #74

Merged
merged 6 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ openpmd_option(ADIOS2 "Enable ADIOS2 support" OFF)
# openpmd_option(JSON "Enable JSON support" AUTO)
# openpmd_option(PYTHON "Enable Python bindings" OFF)

option(openPMD_USE_INTERNAL_VARIANT "Use internally shipped MPark.Variant" ON)

set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
Expand Down Expand Up @@ -190,6 +192,7 @@ set(CORE_SOURCE
src/Series.cpp
src/backend/Attributable.cpp
src/backend/BaseRecordComponent.cpp
src/backend/GenericPatchData.cpp
src/backend/MeshRecordComponent.cpp
src/backend/PatchRecord.cpp
src/backend/PatchRecordComponent.cpp
Expand Down Expand Up @@ -218,6 +221,14 @@ target_include_directories(openPMD PUBLIC
$<INSTALL_INTERFACE:include>
)

# C++11 std::variant (C++17 stdlib preview)
if(openPMD_USE_INTERNAL_VARIANT)
message(STATUS "MPark.Variant: Using INTERNAL version 1.3.0")
else()
find_package(mpark_variant 1.3.0 REQUIRED)
target_link_libraries(openPMD PUBLIC mpark_variant)
endif()

if(TARGET Boost::filesystem)
target_link_libraries(openPMD PUBLIC
Boost::boost Boost::system Boost::filesystem)
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Required:
* CMake 3.10.0+
* Boost 1.62.0+: `filesystem`, `system`, `unit_test_framework`

Shipped internally:
* [MPark.Variant](https://github.com/mpark/variant) 1.3.0+

Optional I/O backends:
* HDF5 1.8.6+
* ADIOS 1.10+ (*not yet implemented*)
Expand Down Expand Up @@ -129,16 +132,23 @@ sudo make install
The following options can be added to the `cmake` call to control features.
CMake controls options with prefixed `-D`, e.g. `-DopenPMD_USE_MPI=OFF`:

| CMake Option | Values | Description |
|--------------------|------------------|----------------------------------------|
| openPMD_USE_MPI | **AUTO**/ON/OFF | Enable MPI support |
| openPMD_USE_HDF5 | **AUTO**/ON/OFF | Enable support for HDF5 |
| openPMD_USE_ADIOS1 | **AUTO**/ON/OFF | Enable support for ADIOS1 <sup>1</sup> |
| openPMD_USE_ADIOS2 | AUTO/ON/**OFF** | Enable support for ADIOS2 <sup>1</sup> |
| openPMD_USE_PYTHON | AUTO/ON/**OFF** | Enable Python bindings <sup>1</sup> |
| CMake Option | Values | Description |
|----------------------|------------------|----------------------------------------|
| `openPMD_USE_MPI` | **AUTO**/ON/OFF | Enable MPI support |
| `openPMD_USE_HDF5` | **AUTO**/ON/OFF | Enable support for HDF5 |
| `openPMD_USE_ADIOS1` | **AUTO**/ON/OFF | Enable support for ADIOS1 <sup>1</sup> |
| `openPMD_USE_ADIOS2` | AUTO/ON/**OFF** | Enable support for ADIOS2 <sup>1</sup> |
| `openPMD_USE_PYTHON` | AUTO/ON/**OFF** | Enable Python bindings <sup>1</sup> |

<sup>1</sup> *not yet implemented*

Additionally, the following libraries are shipped internally.
The following options allow to switch to external installs:

| CMake Option | Values | Library | Version |
|--------------------------------|------------|---------------|---------|
| `openPMD_USE_INTERNAL_VARIANT` | **ON**/OFF | MPark.Variant | 1.13.0+ |

By default, this will build as a static library (`libopenPMD.a`) and installs also its headers.
In order to build a static library, append `-DBUILD_SHARED_LIBS=ON` to the `cmake` command.
You can only build a static or a shared library at a time.
Expand Down Expand Up @@ -170,3 +180,4 @@ if(openPMD_FOUND)
target_link_libraries(YourTarget PRIVATE openPMD::openPMD)
endif()
```

28 changes: 19 additions & 9 deletions docs/source/dev/buildoptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ Build Options
The following options can be added to the ``cmake`` call to control features.
CMake controls options with prefixed ``-D``, e.g. ``-DopenPMD_USE_MPI=OFF``:

=================== =============== ==================================
CMake Option Values Description
=================== =============== ==================================
openPMD_USE_MPI **AUTO**/ON/OFF Enable MPI support
openPMD_USE_HDF5 **AUTO**/ON/OFF Enable support for HDF5
openPMD_USE_ADIOS1 **AUTO**/ON/OFF Enable support for ADIOS1 :sup:`1`
openPMD_USE_ADIOS2 AUTO/ON/**OFF** Enable support for ADIOS2 :sup:`1`
openPMD_USE_PYTHON AUTO/ON/**OFF** Enable Python bindings :sup:`1`
=================== =============== ==================================
====================== =============== ==================================
CMake Option Values Description
====================== =============== ==================================
``openPMD_USE_MPI`` **AUTO**/ON/OFF Enable MPI support
``openPMD_USE_HDF5`` **AUTO**/ON/OFF Enable support for HDF5
``openPMD_USE_ADIOS1`` **AUTO**/ON/OFF Enable support for ADIOS1 :sup:`1`
``openPMD_USE_ADIOS2`` AUTO/ON/**OFF** Enable support for ADIOS2 :sup:`1`
``openPMD_USE_PYTHON`` AUTO/ON/**OFF** Enable Python bindings :sup:`1`
====================== =============== ==================================

:sup:`1` *not yet implemented*

Additionally, the following libraries are shipped internally.
The following options allow to switch to external installs:

================================ =========== ============= ========
CMake Option Values Library Version
================================ =========== ============= ========
``openPMD_USE_INTERNAL_VARIANT`` **ON**/OFF MPark.Variant 1.13.0+
================================ =========== ============= ========

By default, this will build as a static library (``libopenPMD.a``) and installs also its headers.
In order to build a static library, append ``-DBUILD_SHARED_LIBS=ON`` to the ``cmake`` command.
You can only build a static or a shared library at a time.

By default, the ``Release`` version is built.
In order to build with debug symbols, pass ``-DCMAKE_BUILD_TYPE=Debug`` to your ``cmake`` command.

8 changes: 8 additions & 0 deletions docs/source/dev/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Required
* CMake 3.10.0+
* Boost 1.62.0+: ``filesystem``, ``system``, ``unit_test_framework``

Shipped internally
------------------

The following libraries shipped internally:

* `MPark.Variant <https://github.com/mpark/variant>`_ 1.3.0+

Optional: I/O backends
----------------------

Expand All @@ -32,3 +39,4 @@ Optional: language bindings

* pybind11 2.3.0+
* xtensor-python 0.17.0+

1 change: 1 addition & 0 deletions include/IO/IOTask.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "auxiliary/Variadic.hpp"
#include "backend/Attribute.hpp"
#include "backend/Writable.hpp"
#include "Dataset.hpp"
Expand Down
23 changes: 11 additions & 12 deletions include/auxiliary/Variadic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
*/
#pragma once

// boost::variant uses boost::mpl::list to store template types
// the default length of the list is limited to 20 items,
// there are more dtypes handled in openPMD-api
// BOOST_MPL_LIMIT_LIST_SIZE has to be a multiple of 10
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_LIST_SIZE 30

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

#include <type_traits>

Expand All @@ -43,7 +42,7 @@ class Variadic
static_assert(std::is_enum< T_DTYPES >::value, "Datatypes to Variadic must be supplied as enum.");

public:
using resource = boost::variant< T ... >;
using resource = variadicSrc::variant< T ... >;
/** Construct a lightweight wrapper around a generic object that indicates
* the concrete datatype of the specific object stored.
*
Expand All @@ -52,20 +51,20 @@ class Variadic
* @param r Generic object to be stored.
*/
Variadic(resource r)
: dtype{static_cast<T_DTYPES>(r.which())},
: dtype{static_cast<T_DTYPES>(r.index())},
m_data{r}
{ }

/** Retrieve a stored specific object of known datatype with ensured type-safety.
*
* @throw boost::bad_get if stored object is not of type U.
* @throw std::bad_variant_access if stored object is not of type U.
* @tparam U Type of the object to be retrieved.
* @return Copy of the retrieved object of type U.
*/
template< typename U >
U get() const
{
return boost::get< U >(m_data);
return variadicSrc::get< U >(m_data);
}

/** Retrieve the stored generic object.
Expand Down
4 changes: 1 addition & 3 deletions include/backend/GenericPatchData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ class GenericPatchData

private:
enum Dtype { UCHAR, CHAR,
UINT, INT,
FLOAT, DOUBLE,
UINT8, UINT16, UINT32, UINT64,
INT8, INT16, INT32, INT64,
BOOL,
UNDEFINED };
using variadic_t = Variadic< Dtype,
unsigned char, char,
unsigned int, int,
float, double,
uint8_t, uint16_t, uint32_t, uint64_t,
uint8_t, int16_t, int32_t, int64_t,
int8_t, int16_t, int32_t, int64_t,
bool >;
variadic_t m_data;
}; //GenericPatchData
Expand Down
Loading