Pakman
deserialisation.h
Go to the documentation of this file.
1 #ifndef DESERIALISATION_H
2 #define DESERIALISATION_H
3 
4 #include <istream>
5 
6 #include "core/Command.h"
7 #include "core/TaskHandler.h"
8 
9 #include "LineString.h"
10 
22 void read_key(const LineString& key, std::istream& in);
23 
30 std::string read_value(std::istream& in);
31 
39 template <typename value_type>
40 value_type deserialise_scalar_value(const LineString& key, std::istream& in)
41 {
42  // Read key
43  read_key(key, in);
44 
45  // Read value
46  auto value_string = read_value(in);
47 
48  // Read out LineString
49  value_type val;
50  std::istringstream isstr(value_string);
51  isstr >> val;
52 
53  // Check input stream
54  if (!isstr)
55  {
56  std::string error_msg("deserialisation failed, ");
57  error_msg += "could not extract value";
58  std::runtime_error e(error_msg);
59  throw e;
60  }
61 
62  return val;
63 }
64 
72 template <>
73 bool deserialise_scalar_value(const LineString& key, std::istream& in);
74 
82 template <>
83 std::string deserialise_scalar_value(const LineString& key, std::istream& in);
84 
92 template <>
93 Command deserialise_scalar_value(const LineString& key, std::istream& in);
94 
102 template <>
103 TaskHandler deserialise_scalar_value(const LineString& key, std::istream& in);
104 
112 std::istream& operator>>(std::istream& in, LineString& line_string);
113 
114 #endif // DESERIALISATION_H
value_type deserialise_scalar_value(const LineString &key, std::istream &in)
void read_key(const LineString &key, std::istream &in)
std::istream & operator>>(std::istream &in, LineString &line_string)
std::string read_value(std::istream &in)