map_entry.h
Go to the documentation of this file.
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 
31 #ifndef GOOGLE_PROTOBUF_MAP_ENTRY_H__
32 #define GOOGLE_PROTOBUF_MAP_ENTRY_H__
33 
38 #include <google/protobuf/port.h>
42 
43 #include <google/protobuf/port_def.inc>
44 
45 #ifdef SWIG
46 #error "You cannot SWIG proto headers"
47 #endif
48 
49 namespace google {
50 namespace protobuf {
51 class Arena;
52 namespace internal {
53 template <typename Derived, typename Key, typename Value,
54  WireFormatLite::FieldType kKeyFieldType,
55  WireFormatLite::FieldType kValueFieldType, int default_enum_value>
56 class MapField;
57 }
58 } // namespace protobuf
59 } // namespace google
60 
61 namespace google {
62 namespace protobuf {
63 namespace internal {
64 
65 // MapEntry is the returned google::protobuf::Message when calling AddMessage of
66 // google::protobuf::Reflection. In order to let it work with generated message
67 // reflection, its in-memory type is the same as generated message with the same
68 // fields. However, in order to decide the in-memory type of key/value, we need
69 // to know both their cpp type in generated api and proto type. In
70 // implementation, all in-memory types have related wire format functions to
71 // support except ArenaStringPtr. Therefore, we need to define another type with
72 // supporting wire format functions. Since this type is only used as return type
73 // of MapEntry accessors, it's named MapEntry accessor type.
74 //
75 // cpp type: the type visible to users in public API.
76 // proto type: WireFormatLite::FieldType of the field.
77 // in-memory type: type of the data member used to stored this field.
78 // MapEntry accessor type: type used in MapEntry getters/mutators to access the
79 // field.
80 //
81 // cpp type | proto type | in-memory type | MapEntry accessor type
82 // int32 TYPE_INT32 int32 int32
83 // int32 TYPE_FIXED32 int32 int32
84 // string TYPE_STRING ArenaStringPtr string
85 // FooEnum TYPE_ENUM int int
86 // FooMessage TYPE_MESSAGE FooMessage* FooMessage
87 //
88 // The in-memory types of primitive types can be inferred from its proto type,
89 // while we need to explicitly specify the cpp type if proto type is
90 // TYPE_MESSAGE to infer the in-memory type. Moreover, default_enum_value is
91 // used to initialize enum field in proto2.
92 template <typename Derived, typename Key, typename Value,
93  WireFormatLite::FieldType kKeyFieldType,
94  WireFormatLite::FieldType kValueFieldType, int default_enum_value>
95 class MapEntry
96  : public MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
97  kValueFieldType, default_enum_value> {
98  public:
100  explicit MapEntry(Arena* arena)
101  : MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
102  kValueFieldType, default_enum_value>(arena),
103  _internal_metadata_(arena) {}
105  typedef void DestructorSkippable_;
106 
107  typedef
108  typename MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
109  kValueFieldType, default_enum_value>::KeyTypeHandler
111  typedef typename MapEntryImpl<
112  Derived, Message, Key, Value, kKeyFieldType, kValueFieldType,
114  size_t SpaceUsedLong() const override {
115  size_t size = sizeof(Derived);
116  size += KeyTypeHandler::SpaceUsedInMapEntryLong(this->key_);
117  size += ValueTypeHandler::SpaceUsedInMapEntryLong(this->value_);
118  return size;
119  }
120 
122 
123  private:
124  friend class ::PROTOBUF_NAMESPACE_ID::Arena;
125  template <typename C, typename K, typename V,
127  int default_enum>
128  friend class internal::MapField;
129 
131 };
132 
133 // Specialization for the full runtime
134 template <typename Derived, typename Key, typename Value,
135  WireFormatLite::FieldType kKeyFieldType,
136  WireFormatLite::FieldType kValueFieldType, int default_enum_value>
137 struct MapEntryHelper<MapEntry<Derived, Key, Value, kKeyFieldType,
138  kValueFieldType, default_enum_value> >
139  : MapEntryHelper<MapEntryLite<Derived, Key, Value, kKeyFieldType,
140  kValueFieldType, default_enum_value> > {
141  explicit MapEntryHelper(const MapPair<Key, Value>& map_pair)
142  : MapEntryHelper<MapEntryLite<Derived, Key, Value, kKeyFieldType,
143  kValueFieldType, default_enum_value> >(
144  map_pair) {}
145 };
146 
147 template <typename Derived, typename K, typename V,
149  int default_enum>
150 struct DeconstructMapEntry<MapEntry<Derived, K, V, key, value, default_enum> > {
151  typedef K Key;
152  typedef V Value;
153  static const WireFormatLite::FieldType kKeyFieldType = key;
154  static const WireFormatLite::FieldType kValueFieldType = value;
155  static const int default_enum_value = default_enum;
156 };
157 
158 } // namespace internal
159 } // namespace protobuf
160 } // namespace google
161 
162 #include <google/protobuf/port_undef.inc>
163 
164 #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__
reflection_ops.h
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
K
#define K(t)
Definition: sha1.c:43
wire_format_lite.h
google::protobuf.internal::InternalMetadataWithArena
Definition: metadata.h:52
google::protobuf.internal::MapEntry::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry)
google::protobuf.internal::DeconstructMapEntry< MapEntry< Derived, K, V, key, value, default_enum > >::Key
K Key
Definition: map_entry.h:151
google::protobuf.internal::MapEntry::SpaceUsedLong
size_t SpaceUsedLong() const override
Definition: map_entry.h:114
NULL
NULL
Definition: test_security_zap.cpp:405
google::protobuf.internal::MapField
Definition: map.h:78
google::protobuf.internal::MapEntryImpl
Definition: map_entry_lite.h:155
google::protobuf.internal::MapEntry::InternalArenaConstructable_
void InternalArenaConstructable_
Definition: map_entry.h:104
google::protobuf.internal::MapEntry::ValueTypeHandler
MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::ValueTypeHandler ValueTypeHandler
Definition: map_entry.h:113
map_type_handler.h
generated_message_reflection.h
Value
Definition: struct.pb.h:304
google::protobuf.internal::MapEntryLite
Definition: map_entry_lite.h:597
port.h
map_entry_lite.h
google::protobuf.internal::MapEntryHelper< MapEntry< Derived, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value > >::MapEntryHelper
MapEntryHelper(const MapPair< Key, Value > &map_pair)
Definition: map_entry.h:141
unknown_field_set.h
google::protobuf.internal::DeconstructMapEntry< MapEntry< Derived, K, V, key, value, default_enum > >::Value
V Value
Definition: map_entry.h:152
size
#define size
Definition: glcorearb.h:2944
google::protobuf.internal::MapEntry::KeyTypeHandler
MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::KeyTypeHandler KeyTypeHandler
Definition: map_entry.h:110
google::protobuf.internal::WireFormatLite::FieldType
FieldType
Definition: wire_format_lite.h:111
key
const SETUP_TEARDOWN_TESTCONTEXT char * key
Definition: test_wss_transport.cpp:10
google::protobuf.internal::MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::value_
ValueOnMemory value_
Definition: map_entry_lite.h:576
google::protobuf.internal::MapEntry
Definition: map_entry.h:95
google::protobuf.internal::MapEntry::MapEntry
MapEntry(Arena *arena)
Definition: map_entry.h:100
google::protobuf::Message
Definition: src/google/protobuf/message.h:205
size
GLsizeiptr size
Definition: glcorearb.h:2943
google::protobuf.internal::MapEntryHelper
Definition: map_entry_lite.h:691
metadata.h
internal
Definition: any.pb.h:40
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
google::protobuf.internal::MapEntry::DestructorSkippable_
void DestructorSkippable_
Definition: map_entry.h:105
google::protobuf.internal::MapEntry::MapEntry
MapEntry()
Definition: map_entry.h:99
google::protobuf.internal::MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::key_
KeyOnMemory key_
Definition: map_entry_lite.h:575
google::protobuf::Message::Message
Message()
Definition: src/google/protobuf/message.h:207
google::protobuf.internal::DeconstructMapEntry
Definition: map_entry_lite.h:615
google::protobuf.internal::MapEntry::_internal_metadata_
InternalMetadataWithArena _internal_metadata_
Definition: map_entry.h:121
google
Definition: data_proto2_to_proto3_util.h:11
google::protobuf::MapPair
Definition: map.h:92
Value
struct Value Value
Definition: php/ext/google/protobuf/protobuf.h:667


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:56