/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 170 lines · 71 code · 32 blank · 67 comment · 0 complexity · c629e883df1ea12bc80767d759c74d82 MD5 · raw file

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  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. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
  34. #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
  35. #include <string>
  36. #include <google/protobuf/stubs/common.h>
  37. #include <google/protobuf/compiler/cpp/cpp_field.h>
  38. namespace google {
  39. namespace protobuf {
  40. namespace io {
  41. class Printer; // printer.h
  42. }
  43. }
  44. namespace protobuf {
  45. namespace compiler {
  46. namespace cpp {
  47. class EnumGenerator; // enum.h
  48. class ExtensionGenerator; // extension.h
  49. class MessageGenerator {
  50. public:
  51. // See generator.cc for the meaning of dllexport_decl.
  52. explicit MessageGenerator(const Descriptor* descriptor,
  53. const string& dllexport_decl);
  54. ~MessageGenerator();
  55. // Header stuff.
  56. // Generate foward declarations for this class and all its nested types.
  57. void GenerateForwardDeclaration(io::Printer* printer);
  58. // Generate definitions of all nested enums (must come before class
  59. // definitions because those classes use the enums definitions).
  60. void GenerateEnumDefinitions(io::Printer* printer);
  61. // Generate specializations of GetEnumDescriptor<MyEnum>().
  62. // Precondition: in ::google::protobuf namespace.
  63. void GenerateGetEnumDescriptorSpecializations(io::Printer* printer);
  64. // Generate definitions for this class and all its nested types.
  65. void GenerateClassDefinition(io::Printer* printer);
  66. // Generate definitions of inline methods (placed at the end of the header
  67. // file).
  68. void GenerateInlineMethods(io::Printer* printer);
  69. // Source file stuff.
  70. // Generate code which declares all the global descriptor pointers which
  71. // will be initialized by the methods below.
  72. void GenerateDescriptorDeclarations(io::Printer* printer);
  73. // Generate code that initializes the global variable storing the message's
  74. // descriptor.
  75. void GenerateDescriptorInitializer(io::Printer* printer, int index);
  76. // Generate code that calls MessageFactory::InternalRegisterGeneratedMessage()
  77. // for all types.
  78. void GenerateTypeRegistrations(io::Printer* printer);
  79. // Generates code that allocates the message's default instance.
  80. void GenerateDefaultInstanceAllocator(io::Printer* printer);
  81. // Generates code that initializes the message's default instance. This
  82. // is separate from allocating because all default instances must be
  83. // allocated before any can be initialized.
  84. void GenerateDefaultInstanceInitializer(io::Printer* printer);
  85. // Generates code that should be run when ShutdownProtobufLibrary() is called,
  86. // to delete all dynamically-allocated objects.
  87. void GenerateShutdownCode(io::Printer* printer);
  88. // Generate all non-inline methods for this class.
  89. void GenerateClassMethods(io::Printer* printer);
  90. private:
  91. // Generate declarations and definitions of accessors for fields.
  92. void GenerateFieldAccessorDeclarations(io::Printer* printer);
  93. void GenerateFieldAccessorDefinitions(io::Printer* printer);
  94. // Generate the field offsets array.
  95. void GenerateOffsets(io::Printer* printer);
  96. // Generate constructors and destructor.
  97. void GenerateStructors(io::Printer* printer);
  98. // The compiler typically generates multiple copies of each constructor and
  99. // destructor: http://gcc.gnu.org/bugs.html#nonbugs_cxx
  100. // Placing common code in a separate method reduces the generated code size.
  101. //
  102. // Generate the shared constructor code.
  103. void GenerateSharedConstructorCode(io::Printer* printer);
  104. // Generate the shared destructor code.
  105. void GenerateSharedDestructorCode(io::Printer* printer);
  106. // Generate standard Message methods.
  107. void GenerateClear(io::Printer* printer);
  108. void GenerateMergeFromCodedStream(io::Printer* printer);
  109. void GenerateSerializeWithCachedSizes(io::Printer* printer);
  110. void GenerateSerializeWithCachedSizesToArray(io::Printer* printer);
  111. void GenerateSerializeWithCachedSizesBody(io::Printer* printer,
  112. bool to_array);
  113. void GenerateByteSize(io::Printer* printer);
  114. void GenerateMergeFrom(io::Printer* printer);
  115. void GenerateCopyFrom(io::Printer* printer);
  116. void GenerateSwap(io::Printer* printer);
  117. void GenerateIsInitialized(io::Printer* printer);
  118. // Helpers for GenerateSerializeWithCachedSizes().
  119. void GenerateSerializeOneField(io::Printer* printer,
  120. const FieldDescriptor* field,
  121. bool unbounded);
  122. void GenerateSerializeOneExtensionRange(
  123. io::Printer* printer, const Descriptor::ExtensionRange* range,
  124. bool unbounded);
  125. const Descriptor* descriptor_;
  126. string classname_;
  127. string dllexport_decl_;
  128. FieldGeneratorMap field_generators_;
  129. scoped_array<scoped_ptr<MessageGenerator> > nested_generators_;
  130. scoped_array<scoped_ptr<EnumGenerator> > enum_generators_;
  131. scoped_array<scoped_ptr<ExtensionGenerator> > extension_generators_;
  132. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
  133. };
  134. } // namespace cpp
  135. } // namespace compiler
  136. } // namespace protobuf
  137. } // namespace google
  138. #endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__