31 #ifndef GOOGLE_PROTOBUF_TYPE_HANDLER_H__ 32 #define GOOGLE_PROTOBUF_TYPE_HANDLER_H__ 44 template<
bool Flag,
typename TrueType,
typename FalseType>
47 template<
typename TrueType,
typename FalseType>
52 template<
typename TrueType,
typename FalseType>
59 template <
bool IsEnum,
typename Type>
65 template <
typename Type>
69 value =
static_cast<Type>(default_enum_value);
73 template <
typename Type>
79 template <
typename Type,
bool is_arena_constructable>
84 static inline Type* CreateMessage(
Arena* arena);
86 template <
typename Type>
90 return Arena::CreateMessage<Type>(arena);
93 template <
typename Type>
97 return Arena::Create<Type>(arena);
102 template <WireFormatLite::FieldType field_type,
typename Type>
105 #define TYPE_TRAITS(FieldType, CType, WireFormatType, IsMessage, IsEnum) \ 106 template <typename Type> \ 107 class MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, Type> { \ 109 static const bool kIsMessage = IsMessage; \ 110 static const bool kIsEnum = IsEnum; \ 111 typedef typename MapIf<kIsMessage, Type*, CType>::type TypeOnMemory; \ 112 typedef typename MapIf<kIsEnum, int, Type>::type MapEntryAccessorType; \ 113 static const WireFormatLite::WireType kWireType = \ 114 WireFormatLite::WIRETYPE_##WireFormatType; \ 119 TYPE_TRAITS(BYTES , ArenaStringPtr , LENGTH_DELIMITED, false, false)
124 TYPE_TRAITS(SINT64 , int64 , VARINT , false, false)
125 TYPE_TRAITS(SINT32 , int32 , VARINT , false, false)
129 TYPE_TRAITS(FIXED64 , uint64 , FIXED64, false, false)
130 TYPE_TRAITS(FIXED32 , uint32 , FIXED32, false, false)
131 TYPE_TRAITS(SFIXED64, int64 , FIXED64, false, false)
132 TYPE_TRAITS(SFIXED32, int32 , FIXED32, false, false)
137 template <WireFormatLite::FieldType field_type,
typename Type>
140 template <
typename Type>
154 static const bool kIsMessage =
157 static const bool kIsEnum =
161 static inline int ByteSize(
const MapEntryAccessorType&
value);
162 static inline int GetCachedSize(
const MapEntryAccessorType&
value);
164 MapEntryAccessorType*
value);
168 const MapEntryAccessorType&
value,
172 static inline const Type& GetExternalReference(
const Type*
value);
173 static inline void DeleteNoArena(
const Type*
x);
176 static inline void ClearMaybeByDefaultEnum(
Type**
value,
Arena* arena,
177 int default_enum_value);
180 static inline void InitializeMaybeByDefaultEnum(
Type**
x,
181 int default_enum_value,
186 static inline int SpaceUsedInMapEntry(
const Type*
value);
188 static inline int SpaceUsedInMap(
const Type&
value);
190 static inline void AssignDefaultValue(
Type**
value);
193 static inline const Type& DefaultIfNotInitialized(
199 #define MAP_HANDLER(FieldType) \ 200 template <typename Type> \ 201 class MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type> { \ 203 typedef typename MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \ 204 Type>::MapEntryAccessorType \ 205 MapEntryAccessorType; \ 206 typedef typename MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \ 207 Type>::TypeOnMemory TypeOnMemory; \ 208 static const WireFormatLite::WireType kWireType = \ 209 MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \ 211 static const bool kIsMessage = \ 212 MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \ 214 static const bool kIsEnum = \ 215 MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \ 217 static inline int ByteSize(const MapEntryAccessorType& value); \ 218 static inline int GetCachedSize(const MapEntryAccessorType& value); \ 219 static inline bool Read(io::CodedInputStream* input, \ 220 MapEntryAccessorType* value); \ 221 static inline void Write(int field, const MapEntryAccessorType& value, \ 222 io::CodedOutputStream* output); \ 223 static inline uint8* WriteToArray(int field, \ 224 const MapEntryAccessorType& value, \ 226 static inline const MapEntryAccessorType& GetExternalReference( \ 227 const TypeOnMemory& value); \ 228 static inline void DeleteNoArena(const TypeOnMemory& x); \ 229 static inline void Merge(const MapEntryAccessorType& from, \ 230 TypeOnMemory* to, Arena* arena); \ 231 static inline void Clear(TypeOnMemory* value, Arena* arena); \ 232 static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \ 235 static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \ 236 static inline int SpaceUsedInMap(const TypeOnMemory& value); \ 237 static inline int SpaceUsedInMap(const string& value); \ 238 static inline void AssignDefaultValue(TypeOnMemory* value); \ 239 static inline const MapEntryAccessorType& DefaultIfNotInitialized( \ 240 const TypeOnMemory& value, const TypeOnMemory& default_value); \ 241 static inline bool IsInitialized(const TypeOnMemory& value); \ 242 static void DeleteNoArena(TypeOnMemory& value); \ 243 static inline void Initialize(TypeOnMemory* value, Arena* arena); \ 244 static inline void InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ 245 int default_enum_value, \ 247 static inline MapEntryAccessorType* EnsureMutable(TypeOnMemory* value, \ 268 template <
typename Type>
275 #define GOOGLE_PROTOBUF_BYTE_SIZE(FieldType, DeclaredType) \ 276 template <typename Type> \ 277 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \ 278 const MapEntryAccessorType& value) { \ 279 return WireFormatLite::DeclaredType##Size(value); \ 292 #undef GOOGLE_PROTOBUF_BYTE_SIZE 294 #define FIXED_BYTE_SIZE(FieldType, DeclaredType) \ 295 template <typename Type> \ 296 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \ 297 const MapEntryAccessorType& value) { \ 298 return WireFormatLite::k##DeclaredType##Size; \ 309 #undef FIXED_BYTE_SIZE 311 template <
typename Type>
318 #define GET_CACHED_SIZE(FieldType, DeclaredType) \ 319 template <typename Type> \ 321 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \ 322 const MapEntryAccessorType& value) { \ 323 return WireFormatLite::DeclaredType##Size(value); \ 336 #undef GET_CACHED_SIZE 338 #define GET_FIXED_CACHED_SIZE(FieldType, DeclaredType) \ 339 template <typename Type> \ 341 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \ 342 const MapEntryAccessorType& value) { \ 343 return WireFormatLite::k##DeclaredType##Size; \ 354 #undef GET_FIXED_CACHED_SIZE 356 template <
typename Type>
363 template <
typename Type>
370 #define WRITE_METHOD(FieldType, DeclaredType) \ 371 template <typename Type> \ 372 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Write( \ 373 int field, const MapEntryAccessorType& value, \ 374 io::CodedOutputStream* output) { \ 375 return WireFormatLite::Write##DeclaredType(field, value, output); \ 377 template <typename Type> \ 379 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::WriteToArray( \ 380 int field, const MapEntryAccessorType& value, uint8* output) { \ 381 return WireFormatLite::Write##DeclaredType##ToArray(field, value, output); \ 403 template <
typename Type>
409 template <
typename Type>
415 template <
typename Type>
421 #define READ_METHOD(FieldType) \ 422 template <typename Type> \ 423 inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Read( \ 424 io::CodedInputStream* input, MapEntryAccessorType* value) { \ 425 return WireFormatLite::ReadPrimitive<TypeOnMemory, \ 426 WireFormatLite::TYPE_##FieldType>( \ 449 template <
typename Type>
456 template <
typename Type>
463 template <
typename Type>
469 template <
typename Type>
472 if (*value !=
NULL) (*value)->Clear();
474 template <
typename Type>
479 int default_enum_value) {
482 template <
typename Type>
485 (*to)->MergeFrom(from);
488 template <
typename Type>
494 template <
typename Type>
500 template <
typename Type>
507 template <
typename Type>
514 template <
typename Type>
518 if (*value ==
NULL) {
526 template <
typename Type>
529 return value !=
NULL ? *
value : *default_value;
532 template <
typename Type>
540 #define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType) \ 541 template <typename Type> \ 542 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 543 Type>::MapEntryAccessorType& \ 544 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 545 Type>::GetExternalReference(const TypeOnMemory& value) { \ 546 return value.Get(&::google::protobuf::internal::GetEmptyString()); \ 548 template <typename Type> \ 550 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \ 551 const TypeOnMemory& value) { \ 552 return sizeof(value); \ 554 template <typename Type> \ 555 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 556 Type>::SpaceUsedInMap(const TypeOnMemory& value) { \ 557 return sizeof(value); \ 559 template <typename Type> \ 560 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 561 Type>::SpaceUsedInMap(const string& value) { \ 562 return sizeof(value); \ 564 template <typename Type> \ 565 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \ 566 TypeOnMemory* value, Arena* arena) { \ 567 value->ClearToEmpty(&::google::protobuf::internal::GetEmptyString(), arena); \ 569 template <typename Type> \ 571 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 572 Type>::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ 574 int default_enum) { \ 575 Clear(value, arena); \ 577 template <typename Type> \ 578 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \ 579 const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ 580 to->Set(&::google::protobuf::internal::GetEmptyString(), from, arena); \ 582 template <typename Type> \ 583 void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::DeleteNoArena( \ 584 TypeOnMemory& value) { \ 585 value.DestroyNoArena(&::google::protobuf::internal::GetEmptyString()); \ 587 template <typename Type> \ 588 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 589 Type>::AssignDefaultValue(TypeOnMemory* value) {} \ 590 template <typename Type> \ 592 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \ 593 TypeOnMemory* value, Arena* arena) { \ 594 value->UnsafeSetDefault(&::google::protobuf::internal::GetEmptyString()); \ 596 template <typename Type> \ 598 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 599 Type>::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ 600 int default_enum_value, \ 602 Initialize(value, arena); \ 604 template <typename Type> \ 605 inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 606 Type>::MapEntryAccessorType* \ 607 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \ 608 TypeOnMemory* value, Arena* arena) { \ 609 return value->Mutable(&::google::protobuf::internal::GetEmptyString(), arena); \ 611 template <typename Type> \ 612 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 613 Type>::MapEntryAccessorType& \ 614 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 615 Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \ 616 const TypeOnMemory& \ 618 return value.Get(&::google::protobuf::internal::GetEmptyString()); \ 620 template <typename Type> \ 621 inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 622 Type>::IsInitialized(const TypeOnMemory& value) { \ 627 #undef STRING_OR_BYTES_HANDLER_FUNCTIONS 629 #define PRIMITIVE_HANDLER_FUNCTIONS(FieldType) \ 630 template <typename Type> \ 631 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 632 Type>::MapEntryAccessorType& \ 633 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 634 Type>::GetExternalReference(const TypeOnMemory& value) { \ 637 template <typename Type> \ 639 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \ 640 const TypeOnMemory& value) { \ 643 template <typename Type> \ 644 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 645 Type>::SpaceUsedInMap(const TypeOnMemory& value) { \ 646 return sizeof(Type); \ 648 template <typename Type> \ 649 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \ 650 TypeOnMemory* value, Arena* arena) { \ 653 template <typename Type> \ 655 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 656 Type>::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ 658 int default_enum_value) { \ 659 *value = static_cast<TypeOnMemory>(default_enum_value); \ 661 template <typename Type> \ 662 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \ 663 const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ 666 template <typename Type> \ 667 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 668 Type>::DeleteNoArena(TypeOnMemory& x) {} \ 669 template <typename Type> \ 670 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 671 Type>::AssignDefaultValue(TypeOnMemory* value) {} \ 672 template <typename Type> \ 674 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \ 675 TypeOnMemory* value, Arena* arena) { \ 678 template <typename Type> \ 680 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 681 Type>::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ 682 int default_enum_value, \ 684 *value = static_cast<TypeOnMemory>(default_enum_value); \ 686 template <typename Type> \ 687 inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 688 Type>::MapEntryAccessorType* \ 689 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \ 690 TypeOnMemory* value, Arena* arena) { \ 693 template <typename Type> \ 694 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 695 Type>::MapEntryAccessorType& \ 696 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 697 Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \ 698 const TypeOnMemory& \ 702 template <typename Type> \ 703 inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ 704 Type>::IsInitialized(const TypeOnMemory& value) { \ 721 #undef PRIMITIVE_HANDLER_FUNCTIONS 727 #endif // GOOGLE_PROTOBUF_TYPE_HANDLER_H__
Definition: map_type_handler.h:103
DOMString STRING
Definition: TestTypedefs.idl:79
const FieldDescriptor * field
Definition: parser_unittest.cc:2279
#define TYPE_TRAITS(FieldType, CType, WireFormatType, IsMessage, IsEnum)
Definition: map_type_handler.h:105
#define FIXED_BYTE_SIZE(FieldType, DeclaredType)
Definition: map_type_handler.h:294
uint8_t uint8
Definition: port.h:133
static void Initialize(Type &value, int default_enum_value)
Definition: map_type_handler.h:76
static const Type & default_instance()
Definition: type.pb.cc:346
#define PRIMITIVE_HANDLER_FUNCTIONS(FieldType)
Definition: map_type_handler.h:629
uint64_t uint64
Definition: angle_config.h:30
TrueType type
Definition: map_type_handler.h:49
int Write(int fd, const void *buf, unsigned int count)
Definition: gtest-port.h:1393
int64_t int64
Definition: angle_config.h:29
Clear
Definition: python_message.py:1326
#define READ_METHOD(FieldType)
Definition: map_type_handler.h:421
Definition: map_type_handler.h:80
const FieldDescriptor const OneofDescriptor value
Definition: descriptor.h:1717
#define GET_FIXED_CACHED_SIZE(FieldType, DeclaredType)
Definition: map_type_handler.h:338
Definition: map_type_handler.h:45
#define MAP_HANDLER(FieldType)
Definition: map_type_handler.h:199
def Merge(text, message, allow_unknown_extension=False, allow_field_number=False)
Definition: text_format.py:349
IsInitialized
Definition: python_message.py:1169
EGLSurface EGLint x
Definition: eglext.h:950
void Clear()
Definition: type.pb.cc:361
EGLAttrib * value
Definition: eglext.h:120
Definition: gtest_pred_impl_unittest.cc:56
int Read(int fd, void *buf, unsigned int count)
Definition: gtest-port.h:1390
virtual int SpaceUsed() const
Definition: message.cc:163
Definition: map_type_handler.h:60
unrestricted float DOUBLE
Definition: TestTypedefs.idl:71
Definition: __init__.py:1
Definition: map_type_handler.h:138
FalseType type
Definition: map_type_handler.h:54
#define true
Definition: float-mm.c:6
Definition: type.pb.h:133
EGLenum type
Definition: eglext.h:63
static void Initialize(Type &value, int default_enum_value)
Definition: map_type_handler.h:68
Definition: document.h:393
string MESSAGE
Definition: check_root_dir.py:17
bool IsInitialized() const
Definition: type.pb.cc:706
#define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType)
Definition: map_type_handler.h:540
#define false
Definition: float-mm.c:5
#define NULL
Definition: common_types.h:41
#define GET_CACHED_SIZE(FieldType, DeclaredType)
Definition: map_type_handler.h:318
#define WRITE_METHOD(FieldType, DeclaredType)
Definition: map_type_handler.h:370
uint32_t uint32
Definition: angle_config.h:28
static Type * CreateMessage(Arena *arena)
Definition: map_type_handler.h:96
Definition: gflags_completions.h:115
ANGLE_EXPORT EGLBoolean EGLAPIENTRY Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
Definition: entry_points_egl.cpp:48
#define GOOGLE_PROTOBUF_BYTE_SIZE(FieldType, DeclaredType)
Definition: map_type_handler.h:275
string input
Definition: tokenizer_unittest.cc:198
ByteSize
Definition: python_message.py:1040
Definition: coded_stream.h:665
Type
Type of JSON value.
Definition: rapidjson.h:616
int32_t int32
Definition: angle_config.h:27
static Type * CreateMessage(Arena *arena)
Definition: map_type_handler.h:89