From 499a15993293bf3a793690bd8fe75a2459febb73 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 26 Mar 2016 01:24:11 +0100 Subject: Contrib: Added sources of the protoc plugin used to generate services --- contrib/protoc-bnet/BnetCodeGenerator.cpp | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 contrib/protoc-bnet/BnetCodeGenerator.cpp (limited to 'contrib/protoc-bnet/BnetCodeGenerator.cpp') diff --git a/contrib/protoc-bnet/BnetCodeGenerator.cpp b/contrib/protoc-bnet/BnetCodeGenerator.cpp new file mode 100644 index 00000000000..f3627192755 --- /dev/null +++ b/contrib/protoc-bnet/BnetCodeGenerator.cpp @@ -0,0 +1,68 @@ +// +// Created by tea on 10.03.16. +// + +#include +#include "BnetFileGenerator.h" +#include "google/protobuf/compiler/cpp/cpp_helpers.h" +#include +#include +#include + +#include "BnetCodeGenerator.h" + +bool BnetCodeGenerator::Generate(pb::FileDescriptor const* file, std::string const& parameter, + pbc::GeneratorContext* generator_context, std::string* error) const +{ + std::vector> 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 output( + generator_context->Open(basename + ".h")); + google::protobuf::io::Printer printer(output.get(), '$'); + file_generator.GenerateHeader(&printer); + } + + // Generate cc file. + { + pb::scoped_ptr output( + generator_context->Open(basename + ".cc")); + google::protobuf::io::Printer printer(output.get(), '$'); + file_generator.GenerateSource(&printer); + } + + return true; +} + -- cgit v1.2.3