诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

261 lines
9.4 KiB

  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. #ifndef GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
  31. #define GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
  32. #include <string>
  33. #include <utility>
  34. #include <google/protobuf/port.h>
  35. #include <google/protobuf/stubs/strutil.h>
  36. // Must be included last.
  37. #include <google/protobuf/port_def.inc>
  38. #ifdef SWIG
  39. #error "You cannot SWIG proto headers"
  40. #endif
  41. namespace google {
  42. namespace protobuf {
  43. class Arena;
  44. namespace internal {
  45. // InlinedStringField wraps a std::string instance and exposes an API similar to
  46. // ArenaStringPtr's wrapping of a std::string* instance. As std::string is
  47. // never allocated on the Arena, we expose only the *NoArena methods of
  48. // ArenaStringPtr.
  49. //
  50. // default_value parameters are taken for consistency with ArenaStringPtr, but
  51. // are not used for most methods. With inlining, these should be removed from
  52. // the generated binary.
  53. class PROTOBUF_EXPORT InlinedStringField {
  54. public:
  55. InlinedStringField() PROTOBUF_ALWAYS_INLINE;
  56. explicit InlinedStringField(const std::string& default_value);
  57. void AssignWithDefault(const std::string* default_value,
  58. const InlinedStringField& from) PROTOBUF_ALWAYS_INLINE;
  59. void ClearToEmpty(const std::string* default_value,
  60. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  61. ClearToEmptyNoArena(default_value);
  62. }
  63. void ClearNonDefaultToEmpty() PROTOBUF_ALWAYS_INLINE {
  64. ClearNonDefaultToEmptyNoArena();
  65. }
  66. void ClearToEmptyNoArena(const std::string* /*default_value*/)
  67. PROTOBUF_ALWAYS_INLINE {
  68. ClearNonDefaultToEmptyNoArena();
  69. }
  70. void ClearNonDefaultToEmptyNoArena() PROTOBUF_ALWAYS_INLINE;
  71. void ClearToDefault(const std::string* default_value,
  72. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  73. ClearToDefaultNoArena(default_value);
  74. }
  75. void ClearToDefaultNoArena(const std::string* default_value)
  76. PROTOBUF_ALWAYS_INLINE;
  77. void Destroy(const std::string* default_value,
  78. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  79. DestroyNoArena(default_value);
  80. }
  81. void DestroyNoArena(const std::string* default_value) PROTOBUF_ALWAYS_INLINE;
  82. const std::string& Get() const PROTOBUF_ALWAYS_INLINE { return GetNoArena(); }
  83. const std::string& GetNoArena() const PROTOBUF_ALWAYS_INLINE;
  84. std::string* Mutable(const std::string* default_value,
  85. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  86. return MutableNoArena(default_value);
  87. }
  88. std::string* MutableNoArena(const std::string* default_value)
  89. PROTOBUF_ALWAYS_INLINE;
  90. std::string* Release(const std::string* default_value, Arena* /*arena*/) {
  91. return ReleaseNoArena(default_value);
  92. }
  93. std::string* ReleaseNonDefault(const std::string* default_value,
  94. Arena* /*arena*/) {
  95. return ReleaseNonDefaultNoArena(default_value);
  96. }
  97. std::string* ReleaseNoArena(const std::string* default_value) {
  98. return ReleaseNonDefaultNoArena(default_value);
  99. }
  100. std::string* ReleaseNonDefaultNoArena(const std::string* default_value);
  101. void Set(const std::string* default_value, StringPiece value,
  102. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  103. SetNoArena(default_value, value);
  104. }
  105. void SetLite(const std::string* default_value, StringPiece value,
  106. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  107. SetNoArena(default_value, value);
  108. }
  109. void SetNoArena(const std::string* default_value,
  110. StringPiece value) PROTOBUF_ALWAYS_INLINE;
  111. void Set(const std::string* default_value, const std::string& value,
  112. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  113. SetNoArena(default_value, value);
  114. }
  115. void SetLite(const std::string* default_value, const std::string& value,
  116. Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
  117. SetNoArena(default_value, value);
  118. }
  119. void SetNoArena(const std::string* default_value,
  120. const std::string& value) PROTOBUF_ALWAYS_INLINE;
  121. void SetNoArena(const std::string* default_value,
  122. std::string&& value) PROTOBUF_ALWAYS_INLINE;
  123. void SetAllocated(const std::string* default_value, std::string* value,
  124. Arena* /*arena*/) {
  125. SetAllocatedNoArena(default_value, value);
  126. }
  127. void SetAllocatedNoArena(const std::string* default_value,
  128. std::string* value);
  129. void Swap(InlinedStringField* from) PROTOBUF_ALWAYS_INLINE;
  130. std::string* UnsafeMutablePointer();
  131. void UnsafeSetDefault(const std::string* default_value);
  132. std::string* UnsafeArenaRelease(const std::string* default_value,
  133. Arena* arena);
  134. void UnsafeArenaSetAllocated(const std::string* default_value,
  135. std::string* value, Arena* arena);
  136. bool IsDefault(const std::string* /*default_value*/) { return false; }
  137. private:
  138. std::string value_;
  139. };
  140. inline InlinedStringField::InlinedStringField() {}
  141. inline InlinedStringField::InlinedStringField(const std::string& default_value)
  142. : value_(default_value) {}
  143. inline void InlinedStringField::AssignWithDefault(
  144. const std::string* /*default_value*/, const InlinedStringField& from) {
  145. value_ = from.value_;
  146. }
  147. inline const std::string& InlinedStringField::GetNoArena() const {
  148. return value_;
  149. }
  150. inline std::string* InlinedStringField::MutableNoArena(const std::string*) {
  151. return &value_;
  152. }
  153. inline void InlinedStringField::SetAllocatedNoArena(
  154. const std::string* default_value, std::string* value) {
  155. if (value == NULL) {
  156. value_.assign(*default_value);
  157. } else {
  158. value_.assign(std::move(*value));
  159. delete value;
  160. }
  161. }
  162. inline void InlinedStringField::DestroyNoArena(const std::string*) {
  163. // This is invoked from the generated message's ArenaDtor, which is used to
  164. // clean up objects not allocated on the Arena.
  165. this->~InlinedStringField();
  166. }
  167. inline void InlinedStringField::ClearNonDefaultToEmptyNoArena() {
  168. value_.clear();
  169. }
  170. inline void InlinedStringField::ClearToDefaultNoArena(
  171. const std::string* default_value) {
  172. value_.assign(*default_value);
  173. }
  174. inline std::string* InlinedStringField::ReleaseNonDefaultNoArena(
  175. const std::string* default_value) {
  176. std::string* released = new std::string(*default_value);
  177. value_.swap(*released);
  178. return released;
  179. }
  180. inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
  181. StringPiece value) {
  182. value_.assign(value.data(), value.length());
  183. }
  184. inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
  185. const std::string& value) {
  186. value_.assign(value);
  187. }
  188. inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
  189. std::string&& value) {
  190. value_.assign(std::move(value));
  191. }
  192. inline void InlinedStringField::Swap(InlinedStringField* from) {
  193. value_.swap(from->value_);
  194. }
  195. inline std::string* InlinedStringField::UnsafeMutablePointer() {
  196. return &value_;
  197. }
  198. inline void InlinedStringField::UnsafeSetDefault(
  199. const std::string* default_value) {
  200. value_.assign(*default_value);
  201. }
  202. inline std::string* InlinedStringField::UnsafeArenaRelease(
  203. const std::string* default_value, Arena* /*arena*/) {
  204. return ReleaseNoArena(default_value);
  205. }
  206. inline void InlinedStringField::UnsafeArenaSetAllocated(
  207. const std::string* default_value, std::string* value, Arena* /*arena*/) {
  208. if (value == NULL) {
  209. value_.assign(*default_value);
  210. } else {
  211. value_.assign(*value);
  212. }
  213. }
  214. } // namespace internal
  215. } // namespace protobuf
  216. } // namespace google
  217. #include <google/protobuf/port_undef.inc>
  218. #endif // GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__