TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cpp_message.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // Author: [email protected] (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34 
35 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
36 #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
37 
38 #include <memory>
39 #include <string>
40 #include <vector>
43 
44 namespace google {
45 namespace protobuf {
46  namespace io {
47  class Printer; // printer.h
48  }
49 }
50 
51 namespace protobuf {
52 namespace compiler {
53 namespace cpp {
54 
55 class EnumGenerator; // enum.h
56 class ExtensionGenerator; // extension.h
57 
59  public:
60  // See generator.cc for the meaning of dllexport_decl.
61  explicit MessageGenerator(const Descriptor* descriptor,
62  const Options& options);
64 
65  // Header stuff.
66 
67  // Generate foward declarations for this class and all its nested types.
69 
70  // Generate definitions of all nested enums (must come before class
71  // definitions because those classes use the enums definitions).
72  void GenerateEnumDefinitions(io::Printer* printer);
73 
74  // Generate specializations of GetEnumDescriptor<MyEnum>().
75  // Precondition: in ::google::protobuf namespace.
77 
78  // Generate definitions for this class and all its nested types.
79  void GenerateClassDefinition(io::Printer* printer);
80 
81  // Generate definitions of inline methods (placed at the end of the header
82  // file).
83  void GenerateInlineMethods(io::Printer* printer);
84 
85  // Source file stuff.
86 
87  // Generate code which declares all the global descriptor pointers which
88  // will be initialized by the methods below.
90 
91  // Generate code that initializes the global variable storing the message's
92  // descriptor.
93  void GenerateDescriptorInitializer(io::Printer* printer, int index);
94 
95  // Generate code that calls MessageFactory::InternalRegisterGeneratedMessage()
96  // for all types.
98 
99  // Generates code that allocates the message's default instance.
101 
102  // Generates code that initializes the message's default instance. This
103  // is separate from allocating because all default instances must be
104  // allocated before any can be initialized.
106 
107  // Generates code that should be run when ShutdownProtobufLibrary() is called,
108  // to delete all dynamically-allocated objects.
109  void GenerateShutdownCode(io::Printer* printer);
110 
111  // Generate all non-inline methods for this class.
112  void GenerateClassMethods(io::Printer* printer);
113 
114  private:
115  // Generate declarations and definitions of accessors for fields.
118 
119  // Generate the field offsets array.
120  void GenerateOffsets(io::Printer* printer);
121 
122  // Generate constructors and destructor.
123  void GenerateStructors(io::Printer* printer);
124 
125  // The compiler typically generates multiple copies of each constructor and
126  // destructor: http://gcc.gnu.org/bugs.html#nonbugs_cxx
127  // Placing common code in a separate method reduces the generated code size.
128  //
129  // Generate the shared constructor code.
131  // Generate the shared destructor code.
133 
134  // Generate standard Message methods.
135  void GenerateClear(io::Printer* printer);
136  void GenerateOneofClear(io::Printer* printer);
141  bool to_array);
142  void GenerateByteSize(io::Printer* printer);
143  void GenerateMergeFrom(io::Printer* printer);
144  void GenerateCopyFrom(io::Printer* printer);
145  void GenerateSwap(io::Printer* printer);
146  void GenerateIsInitialized(io::Printer* printer);
147 
148  // Helpers for GenerateSerializeWithCachedSizes().
150  const FieldDescriptor* field,
151  bool unbounded);
153  io::Printer* printer, const Descriptor::ExtensionRange* range,
154  bool unbounded);
155 
156 
158  string classname_;
161  vector< vector<string> > runs_of_fields_; // that might be trivially cleared
162  scoped_array<scoped_ptr<MessageGenerator> > nested_generators_;
163  scoped_array<scoped_ptr<EnumGenerator> > enum_generators_;
164  scoped_array<scoped_ptr<ExtensionGenerator> > extension_generators_;
166 
168 };
169 
170 } // namespace cpp
171 } // namespace compiler
172 } // namespace protobuf
173 
174 } // namespace google
175 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
void GenerateInlineMethods(io::Printer *printer)
scoped_array< scoped_ptr< ExtensionGenerator > > extension_generators_
Definition: cpp_message.h:164
void GenerateTypeRegistrations(io::Printer *printer)
void GenerateSerializeWithCachedSizesToArray(io::Printer *printer)
void GenerateIsInitialized(io::Printer *printer)
void GenerateSerializeWithCachedSizesBody(io::Printer *printer, bool to_array)
Definition: descriptor.h:126
void GenerateForwardDeclaration(io::Printer *printer)
void GenerateDefaultInstanceAllocator(io::Printer *printer)
Definition: cpp_options.h:45
void GenerateMergeFromCodedStream(io::Printer *printer)
void GenerateSerializeOneField(io::Printer *printer, const FieldDescriptor *field, bool unbounded)
void GenerateEnumDefinitions(io::Printer *printer)
void GenerateDescriptorDeclarations(io::Printer *printer)
void GenerateGetEnumDescriptorSpecializations(io::Printer *printer)
bool uses_string_
Definition: cpp_message.h:165
Options options_
Definition: cpp_message.h:159
MessageGenerator(const Descriptor *descriptor, const Options &options)
void GenerateSerializeOneExtensionRange(io::Printer *printer, const Descriptor::ExtensionRange *range, bool unbounded)
vector< vector< string > > runs_of_fields_
Definition: cpp_message.h:161
void GenerateFieldAccessorDeclarations(io::Printer *printer)
scoped_array< scoped_ptr< MessageGenerator > > nested_generators_
Definition: cpp_message.h:162
scoped_array< scoped_ptr< EnumGenerator > > enum_generators_
Definition: cpp_message.h:163
void GenerateSharedConstructorCode(io::Printer *printer)
FieldGeneratorMap field_generators_
Definition: cpp_message.h:160
void GenerateFieldAccessorDefinitions(io::Printer *printer)
void GenerateClassDefinition(io::Printer *printer)
void GenerateSerializeWithCachedSizes(io::Printer *printer)
Definition: printer.h:64
const Descriptor * descriptor_
Definition: cpp_message.h:157
void GenerateDescriptorInitializer(io::Printer *printer, int index)
Definition: descriptor.h:342
Definition: BnetFileGenerator.h:47
void GenerateDefaultInstanceInitializer(io::Printer *printer)
string classname_
Definition: cpp_message.h:158
void GenerateSharedDestructorCode(io::Printer *printer)