summaryrefslogtreecommitdiff
path: root/include/CommonAPI/TypeOutputStream.hpp
blob: ec44864596b29c1382641cdd8d416f1ecd490ef8 (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
// Copyright (C) 2014-2015 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.h> 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:
	inline TypeOutputStream &writeType(const bool &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const int8_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const int16_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const int32_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const int64_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const uint8_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const uint16_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const uint32_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const uint64_t &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const float &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const double &_value) {
		return get()->writeType(_value);
	}

	inline TypeOutputStream &writeType(const std::string &_value) {
		return get()->writeType(_value);
	}

	template<typename _Type>
	TypeOutputStream &writeType(const Enumeration<_Type> &_value) {
		_Type tmpValue;
		return get()->writeType(tmpValue);
	}

	template<typename... _Types>
	TypeOutputStream &writeType(const Struct<_Types...> &_value) {
		return get()->writeType(_value);
	}

	template<typename... _Types>
	TypeOutputStream &writeType(const Variant<_Types...> &_value) {
		return get()->writeType(_value);
	}

	template<typename _ElementType>
	TypeOutputStream &writeType(const std::vector<_ElementType> &_value) {
		return get()->writeType(_value);
	}

	template<typename _KeyType, typename _ValueType, typename _HasherType>
	TypeOutputStream &writeType(const std::unordered_map<_KeyType, _ValueType, _HasherType> &_value) {
		return get()->writeType(_value);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

template<class _Derived, typename _Type, typename _TypeDepl>
inline TypeOutputStream<_Derived> &operator<<(TypeOutputStream<_Derived> &_output, const Deployable<_Type, _TypeDepl> &_value) {
	return _output.writeType(_value.getValue());
}

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

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

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

template<class _Derived, typename _ElementType>
TypeOutputStream<_Derived> &operator<<(TypeOutputStream<_Derived> &_output, const std::vector<_ElementType> &_value) {
	return _output.writeType(_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.writeType(_value);
}

} // namespace CommonAPI

#endif // COMMONAPI_TYPEOUTPUTSTREAM_HPP_