diff --git a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd index 394ed1a..b6b80c7 100644 --- a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd +++ b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd @@ -29,9 +29,7 @@ cdef extern from "obidmscolumn.h" nogil: size_t obi_column_get_line_count(OBIDMS_column_p column) const char* obi_column_get_elements_names(OBIDMS_column_p column) void obi_column_make_unwritable(OBIDMS_column_p column) - size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name) OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversion_t version_number) - size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column) OBIType_t obi_column_get_type(OBIDMS_column_p column) int obi_close_column(OBIDMS_column_p column) OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms, const char* column_name) diff --git a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx index 7c9d168..dd22d3e 100644 --- a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx +++ b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx @@ -62,11 +62,7 @@ cdef class OBIDMS_column: def get_elements_names(self): elements_names = obi_column_get_elements_names(self.pointer) return (elements_names.decode('UTF-8')).split(';') - - def get_element_index_from_name(self, element_name): - element_name = element_name.encode(encoding='UTF-8') - return obi_column_get_element_index_from_name(self.pointer, element_name) - + def get_data_type(self): return self.data_type diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd index 77f1051..cb9b503 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd @@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport * cdef extern from "obidmscolumn_bool.h" nogil: - int obi_column_set_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value) - obibool_t obi_column_get_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx) + int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value); + obibool_t obi_column_get_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx index f657f36..b0f99db 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx @@ -6,25 +6,9 @@ from .capidmscolumn_bool cimport * cdef class OBIDMS_column_bool(OBIDMS_column) : def set_item(self, line_nb, element_name, value): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_set_bool(self.pointer, line_nb, element_idx, value) + return obi_column_set_bool_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value) def get_item(self, line_nb, element_name): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_get_bool(self.pointer, line_nb, element_idx) + return obi_column_get_bool_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8')) \ No newline at end of file diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pxd b/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pxd index 32e2b76..a56e84d 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pxd +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pxd @@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport * cdef extern from "obidmscolumn_char.h" nogil: - int obi_column_set_char(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value) - obichar_t* obi_column_get_char(OBIDMS_column_p column, size_t line_nb, size_t element_idx) + int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value) + obichar_t* obi_column_get_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name) diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pyx b/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pyx index d1a8e43..563b092 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pyx +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pyx @@ -6,25 +6,9 @@ from .capidmscolumn_char cimport * cdef class OBIDMS_column_char(OBIDMS_column) : def set_item(self, line_nb, element_name, value): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_set_char(self.pointer, line_nb, element_idx, value) + return obi_column_set_char_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value.encode('utf-8')) def get_item(self, line_nb, element_name): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return (obi_column_get_char(self.pointer, line_nb, element_idx)).decode(encoding='UTF-8')[:1] #not ideal... + return (obi_column_get_char_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))).decode(encoding='utf-8')[:1] \ No newline at end of file diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pxd b/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pxd index d68a2f2..65e775d 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pxd +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pxd @@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport * cdef extern from "obidmscolumn_float.h" nogil: - int obi_column_set_float(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value) - obifloat_t obi_column_get_float(OBIDMS_column_p column, size_t line_nb, size_t element_idx) + int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value); + obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pyx b/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pyx index a82c2e9..ced654a 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pyx +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pyx @@ -6,25 +6,8 @@ from .capidmscolumn_float cimport * cdef class OBIDMS_column_float(OBIDMS_column) : def set_item(self, line_nb, element_name, value): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_set_float(self.pointer, line_nb, element_idx, value) + return obi_column_set_float_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value) def get_item(self, line_nb, element_name): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_get_float(self.pointer, line_nb, element_idx) - + return obi_column_get_float_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8')) \ No newline at end of file diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pxd b/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pxd index b804114..020c044 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pxd +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pxd @@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport * cdef extern from "obidmscolumn_idx.h" nogil: - int obi_column_set_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value) - obiidx_t obi_column_get_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx) + int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value); + obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pyx b/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pyx index 7060506..51babcf 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pyx +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pyx @@ -6,25 +6,8 @@ from .capidmscolumn_idx cimport * cdef class OBIDMS_column_idx(OBIDMS_column) : def set_item(self, line_nb, element_name, value): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_set_idx(self.pointer, line_nb, element_idx, value) + return obi_column_set_idx_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value) def get_item(self, line_nb, element_name): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_get_idx(self.pointer, line_nb, element_idx) - + return obi_column_get_idx_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8')) \ No newline at end of file diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pxd b/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pxd index e142806..6af0835 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pxd +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pxd @@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport * cdef extern from "obidmscolumn_int.h" nogil: - int obi_column_set_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value) - obiint_t obi_column_get_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx) + int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value); + obiint_t obi_column_get_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pyx b/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pyx index b645e0b..bcb5960 100644 --- a/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pyx +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pyx @@ -6,25 +6,9 @@ from .capidmscolumn_int cimport * cdef class OBIDMS_column_int(OBIDMS_column) : def set_item(self, line_nb, element_name, value): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_set_int(self.pointer, line_nb, element_idx, value) + return obi_column_set_int_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value) def get_item(self, line_nb, element_name): - if element_name != "" : - element_idx = self.get_element_index_from_name(element_name) - else : - if obi_column_get_nb_elements_per_line(self.pointer) == 1 : - element_idx = 0 - else : - print("An element name must be specified") - return -1 - return obi_column_get_int(self.pointer, line_nb, element_idx) + return obi_column_get_int_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8')) \ No newline at end of file diff --git a/src/obidmscolumn_bool.c b/src/obidmscolumn_bool.c index 0c07818..22d9ed2 100644 --- a/src/obidmscolumn_bool.c +++ b/src/obidmscolumn_bool.c @@ -19,23 +19,78 @@ #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_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value) +int obi_column_set_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value) { // when/where check if can write? - // check if value in enum? *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; return 0; } -obibool_t obi_column_get_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx) +obibool_t obi_column_get_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx) { return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); } + +int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_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_bool_with_elt_idx(column, line_nb, element_idx, value); + + return 0; +} + + +obibool_t obi_column_get_bool_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_bool_with_elt_idx(column, line_nb, element_idx); +} diff --git a/src/obidmscolumn_bool.h b/src/obidmscolumn_bool.h index d26f0bb..bd1aea0 100644 --- a/src/obidmscolumn_bool.h +++ b/src/obidmscolumn_bool.h @@ -18,7 +18,7 @@ /** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL. + * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line. * * @param column a pointer as returned by obi_create_column() * @warning Pointers returned by obi_open_column() don't allow writing. @@ -34,10 +34,10 @@ * @retvalue 0 on success * @retvalue -1 on failure and the `obi_errno` variable is set. * - * @since August 2015 + * @since July 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value); +int obi_column_set_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value); /** @@ -51,9 +51,51 @@ int obi_column_set_bool(OBIDMS_column_p column, size_t line_nb, size_t element_i * * @return the recovered value * + * @since July 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obibool_t obi_column_get_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * @warning Pointers returned by obi_open_column() don't allow writing. + * + * @param line_nb the number of the line where the value should be set + * + * @param element_name the name of the element that should be set in the line + * If empty, it is checked that there is only one element per line + * + * @param value the value that should be set + * + * @return an integer value indicating the success of the operation. + * + * @retvalue 0 on success + * @retvalue -1 on failure and the `obi_errno` variable is set. + * * @since August 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obibool_t obi_column_get_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx); +int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value); +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * + * @param line_nb the number of the line where the value should be recovered + * + * @param element_name the name of the element that should be recovered in the line + * If empty, it is checked that there is only one element per line + * + * @return the recovered value + * @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obibool_t obi_column_get_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); + diff --git a/src/obidmscolumn_char.c b/src/obidmscolumn_char.c index c399c66..01972d1 100644 --- a/src/obidmscolumn_char.c +++ b/src/obidmscolumn_char.c @@ -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_char(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value) +int obi_column_set_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value) { // when/where check if can write? *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value[0]; @@ -33,8 +36,61 @@ int obi_column_set_char(OBIDMS_column_p column, size_t line_nb, size_t element_i } -obichar_t* obi_column_get_char(OBIDMS_column_p column, size_t line_nb, size_t element_idx) +obichar_t* obi_column_get_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx) { return ((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx; } + +int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_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_char_with_elt_idx(column, line_nb, element_idx, value); + + return 0; +} + + +obichar_t* obi_column_get_char_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 NULL; + } + } + else + { + element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == -1) + return NULL; + } + + return obi_column_get_char_with_elt_idx(column, line_nb, element_idx); +} diff --git a/src/obidmscolumn_char.h b/src/obidmscolumn_char.h index f968c58..bbf76de 100644 --- a/src/obidmscolumn_char.h +++ b/src/obidmscolumn_char.h @@ -18,7 +18,7 @@ /** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR. + * @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the index of the element in the line. * * @param column a pointer as returned by obi_create_column() * @warning Pointers returned by obi_open_column() don't allow writing. @@ -34,10 +34,10 @@ * @retvalue 0 on success * @retvalue -1 on failure and the `obi_errno` variable is set. * - * @since August 2015 + * @since July 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_char(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value); +int obi_column_set_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value); /** @@ -51,9 +51,51 @@ int obi_column_set_char(OBIDMS_column_p column, size_t line_nb, size_t element_i * * @return the recovered value * + * @since July 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obichar_t* obi_column_get_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * @warning Pointers returned by obi_open_column() don't allow writing. + * + * @param line_nb the number of the line where the value should be set + * + * @param element_name the name of the element that should be set in the line + * If empty, it is checked that there is only one element per line + * + * @param value the value that should be set + * + * @return an integer value indicating the success of the operation. + * + * @retvalue 0 on success + * @retvalue -1 on failure and the `obi_errno` variable is set. + * * @since August 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obichar_t* obi_column_get_char(OBIDMS_column_p column, size_t line_nb, size_t element_idx); +int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value); +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * + * @param line_nb the number of the line where the value should be recovered + * + * @param element_name the name of the element that should be recovered in the line + * If empty, it is checked that there is only one element per line + * + * @return the recovered value + * @retvalue NULL on failure and the `obi_errno` variable is set. TODO an other value should be chosen maybe + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obichar_t* obi_column_get_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); + diff --git a/src/obidmscolumn_float.c b/src/obidmscolumn_float.c index e0e0d7d..826aba9 100644 --- a/src/obidmscolumn_float.c +++ b/src/obidmscolumn_float.c @@ -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_float(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value) +int obi_column_set_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value) { // when/where check if can write? *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; @@ -33,8 +36,61 @@ int obi_column_set_float(OBIDMS_column_p column, size_t line_nb, size_t element_ } -obifloat_t obi_column_get_float(OBIDMS_column_p column, size_t line_nb, size_t element_idx) +obifloat_t obi_column_get_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx) { return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); } + +int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_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_float_with_elt_idx(column, line_nb, element_idx, value); + + return 0; +} + + +obifloat_t obi_column_get_float_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_float_with_elt_idx(column, line_nb, element_idx); +} diff --git a/src/obidmscolumn_float.h b/src/obidmscolumn_float.h index 6b800e0..9ef3d4b 100644 --- a/src/obidmscolumn_float.h +++ b/src/obidmscolumn_float.h @@ -18,7 +18,7 @@ /** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT. + * @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the index of the element in the line. * * @param column a pointer as returned by obi_create_column() * @warning Pointers returned by obi_open_column() don't allow writing. @@ -34,10 +34,10 @@ * @retvalue 0 on success * @retvalue -1 on failure and the `obi_errno` variable is set. * - * @since August 2015 + * @since July 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_float(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value); +int obi_column_set_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value); /** @@ -51,9 +51,51 @@ int obi_column_set_float(OBIDMS_column_p column, size_t line_nb, size_t element_ * * @return the recovered value * + * @since July 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obifloat_t obi_column_get_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * @warning Pointers returned by obi_open_column() don't allow writing. + * + * @param line_nb the number of the line where the value should be set + * + * @param element_name the name of the element that should be set in the line + * If empty, it is checked that there is only one element per line + * + * @param value the value that should be set + * + * @return an integer value indicating the success of the operation. + * + * @retvalue 0 on success + * @retvalue -1 on failure and the `obi_errno` variable is set. + * * @since August 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obifloat_t obi_column_get_float(OBIDMS_column_p column, size_t line_nb, size_t element_idx); +int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value); +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * + * @param line_nb the number of the line where the value should be recovered + * + * @param element_name the name of the element that should be recovered in the line + * If empty, it is checked that there is only one element per line + * + * @return the recovered value + * @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); + diff --git a/src/obidmscolumn_idx.c b/src/obidmscolumn_idx.c index 0253956..f26ce99 100644 --- a/src/obidmscolumn_idx.c +++ b/src/obidmscolumn_idx.c @@ -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_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value) +int obi_column_set_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value) { // when/where check if can write? *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; @@ -33,8 +36,61 @@ int obi_column_set_idx(OBIDMS_column_p column, size_t line_nb, size_t element_id } -obiidx_t obi_column_get_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx) +obiidx_t obi_column_get_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx) { 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) +{ + 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_idx_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) +{ + 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_idx_with_elt_idx(column, line_nb, element_idx); +} diff --git a/src/obidmscolumn_idx.h b/src/obidmscolumn_idx.h index 07e6609..e043d5a 100644 --- a/src/obidmscolumn_idx.h +++ b/src/obidmscolumn_idx.h @@ -18,7 +18,7 @@ /** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_IDX. + * @brief Sets a value in an OBIDMS column containing data with the type OBI_IDX, using the index of the element in the line. * * @param column a pointer as returned by obi_create_column() * @warning Pointers returned by obi_open_column() don't allow writing. @@ -34,10 +34,10 @@ * @retvalue 0 on success * @retvalue -1 on failure and the `obi_errno` variable is set. * - * @since August 2015 + * @since July 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value); +int obi_column_set_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value); /** @@ -51,9 +51,51 @@ int obi_column_set_idx(OBIDMS_column_p column, size_t line_nb, size_t element_id * * @return the recovered value * + * @since July 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obiidx_t obi_column_get_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_IDX, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * @warning Pointers returned by obi_open_column() don't allow writing. + * + * @param line_nb the number of the line where the value should be set + * + * @param element_name the name of the element that should be set in the line + * If empty, it is checked that there is only one element per line + * + * @param value the value that should be set + * + * @return an integer value indicating the success of the operation. + * + * @retvalue 0 on success + * @retvalue -1 on failure and the `obi_errno` variable is set. + * * @since August 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obiidx_t obi_column_get_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx); +int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value); +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * + * @param line_nb the number of the line where the value should be recovered + * + * @param element_name the name of the element that should be recovered in the line + * If empty, it is checked that there is only one element per line + * + * @return the recovered value + * @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); + diff --git a/src/obidmscolumn_int.c b/src/obidmscolumn_int.c index d0bd07c..afd4fb5 100644 --- a/src/obidmscolumn_int.c +++ b/src/obidmscolumn_int.c @@ -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); +} + diff --git a/src/obidmscolumn_int.h b/src/obidmscolumn_int.h index c35d02d..ca71653 100644 --- a/src/obidmscolumn_int.h +++ b/src/obidmscolumn_int.h @@ -18,7 +18,7 @@ /** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_INT. + * @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the index of the element in the line. * * @param column a pointer as returned by obi_create_column() * @warning Pointers returned by obi_open_column() don't allow writing. @@ -37,7 +37,7 @@ * @since July 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -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); /** @@ -54,6 +54,48 @@ int obi_column_set_int(OBIDMS_column_p column, size_t line_nb, size_t element_id * @since July 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -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); +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * @warning Pointers returned by obi_open_column() don't allow writing. + * + * @param line_nb the number of the line where the value should be set + * + * @param element_name the name of the element that should be set in the line + * If empty, it is checked that there is only one element per line + * + * @param value the value that should be set + * + * @return an integer value indicating the success of the operation. + * + * @retvalue 0 on success + * @retvalue -1 on failure and the `obi_errno` variable is set. + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT, using the name of the element in the line. + * + * @param column a pointer as returned by obi_create_column() + * + * @param line_nb the number of the line where the value should be recovered + * + * @param element_name the name of the element that should be recovered in the line + * If empty, it is checked that there is only one element per line + * + * @return the recovered value + * @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obiint_t obi_column_get_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name); +