诸暨麻将添加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.
 
 
 
 
 
 

194 lines
7.1 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_IMPLICIT_WEAK_MESSAGE_H__
  31. #define GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
  32. #include <string>
  33. #include <google/protobuf/io/coded_stream.h>
  34. #include <google/protobuf/arena.h>
  35. #include <google/protobuf/message_lite.h>
  36. #include <google/protobuf/repeated_field.h>
  37. #ifdef SWIG
  38. #error "You cannot SWIG proto headers"
  39. #endif
  40. #include <google/protobuf/port_def.inc>
  41. // This file is logically internal-only and should only be used by protobuf
  42. // generated code.
  43. namespace google {
  44. namespace protobuf {
  45. namespace internal {
  46. // An implementation of MessageLite that treats all data as unknown. This type
  47. // acts as a placeholder for an implicit weak field in the case where the true
  48. // message type does not get linked into the binary.
  49. class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
  50. public:
  51. ImplicitWeakMessage() : arena_(NULL) {}
  52. explicit ImplicitWeakMessage(Arena* arena) : arena_(arena) {}
  53. static const ImplicitWeakMessage* default_instance();
  54. std::string GetTypeName() const override { return ""; }
  55. MessageLite* New() const override { return new ImplicitWeakMessage; }
  56. MessageLite* New(Arena* arena) const override {
  57. return Arena::CreateMessage<ImplicitWeakMessage>(arena);
  58. }
  59. Arena* GetArena() const override { return arena_; }
  60. void Clear() override { data_.clear(); }
  61. bool IsInitialized() const override { return true; }
  62. void CheckTypeAndMergeFrom(const MessageLite& other) override {
  63. data_.append(static_cast<const ImplicitWeakMessage&>(other).data_);
  64. }
  65. const char* _InternalParse(const char* ptr, ParseContext* ctx) final;
  66. size_t ByteSizeLong() const override { return data_.size(); }
  67. uint8* InternalSerializeWithCachedSizesToArray(
  68. uint8* target, io::EpsCopyOutputStream* stream) const final {
  69. return stream->WriteRaw(data_.data(), static_cast<int>(data_.size()),
  70. target);
  71. }
  72. int GetCachedSize() const override { return static_cast<int>(data_.size()); }
  73. typedef void InternalArenaConstructable_;
  74. private:
  75. Arena* const arena_;
  76. std::string data_;
  77. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImplicitWeakMessage);
  78. };
  79. // A type handler for use with implicit weak repeated message fields.
  80. template <typename ImplicitWeakType>
  81. class ImplicitWeakTypeHandler {
  82. public:
  83. typedef MessageLite Type;
  84. static const bool Moveable = false;
  85. static inline MessageLite* NewFromPrototype(const MessageLite* prototype,
  86. Arena* arena = NULL) {
  87. return prototype->New(arena);
  88. }
  89. static inline void Delete(MessageLite* value, Arena* arena) {
  90. if (arena == NULL) {
  91. delete value;
  92. }
  93. }
  94. static inline Arena* GetArena(MessageLite* value) {
  95. return value->GetArena();
  96. }
  97. static inline void* GetMaybeArenaPointer(MessageLite* value) {
  98. return value->GetArena();
  99. }
  100. static inline void Clear(MessageLite* value) { value->Clear(); }
  101. static void Merge(const MessageLite& from, MessageLite* to) {
  102. to->CheckTypeAndMergeFrom(from);
  103. }
  104. };
  105. } // namespace internal
  106. template <typename T>
  107. struct WeakRepeatedPtrField {
  108. using TypeHandler = internal::ImplicitWeakTypeHandler<T>;
  109. WeakRepeatedPtrField() : weak() {}
  110. explicit WeakRepeatedPtrField(Arena* arena) : weak(arena) {}
  111. ~WeakRepeatedPtrField() { weak.template Destroy<TypeHandler>(); }
  112. typedef internal::RepeatedPtrIterator<MessageLite> iterator;
  113. typedef internal::RepeatedPtrIterator<const MessageLite> const_iterator;
  114. typedef internal::RepeatedPtrOverPtrsIterator<MessageLite*, void*>
  115. pointer_iterator;
  116. typedef internal::RepeatedPtrOverPtrsIterator<const MessageLite* const,
  117. const void* const>
  118. const_pointer_iterator;
  119. iterator begin() { return iterator(base().raw_data()); }
  120. const_iterator begin() const { return iterator(base().raw_data()); }
  121. const_iterator cbegin() const { return begin(); }
  122. iterator end() { return begin() + base().size(); }
  123. const_iterator end() const { return begin() + base().size(); }
  124. const_iterator cend() const { return end(); }
  125. pointer_iterator pointer_begin() {
  126. return pointer_iterator(base().raw_mutable_data());
  127. }
  128. const_pointer_iterator pointer_begin() const {
  129. return const_pointer_iterator(base().raw_mutable_data());
  130. }
  131. pointer_iterator pointer_end() {
  132. return pointer_iterator(base().raw_mutable_data() + base().size());
  133. }
  134. const_pointer_iterator pointer_end() const {
  135. return const_pointer_iterator(base().raw_mutable_data() + base().size());
  136. }
  137. MessageLite* AddWeak(const MessageLite* prototype) {
  138. return base().AddWeak(prototype);
  139. }
  140. T* Add() { return weak.Add(); }
  141. void Clear() { base().template Clear<TypeHandler>(); }
  142. void MergeFrom(const WeakRepeatedPtrField& other) {
  143. base().template MergeFrom<TypeHandler>(other.base());
  144. }
  145. void InternalSwap(WeakRepeatedPtrField* other) {
  146. base().InternalSwap(&other->base());
  147. }
  148. const internal::RepeatedPtrFieldBase& base() const { return weak; }
  149. internal::RepeatedPtrFieldBase& base() { return weak; }
  150. // Union disables running the destructor. Which would create a strong link.
  151. // Instead we explicitly destroy the underlying base through the virtual
  152. // destructor.
  153. union {
  154. RepeatedPtrField<T> weak;
  155. };
  156. };
  157. } // namespace protobuf
  158. } // namespace google
  159. #include <google/protobuf/port_undef.inc>
  160. #endif // GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__