ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
array.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef UTILS_SERIALIZATION_ARRAY_HPP
20#define UTILS_SERIALIZATION_ARRAY_HPP
21
22#include <boost/mpl/bool_fwd.hpp>
23#include <boost/mpl/greater.hpp>
24#include <boost/mpl/int.hpp>
25#include <boost/mpl/integral_c_tag.hpp>
26#include <boost/serialization/is_bitwise_serializable.hpp>
27#include <boost/serialization/level.hpp>
28#include <boost/serialization/tracking.hpp>
29#include <boost/serialization/tracking_enum.hpp>
30
31#include <cstddef>
32
33#define UTILS_ARRAY_TEMPLATE_T_N template <typename T, std::size_t N>
34#define UTILS_ARRAY_TEMPLATE_T_0 template <typename T>
35#define UTILS_ARRAY_CONTAINER_T_N(Container) Container<T, N>
36#define UTILS_ARRAY_CONTAINER_T_0(Container) Container<T>
37
38// forward declare
39namespace boost {
40namespace mpi {
41template <typename T> struct is_mpi_datatype;
42} /* namespace mpi */
43} /* namespace boost */
44
45/**
46 * @brief Mark array types as MPI data types.
47 * @tparam Container Template template type of the array
48 * @tparam N N if @p Container uses std::size_t N, else 0
49 */
50#define UTILS_ARRAY_BOOST_MPI_T(Container, N) \
51 namespace boost { \
52 namespace mpi { \
53 UTILS_ARRAY_TEMPLATE_T_##N struct is_mpi_datatype< \
54 UTILS_ARRAY_CONTAINER_T_##N(Container)> : public is_mpi_datatype<T> {}; \
55 } /* namespace mpi */ \
56 } /* namespace boost */
57
58/**
59 * @brief Mark array types as MPI bitwise serializable.
60 * @tparam Container Template template type of the array
61 * @tparam N N if @p Container uses std::size_t N, else 0
62 */
63#define UTILS_ARRAY_BOOST_BIT_S(Container, N) \
64 namespace boost { \
65 namespace serialization { \
66 UTILS_ARRAY_TEMPLATE_T_##N struct is_bitwise_serializable< \
67 UTILS_ARRAY_CONTAINER_T_##N(Container)> \
68 : public is_bitwise_serializable<T> {}; \
69 } /* namespace serialization */ \
70 } /* namespace boost */
71
72/**
73 * @brief Redefinition of @c BOOST_CLASS_IMPLEMENTATION for array types.
74 * @tparam Container Template template type of the array
75 * @tparam N N if @p Container uses std::size_t N, else 0
76 * @tparam ImplementationLevel Serialization implementation level
77 */
78#define UTILS_ARRAY_BOOST_CLASS(Container, N, ImplementationLevel) \
79 namespace boost { \
80 namespace serialization { \
81 UTILS_ARRAY_TEMPLATE_T_##N struct implementation_level_impl< \
82 const UTILS_ARRAY_CONTAINER_T_##N(Container)> { \
83 typedef mpl::integral_c_tag tag; \
84 typedef mpl::int_<ImplementationLevel> type; \
85 BOOST_STATIC_CONSTANT(int, \
86 value = implementation_level_impl::type::value); \
87 }; \
88 } /* namespace serialization */ \
89 } /* namespace boost */
90
91/**
92 * @brief Redefinition of @c BOOST_CLASS_TRACKING for array types.
93 * @tparam Container Template template type of the array
94 * @tparam N N if @p Container uses std::size_t N, else 0
95 * @tparam TrackingLevel Tracking level
96 */
97#define UTILS_ARRAY_BOOST_TRACK(Container, N, TrackingLevel) \
98 namespace boost { \
99 namespace serialization { \
100 UTILS_ARRAY_TEMPLATE_T_##N struct tracking_level< \
101 UTILS_ARRAY_CONTAINER_T_##N(Container)> { \
102 typedef mpl::integral_c_tag tag; \
103 typedef mpl::int_<TrackingLevel> type; \
104 BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value); \
105 BOOST_STATIC_ASSERT( \
106 (mpl::greater< \
107 implementation_level<UTILS_ARRAY_CONTAINER_T_##N(Container)>, \
108 mpl::int_<primitive_type>>::value)); \
109 }; \
110 } /* namespace serialization */ \
111 } /* namespace boost */
112
113#endif