WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
array.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_ARRAY_H_
9#define UPB_MESSAGE_ARRAY_H_
10
11#include <stddef.h>
12
14#include "upb/mem/arena.h"
17#include "upb/message/value.h"
19
20// Must be last.
21#include "upb/port/def.inc"
22
23typedef struct upb_Array upb_Array;
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29// Creates a new array on the given arena that holds elements of this type.
31
32// Returns the number of elements in the array.
34
35// Returns the number of elements in the array.
37
38// Returns the given element, which must be within the array's current size.
40
41// Returns a non-null mutating pointer to the given element. `arr` must be an
42// array of a message type, and `i` must be within the array's current size.
44
45// Sets the given element, which must be within the array's current size.
47
48// Appends an element to the array. Returns false on allocation failure.
50 upb_Arena* arena);
51
52// Moves elements within the array using memmove().
53// Like memmove(), the source and destination elements may be overlapping.
54UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx,
55 size_t count);
56
57// Inserts one or more empty elements into the array.
58// Existing elements are shifted right.
59// The new elements have undefined state and must be set with `upb_Array_Set()`.
60// REQUIRES: `i <= upb_Array_Size(arr)`
61UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count,
62 upb_Arena* arena);
63
64// Deletes one or more elements from the array.
65// Existing elements are shifted left.
66// REQUIRES: `i + count <= upb_Array_Size(arr)`
67UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count);
68
69// Reserves |size| elements of storage for the array.
70UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
71 upb_Arena* arena);
72
73// Changes the size of a vector. New elements are initialized to NULL/0.
74// Returns false on allocation failure.
75UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena);
76
77// Returns pointer to array data.
79
80// Returns mutable pointer to array data.
82
83// Mark an array and all of its descendents as frozen/immutable.
84// If the array elements are messages then |m| must point to the minitable for
85// those messages. Otherwise |m| must be NULL.
87
88// Returns whether an array has been frozen.
90
91#ifdef __cplusplus
92} /* extern "C" */
93#endif
94
95#include "upb/port/undef.inc"
96
97#endif /* UPB_MESSAGE_ARRAY_H_ */
#define UPB_API_INLINE
Definition def.inc:163
#define UPB_API
Definition def.inc:162
upb_CType
Definition descriptor_constants.h:18
Definition arena.h:29
Definition array.h:30
Definition types.h:18
Definition message.h:54
UPB_API_INLINE size_t upb_Array_Capacity(const upb_Array *arr)
UPB_API upb_Array * upb_Array_New(upb_Arena *a, upb_CType type)
UPB_API void upb_Array_Delete(upb_Array *array, size_t i, size_t count)
UPB_API struct upb_Message * upb_Array_GetMutable(upb_Array *arr, size_t i)
UPB_API_INLINE bool upb_Array_IsFrozen(const upb_Array *arr)
UPB_API void upb_Array_Freeze(upb_Array *arr, const upb_MiniTable *m)
UPB_API bool upb_Array_Resize(upb_Array *array, size_t size, upb_Arena *arena)
UPB_API_INLINE const void * upb_Array_DataPtr(const upb_Array *arr)
UPB_API_INLINE void * upb_Array_MutableDataPtr(upb_Array *arr)
Definition array.h:72
UPB_API void upb_Array_Move(upb_Array *array, size_t dst_idx, size_t src_idx, size_t count)
UPB_API void upb_Array_Set(upb_Array *arr, size_t i, upb_MessageValue val)
UPB_API bool upb_Array_Insert(upb_Array *array, size_t i, size_t count, upb_Arena *arena)
UPB_API bool upb_Array_Append(upb_Array *array, upb_MessageValue val, upb_Arena *arena)
UPB_API upb_MessageValue upb_Array_Get(const upb_Array *arr, size_t i)
UPB_API_INLINE size_t upb_Array_Size(const upb_Array *arr)
UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array *array, size_t size, upb_Arena *arena)
Definition array.h:124
Definition value.h:27