-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathCppGenerator.cpp
More file actions
64 lines (54 loc) · 2.2 KB
/
CppGenerator.cpp
File metadata and controls
64 lines (54 loc) · 2.2 KB
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
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* CppGenerator.cpp
* Copyright (C) 2013 Simon Newton
*/
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <memory>
#include <string>
#include "protoc/CppGenerator.h"
#include "protoc/CppFileGenerator.h"
#include "protoc/GeneratorHelpers.h"
#include "protoc/ServiceGenerator.h"
#include "protoc/StrUtil.h"
namespace ola {
using google::protobuf::FileDescriptor;
using google::protobuf::ServiceDescriptor;
using google::protobuf::compiler::OutputDirectory;
using google::protobuf::io::Printer;
using std::auto_ptr;
using std::string;
bool CppGenerator::Generate(const FileDescriptor *file,
const string&,
OutputDirectory *generator_context,
string*) const {
string basename = StripProto(string(file->name())) + "Service";
string header_name = basename + ".pb.h";
string code_name = basename + ".pb.cpp";
FileGenerator file_generator(file, basename);
auto_ptr<google::protobuf::io::ZeroCopyOutputStream> header_output(
generator_context->Open(header_name));
Printer header_printer(header_output.get(), '$');
file_generator.GenerateHeader(&header_printer);
auto_ptr<google::protobuf::io::ZeroCopyOutputStream> code_output(
generator_context->Open(code_name));
Printer code_printer(code_output.get(), '$');
file_generator.GenerateImplementation(&code_printer);
return true;
}
} // namespace ola