WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
map.h
Go to the documentation of this file.
1// Protocol Buffers - Google's data interchange format
2// Copyright 2023 Google LLC. All rights reserved.
3//
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file or at
6// https://developers.google.com/open-source/licenses/bsd
7
8#ifndef UPB_MESSAGE_MAP_H_
9#define UPB_MESSAGE_MAP_H_
10
11#include <stddef.h>
12
14#include "upb/mem/arena.h"
17#include "upb/message/value.h"
20
21// Must be last.
22#include "upb/port/def.inc"
23
24typedef struct upb_Map upb_Map;
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30// Creates a new map on the given arena with the given key/value size.
32 upb_CType value_type);
33
34// Returns the number of entries in the map.
36
37// Stores a value for the given key into |*val| (or the zero value if the key is
38// not present). Returns whether the key was present. The |val| pointer may be
39// NULL, in which case the function tests whether the given key is present.
41 upb_MessageValue* val);
42
43// Returns a mutable pointer to the value for the given key. Returns NULL if the
44// key is not present.
45// This function is only legal to call for maps that contain messages.
48
49// Removes all entries in the map.
51
52// Sets the given key to the given value, returning whether the key was inserted
53// or replaced. If the key was inserted, then any existing iterators will be
54// invalidated.
57 upb_Arena* arena);
58
59// Sets the given key to the given value. Returns false if memory allocation
60// failed. If the key is newly inserted, then any existing iterators will be
61// invalidated.
67
68// Deletes this key from the table. Returns true if the key was present.
69// If present and |val| is non-NULL, stores the deleted value.
71 upb_MessageValue* val);
72
73// Map iteration:
74//
75// size_t iter = kUpb_Map_Begin;
76// upb_MessageValue key, val;
77// while (upb_Map_Next(map, &key, &val, &iter)) {
78// ...
79// }
80
81#define kUpb_Map_Begin ((size_t)-1)
82
83// Advances to the next entry. Returns false if no more entries are present.
84// Otherwise returns true and populates both *key and *value.
86 upb_MessageValue* val, size_t* iter);
87
88// Sets the value for the entry pointed to by iter.
89// WARNING: this does not currently work for string values!
92
93// DEPRECATED iterator, slated for removal.
94
95/* Map iteration:
96 *
97 * size_t iter = kUpb_Map_Begin;
98 * while (upb_MapIterator_Next(map, &iter)) {
99 * upb_MessageValue key = upb_MapIterator_Key(map, iter);
100 * upb_MessageValue val = upb_MapIterator_Value(map, iter);
101 * }
102 */
103
104// Advances to the next entry. Returns false if no more entries are present.
105UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter);
106
107// Returns true if the iterator still points to a valid entry, or false if the
108// iterator is past the last element. It is an error to call this function with
109// kUpb_Map_Begin (you must call next() at least once first).
110UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter);
111
112// Returns the key and value for this entry of the map.
115
116// Mark a map and all of its descendents as frozen/immutable.
117// If the map values are messages then |m| must point to the minitable for
118// those messages. Otherwise |m| must be NULL.
120
121// Returns whether a map has been frozen.
123
124#ifdef __cplusplus
125} /* extern "C" */
126#endif
127
128#include "upb/port/undef.inc"
129
130#endif /* UPB_MESSAGE_MAP_H_ */
#define UPB_API_INLINE
Definition def.inc:163
#define UPB_API
Definition def.inc:162
upb_CType
Definition descriptor_constants.h:18
UPB_API_INLINE bool upb_Map_IsFrozen(const struct upb_Map *map)
Definition map.h:57
upb_MapInsertStatus
Definition map.h:25
@ kUpb_MapInsertStatus_OutOfMemory
Definition map.h:28
UPB_API struct upb_Message * upb_Map_GetMutable(upb_Map *map, upb_MessageValue key)
UPB_API bool upb_MapIterator_Done(const upb_Map *map, size_t iter)
UPB_API bool upb_Map_Delete(upb_Map *map, upb_MessageValue key, upb_MessageValue *val)
UPB_API_INLINE bool upb_Map_Set(upb_Map *map, upb_MessageValue key, upb_MessageValue val, upb_Arena *arena)
Definition map.h:62
UPB_API void upb_Map_Freeze(upb_Map *map, const upb_MiniTable *m)
UPB_API void upb_Map_SetEntryValue(upb_Map *map, size_t iter, upb_MessageValue val)
UPB_API bool upb_MapIterator_Next(const upb_Map *map, size_t *iter)
UPB_API bool upb_Map_Get(const upb_Map *map, upb_MessageValue key, upb_MessageValue *val)
UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map *map, size_t iter)
UPB_API void upb_Map_Clear(upb_Map *map)
UPB_API size_t upb_Map_Size(const upb_Map *map)
UPB_API bool upb_Map_Next(const upb_Map *map, upb_MessageValue *key, upb_MessageValue *val, size_t *iter)
UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map *map, upb_MessageValue key, upb_MessageValue val, upb_Arena *arena)
UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map *map, size_t iter)
UPB_API upb_Map * upb_Map_New(upb_Arena *a, upb_CType key_type, upb_CType value_type)
Definition arena.h:29
Definition map.h:38
Definition types.h:18
Definition message.h:54
Definition value.h:27