39
39
extern "C" {
40
40
#endif
41
41
42
- /* Creates a new map on the given arena with the given key/value size. */
43
- upb_Map * upb_Map_New (upb_Arena * a , upb_CType key_type , upb_CType value_type );
42
+ // Creates a new map on the given arena with the given key/value size.
43
+ UPB_API upb_Map * upb_Map_New (upb_Arena * a , upb_CType key_type ,
44
+ upb_CType value_type );
44
45
45
- /* Returns the number of entries in the map. */
46
- size_t upb_Map_Size (const upb_Map * map );
46
+ // Returns the number of entries in the map.
47
+ UPB_API size_t upb_Map_Size (const upb_Map * map );
47
48
48
- /* Stores a value for the given key into |*val| (or the zero value if the key is
49
- * not present). Returns whether the key was present. The |val| pointer may be
50
- * NULL, in which case the function tests whether the given key is present. */
51
- bool upb_Map_Get (const upb_Map * map , upb_MessageValue key ,
52
- upb_MessageValue * val );
49
+ // Stores a value for the given key into |*val| (or the zero value if the key is
50
+ // not present). Returns whether the key was present. The |val| pointer may be
51
+ // NULL, in which case the function tests whether the given key is present.
52
+ UPB_API bool upb_Map_Get (const upb_Map * map , upb_MessageValue key ,
53
+ upb_MessageValue * val );
53
54
54
- /* Removes all entries in the map. */
55
- void upb_Map_Clear (upb_Map * map );
55
+ // Removes all entries in the map.
56
+ UPB_API void upb_Map_Clear (upb_Map * map );
56
57
57
58
typedef enum {
58
59
kUpb_MapInsertStatus_Inserted = 0 ,
59
60
kUpb_MapInsertStatus_Replaced = 1 ,
60
61
kUpb_MapInsertStatus_OutOfMemory = 2 ,
61
62
} upb_MapInsertStatus ;
62
63
63
- /* Sets the given key to the given value, returning whether the key was inserted
64
- * or replaced. If the key was inserted, then any existing iterators will be
65
- * invalidated. */
66
- upb_MapInsertStatus upb_Map_Insert (upb_Map * map , upb_MessageValue key ,
67
- upb_MessageValue val , upb_Arena * arena );
68
-
69
- /* Sets the given key to the given value. Returns false if memory allocation
70
- * failed. If the key is newly inserted, then any existing iterators will be
71
- * invalidated. */
72
- UPB_INLINE bool upb_Map_Set (upb_Map * map , upb_MessageValue key ,
73
- upb_MessageValue val , upb_Arena * arena ) {
64
+ // Sets the given key to the given value, returning whether the key was inserted
65
+ // or replaced. If the key was inserted, then any existing iterators will be
66
+ // invalidated.
67
+ UPB_API upb_MapInsertStatus upb_Map_Insert (upb_Map * map , upb_MessageValue key ,
68
+ upb_MessageValue val ,
69
+ upb_Arena * arena );
70
+
71
+ // Sets the given key to the given value. Returns false if memory allocation
72
+ // failed. If the key is newly inserted, then any existing iterators will be
73
+ // invalidated.
74
+ UPB_API_INLINE bool upb_Map_Set (upb_Map * map , upb_MessageValue key ,
75
+ upb_MessageValue val , upb_Arena * arena ) {
74
76
return upb_Map_Insert (map , key , val , arena ) !=
75
77
kUpb_MapInsertStatus_OutOfMemory ;
76
78
}
77
79
78
80
// Deletes this key from the table. Returns true if the key was present.
79
81
// If present and |val| is non-NULL, stores the deleted value.
80
- bool upb_Map_Delete2 (upb_Map * map , upb_MessageValue key , upb_MessageValue * val );
82
+ UPB_API bool upb_Map_Delete (upb_Map * map , upb_MessageValue key ,
83
+ upb_MessageValue * val );
81
84
82
- // Deletes this key from the table. Returns true if the key was present.
83
85
// (DEPRECATED and going away soon. Do not use.)
84
- UPB_INLINE bool upb_Map_Delete (upb_Map * map , upb_MessageValue key ) {
85
- return upb_Map_Delete2 (map , key , NULL );
86
+ UPB_INLINE bool upb_Map_Delete2 (upb_Map * map , upb_MessageValue key ,
87
+ upb_MessageValue * val ) {
88
+ return upb_Map_Delete (map , key , val );
86
89
}
87
90
88
91
// Map iteration:
@@ -97,8 +100,8 @@ UPB_INLINE bool upb_Map_Delete(upb_Map* map, upb_MessageValue key) {
97
100
98
101
// Advances to the next entry. Returns false if no more entries are present.
99
102
// Otherwise returns true and populates both *key and *value.
100
- bool upb_Map_Next (const upb_Map * map , upb_MessageValue * key ,
101
- upb_MessageValue * val , size_t * iter );
103
+ UPB_API bool upb_Map_Next (const upb_Map * map , upb_MessageValue * key ,
104
+ upb_MessageValue * val , size_t * iter );
102
105
103
106
// DEPRECATED iterator, slated for removal.
104
107
@@ -114,12 +117,12 @@ bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key,
114
117
// Advances to the next entry. Returns false if no more entries are present.
115
118
bool upb_MapIterator_Next (const upb_Map * map , size_t * iter );
116
119
117
- /* Returns true if the iterator still points to a valid entry, or false if the
118
- * iterator is past the last element. It is an error to call this function with
119
- * kUpb_Map_Begin (you must call next() at least once first). */
120
+ // Returns true if the iterator still points to a valid entry, or false if the
121
+ // iterator is past the last element. It is an error to call this function with
122
+ // kUpb_Map_Begin (you must call next() at least once first).
120
123
bool upb_MapIterator_Done (const upb_Map * map , size_t iter );
121
124
122
- /* Returns the key and value for this entry of the map. */
125
+ // Returns the key and value for this entry of the map.
123
126
upb_MessageValue upb_MapIterator_Key (const upb_Map * map , size_t iter );
124
127
upb_MessageValue upb_MapIterator_Value (const upb_Map * map , size_t iter );
125
128
0 commit comments