Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 09:29:20

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef UPB_MESSAGE_ARRAY_H_
0009 #define UPB_MESSAGE_ARRAY_H_
0010 
0011 #include <stddef.h>
0012 
0013 #include "upb/base/descriptor_constants.h"
0014 #include "upb/mem/arena.h"
0015 #include "upb/message/internal/array.h"
0016 #include "upb/message/internal/types.h"
0017 #include "upb/message/value.h"
0018 #include "upb/mini_table/message.h"
0019 
0020 // Must be last.
0021 #include "upb/port/def.inc"
0022 
0023 typedef struct upb_Array upb_Array;
0024 
0025 #ifdef __cplusplus
0026 extern "C" {
0027 #endif
0028 
0029 // Creates a new array on the given arena that holds elements of this type.
0030 UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type);
0031 
0032 // Returns the number of elements in the array.
0033 UPB_API_INLINE size_t upb_Array_Size(const upb_Array* arr);
0034 
0035 // Returns the number of elements in the array.
0036 UPB_API_INLINE size_t upb_Array_Capacity(const upb_Array* arr);
0037 
0038 // Returns the given element, which must be within the array's current size.
0039 UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i);
0040 
0041 // Returns a non-null mutating pointer to the given element. `arr` must be an
0042 // array of a message type, and `i` must be within the array's current size.
0043 UPB_API struct upb_Message* upb_Array_GetMutable(upb_Array* arr, size_t i);
0044 
0045 // Sets the given element, which must be within the array's current size.
0046 UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val);
0047 
0048 // Appends an element to the array. Returns false on allocation failure.
0049 UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val,
0050                               upb_Arena* arena);
0051 
0052 // Moves elements within the array using memmove().
0053 // Like memmove(), the source and destination elements may be overlapping.
0054 UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx,
0055                             size_t count);
0056 
0057 // Inserts one or more empty elements into the array.
0058 // Existing elements are shifted right.
0059 // The new elements have undefined state and must be set with `upb_Array_Set()`.
0060 // REQUIRES: `i <= upb_Array_Size(arr)`
0061 UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count,
0062                               upb_Arena* arena);
0063 
0064 // Deletes one or more elements from the array.
0065 // Existing elements are shifted left.
0066 // REQUIRES: `i + count <= upb_Array_Size(arr)`
0067 UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count);
0068 
0069 // Reserves |size| elements of storage for the array.
0070 UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
0071                                       upb_Arena* arena);
0072 
0073 // Changes the size of a vector. New elements are initialized to NULL/0.
0074 // Returns false on allocation failure.
0075 UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena);
0076 
0077 // Returns pointer to array data.
0078 UPB_API_INLINE const void* upb_Array_DataPtr(const upb_Array* arr);
0079 
0080 // Returns mutable pointer to array data.
0081 UPB_API_INLINE void* upb_Array_MutableDataPtr(upb_Array* arr);
0082 
0083 // Mark an array and all of its descendents as frozen/immutable.
0084 // If the array elements are messages then |m| must point to the minitable for
0085 // those messages. Otherwise |m| must be NULL.
0086 UPB_API void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m);
0087 
0088 // Returns whether an array has been frozen.
0089 UPB_API_INLINE bool upb_Array_IsFrozen(const upb_Array* arr);
0090 
0091 #ifdef __cplusplus
0092 } /* extern "C" */
0093 #endif
0094 
0095 #include "upb/port/undef.inc"
0096 
0097 #endif /* UPB_MESSAGE_ARRAY_H_ */