Major update: obiarrays with columns containing indices referring to
character strings.
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* @file obidsmcolumn_str.c
|
||||
* @author Celine Mercier
|
||||
* @date October 28th 2015
|
||||
* @brief Functions handling OBIColumns containing data with the OBIType OBI_IDX.
|
||||
* @brief Functions handling OBIColumns containing data in the form of indices referring to character strings.
|
||||
*/
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, char* value)
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
|
||||
{
|
||||
byte_t* value_b;
|
||||
index_t idx;
|
||||
@ -59,31 +59,24 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, size_t line_nb, s
|
||||
if (value_b == NULL)
|
||||
return -1;
|
||||
|
||||
obidebug(1, "\nvalue=%s", value);
|
||||
//obidebug(1, "\nbytes=%s", value_b+5);
|
||||
|
||||
// Add in the obiarray
|
||||
idx = obi_array_add(column->array, value_b);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
|
||||
obidebug(1, "\nidx=%d", idx);
|
||||
//obidebug(1, "\nbytes 2=%s", obi_array_get(column->array, idx)+5);
|
||||
|
||||
// Add the value's index in the column
|
||||
*(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
||||
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
||||
|
||||
// TODO free value_b probably
|
||||
free(value_b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
index_t idx;
|
||||
byte_t* value_b;
|
||||
const char* value;
|
||||
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
@ -92,32 +85,22 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, size_t li
|
||||
return "\0"; // TODO
|
||||
}
|
||||
|
||||
idx = *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
|
||||
// Check NA
|
||||
if (idx == OBIIdx_NA)
|
||||
return "\0"; // TODO
|
||||
|
||||
obidebug(1, "\nwhy, idx = %d", idx);
|
||||
|
||||
value_b = obi_array_get(column->array, idx);
|
||||
|
||||
obidebug(1, "\nwhyyyy");
|
||||
|
||||
value = obi_obibytes_to_str(value_b);
|
||||
|
||||
obidebug(1, "\nwhyyyyyyyyyyyy, value=%s %p", value, value);
|
||||
obidebug(1, "\nwhyyyyyyyyyyyy, len value=%d", strlen(value));
|
||||
|
||||
return value;
|
||||
return obi_obibytes_to_str(value_b);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, char* value)
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value)
|
||||
{
|
||||
size_t element_idx;
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == SIZE_MAX) //TODO
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
if (obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
@ -125,12 +108,12 @@ int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, size_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name)
|
||||
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == SIZE_MAX) //TODO
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return "\0";
|
||||
return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
Reference in New Issue
Block a user