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