Added the handling of errors with the functions to get a value in a
column
This commit is contained in:
@ -603,7 +603,18 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
|
||||
new_column = NULL;
|
||||
|
||||
// TODO check that informations are not NULL/invalid?
|
||||
// Check that the informations given are not NULL/invalid/greater than the allowed sizes
|
||||
if (dms == NULL)
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of invalid DMS");
|
||||
return NULL;
|
||||
}
|
||||
if (column_name == NULL)
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of empty column name");
|
||||
return NULL;
|
||||
}
|
||||
//if (type < 1)
|
||||
|
||||
// Get the column directory structure associated to the column
|
||||
column_directory = obi_column_directory(dms, column_name);
|
||||
@ -731,7 +742,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
|
||||
|
||||
// Fill the data with NA values
|
||||
obi_ini_to_NA_values (new_column, 0, nb_lines);
|
||||
obi_ini_to_NA_values(new_column, 0, nb_lines);
|
||||
|
||||
free(column_file_name);
|
||||
close(column_file_descriptor);
|
||||
@ -1146,7 +1157,7 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
column_file_descriptor,
|
||||
(column->header)->header_size
|
||||
header_size
|
||||
);
|
||||
|
||||
if (column->data == MAP_FAILED)
|
||||
|
@ -59,10 +59,11 @@ int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->line_count)
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||
return -1; // TODO return NA value?
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIBool_NA;
|
||||
}
|
||||
return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
@ -108,14 +109,14 @@ obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t li
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
return OBIBool_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
return OBIBool_NA;
|
||||
}
|
||||
|
||||
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
|
||||
|
@ -59,10 +59,11 @@ int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->line_count)
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||
return '\0'; // TODO return NA value?
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIChar_NA;
|
||||
}
|
||||
return *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
@ -108,14 +109,14 @@ obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t li
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return '\0'; // TODO
|
||||
return OBIChar_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return '\0'; // TODO
|
||||
return OBIChar_NA;
|
||||
}
|
||||
|
||||
return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx);
|
||||
|
@ -59,10 +59,11 @@ int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
||||
|
||||
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)
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||
return -1; // TODO return NA value?
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIFloat_NA;
|
||||
}
|
||||
return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
@ -108,14 +109,14 @@ obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
return OBIFloat_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
return OBIFloat_NA;
|
||||
}
|
||||
|
||||
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
|
||||
|
@ -59,10 +59,11 @@ int obi_column_set_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, s
|
||||
|
||||
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)
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||
return -1; // TODO return NA value?
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
return *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
@ -108,14 +109,14 @@ obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
|
||||
return obi_column_get_obiidx_with_elt_idx(column, line_nb, element_idx);
|
||||
|
@ -59,10 +59,11 @@ int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, s
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->line_count)
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||
return -1; // TODO return NA value?
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIInt_NA;
|
||||
}
|
||||
return *(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
@ -108,14 +109,14 @@ obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, size_t line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
return OBIInt_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
return OBIInt_NA;
|
||||
}
|
||||
|
||||
return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx);
|
||||
|
Reference in New Issue
Block a user