-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum.h
56 lines (52 loc) · 1.21 KB
/
enum.h
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
#pragma once
#include <protobuf.h>
class EnumGenerator
{
public:
EnumGenerator(const EnumDescriptor* desc, const Options& options)
: desc_(desc)
, options_(options)
{
}
void GenerateDefine(Printer& p)
{
p.Emit(
{
{ "enum", desc_->name() },
{ "body",
[&] {
for (int j = 0; j < desc_->value_count(); j++) {
auto v = desc_->value(j);
p.Emit(
{
{ "name", v->name() },
{ "value", std::to_string(v->number()) },
},
"$name$ = $value$,\n");
}
} },
},
R"cc(
enum class $enum$ : int32_t
{
$body$
};
)cc");
}
void GenerateHelperFunctions(Printer& p) const
{
p.Emit(
{
{ "enum", desc_->name() },
},
R"cc(
template<>
struct is_enum<$ns$::$enum$> : public std::true_type
{
};
)cc");
}
private:
const EnumDescriptor* desc_;
Options options_;
};