Commit 95dbeb25 by Celine Mercier

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
parent 9d91e907
......@@ -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)
......
......@@ -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
......
......@@ -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);
......@@ -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
......@@ -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)
......@@ -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
......@@ -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);
......@@ -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
......@@ -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);
......@@ -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
......@@ -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);
......@@ -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
......@@ -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);
}
......@@ -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);
......@@ -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);
}
......@@ -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);
......@@ -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);
}
......@@ -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);
......@@ -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);