-
Notifications
You must be signed in to change notification settings - Fork 1
/
tc_template.hpp
89 lines (70 loc) · 1.78 KB
/
tc_template.hpp
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
@require(typecollection)
#ifndef @{typecollection.fqn('_').upper()}_HPP
#define @{typecollection.fqn('_').upper()}_HPP
#include "core/dbus/codec.h"
@{typecollection.dependent_includes()}
@{typecollection.package().namespaces_open()}
namespace @{typecollection.name()} {
@for t in typecollection.types:
@if isinstance(t, franca.struct):
struct @{t.name()}
{
@for m in t.members():
@{m.first.cpp_type()} @{m.second};
@end
};
@elif isinstance(t, franca.enumeration):
enum class @{t.name()} : int32_t
{
@{t.print_enumerators()}
};
@elif isinstance(t, franca.typedef):
typedef @{t.real_type().cpp_type()} @{t.name()};
@end
@end
} // namespace
@{typecollection.package().namespaces_close()}
namespace core
{
namespace dbus
{
@for t in typecollection.types:
@if isinstance(t, franca.struct):
template<>
struct Codec<@{t.fqn("::")}>
{
inline static
void encode_argument(Message::Writer& out, const @{t.cpp_type()}& value)
{
@for m in t.members():
Codec<@{m.first.cpp_type()}>::encode_argument(out, value.@{m.second});
@end
}
inline static
void decode_argument(Message::Reader& in, @{t.cpp_type()}& value)
{
@for m in t.members():
Codec<@{m.first.cpp_type()}>::decode_argument(in, value.@{m.second});
@end
}
};
@elif isinstance(t, franca.enumeration):
template<>
struct Codec<@{t.cpp_type()}>
{
inline static
void encode_argument(Message::Writer& out, const @{t.cpp_type()}& value)
{
out.push_int32(int32_t(value));
}
inline static
void decode_argument(Message::Reader& in, @{t.cpp_type()}& value)
{
value = @{t.cpp_type()}(in.pop_int32());
}
};
@end
@end
} // namespace dbus
} // namespace core
#endif // @{typecollection.fqn('_').upper()}_HPP