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,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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user