Made the function to clone a column in the context of a view private
This commit is contained in:
@ -105,8 +105,6 @@ cdef extern from "obiview.h" nogil:
|
||||
|
||||
int obi_select_lines(Obiview_p view, index_t* line_nbs)
|
||||
|
||||
OBIDMS_column_p obi_view_clone_column(Obiview_p view, const_char_p column_name)
|
||||
|
||||
OBIDMS_column_p obi_view_get_column(Obiview_p view, const_char_p column_name)
|
||||
|
||||
OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const_char_p column_name)
|
||||
|
144
src/obiview.c
144
src/obiview.c
@ -98,6 +98,24 @@ int create_obiview_file(int dms_file_descriptor);
|
||||
int update_lines(Obiview_p view, index_t line_count);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function to clone a column in the context of a view.
|
||||
*
|
||||
* Clones with the right line selection and replaces the cloned columns with the new ones in the view.
|
||||
* If there is a line selection, all columns have to be cloned, otherwise only the column of interest is cloned.
|
||||
*
|
||||
* @param view A pointer on the view.
|
||||
* @param column_name The name of the column in the view that should be cloned.
|
||||
*
|
||||
* @returns A pointer on the new column.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since February 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name);
|
||||
|
||||
|
||||
/**
|
||||
* Internal function preparing to set a value in a column, in the context of a view.
|
||||
*
|
||||
@ -289,6 +307,68 @@ int update_lines(Obiview_p view, index_t line_count)
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name)
|
||||
{
|
||||
int i;
|
||||
OBIDMS_column_p current_line_selection = NULL;
|
||||
OBIDMS_column_p column;
|
||||
OBIDMS_column_p column_buffer;
|
||||
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to delete a column in a read-only view");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (view->new_line_selection != NULL) // TODO Probably shouldn't happen, trigger error?
|
||||
current_line_selection = view->new_line_selection;
|
||||
else
|
||||
current_line_selection = view->line_selection;
|
||||
|
||||
for (i=0; i<(view->column_count); i++)
|
||||
{
|
||||
if ((current_line_selection != NULL) || (!(strcmp((((view->columns)[i])->header)->name, column_name))))
|
||||
{ // Clone with the right line selection and replace (for all columns if there is a line selection)
|
||||
|
||||
// Save pointer to close column after cloning
|
||||
column_buffer = (view->columns)[i];
|
||||
|
||||
// Clone and replace the column in the view
|
||||
(view->columns)[i] = obi_clone_column(view->dms, current_line_selection, (((view->columns)[i])->header)->name, (((view->columns)[i])->header)->version, 1);
|
||||
if ((view->columns)[i] == NULL)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError cloning a column to replace in a view");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Close old cloned column
|
||||
obi_close_column(column_buffer);
|
||||
|
||||
if (!(strcmp((((view->columns)[i])->header)->name, column_name)))
|
||||
// Found the column to return
|
||||
column = (view->columns)[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Close old line selections
|
||||
if (view->line_selection != NULL)
|
||||
{
|
||||
obi_close_column(view->line_selection);
|
||||
view->line_selection = NULL;
|
||||
}
|
||||
if (view->new_line_selection != NULL)
|
||||
{
|
||||
obi_close_column(view->new_line_selection);
|
||||
view->new_line_selection = NULL;
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
|
||||
int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, index_t* line_nb_p)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
@ -307,7 +387,7 @@ int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, i
|
||||
if (view->line_selection != NULL)
|
||||
(*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p));
|
||||
|
||||
(*column_pp) = obi_view_clone_column(view, ((*column_pp)->header)->name);
|
||||
(*column_pp) = clone_column_in_view(view, ((*column_pp)->header)->name);
|
||||
if ((*column_pp) == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
@ -774,68 +854,6 @@ int obi_view_add_column(Obiview_p view,
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_view_clone_column(Obiview_p view, const char* column_name)
|
||||
{
|
||||
int i;
|
||||
OBIDMS_column_p current_line_selection = NULL;
|
||||
OBIDMS_column_p column;
|
||||
OBIDMS_column_p column_buffer;
|
||||
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to delete a column in a read-only view");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (view->new_line_selection != NULL) // TODO Probably shouldn't happen, trigger error?
|
||||
current_line_selection = view->new_line_selection;
|
||||
else
|
||||
current_line_selection = view->line_selection;
|
||||
|
||||
for (i=0; i<(view->column_count); i++)
|
||||
{
|
||||
if ((current_line_selection != NULL) || (!(strcmp((((view->columns)[i])->header)->name, column_name))))
|
||||
{ // Clone with the right line selection and replace (for all columns if there is a line selection)
|
||||
|
||||
// Save pointer to close column after cloning
|
||||
column_buffer = (view->columns)[i];
|
||||
|
||||
// Clone and replace the column in the view
|
||||
(view->columns)[i] = obi_clone_column(view->dms, current_line_selection, (((view->columns)[i])->header)->name, (((view->columns)[i])->header)->version, 1);
|
||||
if ((view->columns)[i] == NULL)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError cloning a column to replace in a view");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Close old cloned column
|
||||
obi_close_column(column_buffer);
|
||||
|
||||
if (!(strcmp((((view->columns)[i])->header)->name, column_name)))
|
||||
// Found the column to return
|
||||
column = (view->columns)[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Close old line selections
|
||||
if (view->line_selection != NULL)
|
||||
{
|
||||
obi_close_column(view->line_selection);
|
||||
view->line_selection = NULL;
|
||||
}
|
||||
if (view->new_line_selection != NULL)
|
||||
{
|
||||
obi_close_column(view->new_line_selection);
|
||||
view->new_line_selection = NULL;
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
|
||||
int obi_view_delete_column(Obiview_p view, const char* column_name)
|
||||
{
|
||||
int i;
|
||||
|
@ -326,24 +326,6 @@ int obi_view_add_column(Obiview_p view,
|
||||
bool create);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clones a column in the context of a view.
|
||||
*
|
||||
* Clones with the right line selection and replaces the cloned columns with the new ones in the view.
|
||||
* If there is a line selection, all columns have to be cloned, otherwise only the column of interest is cloned.
|
||||
*
|
||||
* @param view A pointer on the view.
|
||||
* @param column_name The name of the column in the view that should be cloned.
|
||||
*
|
||||
* @returns A pointer on the new column.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since February 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_column_p obi_view_clone_column(Obiview_p view, const char* column_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deletes a column from a view.
|
||||
*
|
||||
|
Reference in New Issue
Block a user