Skip to content

Commit 20497a5

Browse files
Gabriele Gaetano Fronzématthiasrichter
authored andcommitted
Moving is_boost_serializable type trait in TypeTraits.h
1 parent c8d60ce commit 20497a5

File tree

5 files changed

+61
-96
lines changed

5 files changed

+61
-96
lines changed

Common/Utils/include/CommonUtils/BoostSerializer.h

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,8 @@ namespace o2
3939
{
4040
namespace utils
4141
{
42-
namespace check
43-
{
44-
// template <class Type, class Archive, typename = typename std::enable_if<std::is_class<Type>::value>::type>
45-
template <typename...>
46-
using void_t = void;
47-
48-
template <typename Type, typename Archive = boost::archive::binary_oarchive, typename = void_t<>>
49-
struct is_boost_serializable_base : std::false_type {
50-
};
51-
52-
template <class Type, typename Archive>
53-
struct is_boost_serializable_base<Type, Archive,
54-
void_t<decltype(std::declval<Type &>().serialize(std::declval<Archive &>(), 0))>>
55-
: std::true_type {
56-
};
57-
58-
// template <class Type, typename Archive>
59-
// struct is_boost_serializable_base<Type, Archive,
60-
// typename std::enable_if<boost::serialization::is_bitwise_serializable<typename Type::value_type>::value>::type>
61-
// : std::true_type {
62-
// };
63-
64-
template <class Type, typename Archive = boost::archive::binary_oarchive, typename = void_t<>>
65-
struct is_boost_serializable
66-
: is_boost_serializable_base<Type, Archive> {
67-
};
68-
69-
template <class Type, typename Archive>
70-
struct is_boost_serializable<Type, Archive, void_t<typename Type::value_type>>
71-
: is_boost_serializable<typename Type::value_type, Archive> {
72-
};
73-
74-
template <class Type>
75-
struct is_boost_serializable<Type, boost::archive::binary_oarchive, void_t<typename Type::value_type>>
76-
: is_boost_serializable<typename Type::value_type, boost::archive::binary_oarchive> {
77-
};
78-
} // namespace check
79-
8042
template <typename ContT>
81-
typename std::enable_if<check::is_boost_serializable<ContT, boost::archive::binary_oarchive>::value, std::ostringstream>::type
82-
BoostSerialize(const ContT& dataSet)
43+
std::ostringstream BoostSerialize(const ContT& dataSet)
8344
{
8445
/// Serialises a container (vector, array or list) using boost serialisation routines.
8546
/// Requires the contained type to be either trivial or provided with an overried of boost::serialise method.
@@ -90,8 +51,7 @@ typename std::enable_if<check::is_boost_serializable<ContT, boost::archive::bina
9051
}
9152

9253
template <typename ContT>
93-
typename std::enable_if<check::is_boost_serializable<ContT, boost::archive::binary_iarchive>::value, ContT>::type
94-
BoostDeserialize(std::string& msgStr)
54+
ContT BoostDeserialize(std::string& msgStr)
9555
{
9656
/// Deserialises a msg contained in a string in a container type (vector, array or list) of the provided type.
9757
ContT output;

Framework/Core/include/Framework/DataAllocator.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ class DataAllocator
143143
return make_boost<WT>(std::move(specs));
144144
}
145145

146-
template<typename T>
147-
typename std::enable_if<is_specialization<T,BoostSerialized>::value == false
148-
&& is_messageable<T>::value == false
149-
&& o2::utils::check::is_boost_serializable<T>::value == true
150-
&& std::is_base_of<std::string, T>::value == false, T&>::type
146+
template <typename T>
147+
typename std::enable_if<is_specialization<T, BoostSerialized>::value == false //
148+
&& is_messageable<T>::value == false //
149+
&& framework::is_boost_serializable<T>::value == true //
150+
&& std::is_base_of<std::string, T>::value == false,
151+
T&>::type
151152
make(const Output& spec)
152153
{
153154
return make_boost<T>(std::move(spec));
@@ -166,12 +167,12 @@ class DataAllocator
166167
/// the arguments and the different return types
167168
template <typename T>
168169
typename std::enable_if<
169-
is_specialization<T,BoostSerialized>::value == false
170-
&& std::is_base_of<TObject, T>::value == false
171-
&& std::is_base_of<TableBuilder, T>::value == false
172-
&& is_messageable<T>::value == false
173-
&& std::is_same<std::string, T>::value == false
174-
&& o2::utils::check::is_boost_serializable<T>::value == false,
170+
is_specialization<T, BoostSerialized>::value == false //
171+
&& std::is_base_of<TObject, T>::value == false //
172+
&& std::is_base_of<TableBuilder, T>::value == false //
173+
&& is_messageable<T>::value == false //
174+
&& std::is_same<std::string, T>::value == false //
175+
&& framework::is_boost_serializable<T>::value == false, //
175176
T&>::type
176177
make(const Output&)
177178
{
@@ -187,10 +188,10 @@ class DataAllocator
187188
/// catching unsupported type for case of span of objects
188189
template <typename T>
189190
typename std::enable_if<
190-
std::is_base_of<TObject, T>::value == false
191-
&& is_messageable<T>::value == false
192-
&& std::is_same<std::string, T>::value == false
193-
&& o2::utils::check::is_boost_serializable<T>::value == false,
191+
std::is_base_of<TObject, T>::value == false //
192+
&& is_messageable<T>::value == false //
193+
&& std::is_same<std::string, T>::value == false //
194+
&& framework::is_boost_serializable<T>::value == false, //
194195
gsl::span<T>>::type
195196
make(const Output&, size_t)
196197
{
@@ -206,10 +207,10 @@ class DataAllocator
206207
/// catching unsupported type for case of at least two additional arguments
207208
template <typename T, typename U, typename V, typename... Args>
208209
typename std::enable_if<
209-
std::is_base_of<TObject, T>::value == false
210-
&& is_messageable<T>::value == false
211-
&& std::is_same<std::string, T>::value == false
212-
&& o2::utils::check::is_boost_serializable<T>::value == false,
210+
std::is_base_of<TObject, T>::value == false //
211+
&& is_messageable<T>::value == false //
212+
&& std::is_same<std::string, T>::value == false //
213+
&& framework::is_boost_serializable<T>::value == false, //
213214
T&>::type
214215
make(const Output&, U, V, Args...)
215216
{

Framework/Core/include/Framework/InputRecord.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class InputRecord
162162
/// Note: is_messagable also checks that T is not a pointer
163163
/// @return const ref to specified type
164164
template <typename T>
165-
typename std::enable_if<is_messageable<T>::value && std::is_same<T, DataRef>::value == false && o2::utils::check::is_boost_serializable<T>::value == false, //
165+
typename std::enable_if<is_messageable<T>::value && std::is_same<T, DataRef>::value == false && framework::is_boost_serializable<T>::value == false, //
166166
T>::type const&
167167
get(char const* binding) const
168168
{
@@ -246,10 +246,12 @@ class InputRecord
246246
/// FIXME: check that the string is null terminated.
247247
/// @return deserialized copy of payload
248248
template <typename T>
249-
typename std::enable_if<o2::utils::check::is_boost_serializable<T>::value == true
250-
&& std::is_same<T, std::string>::value == false
251-
&& has_root_dictionary<T>::value == false, T>::type
252-
get(char const *binding) const {
249+
typename std::enable_if<framework::is_boost_serializable<T>::value == true //
250+
&& std::is_same<T, std::string>::value == false //
251+
&& has_root_dictionary<T>::value == false,
252+
T>::type
253+
get(char const* binding) const
254+
{
253255
auto&& ref = get<DataRef>(binding);
254256
auto header = header::get<const header::DataHeader*>(ref.header);
255257
assert(header);
@@ -399,12 +401,12 @@ class InputRecord
399401
// will be unified in a later refactoring
400402
// FIXME: request a pointer where you get a pointer
401403
template <typename T>
402-
typename std::enable_if_t<is_messageable<T>::value == false
403-
&& std::is_pointer<T>::value == false
404-
&& std::is_same<T, DataRef>::value == false
405-
&& std::is_same<T, std::string>::value == false
406-
&& has_root_dictionary<T>::value == false
407-
&& o2::utils::check::is_boost_serializable<T>::value == false,
404+
typename std::enable_if_t<is_messageable<T>::value == false //
405+
&& std::is_pointer<T>::value == false //
406+
&& std::is_same<T, DataRef>::value == false //
407+
&& std::is_same<T, std::string>::value == false //
408+
&& has_root_dictionary<T>::value == false //
409+
&& framework::is_boost_serializable<T>::value == false, //
408410
std::unique_ptr<T const, Deleter<T const>>>::type
409411
get(char const* binding) const
410412
{

Framework/Core/include/Framework/SerializationMethods.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class BoostSerialized
8888
using non_messageable = o2::framework::MarkAsNonMessageable;
8989
using wrapped_type = T;
9090

91-
static_assert(o2::utils::check::is_boost_serializable<T>::value == true, "wrapped type provides no boost serialize override");
91+
static_assert(framework::is_boost_serializable<T>::value == true, "wrapped type provides no boost serialize override");
9292

9393
BoostSerialized() = delete;
9494
BoostSerialized(wrapped_type& ref) : mRef(ref) {}

Framework/Core/include/Framework/TypeTraits.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,31 @@ namespace framework
2525
/// is a specialization of a given reference type Ref.
2626
/// See Framework/Core/test_TypeTraits.cxx for an example
2727

28-
template<typename T, template<typename...> class Ref>
29-
struct is_specialization : std::false_type {};
28+
template <typename T, template <typename...> class Ref>
29+
struct is_specialization : std::false_type {
30+
};
3031

31-
template<template<typename...> class Ref, typename... Args>
32-
struct is_specialization<Ref<Args...>, Ref>: std::true_type {};
32+
template <template <typename...> class Ref, typename... Args>
33+
struct is_specialization<Ref<Args...>, Ref> : std::true_type {
34+
};
3335

3436
// helper struct to mark a type as non-messageable by defining a type alias
3537
// with name 'non-messageable'
36-
struct MarkAsNonMessageable {};
38+
struct MarkAsNonMessageable {
39+
};
3740

3841
// detect if a type is forced to be non-messageable, this is done by defining
3942
// a type alias with name 'non-messageable' of the type MarkAsNonMessageable
40-
template< typename T, typename _ = void >
41-
struct is_forced_non_messageable : public std::false_type {};
43+
template <typename T, typename _ = void>
44+
struct is_forced_non_messageable : public std::false_type {
45+
};
4246

4347
// specialization to detect the type a lias
4448
template <typename T>
4549
struct is_forced_non_messageable<
4650
T,
47-
typename std::enable_if<std::is_same<typename T::non_messageable, MarkAsNonMessageable>::value>::type
48-
> : public std::true_type {};
51+
typename std::enable_if<std::is_same<typename T::non_messageable, MarkAsNonMessageable>::value>::type> : public std::true_type {
52+
};
4953

5054
// TODO: extend this to exclude structs with pointer data members
5155
// see e.g. https://stackoverflow.com/questions/32880990/how-to-check-if-class-has-pointers-in-c14
@@ -61,12 +65,14 @@ struct is_messageable : std::conditional<std::is_trivially_copyable<T>::value &&
6165
// Detect a container by checking on the container properties
6266
// this is the default trait implementation inheriting from false_type
6367
template <typename T, typename _ = void>
64-
struct is_container : std::false_type {};
68+
struct is_container : std::false_type {
69+
};
6570

6671
// helper to be substituted if the specified template arguments are
6772
// available
6873
template <typename... Ts>
69-
struct class_member_checker {};
74+
struct class_member_checker {
75+
};
7076

7177
// the specialization for container types inheriting from true_type
7278
// the helper can be substituted if all the specified members are available
@@ -86,12 +92,9 @@ struct is_container<
8692
decltype(std::declval<T>().begin()),
8793
decltype(std::declval<T>().end()),
8894
decltype(std::declval<T>().cbegin()),
89-
decltype(std::declval<T>().cend())
90-
>,
91-
void
92-
>
93-
> : public std::true_type {};
94-
95+
decltype(std::declval<T>().cend())>,
96+
void>> : public std::true_type {
97+
};
9598

9699
// Detect whether a class has a ROOT dictionary
97100
// This member detector idiom is implemented using SFINAE idiom to look for
@@ -100,19 +103,18 @@ struct is_container<
100103
// serialization however is also possible for types only having the link
101104
// in the LinkDef file. Such types can only be detected at runtime.
102105
template <typename T, typename _ = void>
103-
struct has_root_dictionary : std::false_type {};
106+
struct has_root_dictionary : std::false_type {
107+
};
104108

105109
template <typename T>
106110
struct has_root_dictionary<
107111
T,
108112
std::conditional_t<
109113
false,
110114
class_member_checker<
111-
decltype(std::declval<T>().Class())
112-
>,
113-
void
114-
>
115-
> : public std::true_type {};
115+
decltype(std::declval<T>().Class())>,
116+
void>> : public std::true_type {
117+
};
116118

117119
// specialization for containers
118120
// covers cases with T::value_type having ROOT dictionary, meaning that

0 commit comments

Comments
 (0)