Commit 59dd0a8a by Celine Mercier

Standardized and improved the API to create new columns, updated the doc

parent c88df2e1
......@@ -827,11 +827,11 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
index_t nb_lines,
index_t nb_elements_per_line,
char* elements_names,
bool elt_names_formatted,
const char* indexer_name,
const char* associated_column_name,
obiversion_t associated_column_version,
const char* comments,
bool elt_names_formatted
const char* comments
)
{
OBIDMS_column_p new_column;
......@@ -865,7 +865,13 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
obidebug(1, "\nCan't create column because of empty column name");
return NULL;
}
if ((data_type < 1) || (data_type > 8)) // TODO check in more robust way and use macro define somewhere
if (nb_elements_per_line < 1)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nCan't create column: the number of elements per line can't be less than 1");
return NULL;
}
if ((data_type < 1) || (data_type > 8)) // TODO check in more robust way ?
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nCan't create column because of invalid data type");
......@@ -922,7 +928,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
nb_lines = minimum_line_count;
// Check, format, and build if needed the element names
if ((elements_names == NULL) || (*elements_names == '\0')) // Build the default element names: str of the element index
if ((elements_names == NULL) || (*elements_names == '\0')) // Build the default element names
{
built_elements_names = build_default_elements_names(nb_elements_per_line);
if (built_elements_names == NULL)
......@@ -953,9 +959,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
// Get the column file name
column_file_name = build_column_file_name(column_name, version_number);
if (column_file_name == NULL)
{
return NULL;
}
// Open the column file
column_file_descriptor = openat(column_directory->dir_fd, column_file_name, O_RDWR | O_CREAT | O_EXCL, 0777);
......@@ -1048,13 +1052,13 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
strncpy(header->name, column_name, OBIDMS_COLUMN_MAX_NAME);
if (comments != NULL)
if ((comments != NULL) && (*comments != '\0'))
strncpy(header->comments, comments, COMMENTS_MAX_LENGTH);
// Store the associated column reference if needed // TODO discuss cases
if (data_type == OBI_QUAL)
{
if (associated_column_name == NULL)
if ((associated_column_name == NULL) || (*associated_column_name == '\0'))
{
obidebug(1, "\nError: The name of the associated column when creating a new column is NULL");
munmap(new_column->header, header_size);
......@@ -1306,11 +1310,11 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
nb_lines,
nb_elements_per_line,
(column_to_clone->header)->elements_names,
true,
(column_to_clone->header)->indexer_name,
((column_to_clone->header)->associated_column).column_name,
((column_to_clone->header)->associated_column).version,
(column_to_clone->header)->comments,
true
(column_to_clone->header)->comments
);
if (new_column == NULL)
......
......@@ -196,16 +196,16 @@ size_t obi_get_platform_header_size();
* @param dms A pointer on an OBIDMS.
* @param column_name The name of the new column.
* @param data_type The OBIType code of the data.
* @param nb_lines The number of lines to be stored.
* @param nb_elements_per_line The number of elements per line. // TODO talk about default values
* @param nb_lines The number of lines to be stored (can be 0 if not known).
* @param nb_elements_per_line The number of elements per line.
* @param elements_names The names of the elements with ';' as separator (no terminal ';'),
* NULL or "" if the default names are to be used ("0\01\02\0...\0n").
* @param elt_names_formatted Whether the separator for the elements names is ';' (false), or '\0' (true, as formatted by format_elements_names()).
* @param indexer_name The name of the indexer if there is one associated with the column.
* If NULL or "", the indexer name is set as the column name.
* @param associated_column_name The name of the associated column if there is one.
* @param associated_column_version The version of the associated column if there is one.
* @param comments Optional comments associated with the column.
* @param elt_names_formatted Whether the separator for the elements names is ';' (false), or '\0' (true, as formatted by format_elements_names()).
* @param associated_column_name The name of the associated column if there is one (otherwise NULL or "").
* @param associated_column_version The version of the associated column if there is one (otherwise -1).
* @param comments Optional comments associated with the column (NULL or "" if no comments associated).
*
* @returns A pointer on the newly created column structure.
* @retval NULL if an error occurred.
......@@ -219,11 +219,11 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
index_t nb_lines,
index_t nb_elements_per_line,
char* elements_names,
bool elt_names_formatted,
const char* indexer_name,
const char* associated_column_name,
obiversion_t associated_column_version,
const char* comments,
bool elt_names_formatted
const char* comments
);
......
......@@ -1619,7 +1619,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
// 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, NULL, NULL, NULL, -1, NULL, false);
view->line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, NULL, false, NULL, NULL, -1, NULL);
if ((view->line_selection) == NULL)
{
obidebug(1, "\nError creating a column corresponding to a line selection");
......@@ -1838,19 +1838,19 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
if (view_to_clone == NULL)
{
// Adding sequence column
if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, NUC_SEQUENCE_COLUMN, OBI_SEQ, 0, 1, NULL, "", NULL, -1, "Nucleotide sequences", true) < 0)
if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, NULL, OBI_SEQ, 0, 1, NULL, NULL, NULL, -1, "Nucleotide sequences", true) < 0)
{
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
return NULL;
}
// Adding id column
if (obi_view_add_column(view, ID_COLUMN, -1, ID_COLUMN, OBI_STR, 0, 1, NULL, "", NULL, -1, "Sequence identifiers", true) < 0)
if (obi_view_add_column(view, ID_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, NULL, NULL, -1, "Sequence identifiers", true) < 0)
{
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
return NULL;
}
// Adding definition column
if (obi_view_add_column(view, DEFINITION_COLUMN, -1, DEFINITION_COLUMN, OBI_STR, 0, 1, NULL, "", NULL, -1, "Definitions", true) < 0)
if (obi_view_add_column(view, DEFINITION_COLUMN, -1, NULL, OBI_STR, 0, 1, NULL, NULL, NULL, -1, "Definitions", true) < 0)
{
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
return NULL;
......@@ -1859,7 +1859,7 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
if (quality_column)
{
associated_nuc_column = obi_view_get_column(view, NUC_SEQUENCE_COLUMN);
if (obi_view_add_column(view, QUALITY_COLUMN, -1, QUALITY_COLUMN, OBI_QUAL, 0, 1, NULL, "", (associated_nuc_column->header)->name, (associated_nuc_column->header)->version, "Sequence qualities", true) < 0) // TODO discuss automatic association
if (obi_view_add_column(view, QUALITY_COLUMN, -1, NULL, OBI_QUAL, 0, 1, NULL, NULL, (associated_nuc_column->header)->name, (associated_nuc_column->header)->version, "Sequence qualities", true) < 0) // TODO discuss automatic association
{
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
return NULL;
......@@ -2265,7 +2265,7 @@ int obi_view_add_column(Obiview_p view,
// Open or create the column
if (create)
{ // Create column
column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, indexer_name, associated_column_name, associated_column_version, comments, false);
column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, false, indexer_name, associated_column_name, associated_column_version, comments);
if (column == NULL)
{
obidebug(1, "\nError creating a column to add to a view");
......@@ -2304,8 +2304,8 @@ int obi_view_add_column(Obiview_p view,
return -1;
}
// If an alias is not defined, it's the original name of the column. // TODO discuss
if (alias == NULL)
// If an alias is not defined, it's the original name of the column.
if ((alias == NULL) || (*alias == '\0'))
alias = column_name;
// Save column alias
......@@ -2411,6 +2411,12 @@ OBIDMS_column_p obi_view_get_column(Obiview_p view, const char* column_name)
}
OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const char* column_name)
{
return (OBIDMS_column_p*)(ht_get(view->column_dict, column_name));
}
bool obi_view_column_exists(Obiview_p view, const char* column_name)
{
if (obi_view_get_column(view, column_name) == NULL)
......@@ -2420,12 +2426,6 @@ bool obi_view_column_exists(Obiview_p view, const char* column_name)
}
OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const char* column_name)
{
return (OBIDMS_column_p*)(ht_get(view->column_dict, column_name));
}
int obi_view_create_column_alias(Obiview_p view, const char* current_name, const char* alias)
{
int i;
......
......@@ -344,16 +344,20 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name);
*
* @param view A pointer on the view.
* @param column_name The name of the column.
* @param version_number The version of the column if it should be opened and not created (if -1, the latest version is retrieved).
* @param version_number The version of the column if it should be opened and not created
* (if -1, the latest version is retrieved).
* @param alias The unique name used to identify the column in the context of this view.
* @param data_type The OBIType code of the data.
* @param nb_lines The number of lines to be stored.
* @param nb_elements_per_line The number of elements per line.
* If NULL or "", column_name is used.
* @param data_type The OBIType code of the data, if the column is created.
* @param nb_lines The number of lines to be stored (can be 0 if not known), if the column is created.
* @param nb_elements_per_line The number of elements per line, if the column is created.
* @param elements_names The names of the elements with ';' as separator (no terminal ';'),
* NULL or "" if the default names are to be used ("0;1;2;...;n").
* @param indexer_name The name of the indexer if there is one associated with the column.
* if the column is created; NULL or "" if the default names are to be used ("0\01\02\0...\0n").
* @param indexer_name The name of the indexer if there is one associated with the column, if the column is created.
* If NULL or "", the indexer name is set as the column name.
* @param comments Optional comments associated with the column if it is created.
* @param associated_column_name The name of the associated column if there is one (otherwise NULL or ""), if the column is created.
* @param associated_column_version The version of the associated column if there is one (otherwise -1), if the column is created.
* @param comments Optional comments associated with the column if it is created (NULL or "" if no comments associated).
* @param create Whether the column should be created (create == true) or opened (create == false).
*
* @returns A value indicating the success of the operation.
......
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