summaryrefslogtreecommitdiff
path: root/include/CommonAPI/OutputStream.hpp
blob: f68ca2b25f6a2c81a86730f34fe2bf9ced6a56fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#if !defined (COMMONAPI_INTERNAL_COMPILATION)
#error "Only <CommonAPI/CommonAPI.hpp> can be included directly, this file may disappear or change contents."
#endif

#ifndef COMMONAPI_OUTPUTSTREAM_HPP_
#define COMMONAPI_OUTPUTSTREAM_HPP_

#include <unordered_map>

#include <CommonAPI/ByteBuffer.hpp>
#include <CommonAPI/Deployable.hpp>
#include <CommonAPI/Deployment.hpp>
#include <CommonAPI/Enumeration.hpp>
#include <CommonAPI/RangedInteger.hpp>
#include <CommonAPI/Struct.hpp>
#include <CommonAPI/Variant.hpp>
#include <CommonAPI/Version.hpp>

namespace CommonAPI {

template<class Derived_>
class OutputStream {
public:
    template<class Deployment_>
    OutputStream &writeValue(const bool &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const int8_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const int16_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const int32_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const int64_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const uint8_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const uint16_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const uint32_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const uint64_t &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const float &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const double &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const std::string &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_>
    OutputStream &writeValue(const Version &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_, typename Base_>
    OutputStream &writeValue(const Enumeration<Base_> &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_, int minimum, int maximum>
    OutputStream &writeValue(const RangedInteger<minimum, maximum> &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_, typename... Types_>
    OutputStream &writeValue(const Struct<Types_...> &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_, class PolymorphicStruct_>
    OutputStream &writeValue(const std::shared_ptr<PolymorphicStruct_> &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_, typename... Types_>
    OutputStream &writeValue(const Variant<Types_...> &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_, typename ElementType_>
    OutputStream &writeValue(const std::vector<ElementType_> &_value, const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    template<class Deployment_, typename KeyType_, typename ValueType_, typename HasherType_>
    OutputStream &writeValue(const std::unordered_map<KeyType_, ValueType_, HasherType_> &_value,
                             const Deployment_ *_depl = nullptr) {
        return get()->writeValue(_value, _depl);
    }

    bool hasError() const {
        return get()->hasError();
    }

private:
    inline Derived_ *get() {
        return static_cast<Derived_ *>(this);
    }

    inline const Derived_ *get() const {
        return static_cast<const Derived_ *>(this);
    }
};

template<class Derived_>
inline OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output, const bool &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const int8_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const int16_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const int32_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const int64_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const uint8_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const uint16_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const uint32_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const uint64_t &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const float &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const double &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const std::string &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_, typename Type_, typename TypeDepl_>
inline OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output, const Deployable<Type_, TypeDepl_> &_value) {
    return _output.template writeValue<TypeDepl_>(_value.getValue(), _value.getDepl());
}

template<class Derived_>
inline OutputStream<Derived_>& operator<<(OutputStream<Derived_> &_output, const Version &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_, typename Base_>
OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output, const Enumeration<Base_> &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_, int minimum, int maximum>
OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output, const RangedInteger<minimum, maximum> &_value) {
    return _output.template writeValue<EmptyDeployment, minimum, maximum>(_value);
}

template<class Derived_, typename... Types_>
OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output, const Struct<Types_...> &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_, class PolymorphicStruct_>
OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output,    const std::shared_ptr<PolymorphicStruct_> &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_, typename... Types_>
OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output, const Variant<Types_...> &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_, typename ElementType_>
OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output, const std::vector<ElementType_> &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

template<class Derived_, typename KeyType_, typename ValueType_, typename HasherType_>
OutputStream<Derived_> &operator<<(OutputStream<Derived_> &_output,
                         const std::unordered_map<KeyType_, ValueType_, HasherType_> &_value) {
    return _output.template writeValue<EmptyDeployment>(_value);
}

} // namespace CommonAPI

#endif // COMMONAPI_OUTPUTSTREAM_HPP_