blob: f362719275514f4303a9c6b9cff9ff28d8502a2f (
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
|
//
// Created by tea on 10.03.16.
//
#include <vector>
#include "BnetFileGenerator.h"
#include "google/protobuf/compiler/cpp/cpp_helpers.h"
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.pb.h>
#include "BnetCodeGenerator.h"
bool BnetCodeGenerator::Generate(pb::FileDescriptor const* file, std::string const& parameter,
pbc::GeneratorContext* generator_context, std::string* error) const
{
std::vector<std::pair<std::string, std::string>> options;
google::protobuf::compiler::ParseGeneratorParameter(parameter, &options);
// -----------------------------------------------------------------
// parse generator options
google::protobuf::compiler::cpp::Options file_options;
for (int i = 0; i < options.size(); i++)
{
if (options[i].first == "dllexport_decl")
{
file_options.dllexport_decl = options[i].second;
}
else if (options[i].first == "safe_boundary_check")
{
file_options.safe_boundary_check = true;
}
else
{
*error = "Unknown generator option: " + options[i].first;
return false;
}
}
// -----------------------------------------------------------------
std::string basename = google::protobuf::compiler::cpp::StripProto(file->name());
basename.append(".pb");
BnetFileGenerator file_generator(file, file_options);
// Generate header.
{
pb::scoped_ptr <google::protobuf::io::ZeroCopyOutputStream> output(
generator_context->Open(basename + ".h"));
google::protobuf::io::Printer printer(output.get(), '$');
file_generator.GenerateHeader(&printer);
}
// Generate cc file.
{
pb::scoped_ptr <google::protobuf::io::ZeroCopyOutputStream> output(
generator_context->Open(basename + ".cc"));
google::protobuf::io::Printer printer(output.get(), '$');
file_generator.GenerateSource(&printer);
}
return true;
}
|