Documentation for views and reworked the code a little

This commit is contained in:
Celine Mercier
2016-04-25 17:58:12 +02:00
parent 0a55e26520
commit 8cdfbb379e
3 changed files with 618 additions and 221 deletions

View File

@ -78,12 +78,41 @@ static char* build_obiview_file_name();
int create_obiview_file(int dms_file_descriptor);
// TODO doc
/**
* Internal function preparing to set a value in a column, in the context of a view.
*
* The function checks that the view is not read-only, clones the column or all columns if needed,
* and updates the line count if needed.
*
* @param view The view.
* @param column_pp A pointer on the pointer on the column, to allow replacing the column if it is cloned.
* @param line_nb_p A pointer on the index of the line that will be modified, to allow replacing it if needed.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since April 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, index_t* line_nb_p);
// TODO doc
int prepare_to_get_value_in_column(Obiview_p view, OBIDMS_column_p column, index_t* line_nb_p);
/**
* Internal function preparing to get a value from a column, in the context of a view.
*
* The function checks that the line index is not beyond the current line count of the view,
* and modifies it if there is a line selection associated with the view.
*
* @param view The view.
* @param line_nb_p A pointer on the index of the line, to allow replacing it if needed.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since April 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int prepare_to_get_value_from_column(Obiview_p view, index_t* line_nb_p);
/************************************************************************
@ -256,7 +285,7 @@ int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, i
}
int prepare_to_get_value_from_column(Obiview_p view, OBIDMS_column_p column, index_t* line_nb_p)
int prepare_to_get_value_from_column(Obiview_p view, index_t* line_nb_p)
{
if (((*line_nb_p)+1) > (view->line_count))
{
@ -379,7 +408,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
return NULL;
view->line_count = view_to_clone->line_count;
}
// If there is a new line selection, build it by combining it with the pre-existing one if there is one
// If there is a new line selection, build it by combining it with the one from the view to clone if there is one
else if (line_selection != NULL)
{
view->line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL);
@ -566,7 +595,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name)
return NULL;
}
// Find and open view that should be read with the line selection associated
// Find and open the view that should be read with the line selection associated
view_number = -1;
if (view_name == NULL) // If view name is NULL, open the latest view TODO discuss
view_number = (header->view_count) - 1;
@ -927,7 +956,7 @@ int obi_select_line(Obiview_p view, index_t line_nb)
return -1;
}
// If column for line selection doesn't already exists, create it and store its informations
// If the column for line selection doesn't already exists, create it and store its informations
if ((view->new_line_selection) == NULL)
{
view->new_line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL);
@ -1240,7 +1269,7 @@ int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p
obibool_t obi_column_get_obibool_with_elt_idx_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, column, &line_nb) < 0)
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
return OBIBool_NA;
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
}
@ -1278,7 +1307,7 @@ int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p
obichar_t obi_column_get_obichar_with_elt_idx_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, column, &line_nb) < 0)
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
return OBIChar_NA;
return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx);
}
@ -1316,7 +1345,7 @@ int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p
obifloat_t obi_column_get_obifloat_with_elt_idx_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, column, &line_nb) < 0)
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
return OBIFloat_NA;
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
}
@ -1354,7 +1383,7 @@ int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c
obiint_t obi_column_get_obiint_with_elt_idx_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, column, &line_nb) < 0)
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
return OBIInt_NA;
return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx);
}
@ -1392,7 +1421,7 @@ int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c
char* obi_column_get_obiseq_with_elt_idx_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, column, &line_nb) < 0)
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
return OBISeq_NA;
return obi_column_get_obiseq_with_elt_idx(column, line_nb, element_idx);
}
@ -1430,7 +1459,7 @@ int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c
const char* obi_column_get_obistr_with_elt_idx_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, column, &line_nb) < 0)
if (prepare_to_get_value_from_column(view, &line_nb) < 0)
return OBIStr_NA;
return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
}