Pakman
serialisation.h
Go to the documentation of this file.
1 #ifndef SERIALISATION_H
2 #define SERIALISATION_H
3 
4 #include <ostream>
5 
6 #include "core/Command.h"
7 #include "core/TaskHandler.h"
8 
9 #include "LineString.h"
10 
23 template <typename value_type>
24 void serialise_scalar_value(const LineString& key, const value_type& value,
25  std::ostream& out)
26 {
27  out << key.str() << ":" << value << std::endl;
28 }
29 
36 template <>
37 void serialise_scalar_value(const LineString& key, const bool& value,
38  std::ostream& out);
39 
49 template <>
50 void serialise_scalar_value(const LineString& key, const std::string& value,
51  std::ostream& out);
52 
61 template <>
62 void serialise_scalar_value(const LineString& key, const Command& value,
63  std::ostream& out);
64 
74 template <>
75 void serialise_scalar_value(const LineString& key, const TaskHandler& value,
76  std::ostream& out);
77 
84 template <typename value_type>
85 void serialise_vector(const LineString& key,
86  const std::vector<value_type>& values,
87  std::ostream& out)
88 {
89  // Print key and number of elements
90  out << key.str() << ":" << values.size() << std::endl;
91 
92  // Print each element with key_n
93  for (unsigned idx = 0; idx < values.size(); ++idx)
94  {
95  serialise_scalar_value<value_type>(key.str() + "_" + std::to_string(idx),
96  values[idx], out);
97  }
98 }
99 
107 std::ostream& operator<<(std::ostream& out, const LineString& line_string);
108 
109 #endif // SERIALISATION_H
const std::string & str() const
Definition: LineString.cc:45
void serialise_vector(const LineString &key, const std::vector< value_type > &values, std::ostream &out)
Definition: serialisation.h:85
std::ostream & operator<<(std::ostream &out, const LineString &line_string)
void serialise_scalar_value(const LineString &key, const value_type &value, std::ostream &out)
Definition: serialisation.h:24