Commit 9a97f1f6 by Celine Mercier

View predicates are now carried over when cloning a view

parent 00014eb0
......@@ -43,6 +43,37 @@
*
**************************************************************************/
/**
* Internal function building the file name where the informations about an obiview are stored.
*
* @warning The returned pointer has to be freed by the caller.
*
* @param view_name The name of the view.
*
* @returns A pointer to the file name.
* @retval NULL if an error occurred.
*
* @since June 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
static char* build_obiview_file_name(const char* view_name);
/**
* Internal function checking if a view with a given name already exists in a DMS.
*
* @param dms The DMS.
* @param view_name The name of the view.
*
* @returns A boolean value indicating whether the view already exists or not.
*
* @since September 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
bool view_exists(OBIDMS_p dms, const char* view_name);
/**
* Internal function calculating the initial size of the file where the informations about an obiview are stored.
*
......@@ -88,22 +119,6 @@ int write_comments_to_view_file(Obiview_p view, const char* comments);
/**
* Internal function building the file name where the informations about an obiview are stored.
*
* @warning The returned pointer has to be freed by the caller.
*
* @param view_name The name of the view.
*
* @returns A pointer to the file name.
* @retval NULL if an error occurred.
*
* @since June 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
static char* build_obiview_file_name(const char* view_name);
/**
* @brief Internal function creating a file containing all the informations on a view.
*
* The file is named with the name of the view.
......@@ -426,6 +441,27 @@ static char* build_obiview_file_name(const char* view_name)
}
bool view_exists(OBIDMS_p dms, const char* view_name)
{
struct dirent* dp;
char* file_name;
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, file_name) == 0)
return true;
}
return false;
}
size_t get_platform_view_file_size()
{
size_t obiview_size;
......@@ -1104,28 +1140,6 @@ char* view_check_all_predicates(Obiview_p view)
**********************************************************************/
bool view_exists(OBIDMS_p dms, const char* view_name)
{
struct dirent* dp;
char* file_name;
int i;
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, file_name) == 0)
return true;
}
return false;
}
Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments)
{
Obiview_p view;
......@@ -1249,6 +1263,16 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
strcpy((view->infos)->view_type, (view_to_clone->infos)->view_type);
strcpy((view->infos)->created_from, (view_to_clone->infos)->name);
view->new_line_selection = NULL;
// Copy predicates
view->nb_predicates = view_to_clone->nb_predicates;
if (view->nb_predicates > 0)
{
view->predicate_functions = malloc((view->nb_predicates) * sizeof(char* (*) (Obiview_p)));
for (i=0; i<(view->nb_predicates); i++)
(view->predicate_functions)[i] = (view_to_clone->predicate_functions)[i];
}
else
view->predicate_functions = NULL;
}
// Else, fill empty view structure
......@@ -1261,14 +1285,14 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
view->new_line_selection = NULL;
((view->infos)->created_from)[0] = '\0';
((view->infos)->view_type)[0] = '\0';
view->nb_predicates = 0;
view->predicate_functions = NULL;
//view->columns = NULL; // TODO
}
// Fill last informations
strcpy((view->infos)->name, view_name);
(view->infos)->creation_date = time(NULL);
view->nb_predicates = 0;
view->predicate_functions = NULL;
if (write_comments_to_view_file(view, comments) < 0) // TODO copy comments if cloning view?
{
......@@ -1409,7 +1433,7 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
else
view->nb_predicates = 3;
view->predicate_functions = malloc((view->nb_predicates) * sizeof(char* (*) (bool)));
view->predicate_functions = malloc((view->nb_predicates) * sizeof(char* (*) (Obiview_p)));
(view->predicate_functions)[0] = view_has_nuc_sequence_column;
(view->predicate_functions)[1] = view_has_id_column;
......@@ -1450,7 +1474,7 @@ Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name)
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
return NULL;
// Open view file
obiview_file_descriptor = openat(dms->view_dir_fd, file_name, O_RDWR, 0777);
......
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