Columns are now enlarged if needed when setting a value

This commit is contained in:
Celine Mercier
2015-09-01 17:38:08 +02:00
parent 3b7536c0df
commit f31d8983bb
22 changed files with 406 additions and 111 deletions

View File

@ -28,23 +28,47 @@
*
**********************************************************************/
int obi_column_set_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value)
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value)
{
// Check that the line number is not greater than the maximum allowed
if (line_nb >= MAXIMUM_LINE_COUNT)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
return -1;
}
// Check if the file needs to be enlarged
while ((line_nb+1) > (column->header)->line_count)
{
// Enlarge the file
if (obi_enlarge_column(column) < 0)
return -1;
}
// Update lines used
if ((line_nb+1) > (column->header)->lines_used)
(column->header)->lines_used = line_nb+1;
// Set the value
*(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
return 0;
}
obifloat_t obi_column_get_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
{
if ((line_nb+1) > (column->header)->line_count)
{
obidebug(1, "\nError trying to get a value that is beyond the current line count");
return -1; // TODO return NA value?
}
return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
}
int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value)
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value)
{
size_t element_idx;
@ -66,13 +90,13 @@ int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, c
return -1;
}
obi_column_set_float_with_elt_idx(column, line_nb, element_idx, value);
obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
return 0;
}
obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
{
size_t element_idx;
@ -94,5 +118,6 @@ obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t lin
return -1;
}
return obi_column_get_float_with_elt_idx(column, line_nb, element_idx);
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
}