summaryrefslogtreecommitdiff
path: root/include/CommonAPI/TypeOutputStream.hpp
blob: 35e76a20e0e87035aacee26fce2049f7659cdf7d (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
// Copyright (C) 2014-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_TYPEOUTPUTSTREAM_HPP_
#define COMMONAPI_TYPEOUTPUTSTREAM_HPP_

#include <unordered_map>

#include <CommonAPI/Struct.hpp>
#include <CommonAPI/Variant.hpp>
#include <CommonAPI/Types.hpp>

namespace CommonAPI {

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

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

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

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

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

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

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

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

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

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

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

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

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

    template<class Deployment_, typename Type_>
    TypeOutputStream &writeType(const Enumeration<Type_> &_value, const Deployment_ *_depl = nullptr) {
        (void)_value;
        Type_ tmpValue;
        return get()->writeType(tmpValue, _depl);
    }

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

} // namespace CommonAPI

#endif // COMMONAPI_TYPEOUTPUTSTREAM_HPP_