S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_array.h
Go to the documentation of this file.
1/*
2 * Licensed to Systerel under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work
4 * for additional information regarding copyright ownership.
5 * Systerel licenses this file to you under the Apache
6 * License, Version 2.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain
8 * a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
25#ifndef SOPC_ARRAY_H_
26#define SOPC_ARRAY_H_
27
28#include <stdbool.h>
29#include <stddef.h>
30
31typedef struct _SOPC_Array SOPC_Array;
32
40typedef void SOPC_Array_Free_Func(void* data);
41
52typedef int SOPC_Array_Compare_Func(const void* a, const void* b);
53
66SOPC_Array* SOPC_Array_Create(size_t element_size, size_t initial_capacity, SOPC_Array_Free_Func* free_func);
67
77
87
96#define SOPC_Array_Append(array, val) SOPC_Array_Append_Values((array), &(val), 1)
97
108bool SOPC_Array_Append_Values(SOPC_Array* array, const void* data, size_t n_elements);
109
119#define SOPC_Array_Get(array, ty, index) (*((ty*) SOPC_Array_Get_Ptr((array), (index))))
120
129void* SOPC_Array_Get_Ptr(const SOPC_Array* array, size_t index);
130
138size_t SOPC_Array_Size(const SOPC_Array* array);
139
149
163
173
183
184#endif /* SOPC_ARRAY_H_ */
bool SOPC_Array_Append_Values(SOPC_Array *array, const void *data, size_t n_elements)
Appends several values contiguous in memory to an array.
void SOPC_Array_Delete(SOPC_Array *array)
Deletes an array.
SOPC_Array_Free_Func * SOPC_Array_Get_Free_Func(SOPC_Array *array)
Returns the function used to clear the elements of an array on deletion.
struct _SOPC_Array SOPC_Array
Definition sopc_array.h:31
int SOPC_Array_Compare_Func(const void *a, const void *b)
Type of functions used to compare items when sorting an array.
Definition sopc_array.h:52
void SOPC_Array_Sort(SOPC_Array *array, SOPC_Array_Compare_Func *compare_func)
Sorts the elements in an array.
void * SOPC_Array_Get_Ptr(const SOPC_Array *array, size_t index)
Gets a pointer to a value in an array by its index.
SOPC_Array * SOPC_Array_Copy(const SOPC_Array *array)
Makes a copy of an array.
size_t SOPC_Array_Size(const SOPC_Array *array)
Gets the number of elements in an array.
void SOPC_Array_Free_Func(void *data)
Type of functions used to free array values.
Definition sopc_array.h:40
void * SOPC_Array_Into_Raw(SOPC_Array *array)
Converts a SOPC_Array into a raw C array.
SOPC_Array * SOPC_Array_Create(size_t element_size, size_t initial_capacity, SOPC_Array_Free_Func *free_func)
Creates a new array with a given capacity.
void SOPC_Array_Set_Free_Func(SOPC_Array *array, SOPC_Array_Free_Func *func)
Sets the function used to clear the array elements when it is deleted.