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

http://github.com/tomahawk-player/tomahawk · C++ Header · 167 lines · 58 code · 31 blank · 78 comment · 0 complexity · ec773baa0734ab605a7f68bcabaf1700 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_FIELD_H__
  34. #define GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__
  35. #include <map>
  36. #include <string>
  37. #include <google/protobuf/stubs/common.h>
  38. #include <google/protobuf/descriptor.h>
  39. namespace google {
  40. namespace protobuf {
  41. namespace io {
  42. class Printer; // printer.h
  43. }
  44. }
  45. namespace protobuf {
  46. namespace compiler {
  47. namespace cpp {
  48. // Helper function: set variables in the map that are the same for all
  49. // field code generators.
  50. // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size',
  51. // 'deprecation'].
  52. void SetCommonFieldVariables(const FieldDescriptor* descriptor,
  53. map<string, string>* variables);
  54. class FieldGenerator {
  55. public:
  56. FieldGenerator() {}
  57. virtual ~FieldGenerator();
  58. // Generate lines of code declaring members fields of the message class
  59. // needed to represent this field. These are placed inside the message
  60. // class.
  61. virtual void GeneratePrivateMembers(io::Printer* printer) const = 0;
  62. // Generate prototypes for all of the accessor functions related to this
  63. // field. These are placed inside the class definition.
  64. virtual void GenerateAccessorDeclarations(io::Printer* printer) const = 0;
  65. // Generate inline definitions of accessor functions for this field.
  66. // These are placed inside the header after all class definitions.
  67. virtual void GenerateInlineAccessorDefinitions(
  68. io::Printer* printer) const = 0;
  69. // Generate definitions of accessors that aren't inlined. These are
  70. // placed somewhere in the .cc file.
  71. // Most field types don't need this, so the default implementation is empty.
  72. virtual void GenerateNonInlineAccessorDefinitions(
  73. io::Printer* printer) const {}
  74. // Generate lines of code (statements, not declarations) which clear the
  75. // field. This is used to define the clear_$name$() method as well as
  76. // the Clear() method for the whole message.
  77. virtual void GenerateClearingCode(io::Printer* printer) const = 0;
  78. // Generate lines of code (statements, not declarations) which merges the
  79. // contents of the field from the current message to the target message,
  80. // which is stored in the generated code variable "from".
  81. // This is used to fill in the MergeFrom method for the whole message.
  82. // Details of this usage can be found in message.cc under the
  83. // GenerateMergeFrom method.
  84. virtual void GenerateMergingCode(io::Printer* printer) const = 0;
  85. // Generate lines of code (statements, not declarations) which swaps
  86. // this field and the corresponding field of another message, which
  87. // is stored in the generated code variable "other". This is used to
  88. // define the Swap method. Details of usage can be found in
  89. // message.cc under the GenerateSwap method.
  90. virtual void GenerateSwappingCode(io::Printer* printer) const = 0;
  91. // Generate initialization code for private members declared by
  92. // GeneratePrivateMembers(). These go into the message class's SharedCtor()
  93. // method, invoked by each of the generated constructors.
  94. virtual void GenerateConstructorCode(io::Printer* printer) const = 0;
  95. // Generate any code that needs to go in the class's SharedDtor() method,
  96. // invoked by the destructor.
  97. // Most field types don't need this, so the default implementation is empty.
  98. virtual void GenerateDestructorCode(io::Printer* printer) const {}
  99. // Generate lines to decode this field, which will be placed inside the
  100. // message's MergeFromCodedStream() method.
  101. virtual void GenerateMergeFromCodedStream(io::Printer* printer) const = 0;
  102. // Generate lines to decode this field from a packed value, which will be
  103. // placed inside the message's MergeFromCodedStream() method.
  104. virtual void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer)
  105. const;
  106. // Generate lines to serialize this field, which are placed within the
  107. // message's SerializeWithCachedSizes() method.
  108. virtual void GenerateSerializeWithCachedSizes(io::Printer* printer) const = 0;
  109. // Generate lines to serialize this field directly to the array "target",
  110. // which are placed within the message's SerializeWithCachedSizesToArray()
  111. // method. This must also advance "target" past the written bytes.
  112. virtual void GenerateSerializeWithCachedSizesToArray(
  113. io::Printer* printer) const = 0;
  114. // Generate lines to compute the serialized size of this field, which
  115. // are placed in the message's ByteSize() method.
  116. virtual void GenerateByteSize(io::Printer* printer) const = 0;
  117. private:
  118. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);
  119. };
  120. // Convenience class which constructs FieldGenerators for a Descriptor.
  121. class FieldGeneratorMap {
  122. public:
  123. explicit FieldGeneratorMap(const Descriptor* descriptor);
  124. ~FieldGeneratorMap();
  125. const FieldGenerator& get(const FieldDescriptor* field) const;
  126. private:
  127. const Descriptor* descriptor_;
  128. scoped_array<scoped_ptr<FieldGenerator> > field_generators_;
  129. static FieldGenerator* MakeGenerator(const FieldDescriptor* field);
  130. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
  131. };
  132. } // namespace cpp
  133. } // namespace compiler
  134. } // namespace protobuf
  135. } // namespace google
  136. #endif // GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__