Commit 4ad8c16a authored by Celine Mercier's avatar Celine Mercier

Finished adding all the functions to directly set and get indices in

columns containing indices referring to any type of data.
parent 6f609968
......@@ -24,33 +24,34 @@
**********************************************************************/
int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value)
int obi_column_set_index_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, index_t value)
{
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
return -1;
// Set the value
*(((index_t*) (column->data)) + line_nb) = value;
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
return 0;
}
index_t obi_column_get_index(OBIDMS_column_p column, index_t line_nb)
index_t obi_column_get_index_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
{
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
return OBIIdx_NA;
return *(((index_t*) (column->data)) + line_nb);
return *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
}
index_t obi_column_get_index_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
int obi_column_set_index_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, index_t value)
{
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
return OBIIdx_NA;
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
if (element_idx == OBIIdx_NA)
return -1;
return *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
return obi_column_set_index_with_elt_idx(column, line_nb, element_idx, value);
}
......
......@@ -6,10 +6,10 @@
* @file obidsmcolumn_idx.h
* @author Celine Mercier
* @date February 14th 2016
* @brief Header file for the functions handling OBIColumns containing data with the OBIType OBI_IDX.
* @brief Header file for the functions handling OBIColumns containing indices (stored data type: OBI_IDX).
*
* Note: OBI_IDX columns contain indices referring to data stored elsewhere
* (for example lines in other columns) and contain only one element (index) per line.
* Note: Columns containing indices refer to data stored elsewhere, for example lines in other columns,
* or data stored in indexers.
*/
......@@ -25,65 +25,90 @@
/**
* @brief Sets a value in an OBIDMS column containing data with the type OBI_IDX.
* @brief Sets a value in an OBIDMS column containing indices (stored data type: OBI_IDX),
* using the index of the element in the line.
*
* Note: OBI_IDX columns contain indices referring to data stored elsewhere
* (for example lines in other columns) and contain only one element (index) per line.
* Note: Columns containing indices refer to data stored elsewhere, for example lines in other columns,
* or data stored in indexers.
*
* In the case of columns referring to values stored in indexers, this allows to directly set already-known
* indices without going through the time-consuming step of indexing the value.
*
* @warning Pointers returned by obi_open_column() don't allow writing.
*
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be set.
* @param value The value that should be set.
* @param element_idx The index of the element that should be set in the line.
* @param value The index that should be set.
*
* @returns An integer value indicating the success of the operation.
* @retval 0 on success.
* @retval -1 if an error occurred.
*
* @since February 2016
* @since November 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value);
int obi_column_set_index_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, index_t value);
/**
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX.
* @brief Recovers a value in an OBIDMS column containing indices (stored data type: OBI_IDX),
* using the index of the element in the line.
*
* Note: OBI_IDX columns contain indices referring to data stored elsewhere
* (for example lines in other columns) and contain only one element (index) per line.
* Note: Columns containing indices refer to data stored elsewhere, for example lines in other columns,
* or data stored in indexers.
*
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
* The value recovered is the index itself and not the data it is referring to.
*
* @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_idx The index of the element that should be recovered in the line.
*
* @returns The recovered value.
* @retval OBIIdx_NA the NA value of the type if an error occurred and obi_errno is set.
*
* @since February 2016
* @since November 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
index_t obi_column_get_index(OBIDMS_column_p column, index_t line_nb);
index_t obi_column_get_index_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
/**
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX.
* @brief Sets a value in an OBIDMS column containing indices (stored data type: OBI_IDX),
* using the index 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_idx The index of the element that should be recovered in the line.
* Note: Columns containing indices refer to data stored elsewhere, for example lines in other columns,
* or data stored in indexers.
*
* @returns The recovered value.
* @retval OBIIdx_NA the NA value of the type if an error occurred and obi_errno is set.
* In the case of columns referring to values stored in indexers, this allows to directly set already-known
* indices without going through the time-consuming step of indexing the value.
*
* @warning Pointers returned by obi_open_column() don't allow writing.
*
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @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.
* @param value The index that should be set.
*
* @returns An integer value indicating the success of the operation.
* @retval 0 on success.
* @retval -1 if an error occurred.
*
* @since November 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
index_t obi_column_get_index_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
int obi_column_set_index_with_elt_name(OBIDMS_column_p column, index_t line_nb, index_t element_idx, index_t value);
/**
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX,
* @brief Recovers a value in an OBIDMS column containing indices (stored data type: OBI_IDX),
* using the name of the element in the line.
*
* Note: Columns containing indices refer to data stored elsewhere, for example lines in other columns,
* or data stored in indexers.
*
* The value recovered is the index itself and not the data it is referring to.
*
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
......
......@@ -1263,9 +1263,9 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
}
if (view_to_clone->line_selection != NULL)
line_nb = obi_column_get_index(view_to_clone->line_selection, line_nb);
line_nb = obi_column_get_index_with_elt_idx(view_to_clone->line_selection, line_nb, 0);
if (obi_column_set_index(view->line_selection, ((view->line_selection)->header)->lines_used, line_nb) < 0)
if (obi_column_set_index_with_elt_idx(view->line_selection, ((view->line_selection)->header)->lines_used, 0, line_nb) < 0)
{
obi_close_column(view->line_selection);
obi_view_unmap_file(view->dms, view->infos);
......@@ -2724,6 +2724,15 @@ const char* obi_get_str_with_elt_name_and_col_name_in_view(Obiview_p view, const
/*********** FOR COLUMNS WITH INDEXED VALUES ***********/
int obi_set_index_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, index_t value)
{
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
return -1;
return obi_column_set_index_with_elt_idx(column, line_nb, element_idx, value);
}
index_t obi_get_index_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx)
{
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
......@@ -2732,6 +2741,15 @@ index_t obi_get_index_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_colu
}
int obi_set_index_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, index_t value)
{
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
if (element_idx == OBIIdx_NA)
return -1;
return obi_set_index_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value);
}
index_t obi_get_index_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name)
{
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
......@@ -2741,6 +2759,26 @@ index_t obi_get_index_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_col
}
int obi_set_index_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, index_t value)
{
OBIDMS_column_p column_p;
column_p = obi_view_get_column(view, column_name);
if (column_p == NULL)
return -1;
return obi_set_index_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value);
}
int obi_set_index_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, index_t value)
{
OBIDMS_column_p column_p;
column_p = obi_view_get_column(view, column_name);
if (column_p == NULL)
return -1;
return obi_set_index_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value);
}
index_t obi_get_index_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx)
{
OBIDMS_column_p column_p;
......
......@@ -1314,6 +1314,38 @@ const char* obi_get_str_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_c
const char* obi_get_str_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name);
/**
* @brief Sets a value in an OBIDMS column containing indices, using the index of the element in the line,
* in the context of a view.
*
* Note: If the column is read-only or if there is a line selection associated with the view (making columns non-writable), it is cloned.
*
* Note: Columns containing indices refer to data stored elsewhere, for example lines in other columns,
* or data stored in indexers.
*
* In the case of columns referring to values stored in indexers, this allows to directly set already-known
* indices without going through the time-consuming step of indexing the value.
*
* @param view A pointer on the opened writable view.
* @param column A pointer on the column.
* @param line_nb The number of the line where the value should be set.
* @param element_idx The index of the element that should be set in the line.
* @param value The value that should be set.
*
* @returns An integer value indicating the success of the operation.
* @retval 0 on success.
* @retval -1 if an error occurred.
*
* @since November 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_set_index_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, index_t value);
// TODO
int obi_set_index_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, index_t value);
/**
* @brief Recovers a value in an OBIDMS column containing indexes, in the context of a view.
*
......@@ -1338,6 +1370,38 @@ index_t obi_get_index_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_colu
index_t obi_get_index_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx);
/**
* @brief Sets a value in an OBIDMS column containing indices, using the index of the element in the line,
* in the context of a view.
*
* Note: If the column is read-only or if there is a line selection associated with the view (making columns non-writable), it is cloned.
*
* Note: Columns containing indices refer to data stored elsewhere, for example lines in other columns,
* or data stored in indexers.
*
* In the case of columns referring to values stored in indexers, this allows to directly set already-known
* indices without going through the time-consuming step of indexing the value.
*
* @param view A pointer on the opened writable view.
* @param column A pointer on the column.
* @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 recovered in the line.
* @param value The value that should be set.
*
* @returns An integer value indicating the success of the operation.
* @retval 0 on success.
* @retval -1 if an error occurred.
*
* @since November 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_set_index_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, index_t value);
// TODO
int obi_set_index_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, index_t value);
/**
* @brief Recovers a value in an OBIDMS column containing indexes,
* using the name of the element in the line, in the context of a view.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment