java_string_field.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. // Author: jonp@google.com (Jon Perlow)
  32. // Based on original Protocol Buffers design by
  33. // Sanjay Ghemawat, Jeff Dean, and others.
  34. #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__
  35. #define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__
  36. #include <map>
  37. #include <string>
  38. #include <google/protobuf/compiler/java/java_field.h>
  39. namespace google {
  40. namespace protobuf {
  41. namespace compiler {
  42. namespace java {
  43. class Context; // context.h
  44. class ClassNameResolver; // name_resolver.h
  45. }
  46. }
  47. }
  48. namespace protobuf {
  49. namespace compiler {
  50. namespace java {
  51. class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
  52. public:
  53. explicit ImmutableStringFieldGenerator(
  54. const FieldDescriptor* descriptor, int messageBitIndex,
  55. int builderBitIndex, Context* context);
  56. ~ImmutableStringFieldGenerator();
  57. // implements ImmutableFieldGenerator ---------------------------------------
  58. int GetNumBitsForMessage() const;
  59. int GetNumBitsForBuilder() const;
  60. void GenerateInterfaceMembers(io::Printer* printer) const;
  61. void GenerateMembers(io::Printer* printer) const;
  62. void GenerateBuilderMembers(io::Printer* printer) const;
  63. void GenerateInitializationCode(io::Printer* printer) const;
  64. void GenerateBuilderClearCode(io::Printer* printer) const;
  65. void GenerateMergingCode(io::Printer* printer) const;
  66. void GenerateBuildingCode(io::Printer* printer) const;
  67. void GenerateParsingCode(io::Printer* printer) const;
  68. void GenerateParsingDoneCode(io::Printer* printer) const;
  69. void GenerateSerializationCode(io::Printer* printer) const;
  70. void GenerateSerializedSizeCode(io::Printer* printer) const;
  71. void GenerateFieldBuilderInitializationCode(io::Printer* printer) const;
  72. void GenerateEqualsCode(io::Printer* printer) const;
  73. void GenerateHashCode(io::Printer* printer) const;
  74. string GetBoxedType() const;
  75. protected:
  76. const FieldDescriptor* descriptor_;
  77. std::map<string, string> variables_;
  78. const int messageBitIndex_;
  79. const int builderBitIndex_;
  80. Context* context_;
  81. ClassNameResolver* name_resolver_;
  82. private:
  83. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldGenerator);
  84. };
  85. class ImmutableStringOneofFieldGenerator
  86. : public ImmutableStringFieldGenerator {
  87. public:
  88. ImmutableStringOneofFieldGenerator(
  89. const FieldDescriptor* descriptor, int messageBitIndex,
  90. int builderBitIndex, Context* context);
  91. ~ImmutableStringOneofFieldGenerator();
  92. private:
  93. void GenerateMembers(io::Printer* printer) const;
  94. void GenerateBuilderMembers(io::Printer* printer) const;
  95. void GenerateMergingCode(io::Printer* printer) const;
  96. void GenerateBuildingCode(io::Printer* printer) const;
  97. void GenerateParsingCode(io::Printer* printer) const;
  98. void GenerateSerializationCode(io::Printer* printer) const;
  99. void GenerateSerializedSizeCode(io::Printer* printer) const;
  100. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldGenerator);
  101. };
  102. class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator {
  103. public:
  104. explicit RepeatedImmutableStringFieldGenerator(
  105. const FieldDescriptor* descriptor, int messageBitIndex,
  106. int builderBitIndex, Context* context);
  107. ~RepeatedImmutableStringFieldGenerator();
  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 GenerateParsingDoneCode(io::Printer* printer) const;
  120. void GenerateSerializationCode(io::Printer* printer) const;
  121. void GenerateSerializedSizeCode(io::Printer* printer) const;
  122. void GenerateFieldBuilderInitializationCode(io::Printer* printer) const;
  123. void GenerateEqualsCode(io::Printer* printer) const;
  124. void GenerateHashCode(io::Printer* printer) const;
  125. string GetBoxedType() const;
  126. private:
  127. const FieldDescriptor* descriptor_;
  128. std::map<string, string> variables_;
  129. const int messageBitIndex_;
  130. const int builderBitIndex_;
  131. Context* context_;
  132. ClassNameResolver* name_resolver_;
  133. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldGenerator);
  134. };
  135. } // namespace java
  136. } // namespace compiler
  137. } // namespace protobuf
  138. } // namespace google
  139. #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__