Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:12:22

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef GOOGLE_PROTOBUF_MAP_ENTRY_H__
0009 #define GOOGLE_PROTOBUF_MAP_ENTRY_H__
0010 
0011 #include <cstddef>
0012 #include <cstdint>
0013 #include <string>
0014 
0015 #include "google/protobuf/generated_message_reflection.h"
0016 #include "google/protobuf/has_bits.h"
0017 #include "google/protobuf/map_type_handler.h"
0018 #include "google/protobuf/message.h"
0019 #include "google/protobuf/message_lite.h"
0020 #include "google/protobuf/parse_context.h"
0021 #include "google/protobuf/unknown_field_set.h"
0022 #include "google/protobuf/wire_format_lite.h"
0023 
0024 // Must be included last.
0025 #include "google/protobuf/port_def.inc"
0026 
0027 #ifdef SWIG
0028 #error "You cannot SWIG proto headers"
0029 #endif
0030 
0031 namespace google {
0032 namespace protobuf {
0033 class Arena;
0034 namespace internal {
0035 template <typename Derived, typename Key, typename Value,
0036           WireFormatLite::FieldType kKeyFieldType,
0037           WireFormatLite::FieldType kValueFieldType>
0038 class MapField;
0039 }
0040 }  // namespace protobuf
0041 }  // namespace google
0042 
0043 namespace google {
0044 namespace protobuf {
0045 namespace internal {
0046 
0047 // MapEntry is the returned google::protobuf::Message when calling AddMessage of
0048 // google::protobuf::Reflection. In order to let it work with generated message
0049 // reflection, its in-memory type is the same as generated message with the same
0050 // fields. However, in order to decide the in-memory type of key/value, we need
0051 // to know both their cpp type in generated api and proto type. In
0052 // implementation, all in-memory types have related wire format functions to
0053 // support except ArenaStringPtr. Therefore, we need to define another type with
0054 // supporting wire format functions. Since this type is only used as return type
0055 // of MapEntry accessors, it's named MapEntry accessor type.
0056 //
0057 // cpp type:               the type visible to users in public API.
0058 // proto type:             WireFormatLite::FieldType of the field.
0059 // in-memory type:         type of the data member used to stored this field.
0060 // MapEntry accessor type: type used in MapEntry getters/mutators to access the
0061 //                         field.
0062 //
0063 // cpp type | proto type  | in-memory type | MapEntry accessor type
0064 // int32_t    TYPE_INT32    int32_t          int32_t
0065 // int32_t    TYPE_FIXED32  int32_t          int32_t
0066 // string     TYPE_STRING   ArenaStringPtr   string
0067 // FooEnum    TYPE_ENUM     int              int
0068 // FooMessage TYPE_MESSAGE  FooMessage*      FooMessage
0069 //
0070 // The in-memory types of primitive types can be inferred from its proto type,
0071 // while we need to explicitly specify the cpp type if proto type is
0072 // TYPE_MESSAGE to infer the in-memory type.
0073 template <typename Derived, typename Key, typename Value,
0074           WireFormatLite::FieldType kKeyFieldType,
0075           WireFormatLite::FieldType kValueFieldType>
0076 class MapEntry : public Message {
0077   // Provide utilities to parse/serialize key/value.  Provide utilities to
0078   // manipulate internal stored type.
0079   using KeyTypeHandler = MapTypeHandler<kKeyFieldType, Key>;
0080   using ValueTypeHandler = MapTypeHandler<kValueFieldType, Value>;
0081 
0082   // Define internal memory layout. Strings and messages are stored as
0083   // pointers, while other types are stored as values.
0084   using KeyOnMemory = typename KeyTypeHandler::TypeOnMemory;
0085   using ValueOnMemory = typename ValueTypeHandler::TypeOnMemory;
0086 
0087  public:
0088 #if !defined(PROTOBUF_CUSTOM_VTABLE)
0089   constexpr MapEntry() {}
0090 #endif  // PROTOBUF_CUSTOM_VTABLE
0091   using Message::Message;
0092 
0093   MapEntry(const MapEntry&) = delete;
0094   MapEntry& operator=(const MapEntry&) = delete;
0095 
0096   ~MapEntry() PROTOBUF_OVERRIDE {
0097     if (GetArena() != nullptr) return;
0098     this->_internal_metadata_.template Delete<UnknownFieldSet>();
0099     KeyTypeHandler::DeleteNoArena(_impl_.key_);
0100     ValueTypeHandler::DeleteNoArena(_impl_.value_);
0101   }
0102 
0103   using InternalArenaConstructable_ = void;
0104   using DestructorSkippable_ = void;
0105 
0106   Message* New(Arena* arena) const PROTOBUF_FINAL {
0107     return Arena::Create<Derived>(arena);
0108   }
0109 
0110   struct _Internal;
0111 
0112  protected:
0113   friend class google::protobuf::Arena;
0114 
0115   // Field naming follows the convention of generated messages to make code
0116   // sharing easier.
0117   struct {
0118     HasBits<1> _has_bits_{};
0119     mutable CachedSize _cached_size_{};
0120 
0121     KeyOnMemory key_{KeyTypeHandler::Constinit()};
0122     ValueOnMemory value_{ValueTypeHandler::Constinit()};
0123   } _impl_;
0124 };
0125 
0126 template <typename Derived, typename Key, typename Value,
0127           WireFormatLite::FieldType kKeyFieldType,
0128           WireFormatLite::FieldType kValueFieldType>
0129 struct MapEntry<Derived, Key, Value, kKeyFieldType,
0130                 kValueFieldType>::_Internal {
0131   static constexpr ::int32_t kHasBitsOffset =
0132       8 * PROTOBUF_FIELD_OFFSET(MapEntry, _impl_._has_bits_);
0133 };
0134 
0135 }  // namespace internal
0136 }  // namespace protobuf
0137 }  // namespace google
0138 
0139 #include "google/protobuf/port_undef.inc"
0140 
0141 #endif  // GOOGLE_PROTOBUF_MAP_ENTRY_H__