CppSerialization  1.0.4.0
C++ Serialization Library
serializer.h
Go to the documentation of this file.
1 
9 #ifndef CPPSERIALIZATION_JSON_SERIALIZER_H
10 #define CPPSERIALIZATION_JSON_SERIALIZER_H
11 
12 #include "json.h"
13 
14 namespace CppSerialization {
15 namespace JSON {
16 
18 
22 template <class OutputStream>
23 class Serializer : public Writer<OutputStream>
24 {
25 public:
26  Serializer() = default;
27  explicit Serializer(OutputStream& stream) : Writer<OutputStream>(stream) {}
28  Serializer(const Serializer&) = delete;
29  Serializer(Serializer&&) = default;
30  ~Serializer() = default;
31 
32  Serializer& operator=(const Serializer&) = delete;
34 
36  void StartObject();
38  void EndObject();
39 
41  void StartArray();
43  void EndArray();
44 
46  void Key(const char* key);
48  void Key(const char* key, size_t size);
50  void Key(const std::string& key);
52  template <std::size_t N>
53  void Key(const char (&key)[N]);
54 
56  void Value(std::nullptr_t value);
58  void Value(bool value);
60  void Value(int value);
62  void Value(unsigned value);
64  void Value(int64_t value);
66  void Value(uint64_t value);
68  void Value(double value);
70  void Value(const char* value);
72  void Value(const char* value, size_t size);
74  void Value(const std::string& value);
76  template <std::size_t N>
77  void Value(const char (&value)[N]);
78 
80  void Pair(const char* key, std::nullptr_t value)
81  { Key(key); Value(value); }
83  void Pair(const char* key, bool value)
84  { Key(key); Value(value); }
86  void Pair(const char* key, int value)
87  { Key(key); Value(value); }
89  void Pair(const char* key, unsigned value)
90  { Key(key); Value(value); }
92  void Pair(const char* key, int64_t value)
93  { Key(key); Value(value); }
95  void Pair(const char* key, uint64_t value)
96  { Key(key); Value(value); }
98  void Pair(const char* key, double value)
99  { Key(key); Value(value); }
101  void Pair(const char* key, const char* value)
102  { Key(key); Value(value); }
104  void Pair(const char* key, const char* value, size_t size)
105  { Key(key); Value(value, size); }
107  void Pair(const char* key, const std::string& value)
108  { Key(key); Value(value); }
110  template <std::size_t N>
111  void Pair(const char* key, const char (&value)[N])
112  { Key(key); Value(value); }
113 };
114 
115 } // namespace JSON
116 } // namespace CppSerialization
117 
118 #include "serializer.inl"
119 
120 #endif // CPPSERIALIZATION_JSON_SERIALIZER_H
void Pair(const char *key, const std::string &value)
Put the string key/value pair.
Definition: serializer.h:107
void Pair(const char *key, int value)
Put the integer key/value pair.
Definition: serializer.h:86
void StartArray()
Start new array.
Definition: serializer.inl:27
void Pair(const char *key, std::nullptr_t value)
Put the null key/value pair.
Definition: serializer.h:80
void Pair(const char *key, const char(&value)[N])
Put the fixed string array key/value pair.
Definition: serializer.h:111
void Pair(const char *key, const char *value)
Put the C-string key/value pair.
Definition: serializer.h:101
void Pair(const char *key, uint64_t value)
Put the 64-bit unsigned integer key/value pair.
Definition: serializer.h:95
void EndObject()
End the current object.
Definition: serializer.inl:20
void Pair(const char *key, unsigned value)
Put the unsigned integer key/value pair.
Definition: serializer.h:89
Serializer & operator=(Serializer &&)=default
void Pair(const char *key, const char *value, size_t size)
Put the C-string key/value pair with a given size.
Definition: serializer.h:104
void Pair(const char *key, bool value)
Put the boolean key/value pair.
Definition: serializer.h:83
void Pair(const char *key, int64_t value)
Put the 64-bit integer key/value pair.
Definition: serializer.h:92
void StartObject()
Start new object.
Definition: serializer.inl:13
Serializer & operator=(const Serializer &)=delete
void Key(const char *key)
Put the C-string key.
Definition: serializer.inl:41
void EndArray()
End the current array.
Definition: serializer.inl:34
void Value(std::nullptr_t value)
Put the null value.
Definition: serializer.inl:70
Serializer(Serializer &&)=default
Serializer(const Serializer &)=delete
Serializer(OutputStream &stream)
Definition: serializer.h:27
void Pair(const char *key, double value)
Put the double key/value pair.
Definition: serializer.h:98
JSON C++ Library definition.
C++ Serialization project definitions.
Definition: exceptions.h:14
JSON serializer inline implementation.