java_enum_field.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // 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_JAVA_ENUM_FIELD_H__
  34. #define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__
  35. #include <map>
  36. #include <string>
  37. #include <google/protobuf/compiler/java/java_field.h>
  38. namespace google {
  39. namespace protobuf {
  40. namespace compiler {
  41. namespace java {
  42. class Context; // context.h
  43. class ClassNameResolver; // name_resolver.h
  44. }
  45. }
  46. }
  47. namespace protobuf {
  48. namespace compiler {
  49. namespace java {
  50. class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
  51. public:
  52. explicit ImmutableEnumFieldGenerator(
  53. const FieldDescriptor* descriptor, int messageBitIndex,
  54. int builderBitIndex, Context* context);
  55. ~ImmutableEnumFieldGenerator();
  56. // implements ImmutableFieldGenerator ---------------------------------------
  57. int GetNumBitsForMessage() const;
  58. int GetNumBitsForBuilder() const;
  59. void GenerateInterfaceMembers(io::Printer* printer) const;
  60. void GenerateMembers(io::Printer* printer) const;
  61. void GenerateBuilderMembers(io::Printer* printer) const;
  62. void GenerateInitializationCode(io::Printer* printer) const;
  63. void GenerateBuilderClearCode(io::Printer* printer) const;
  64. void GenerateMergingCode(io::Printer* printer) const;
  65. void GenerateBuildingCode(io::Printer* printer) const;
  66. void GenerateParsingCode(io::Printer* printer) const;
  67. void GenerateParsingDoneCode(io::Printer* printer) const;
  68. void GenerateSerializationCode(io::Printer* printer) const;
  69. void GenerateSerializedSizeCode(io::Printer* printer) const;
  70. void GenerateFieldBuilderInitializationCode(io::Printer* printer) const;
  71. void GenerateEqualsCode(io::Printer* printer) const;
  72. void GenerateHashCode(io::Printer* printer) const;
  73. string GetBoxedType() const;
  74. protected:
  75. const FieldDescriptor* descriptor_;
  76. std::map<string, string> variables_;
  77. const int messageBitIndex_;
  78. const int builderBitIndex_;
  79. Context* context_;
  80. ClassNameResolver* name_resolver_;
  81. private:
  82. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldGenerator);
  83. };
  84. class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator {
  85. public:
  86. ImmutableEnumOneofFieldGenerator(
  87. const FieldDescriptor* descriptor, int messageBitIndex,
  88. int builderBitIndex, Context* context);
  89. ~ImmutableEnumOneofFieldGenerator();
  90. void GenerateMembers(io::Printer* printer) const;
  91. void GenerateBuilderMembers(io::Printer* printer) const;
  92. void GenerateMergingCode(io::Printer* printer) const;
  93. void GenerateBuildingCode(io::Printer* printer) const;
  94. void GenerateParsingCode(io::Printer* printer) const;
  95. void GenerateSerializationCode(io::Printer* printer) const;
  96. void GenerateSerializedSizeCode(io::Printer* printer) const;
  97. void GenerateEqualsCode(io::Printer* printer) const;
  98. void GenerateHashCode(io::Printer* printer) const;
  99. private:
  100. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldGenerator);
  101. };
  102. class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
  103. public:
  104. explicit RepeatedImmutableEnumFieldGenerator(
  105. const FieldDescriptor* descriptor, int messageBitIndex,
  106. int builderBitIndex, Context* context);
  107. ~RepeatedImmutableEnumFieldGenerator();
  108. // implements ImmutableFieldGenerator ---------------------------------------
  109. int GetNumBitsForMessage() const;
  110. int GetNumBitsForBuilder() const;
  111. void GenerateInterfaceMembers(io::Printer* printer) const;
  112. void GenerateMembers(io::Printer* printer) const;
  113. void GenerateBuilderMembers(io::Printer* printer) const;
  114. void GenerateInitializationCode(io::Printer* printer) const;
  115. void GenerateBuilderClearCode(io::Printer* printer) const;
  116. void GenerateMergingCode(io::Printer* printer) const;
  117. void GenerateBuildingCode(io::Printer* printer) const;
  118. void GenerateParsingCode(io::Printer* printer) const;
  119. void GenerateParsingCodeFromPacked(io::Printer* printer) const;
  120. void GenerateParsingDoneCode(io::Printer* printer) const;
  121. void GenerateSerializationCode(io::Printer* printer) const;
  122. void GenerateSerializedSizeCode(io::Printer* printer) const;
  123. void GenerateFieldBuilderInitializationCode(io::Printer* printer) const;
  124. void GenerateEqualsCode(io::Printer* printer) const;
  125. void GenerateHashCode(io::Printer* printer) const;
  126. string GetBoxedType() const;
  127. private:
  128. const FieldDescriptor* descriptor_;
  129. std::map<string, string> variables_;
  130. const int messageBitIndex_;
  131. const int builderBitIndex_;
  132. Context* context_;
  133. ClassNameResolver* name_resolver_;
  134. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldGenerator);
  135. };
  136. } // namespace java
  137. } // namespace compiler
  138. } // namespace protobuf
  139. } // namespace google
  140. #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__