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

This commit is contained in:
Celine Mercier
2017-07-18 17:34:32 +02:00
parent c88df2e12c
commit 59dd0a8a8c
4 changed files with 47 additions and 39 deletions

View File

@ -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)