Added functions to get and set values in columns using the element name
(for columns with lines made of vectors of elements), for all data types
This commit is contained in:
@ -19,13 +19,16 @@
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value)
|
||||
int obi_column_set_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value)
|
||||
{
|
||||
// when/where check if can write?
|
||||
*(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||
@ -33,13 +36,62 @@ int obi_column_set_int(OBIDMS_column_p column, size_t line_nb, size_t element_id
|
||||
}
|
||||
|
||||
|
||||
obiint_t obi_column_get_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
obiint_t obi_column_get_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
{
|
||||
return *(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
//obiint_t* obi_column_get_line_address_int(OBIDMS_column_p column, size_t nb_elements_per_line, size_t line_nb)
|
||||
//{
|
||||
// return (((obiint_t*) (column->data)) + (line_nb * nb_elements_per_line));
|
||||
//}
|
||||
int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
obi_column_set_int_with_elt_idx(column, line_nb, element_idx, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obiint_t obi_column_get_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return obi_column_get_int_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user