PhoenixSerializer  3.0.0
PhoenixSerializer is a framework to save/load/serialize/deserialize data
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
13template <typename 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
23 return b;
24 }
25};
26
28template <typename T>
29struct 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());
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) {
44 }
45 return b;
46 }
47};
48
50template <typename T>
51struct 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());
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) {
66 }
67 return b;
68 }
69};
70
72template <typename T, typename U>
73struct 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());
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
89 }
90 return b;
91 }
92};
93
95template <typename T, typename U>
96struct 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
105 return b;
106 }
107};
108
109#endif
SerializeType * SerializeIter
static bool phoenix_serialize(SerializeIter &ds, T *&data)
Write a pointer address in a message.
static bool phoenix_serialize(SerializeIter &ds, std::list< T > &data)
Get the size of a class std::list T.
static bool phoenix_serialize(SerializeIter &ds, std::map< T, U > &data)
Get the size of a class std::list T.
static bool phoenix_serialize(SerializeIter &ds, std::pair< T, U > &data)
Get the size of a class std::list T.
static bool phoenix_serialize(SerializeIter &ds, std::vector< T > &data)
Get the size of a class std::vector T.
Generic Serializer class.
static bool phoenix_serialize(Stream &ds, T &data)
Dummy function to catch if a type is not specialised.