PhoenixSerializer
3.0.0
PhoenixSerializer is a framework to save/load/serialize/deserialize data
Toggle main menu visibility
Loading...
Searching...
No Matches
data_stream_write_message.h
Go to the documentation of this file.
1
/***************************************
2
Auteur : Pierre Aubert
3
Mail : pierre.aubert@lapp.in2p3.fr
4
Licence : LGPL-3.0-only
5
****************************************/
6
7
#ifndef __DATA_STREAM_WRITE_MESSAGE_H__
8
#define __DATA_STREAM_WRITE_MESSAGE_H__
9
10
#include "
data_stream_include.h
"
11
13
template
<
typename
T>
14
struct
Serializer
<
SerializeIter
,
SerializeMode
::WRITE, T *> {
16
20
static
bool
phoenix_serialize
(
SerializeIter
& ds, T *& data) {
21
size_t
value =
reinterpret_cast<
size_t
>
(data);
// NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) the pointer address itself is serialised, only reinterpret_cast converts between pointer and integer
22
bool
b =
Serializer<SerializeIter, SerializeMode::WRITE, size_t>::phoenix_serialize
(ds, value);
23
return
b;
24
}
25
};
26
28
template
<
typename
T>
29
struct
Serializer
<
SerializeIter
,
SerializeMode
::WRITE, std::vector<T>> {
31
35
static
bool
phoenix_serialize
(
SerializeIter
& ds, std::vector<T> & data) {
36
//Save the size of the data
37
size_t
nbElement(data.size());
38
bool
b =
Serializer<SerializeIter, SerializeMode::WRITE, size_t>::phoenix_serialize
(ds, nbElement);
39
if
(nbElement == 0LU || !b) {
40
return
b;
41
}
//If there is no element, quit now
42
for
(
typename
std::vector<T>::iterator it(data.begin()); it != data.end(); ++it) {
43
b &=
Serializer<SerializeIter, SerializeMode::WRITE, T>::phoenix_serialize
(ds, *it);
44
}
45
return
b;
46
}
47
};
48
50
template
<
typename
T>
51
struct
Serializer
<
SerializeIter
,
SerializeMode
::WRITE, std::list<T>> {
53
57
static
bool
phoenix_serialize
(
SerializeIter
& ds, std::list<T> & data) {
58
//Save the size of the data
59
size_t
nbElement(data.size());
60
bool
b =
Serializer<SerializeIter, SerializeMode::WRITE, size_t>::phoenix_serialize
(ds, nbElement);
61
if
(nbElement == 0LU || !b) {
62
return
b;
63
}
//If there is no element, quit now
64
for
(
typename
std::list<T>::iterator it(data.begin()); it != data.end(); ++it) {
65
b &=
Serializer<SerializeIter, SerializeMode::WRITE, T>::phoenix_serialize
(ds, *it);
66
}
67
return
b;
68
}
69
};
70
72
template
<
typename
T,
typename
U>
73
struct
Serializer
<
SerializeIter
,
SerializeMode
::WRITE, std::map<T, U>> {
75
79
static
bool
phoenix_serialize
(
SerializeIter
& ds, std::map<T, U> & data) {
80
//Save the size of the data
81
size_t
nbElement(data.size());
82
bool
b =
Serializer<SerializeIter, SerializeMode::WRITE, size_t>::phoenix_serialize
(ds, nbElement);
83
if
(nbElement == 0LU || !b) {
84
return
b;
85
}
//If there is no element, quit now
86
for
(
typename
std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it) {
87
b &=
Serializer<SerializeIter, SerializeMode::WRITE, T>::phoenix_serialize
(ds, (T &)it->first);
// NOLINT(modernize-avoid-c-style-cast) WRITE never modifies data, but Serializer takes T & to share one function with READ
88
b &=
Serializer<SerializeIter, SerializeMode::WRITE, U>::phoenix_serialize
(ds, it->second);
89
}
90
return
b;
91
}
92
};
93
95
template
<
typename
T,
typename
U>
96
struct
Serializer
<
SerializeIter
,
SerializeMode
::WRITE, std::pair<T, U>> {
98
102
static
bool
phoenix_serialize
(
SerializeIter
& ds, std::pair<T, U> & data) {
103
bool
b =
Serializer<SerializeIter, SerializeMode::WRITE, T>::phoenix_serialize
(ds, (T &)data.first);
// NOLINT(modernize-avoid-c-style-cast) WRITE never modifies data, but Serializer takes T & to share one function with READ
104
b &=
Serializer<SerializeIter, SerializeMode::WRITE, U>::phoenix_serialize
(ds, data.second);
105
return
b;
106
}
107
};
108
109
#endif
data_stream_include.h
SerializeIter
SerializeType * SerializeIter
Definition
data_stream_include.h:28
SerializeMode
Definition
data_stream_include.h:18
Serializer< SerializeIter, SerializeMode::WRITE, T * >::phoenix_serialize
static bool phoenix_serialize(SerializeIter &ds, T *&data)
Write a pointer address in a message.
Definition
data_stream_write_message.h:20
Serializer< SerializeIter, SerializeMode::WRITE, std::list< T > >::phoenix_serialize
static bool phoenix_serialize(SerializeIter &ds, std::list< T > &data)
Get the size of a class std::list T.
Definition
data_stream_write_message.h:57
Serializer< SerializeIter, SerializeMode::WRITE, std::map< T, U > >::phoenix_serialize
static bool phoenix_serialize(SerializeIter &ds, std::map< T, U > &data)
Get the size of a class std::list T.
Definition
data_stream_write_message.h:79
Serializer< SerializeIter, SerializeMode::WRITE, std::pair< T, U > >::phoenix_serialize
static bool phoenix_serialize(SerializeIter &ds, std::pair< T, U > &data)
Get the size of a class std::list T.
Definition
data_stream_write_message.h:102
Serializer< SerializeIter, SerializeMode::WRITE, std::vector< T > >::phoenix_serialize
static bool phoenix_serialize(SerializeIter &ds, std::vector< T > &data)
Get the size of a class std::vector T.
Definition
data_stream_write_message.h:35
Serializer
Generic Serializer class.
Definition
data_stream_include.h:32
Serializer::phoenix_serialize
static bool phoenix_serialize(Stream &ds, T &data)
Dummy function to catch if a type is not specialised.
Definition
data_stream_include.h:37
src
data_stream_write_message.h
Generated by
1.18.0