PhoenixSerializer  3.0.0
PhoenixSerializer is a framework to save/load/serialize/deserialize data
Loading...
Searching...
No Matches
data_stream_write_file.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_FILE_H__
8#define __DATA_STREAM_WRITE_FILE_H__
9
10#include "data_stream_include.h"
12
14template <typename T>
15struct Serializer<FILE *, SerializeMode::WRITE, T *> {
17
21 static bool phoenix_serialize(FILE *& ds, T *& data) {
22 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
24 return b;
25 }
26};
27
29template <typename T>
30struct Serializer<FILE *, SerializeMode::WRITE, std::vector<T>> {
32
36 static bool phoenix_serialize(FILE *& ds, std::vector<T> & data) {
37 //Save the size of the data
38 size_t nbElement(data.size());
40 if(nbElement == 0LU || !b) {
41 return b;
42 } //If there is no element, quit now
43
44 // if(phoenix_serialize_isSimpleType<T>()){
45 // b &= Serializer<FILE*, SerializeMode::WRITE, T>::phoenix_serialize_tab(ds, (T*)data.data(), nbElement);
46 // }else{
47 for(typename std::vector<T>::iterator it(data.begin()); it != data.end(); ++it) {
49 }
50 // }
51 return b;
52 }
53};
54
56template <typename T>
57struct Serializer<FILE *, SerializeMode::WRITE, std::list<T>> {
59
63 static bool phoenix_serialize(FILE *& ds, std::list<T> & data) {
64 //Save the size of the data
65 size_t nbElement(data.size());
67 if(nbElement == 0LU || !b) {
68 return b;
69 } //If there is no element, quit now
70 for(typename std::list<T>::iterator it(data.begin()); it != data.end(); ++it) {
72 }
73 return b;
74 }
75};
76
78template <typename T, typename U>
79struct Serializer<FILE *, SerializeMode::WRITE, std::map<T, U>> {
81
85 static bool phoenix_serialize(FILE *& ds, std::map<T, U> & data) {
86 //Save the size of the data
87 size_t nbElement(data.size());
89 if(nbElement == 0LU || !b) {
90 return b;
91 } //If there is no element, quit now
92 for(typename std::map<T, U>::iterator it(data.begin()); it != data.end(); ++it) {
93 b &= Serializer<FILE *, 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
95 }
96 return b;
97 }
98};
99
101template <typename T, typename U>
102struct Serializer<FILE *, SerializeMode::WRITE, std::pair<T, U>> {
104
108 static bool phoenix_serialize(FILE *& ds, std::pair<T, U> & data) {
109 bool b = Serializer<FILE *, 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
111 return b;
112 }
113};
114
115#endif
static bool phoenix_serialize(FILE *&ds, T *&data)
Write a pointer address in a file.
static bool phoenix_serialize(FILE *&ds, std::list< T > &data)
Get the size of a class std::list T.
static bool phoenix_serialize(FILE *&ds, std::map< T, U > &data)
Get the size of a class std::list T.
static bool phoenix_serialize(FILE *&ds, std::pair< T, U > &data)
Get the size of a class std::list T.
static bool phoenix_serialize(FILE *&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.