Columns are now enlarged if needed when setting a value
This commit is contained in:
@ -28,23 +28,47 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value)
|
||||
int obi_column_set_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_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
|
||||
*(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obiidx_t obi_column_get_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
obiidx_t obi_column_get_obiidx_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 *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value)
|
||||
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
@ -66,13 +90,13 @@ int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, cha
|
||||
return -1;
|
||||
}
|
||||
|
||||
obi_column_set_idx_with_elt_idx(column, line_nb, element_idx, value);
|
||||
obi_column_set_obiidx_with_elt_idx(column, line_nb, element_idx, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
@ -94,5 +118,6 @@ obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb
|
||||
return -1;
|
||||
}
|
||||
|
||||
return obi_column_get_idx_with_elt_idx(column, line_nb, element_idx);
|
||||
return obi_column_get_obiidx_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user