TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BnetFileGenerator Class Reference

#include <BnetFileGenerator.h>

Public Member Functions

 BnetFileGenerator (const pb::FileDescriptor *file, const pbcpp::Options &options)
 
 ~BnetFileGenerator ()
 
void GenerateHeader (pb::io::Printer *printer)
 
void GenerateSource (pb::io::Printer *printer)
 

Private Member Functions

void GenerateBuildDescriptors (pb::io::Printer *printer)
 
void GenerateNamespaceOpeners (pb::io::Printer *printer)
 
void GenerateNamespaceClosers (pb::io::Printer *printer)
 
 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS (BnetFileGenerator)
 

Private Attributes

const pb::FileDescriptorfile_
 
pb::scoped_array
< pb::scoped_ptr
< pbcpp::MessageGenerator > > 
message_generators_
 
pb::scoped_array
< pb::scoped_ptr
< pbcpp::EnumGenerator > > 
enum_generators_
 
pb::scoped_array
< pb::scoped_ptr
< BnetServiceGenerator > > 
service_generators_
 
pb::scoped_array
< pb::scoped_ptr
< pbcpp::ExtensionGenerator > > 
extension_generators_
 
std::vector< std::string > package_parts_
 
const pbcpp::Options options_
 

Constructor & Destructor Documentation

BnetFileGenerator::BnetFileGenerator ( const pb::FileDescriptor file,
const pbcpp::Options &  options 
)
explicit
54  : file_(file),
56  new pb::scoped_ptr<pbcpp::MessageGenerator>[file->message_type_count()]),
58  new pb::scoped_ptr<pbcpp::EnumGenerator>[file->enum_type_count()]),
60  new pb::scoped_ptr<BnetServiceGenerator>[file->service_count()]),
62  new pb::scoped_ptr<pbcpp::ExtensionGenerator>[file->extension_count()]),
63  options_(options)
64 {
65 
66  for (int i = 0; i < file->message_type_count(); i++)
67  {
68  message_generators_[i].reset(
69  new pbcpp::MessageGenerator(file->message_type(i), options));
70  }
71 
72  for (int i = 0; i < file->enum_type_count(); i++)
73  {
74  enum_generators_[i].reset(
75  new pbcpp::EnumGenerator(file->enum_type(i), options));
76  }
77 
78  for (int i = 0; i < file->service_count(); i++)
79  {
80  service_generators_[i].reset(
81  new BnetServiceGenerator(file->service(i), options));
82  }
83 
84  for (int i = 0; i < file->extension_count(); i++)
85  {
86  extension_generators_[i].reset(
87  new pbcpp::ExtensionGenerator(file->extension(i), options));
88  }
89 
91 }
const string & package() const
pb::scoped_array< pb::scoped_ptr< pbcpp::EnumGenerator > > enum_generators_
Definition: BnetFileGenerator.h:98
LIBPROTOBUF_EXPORT void SplitStringUsing(const string &full, const char *delim, vector< string > *res)
const pbcpp::Options options_
Definition: BnetFileGenerator.h:104
pb::scoped_array< pb::scoped_ptr< pbcpp::ExtensionGenerator > > extension_generators_
Definition: BnetFileGenerator.h:100
const FieldDescriptor * extension(int index) const
const ServiceDescriptor * service(int index) const
const Descriptor * message_type(int index) const
std::vector< std::string > package_parts_
Definition: BnetFileGenerator.h:103
pb::scoped_array< pb::scoped_ptr< BnetServiceGenerator > > service_generators_
Definition: BnetFileGenerator.h:99
pb::scoped_array< pb::scoped_ptr< pbcpp::MessageGenerator > > message_generators_
Definition: BnetFileGenerator.h:97
Definition: BnetServiceGenerator.h:37
const EnumDescriptor * enum_type(int index) const
const pb::FileDescriptor * file_
Definition: BnetFileGenerator.h:95

+ Here is the call graph for this function:

BnetFileGenerator::~BnetFileGenerator ( )
93 { }

Member Function Documentation

void BnetFileGenerator::GenerateBuildDescriptors ( pb::io::Printer *  printer)
private
446 {
447  // AddDescriptors() is a file-level procedure which adds the encoded
448  // FileDescriptorProto for this .proto file to the global DescriptorPool for
449  // generated files (DescriptorPool::generated_pool()). It either runs at
450  // static initialization time (by default) or when default_instance() is
451  // called for the first time (in LITE_RUNTIME mode with
452  // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER flag enabled). This procedure also
453  // constructs default instances and registers extensions.
454  //
455  // Its sibling, AssignDescriptors(), actually pulls the compiled
456  // FileDescriptor from the DescriptorPool and uses it to populate all of
457  // the global variables which store pointers to the descriptor objects.
458  // It also constructs the reflection objects. It is called the first time
459  // anyone calls descriptor() or GetReflection() on one of the types defined
460  // in the file.
461 
462  // In optimize_for = LITE_RUNTIME mode, we don't generate AssignDescriptors()
463  // and we only use AddDescriptors() to allocate default instances.
465  {
466  printer->Print(
467  "\n"
468  "void $assigndescriptorsname$() {\n",
469  "assigndescriptorsname", pbcpp::GlobalAssignDescriptorsName(file_->name()));
470  printer->Indent();
471 
472  // Make sure the file has found its way into the pool. If a descriptor
473  // is requested *during* static init then AddDescriptors() may not have
474  // been called yet, so we call it manually. Note that it's fine if
475  // AddDescriptors() is called multiple times.
476  printer->Print(
477  "$adddescriptorsname$();\n",
478  "adddescriptorsname", pbcpp::GlobalAddDescriptorsName(file_->name()));
479 
480  // Get the file's descriptor from the pool.
481  printer->Print(
482  "const ::google::protobuf::FileDescriptor* file =\n"
483  " ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(\n"
484  " \"$filename$\");\n"
485  // Note that this GOOGLE_CHECK is necessary to prevent a warning about "file"
486  // being unused when compiling an empty .proto file.
487  "GOOGLE_CHECK(file != NULL);\n",
488  "filename", file_->name());
489 
490  // Go through all the stuff defined in this file and generated code to
491  // assign the global descriptor pointers based on the file descriptor.
492  for (int i = 0; i < file_->message_type_count(); i++)
493  {
494  message_generators_[i]->GenerateDescriptorInitializer(printer, i);
495  }
496  for (int i = 0; i < file_->enum_type_count(); i++)
497  {
498  enum_generators_[i]->GenerateDescriptorInitializer(printer, i);
499  }
500  for (int i = 0; i < file_->service_count(); i++)
501  {
502  service_generators_[i]->GenerateDescriptorInitializer(printer, i);
503  }
504 
505  printer->Outdent();
506  printer->Print(
507  "}\n"
508  "\n");
509 
510  // ---------------------------------------------------------------
511 
512  // protobuf_AssignDescriptorsOnce(): The first time it is called, calls
513  // AssignDescriptors(). All later times, waits for the first call to
514  // complete and then returns.
515  printer->Print(
516  "namespace {\n"
517  "\n"
518  "GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);\n"
519  "inline void protobuf_AssignDescriptorsOnce() {\n"
520  " ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,\n"
521  " &$assigndescriptorsname$);\n"
522  "}\n"
523  "\n",
524  "assigndescriptorsname", pbcpp::GlobalAssignDescriptorsName(file_->name()));
525 
526  // protobuf_RegisterTypes(): Calls
527  // MessageFactory::InternalRegisterGeneratedType() for each message type.
528  printer->Print(
529  "void protobuf_RegisterTypes(const ::std::string&) {\n"
530  " protobuf_AssignDescriptorsOnce();\n");
531  printer->Indent();
532 
533  for (int i = 0; i < file_->message_type_count(); i++)
534  {
535  message_generators_[i]->GenerateTypeRegistrations(printer);
536  }
537 
538  printer->Outdent();
539  printer->Print(
540  "}\n"
541  "\n"
542  "} // namespace\n");
543  }
544 
545  // -----------------------------------------------------------------
546 
547  // ShutdownFile(): Deletes descriptors, default instances, etc. on shutdown.
548  printer->Print(
549  "\n"
550  "void $shutdownfilename$() {\n",
551  "shutdownfilename", pbcpp::GlobalShutdownFileName(file_->name()));
552  printer->Indent();
553 
554  for (int i = 0; i < file_->message_type_count(); i++)
555  {
556  message_generators_[i]->GenerateShutdownCode(printer);
557  }
558 
559  printer->Outdent();
560  printer->Print(
561  "}\n\n");
562 
563  // -----------------------------------------------------------------
564 
565  // Now generate the AddDescriptors() function.
567  file_, printer,
568  // With static initializers.
569  // Note that we don't need any special synchronization in the following code
570  // because it is called at static init time before any threads exist.
571  "void $adddescriptorsname$() {\n"
572  " static bool already_here = false;\n"
573  " if (already_here) return;\n"
574  " already_here = true;\n"
575  " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
576  "\n",
577  // Without.
578  "void $adddescriptorsname$_impl() {\n"
579  " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
580  "\n",
581  // Vars.
582  "adddescriptorsname", pbcpp::GlobalAddDescriptorsName(file_->name()));
583 
584  printer->Indent();
585 
586  // Call the AddDescriptors() methods for all of our dependencies, to make
587  // sure they get added first.
588  for (int i = 0; i < file_->dependency_count(); i++)
589  {
590  const pb::FileDescriptor* dependency = file_->dependency(i);
591  // Print the namespace prefix for the dependency.
592  std::string add_desc_name = pbcpp::QualifiedFileLevelSymbol(
593  dependency->package(), pbcpp::GlobalAddDescriptorsName(dependency->name()));
594  // Call its AddDescriptors function.
595  printer->Print(
596  "$name$();\n",
597  "name", add_desc_name);
598  }
599 
601  {
602  // Embed the descriptor. We simply serialize the entire FileDescriptorProto
603  // and embed it as a string literal, which is parsed and built into real
604  // descriptors at initialization time.
605  pb::FileDescriptorProto file_proto;
606  file_->CopyTo(&file_proto);
607  std::string file_data;
608  file_proto.SerializeToString(&file_data);
609 
610  printer->Print(
611  "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(");
612 
613  // Only write 40 bytes per line.
614  static const int kBytesPerLine = 40;
615  for (int i = 0; i < file_data.size(); i += kBytesPerLine)
616  {
617  printer->Print("\n \"$data$\"",
618  "data",
620  pb::CEscape(file_data.substr(i, kBytesPerLine))));
621  }
622  printer->Print(
623  ", $size$);\n",
624  "size", pb::SimpleItoa(file_data.size()));
625 
626  // Call MessageFactory::InternalRegisterGeneratedFile().
627  printer->Print(
628  "::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(\n"
629  " \"$filename$\", &protobuf_RegisterTypes);\n",
630  "filename", file_->name());
631  }
632 
633  // Allocate and initialize default instances. This can't be done lazily
634  // since default instances are returned by simple accessors and are used with
635  // extensions. Speaking of which, we also register extensions at this time.
636  for (int i = 0; i < file_->message_type_count(); i++)
637  {
638  message_generators_[i]->GenerateDefaultInstanceAllocator(printer);
639  }
640  for (int i = 0; i < file_->extension_count(); i++)
641  {
642  extension_generators_[i]->GenerateRegistration(printer);
643  }
644  for (int i = 0; i < file_->message_type_count(); i++)
645  {
646  message_generators_[i]->GenerateDefaultInstanceInitializer(printer);
647  }
648 
649  printer->Print(
650  "::google::protobuf::internal::OnShutdown(&$shutdownfilename$);\n",
651  "shutdownfilename", pbcpp::GlobalShutdownFileName(file_->name()));
652 
653  printer->Outdent();
654  printer->Print(
655  "}\n"
656  "\n");
657 
659  file_, printer,
660  // With static initializers.
661  "// Force AddDescriptors() to be called at static initialization time.\n"
662  "struct StaticDescriptorInitializer_$filename$ {\n"
663  " StaticDescriptorInitializer_$filename$() {\n"
664  " $adddescriptorsname$();\n"
665  " }\n"
666  "} static_descriptor_initializer_$filename$_;\n",
667  // Without.
668  "GOOGLE_PROTOBUF_DECLARE_ONCE($adddescriptorsname$_once_);\n"
669  "void $adddescriptorsname$() {\n"
670  " ::google::protobuf::GoogleOnceInit(&$adddescriptorsname$_once_,\n"
671  " &$adddescriptorsname$_impl);\n"
672  "}\n",
673  // Vars.
674  "adddescriptorsname", pbcpp::GlobalAddDescriptorsName(file_->name()),
675  "filename", pbcpp::FilenameIdentifier(file_->name()));
676 }
string GlobalShutdownFileName(const string &filename)
bool SerializeToString(string *output) const
const string & package() const
LIBPROTOBUF_EXPORT string CEscape(const string &src)
const string & name() const
pb::scoped_array< pb::scoped_ptr< pbcpp::EnumGenerator > > enum_generators_
Definition: BnetFileGenerator.h:98
string FilenameIdentifier(const string &filename)
string GlobalAddDescriptorsName(const string &filename)
const FileDescriptor * dependency(int index) const
Definition: descriptor.h:1668
string GlobalAssignDescriptorsName(const string &filename)
pb::scoped_array< pb::scoped_ptr< pbcpp::ExtensionGenerator > > extension_generators_
Definition: BnetFileGenerator.h:100
string QualifiedFileLevelSymbol(const string &package, const string &name)
bool HasDescriptorMethods(const FileDescriptor *file)
Definition: cpp_helpers.h:155
void CopyTo(FileDescriptorProto *proto) const
string EscapeTrigraphs(const string &to_escape)
pb::scoped_array< pb::scoped_ptr< BnetServiceGenerator > > service_generators_
Definition: BnetFileGenerator.h:99
LIBPROTOBUF_EXPORT string SimpleItoa(int i)
pb::scoped_array< pb::scoped_ptr< pbcpp::MessageGenerator > > message_generators_
Definition: BnetFileGenerator.h:97
const pb::FileDescriptor * file_
Definition: BnetFileGenerator.h:95
void PrintHandlingOptionalStaticInitializers(const FileDescriptor *file, io::Printer *printer, const char *with_static_init, const char *without_static_init, const char *var1=NULL, const string &val1="", const char *var2=NULL, const string &val2="")
Definition: descriptor.pb.h:239
Definition: descriptor.h:986

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BnetFileGenerator::GenerateHeader ( pb::io::Printer *  printer)
96 {
97  std::string filename_identifier = pbcpp::FilenameIdentifier(file_->name());
98 
99  // Generate top of header.
100  printer->Print(
101  "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
102  "// source: $filename$\n"
103  "\n"
104  "#ifndef PROTOBUF_$filename_identifier$__INCLUDED\n"
105  "#define PROTOBUF_$filename_identifier$__INCLUDED\n"
106  "\n"
107  "#include <string>\n"
108  "\n",
109  "filename", file_->name(),
110  "filename_identifier", filename_identifier);
111 
112  printer->Print("#include <google/protobuf/stubs/common.h>\n\n");
113 
114  // Verify the protobuf library header version is compatible with the protoc
115  // version before going any further.
116  printer->Print(
117  "#if GOOGLE_PROTOBUF_VERSION < $min_header_version$\n"
118  "#error This file was generated by a newer version of protoc which is\n"
119  "#error incompatible with your Protocol Buffer headers. Please update\n"
120  "#error your headers.\n"
121  "#endif\n"
122  "#if $protoc_version$ < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION\n"
123  "#error This file was generated by an older version of protoc which is\n"
124  "#error incompatible with your Protocol Buffer headers. Please\n"
125  "#error regenerate this file with a newer version of protoc.\n"
126  "#endif\n"
127  "\n",
128  "min_header_version",
130  "protoc_version", pb::SimpleItoa(GOOGLE_PROTOBUF_VERSION));
131 
132  // OK, it's now safe to #include other files.
133  printer->Print("#include <google/protobuf/generated_message_util.h>\n");
134  if (file_->message_type_count() > 0)
135  {
137  printer->Print("#include <google/protobuf/message.h>\n");
138  else
139  printer->Print("#include <google/protobuf/message_lite.h>\n");
140  }
141 
142  printer->Print(
143  "#include <google/protobuf/repeated_field.h>\n"
144  "#include <google/protobuf/extension_set.h>\n");
145 
147  printer->Print("#include <google/protobuf/generated_enum_reflection.h>\n");
148 
150  {
151  printer->Print("#include <google/protobuf/unknown_field_set.h>\n");
152  }
153 
154  std::set<std::string> public_import_names;
155  for (int i = 0; i < file_->public_dependency_count(); i++)
156  public_import_names.insert(file_->public_dependency(i)->name());
157 
158  for (int i = 0; i < file_->dependency_count(); i++)
159  {
160  const std::string& name = file_->dependency(i)->name();
161  bool public_import = (public_import_names.count(name) != 0);
162 
163  printer->Print(
164  "#include \"$dependency$.pb.h\"$iwyu$\n",
165  "dependency", pbcpp::StripProto(name),
166  "iwyu", (public_import) ? " // IWYU pragma: export" : "");
167  }
168 
169  if (file_->service_count() > 0)
170  {
171  printer->Print("#include \"ServiceBase.h\"\n");
172  printer->Print("#include \"MessageBuffer.h\"\n");
173  printer->Print("#include <functional>\n");
174  printer->Print("#include <type_traits>\n");
175  }
176  else
177  printer->Print("#include \"Define.h\" // for TC_SHARED_API\n");
178 
179 
180  printer->Print("// @@protoc_insertion_point(includes)\n");
181 
182  // Open namespace.
183  GenerateNamespaceOpeners(printer);
184 
185  // Forward-declare the AddDescriptors, AssignDescriptors, and ShutdownFile
186  // functions, so that we can declare them to be friends of each class.
187  printer->Print(
188  "\n"
189  "// Internal implementation detail -- do not call these.\n"
190  "void $dllexport_decl$ $adddescriptorsname$();\n",
191  "adddescriptorsname", pbcpp::GlobalAddDescriptorsName(file_->name()),
192  "dllexport_decl", options_.dllexport_decl);
193 
194  printer->Print(
195  // Note that we don't put dllexport_decl on these because they are only
196  // called by the .pb.cc file in which they are defined.
197  "void $assigndescriptorsname$();\n"
198  "void $shutdownfilename$();\n"
199  "\n",
200  "assigndescriptorsname", pbcpp::GlobalAssignDescriptorsName(file_->name()),
201  "shutdownfilename", pbcpp::GlobalShutdownFileName(file_->name()));
202 
203  // Generate forward declarations of classes.
204  for (int i = 0; i < file_->message_type_count(); i++)
205  message_generators_[i]->GenerateForwardDeclaration(printer);
206 
207  printer->Print("\n");
208 
209  // Generate enum definitions.
210  for (int i = 0; i < file_->message_type_count(); i++)
211  message_generators_[i]->GenerateEnumDefinitions(printer);
212 
213  for (int i = 0; i < file_->enum_type_count(); i++)
214  enum_generators_[i]->GenerateDefinition(printer);
215 
216  printer->Print(pbcpp::kThickSeparator);
217  printer->Print("\n");
218 
219  // Generate class definitions.
220  for (int i = 0; i < file_->message_type_count(); i++)
221  {
222  if (i > 0)
223  {
224  printer->Print("\n");
225  printer->Print(pbcpp::kThinSeparator);
226  printer->Print("\n");
227  }
228  message_generators_[i]->GenerateClassDefinition(printer);
229  }
230 
231  printer->Print("\n");
232  printer->Print(pbcpp::kThickSeparator);
233  printer->Print("\n");
234 
235  // Generate service definitions.
236  for (int i = 0; i < file_->service_count(); i++)
237  {
238  if (i > 0)
239  {
240  printer->Print("\n");
241  printer->Print(pbcpp::kThinSeparator);
242  printer->Print("\n");
243  }
244  service_generators_[i]->GenerateDeclarations(printer);
245  }
246 
247  printer->Print("\n");
248  printer->Print(pbcpp::kThickSeparator);
249  printer->Print("\n");
250 
251  // Declare extension identifiers.
252  for (int i = 0; i < file_->extension_count(); i++)
253  {
254  extension_generators_[i]->GenerateDeclaration(printer);
255  }
256 
257  printer->Print("\n");
258  printer->Print(pbcpp::kThickSeparator);
259  printer->Print("\n");
260 
261 
262  // Generate class inline methods.
263  for (int i = 0; i < file_->message_type_count(); i++)
264  {
265  if (i > 0)
266  {
267  printer->Print(pbcpp::kThinSeparator);
268  printer->Print("\n");
269  }
270  message_generators_[i]->GenerateInlineMethods(printer);
271  }
272 
273  printer->Print(
274  "\n"
275  "// @@protoc_insertion_point(namespace_scope)\n");
276 
277  // Close up namespace.
278  GenerateNamespaceClosers(printer);
279 
280  // Emit GetEnumDescriptor specializations into google::protobuf namespace:
282  {
283  // The SWIG conditional is to avoid a null-pointer dereference
284  // (bug 1984964) in swig-1.3.21 resulting from the following syntax:
285  // namespace X { void Y<Z::W>(); }
286  // which appears in GetEnumDescriptor() specializations.
287  printer->Print(
288  "\n"
289  "#ifndef SWIG\n"
290  "namespace google {\nnamespace protobuf {\n"
291  "\n");
292  for (int i = 0; i < file_->message_type_count(); i++)
293  {
294  message_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
295  }
296  for (int i = 0; i < file_->enum_type_count(); i++)
297  {
298  enum_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
299  }
300  printer->Print(
301  "\n"
302  "} // namespace google\n} // namespace protobuf\n"
303  "#endif // SWIG\n");
304  }
305 
306  printer->Print(
307  "\n"
308  "// @@protoc_insertion_point(global_scope)\n"
309  "\n");
310 
311  printer->Print(
312  "#endif // PROTOBUF_$filename_identifier$__INCLUDED\n",
313  "filename_identifier", filename_identifier);
314 }
string GlobalShutdownFileName(const string &filename)
const string & name() const
pb::scoped_array< pb::scoped_ptr< pbcpp::EnumGenerator > > enum_generators_
Definition: BnetFileGenerator.h:98
string FilenameIdentifier(const string &filename)
#define GOOGLE_PROTOBUF_VERSION
Definition: common.h:116
string GlobalAddDescriptorsName(const string &filename)
bool HasEnumDefinitions(const FileDescriptor *file)
const FileDescriptor * dependency(int index) const
Definition: descriptor.h:1668
const pbcpp::Options options_
Definition: BnetFileGenerator.h:104
string GlobalAssignDescriptorsName(const string &filename)
pb::scoped_array< pb::scoped_ptr< pbcpp::ExtensionGenerator > > extension_generators_
Definition: BnetFileGenerator.h:100
bool HasDescriptorMethods(const FileDescriptor *file)
Definition: cpp_helpers.h:155
void GenerateNamespaceOpeners(pb::io::Printer *printer)
Definition: BnetFileGenerator.cpp:678
pb::scoped_array< pb::scoped_ptr< BnetServiceGenerator > > service_generators_
Definition: BnetFileGenerator.h:99
const FileDescriptor * public_dependency(int index) const
Definition: descriptor.h:1672
LIBPROTOBUF_EXPORT string SimpleItoa(int i)
pb::scoped_array< pb::scoped_ptr< pbcpp::MessageGenerator > > message_generators_
Definition: BnetFileGenerator.h:97
static const int kMinHeaderVersionForProtoc
Definition: common.h:133
string StripProto(const string &filename)
void GenerateNamespaceClosers(pb::io::Printer *printer)
Definition: BnetFileGenerator.cpp:690
const pb::FileDescriptor * file_
Definition: BnetFileGenerator.h:95
bool UseUnknownFieldSet(const FileDescriptor *file)
Definition: cpp_helpers.h:140

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BnetFileGenerator::GenerateNamespaceClosers ( pb::io::Printer *  printer)
private
691 {
692  if (package_parts_.size() > 0)
693  printer->Print("\n");
694 
695  for (int i = package_parts_.size() - 1; i >= 0; i--)
696  {
697  printer->Print("} // namespace $part$\n",
698  "part", package_parts_[i]);
699  }
700 }
std::vector< std::string > package_parts_
Definition: BnetFileGenerator.h:103

+ Here is the caller graph for this function:

void BnetFileGenerator::GenerateNamespaceOpeners ( pb::io::Printer *  printer)
private
679 {
680  if (package_parts_.size() > 0)
681  printer->Print("\n");
682 
683  for (int i = 0; i < package_parts_.size(); i++)
684  {
685  printer->Print("namespace $part$ {\n",
686  "part", package_parts_[i]);
687  }
688 }
std::vector< std::string > package_parts_
Definition: BnetFileGenerator.h:103

+ Here is the caller graph for this function:

void BnetFileGenerator::GenerateSource ( pb::io::Printer *  printer)
317 {
318  printer->Print(
319  "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
320  "// source: $filename$\n"
321  "\n"
322 
323  // The generated code calls accessors that might be deprecated. We don't
324  // want the compiler to warn in generated code.
325  "#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION\n"
326  "#include \"$basename$.pb.h\"\n"
327  "\n"
328  "#include <algorithm>\n" // for swap()
329  "#include <utility>\n" // for move()
330  "\n"
331  "#include <google/protobuf/stubs/common.h>\n"
332  "#include <google/protobuf/stubs/once.h>\n"
333  "#include <google/protobuf/io/coded_stream.h>\n"
334  "#include <google/protobuf/wire_format_lite_inl.h>\n",
335  "filename", file_->name(),
336  "basename", pbcpp::StripProto(file_->name()));
337 
338  // Unknown fields implementation in lite mode uses StringOutputStream
340  {
341  printer->Print(
342  "#include <google/protobuf/io/zero_copy_stream_impl_lite.h>\n");
343  }
344 
346  {
347  printer->Print(
348  "#include <google/protobuf/descriptor.h>\n"
349  "#include <google/protobuf/generated_message_reflection.h>\n"
350  "#include <google/protobuf/reflection_ops.h>\n"
351  "#include <google/protobuf/wire_format.h>\n");
352  }
353 
354  printer->Print("#include \"Log.h\"\n");
355 
356  if (file_->service_count() > 0)
357  printer->Print("#include \"BattlenetRpcErrorCodes.h\"\n");
358 
359  printer->Print(
360  "// @@protoc_insertion_point(includes)\n");
361 
362  printer->Print("\n// Fix stupid windows.h included from Log.h->Common.h\n");
363  printer->Print("#ifdef SendMessage\n");
364  printer->Print("#undef SendMessage\n");
365  printer->Print("#endif\n");
366 
367  GenerateNamespaceOpeners(printer);
368 
370  {
371  printer->Print(
372  "\n"
373  "namespace {\n"
374  "\n");
375  for (int i = 0; i < file_->message_type_count(); i++)
376  {
377  message_generators_[i]->GenerateDescriptorDeclarations(printer);
378  }
379  for (int i = 0; i < file_->enum_type_count(); i++)
380  {
381  printer->Print(
382  "const ::google::protobuf::EnumDescriptor* $name$_descriptor_ = NULL;\n",
383  "name", pbcpp::ClassName(file_->enum_type(i), false));
384  }
385 
386  for (int i = 0; i < file_->service_count(); i++)
387  {
388  printer->Print(
389  "const ::google::protobuf::ServiceDescriptor* $name$_descriptor_ = NULL;\n",
390  "name", file_->service(i)->name());
391  }
392 
393  printer->Print(
394  "\n"
395  "} // namespace\n"
396  "\n");
397  }
398 
399  // Define our externally-visible BuildDescriptors() function. (For the lite
400  // library, all this does is initialize default instances.)
401  GenerateBuildDescriptors(printer);
402 
403  // Generate enums.
404  for (int i = 0; i < file_->enum_type_count(); i++)
405  {
406  enum_generators_[i]->GenerateMethods(printer);
407  }
408 
409  // Generate classes.
410  for (int i = 0; i < file_->message_type_count(); i++)
411  {
412  printer->Print("\n");
413  printer->Print(pbcpp::kThickSeparator);
414  printer->Print("\n");
415  message_generators_[i]->GenerateClassMethods(printer);
416  }
417 
418  // Generate services.
419  for (int i = 0; i < file_->service_count(); i++)
420  {
421  if (i == 0)
422  printer->Print("\n");
423  printer->Print(pbcpp::kThickSeparator);
424  printer->Print("\n");
425  service_generators_[i]->GenerateImplementation(printer);
426  }
427 
428  // Define extensions.
429  for (int i = 0; i < file_->extension_count(); i++)
430  {
431  extension_generators_[i]->GenerateDefinition(printer);
432  }
433 
434  printer->Print(
435  "\n"
436  "// @@protoc_insertion_point(namespace_scope)\n");
437 
438  GenerateNamespaceClosers(printer);
439 
440  printer->Print(
441  "\n"
442  "// @@protoc_insertion_point(global_scope)\n");
443 }
const string & name() const
pb::scoped_array< pb::scoped_ptr< pbcpp::EnumGenerator > > enum_generators_
Definition: BnetFileGenerator.h:98
const string & name() const
void GenerateBuildDescriptors(pb::io::Printer *printer)
Definition: BnetFileGenerator.cpp:445
pb::scoped_array< pb::scoped_ptr< pbcpp::ExtensionGenerator > > extension_generators_
Definition: BnetFileGenerator.h:100
bool HasDescriptorMethods(const FileDescriptor *file)
Definition: cpp_helpers.h:155
const ServiceDescriptor * service(int index) const
void GenerateNamespaceOpeners(pb::io::Printer *printer)
Definition: BnetFileGenerator.cpp:678
pb::scoped_array< pb::scoped_ptr< BnetServiceGenerator > > service_generators_
Definition: BnetFileGenerator.h:99
pb::scoped_array< pb::scoped_ptr< pbcpp::MessageGenerator > > message_generators_
Definition: BnetFileGenerator.h:97
string StripProto(const string &filename)
string ClassName(const Descriptor *descriptor, bool qualified)
void GenerateNamespaceClosers(pb::io::Printer *printer)
Definition: BnetFileGenerator.cpp:690
const EnumDescriptor * enum_type(int index) const
const pb::FileDescriptor * file_
Definition: BnetFileGenerator.h:95
bool UseUnknownFieldSet(const FileDescriptor *file)
Definition: cpp_helpers.h:140

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

BnetFileGenerator::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS ( BnetFileGenerator  )
private

Member Data Documentation

pb::scoped_array<pb::scoped_ptr<pbcpp::EnumGenerator> > BnetFileGenerator::enum_generators_
private
pb::scoped_array<pb::scoped_ptr<pbcpp::ExtensionGenerator> > BnetFileGenerator::extension_generators_
private
const pb::FileDescriptor* BnetFileGenerator::file_
private
pb::scoped_array<pb::scoped_ptr<pbcpp::MessageGenerator> > BnetFileGenerator::message_generators_
private
const pbcpp::Options BnetFileGenerator::options_
private
std::vector<std::string> BnetFileGenerator::package_parts_
private
pb::scoped_array<pb::scoped_ptr<BnetServiceGenerator> > BnetFileGenerator::service_generators_
private

The documentation for this class was generated from the following files: