19 #ifndef OPAL_VALUE_ARRAY_H
20 #define OPAL_VALUE_ARRAY_H
22 #include "opal_config.h"
30 #include "opal/constants.h"
41 unsigned char* array_items;
42 size_t array_item_sizeof;
44 size_t array_alloc_size;
65 array->array_item_sizeof = item_sizeof;
66 array->array_alloc_size = 1;
67 array->array_size = 0;
68 array->array_items = (
unsigned char*)realloc(array->array_items, item_sizeof * array->array_alloc_size);
69 return (NULL != array->array_items) ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE;
83 if(size > array->array_alloc_size) {
84 array->array_items = (
unsigned char*)realloc(array->array_items, array->array_item_sizeof * size);
85 if(NULL == array->array_items) {
86 array->array_size = 0;
87 array->array_alloc_size = 0;
88 return OPAL_ERR_OUT_OF_RESOURCE;
90 array->array_alloc_size = size;
106 return array->array_size;
142 #define OPAL_VALUE_ARRAY_GET_ITEM(array, item_type, item_index) \
143 ((item_type*)((array)->array_items))[item_index]
157 static inline void* opal_value_array_get_item(
opal_value_array_t *array,
size_t item_index)
159 if(item_index >= array->array_size && opal_value_array_set_size(array, item_index+1) != OPAL_SUCCESS)
161 return array->array_items + (item_index * array->array_item_sizeof);
180 #define OPAL_VALUE_ARRAY_SET_ITEM(array, item_type, item_index, item_value) \
181 (((item_type*)((array)->array_items))[item_index] = item_value)
197 static inline int opal_value_array_set_item(
opal_value_array_t *array,
size_t item_index,
const void* item)
200 if(item_index >= array->array_size &&
201 (rc = opal_value_array_set_size(array, item_index+1)) != OPAL_SUCCESS)
203 memcpy(array->array_items + (item_index * array->array_item_sizeof), item, array->array_item_sizeof);
222 static inline int opal_value_array_append_item(
opal_value_array_t *array,
const void *item)
224 return opal_value_array_set_item(array, array->array_size, item);
240 static inline int opal_value_array_remove_item(
opal_value_array_t *array,
size_t item_index)
242 #if OPAL_ENABLE_DEBUG
243 if (item_index >= array->array_size) {
244 opal_output(0,
"opal_value_array_remove_item: invalid index %lu\n", (
unsigned long)item_index);
245 return OPAL_ERR_BAD_PARAM;
248 memmove(array->array_items+(array->array_item_sizeof * item_index),
249 array->array_items+(array->array_item_sizeof * (item_index+1)),
250 array->array_item_sizeof * (array->array_size - item_index - 1));
271 #define OPAL_VALUE_ARRAY_GET_BASE(array, item_type) \
272 ((item_type*) ((array)->array_items))
OPAL output stream facility.
OPAL_DECLSPEC void opal_output(int output_id, const char *format,...) __opal_attribute_format__(__printf__
Main function to send output to a stream.
Base object.
Definition: opal_object.h:182
Definition: opal_value_array.h:38
A simple C-language object-oriented system with single inheritance and ownership-based memory managem...
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236