The default element names for columns with multiple elements per line
are now "O;1;2;...;n"
This commit is contained in:
@ -422,10 +422,18 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
|
||||
|
||||
int obi_column_set_elements_names(OBIDMS_column_p column, const char* elements_names)
|
||||
{
|
||||
if (strlen(elements_names) > ELEMENTS_NAMES_MAX)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError: element names too long (max: %d)", ELEMENTS_NAMES_MAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy((column->header)->elements_names, elements_names);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
index_t get_line_count_per_page(OBIType_t data_type, index_t nb_elements_per_line)
|
||||
{
|
||||
return getpagesize() / (obi_sizeof(data_type) * nb_elements_per_line);
|
||||
@ -543,6 +551,37 @@ size_t obi_get_platform_header_size()
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
char* build_default_elements_names(index_t nb_elements_per_line)
|
||||
{
|
||||
char* elements_names;
|
||||
int i;
|
||||
|
||||
elements_names = (char*) malloc(ELEMENTS_NAMES_MAX * sizeof(char));
|
||||
if (elements_names == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError allocating memory for elements names");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (nb_elements_per_line > NB_ELTS_MAX_IF_DEFAULT_NAME)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError: too many elements per line to use the default names (max = %d elements)", NB_ELTS_MAX_IF_DEFAULT_NAME);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i= 0; i < nb_elements_per_line; i++)
|
||||
sprintf(elements_names, "%d", i);
|
||||
|
||||
// Terminal character
|
||||
elements_names[strlen(elements_names)] = '\0';
|
||||
|
||||
return elements_names;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
OBIType_t data_type,
|
||||
@ -574,16 +613,19 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
// Check that the informations given are not NULL/invalid/greater than the allowed sizes
|
||||
if (dms == NULL)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nCan't create column because of invalid DMS");
|
||||
return NULL;
|
||||
}
|
||||
if (column_name == NULL)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
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
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nCan't create column because of invalid data type");
|
||||
return NULL;
|
||||
}
|
||||
@ -637,14 +679,15 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
else if (nb_lines < minimum_line_count)
|
||||
nb_lines = minimum_line_count;
|
||||
|
||||
// The number of elements names should be equal to the number of elements per line
|
||||
if ((elements_names == NULL) && (nb_elements_per_line > 1))
|
||||
// Check and build if needed the element names
|
||||
if ((elements_names == NULL) || (strcmp(elements_names, "") == 0)) // Build the default element names: str of the element index
|
||||
{
|
||||
obidebug(1, "\nCan't create column because no elements names were given for a number of elements per line greater than 1");
|
||||
return NULL;
|
||||
elements_names = build_default_elements_names(nb_elements_per_line);
|
||||
if (elements_names == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else if ((elements_names != NULL) && (nb_elements_per_line > 1))
|
||||
{
|
||||
else if (((elements_names == NULL) || (strcmp(elements_names, "") != 0)) && (nb_elements_per_line > 1))
|
||||
{ // The number of elements names should be equal to the number of elements per line
|
||||
char* token;
|
||||
index_t n = 0;
|
||||
token = strdup(elements_names);
|
||||
@ -660,11 +703,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if ((nb_elements_per_line == 1) && (strcmp(elements_names, column_name) != 0)) // TODO Discuss, maybe just make it the column name
|
||||
{
|
||||
obidebug(1, "\nCan't create column because the element name does not match the column name");
|
||||
return NULL;
|
||||
}
|
||||
// TODO what if 1 element and name specified? doc
|
||||
|
||||
// Calculate the size needed
|
||||
header_size = obi_get_platform_header_size();
|
||||
@ -1060,7 +1099,7 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
for (i=0; i<((line_selection->header)->lines_used); i++)
|
||||
{
|
||||
// Get the index in the line selection column
|
||||
index = obi_column_get_index(line_selection, i);
|
||||
index = obi_column_get_index_with_elt_idx(line_selection, i, 0);
|
||||
// Copy the line at the index in the column to clone to the new column
|
||||
memcpy((new_column->data)+(i*line_size), (column_to_clone->data)+(index*line_size), line_size);
|
||||
}
|
||||
@ -1590,7 +1629,7 @@ int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb)
|
||||
}
|
||||
|
||||
|
||||
int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb) // TODO problem with some columns in a view being empty or shorter and triggering an error because they've been truncated when the view was closed. Fixed with obiview.c in update_lines() for now
|
||||
int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb)
|
||||
{
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
|
Reference in New Issue
Block a user