2015-08-10 16:30:55 +02:00
|
|
|
/****************************************************************************
|
2015-11-03 14:22:00 +01:00
|
|
|
* OBIDMS_column_str functions *
|
2015-08-10 16:30:55 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2015-11-03 14:22:00 +01:00
|
|
|
* @file obidsmcolumn_str.c
|
2015-08-10 16:30:55 +02:00
|
|
|
* @author Celine Mercier
|
2015-11-03 14:22:00 +01:00
|
|
|
* @date October 28th 2015
|
2015-11-06 17:55:15 +01:00
|
|
|
* @brief Functions handling OBIColumns containing data in the form of indices referring to character strings.
|
2015-08-10 16:30:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "obidmscolumn.h"
|
|
|
|
#include "obitypes.h"
|
2016-04-12 17:21:01 +02:00
|
|
|
#include "char_str_indexer.h"
|
2015-08-10 16:30:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2016-04-13 15:10:24 +02:00
|
|
|
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value)
|
2015-08-10 16:30:55 +02:00
|
|
|
{
|
2016-04-13 15:10:24 +02:00
|
|
|
index_t idx;
|
2016-05-18 13:23:48 +02:00
|
|
|
char* new_indexer_name;
|
2016-04-13 15:10:24 +02:00
|
|
|
|
|
|
|
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-06-03 19:02:46 +02:00
|
|
|
// TODO NA
|
|
|
|
|
2016-04-13 15:10:24 +02:00
|
|
|
// Add the value in the indexer
|
2016-04-12 17:21:01 +02:00
|
|
|
idx = obi_index_char_str(column->indexer, value);
|
2016-05-18 13:23:48 +02:00
|
|
|
if (idx == -1) // An error occurred
|
|
|
|
{
|
|
|
|
if (obi_errno == OBI_READ_ONLY_INDEXER_ERROR)
|
|
|
|
{
|
2016-06-03 19:02:46 +02:00
|
|
|
// TODO PUT IN A COLUMN FUNCTION
|
2016-05-18 13:23:48 +02:00
|
|
|
// If the error is that the indexer is read-only, clone it
|
|
|
|
new_indexer_name = obi_build_indexer_name((column->header)->name, (column->header)->version);
|
|
|
|
if (new_indexer_name == NULL)
|
|
|
|
return -1;
|
|
|
|
column->indexer = obi_clone_indexer(column->indexer, new_indexer_name); // TODO Need to lock this somehow?
|
2016-06-03 19:02:46 +02:00
|
|
|
strcpy((column->header)->indexer_name, new_indexer_name);
|
|
|
|
free(new_indexer_name);
|
|
|
|
obi_set_errno(0);
|
|
|
|
|
2016-05-18 13:23:48 +02:00
|
|
|
// Add the value in the new indexer
|
|
|
|
idx = obi_index_char_str(column->indexer, value);
|
|
|
|
if (idx == -1)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
2015-11-03 14:22:00 +01:00
|
|
|
|
|
|
|
// Add the value's index in the column
|
2016-02-18 10:38:51 +01:00
|
|
|
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
2015-11-03 14:22:00 +01:00
|
|
|
|
2015-08-10 16:30:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-06 17:55:15 +01:00
|
|
|
const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
2015-08-10 16:30:55 +02:00
|
|
|
{
|
2016-04-13 15:10:24 +02:00
|
|
|
index_t idx;
|
2015-11-03 14:22:00 +01:00
|
|
|
|
2016-04-13 15:10:24 +02:00
|
|
|
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
2016-06-03 19:02:46 +02:00
|
|
|
return OBIStr_NA;
|
2015-11-03 14:22:00 +01:00
|
|
|
|
2016-02-18 10:38:51 +01:00
|
|
|
idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
2015-11-03 14:22:00 +01:00
|
|
|
|
|
|
|
// Check NA
|
|
|
|
if (idx == OBIIdx_NA)
|
2016-02-18 10:38:51 +01:00
|
|
|
return OBIStr_NA;
|
2015-11-03 14:22:00 +01:00
|
|
|
|
2016-04-12 17:21:01 +02:00
|
|
|
return obi_retrieve_char_str(column->indexer, idx);
|
2015-08-10 16:30:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-26 15:05:23 +02:00
|
|
|
|
2016-04-13 15:10:24 +02:00
|
|
|
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value)
|
2016-02-18 10:38:51 +01:00
|
|
|
{
|
2016-04-13 15:10:24 +02:00
|
|
|
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
2015-11-06 17:55:15 +01:00
|
|
|
if (element_idx == OBIIdx_NA)
|
2015-10-14 18:05:34 +02:00
|
|
|
return -1;
|
2016-02-18 10:38:51 +01:00
|
|
|
|
2016-04-13 15:10:24 +02:00
|
|
|
return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
|
2015-08-26 15:05:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-06 17:55:15 +01:00
|
|
|
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
2015-08-26 15:05:23 +02:00
|
|
|
{
|
2016-04-13 15:10:24 +02:00
|
|
|
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
2015-11-06 17:55:15 +01:00
|
|
|
if (element_idx == OBIIdx_NA)
|
2016-02-18 10:38:51 +01:00
|
|
|
return OBIStr_NA;
|
|
|
|
|
2016-04-13 15:10:24 +02:00
|
|
|
return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
|
2016-02-18 10:38:51 +01:00
|
|
|
}
|
|
|
|
|