2004-02-10 16:53:41 +00:00
|
|
|
/*
|
2005-11-05 19:57:48 +00:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 20:09:25 +00:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 12:43:37 +00:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 01:38:40 +00:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-02-10 16:53:41 +00:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2006-02-12 01:33:29 +00:00
|
|
|
#include "opal_config.h"
|
2004-08-18 23:24:27 +00:00
|
|
|
|
2005-07-03 16:38:52 +00:00
|
|
|
#include "opal/class/opal_value_array.h"
|
2004-02-10 16:53:41 +00:00
|
|
|
|
|
|
|
|
2005-07-03 16:38:52 +00:00
|
|
|
static void opal_value_array_construct(opal_value_array_t* array)
|
2004-02-10 16:53:41 +00:00
|
|
|
{
|
|
|
|
array->array_items = NULL;
|
|
|
|
array->array_size = 0;
|
|
|
|
array->array_item_sizeof = 0;
|
|
|
|
array->array_alloc_size = 0;
|
|
|
|
}
|
|
|
|
|
2005-07-03 16:38:52 +00:00
|
|
|
static void opal_value_array_destruct(opal_value_array_t* array)
|
2004-02-10 16:53:41 +00:00
|
|
|
{
|
|
|
|
if (NULL != array->array_items)
|
|
|
|
free(array->array_items);
|
|
|
|
}
|
|
|
|
|
2005-07-03 16:38:52 +00:00
|
|
|
opal_class_t opal_value_array_t_class = {
|
|
|
|
"opal_value_array_t",
|
2005-07-03 16:06:07 +00:00
|
|
|
OBJ_CLASS(opal_object_t),
|
2005-07-03 16:38:52 +00:00
|
|
|
(opal_construct_t)opal_value_array_construct,
|
|
|
|
(opal_destruct_t)opal_value_array_destruct
|
2004-02-10 16:53:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-07-03 16:38:52 +00:00
|
|
|
int opal_value_array_set_size(opal_value_array_t* array, size_t size)
|
2004-02-10 16:53:41 +00:00
|
|
|
{
|
2004-06-07 15:33:53 +00:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
2004-02-10 16:53:41 +00:00
|
|
|
if(array->array_item_sizeof == 0) {
|
2005-07-03 23:31:27 +00:00
|
|
|
opal_output(0, "opal_value_array_set_size: item size must be initialized");
|
2006-02-12 01:33:29 +00:00
|
|
|
return OPAL_ERR_BAD_PARAM;
|
2004-02-10 16:53:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-10 21:54:27 +00:00
|
|
|
if(size > array->array_alloc_size) {
|
|
|
|
while(array->array_alloc_size < size)
|
2004-02-10 16:53:41 +00:00
|
|
|
array->array_alloc_size <<= 1;
|
2004-10-18 16:55:20 +00:00
|
|
|
array->array_items = (unsigned char *)realloc(array->array_items,
|
2004-02-10 16:53:41 +00:00
|
|
|
array->array_alloc_size * array->array_item_sizeof);
|
|
|
|
if (NULL == array->array_items)
|
2006-02-12 01:33:29 +00:00
|
|
|
return OPAL_ERR_OUT_OF_RESOURCE;
|
2004-02-10 16:53:41 +00:00
|
|
|
}
|
|
|
|
array->array_size = size;
|
2006-02-12 01:33:29 +00:00
|
|
|
return OPAL_SUCCESS;
|
2004-02-10 16:53:41 +00:00
|
|
|
}
|
|
|
|
|