Columns are now enlarged if needed when setting a value
This commit is contained in:
@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
|
|||||||
|
|
||||||
cdef extern from "obidmscolumn_bool.h" nogil:
|
cdef extern from "obidmscolumn_bool.h" nogil:
|
||||||
|
|
||||||
int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value);
|
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value);
|
||||||
obibool_t obi_column_get_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
@ -6,7 +6,7 @@ from .capidmscolumn_bool cimport *
|
|||||||
cdef class OBIDMS_column_bool(OBIDMS_column) :
|
cdef class OBIDMS_column_bool(OBIDMS_column) :
|
||||||
|
|
||||||
def get_item(self, line_nb, element_name):
|
def get_item(self, line_nb, element_name):
|
||||||
return obi_column_get_bool_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
return obi_column_get_obibool_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
cdef class OBIDMS_column_bool_read(OBIDMS_column_bool) :
|
cdef class OBIDMS_column_bool_read(OBIDMS_column_bool) :
|
||||||
@ -22,7 +22,7 @@ cdef class OBIDMS_column_bool_read(OBIDMS_column_bool) :
|
|||||||
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool) :
|
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool) :
|
||||||
|
|
||||||
def set_item(self, line_nb, element_name, value):
|
def set_item(self, line_nb, element_name, value):
|
||||||
return obi_column_set_bool_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
return obi_column_set_obibool_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||||
|
@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
|
|||||||
|
|
||||||
cdef extern from "obidmscolumn_char.h" nogil:
|
cdef extern from "obidmscolumn_char.h" nogil:
|
||||||
|
|
||||||
int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value)
|
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value)
|
||||||
obichar_t* obi_column_get_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
obichar_t* obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||||
|
@ -6,7 +6,7 @@ from .capidmscolumn_char cimport *
|
|||||||
cdef class OBIDMS_column_char(OBIDMS_column) :
|
cdef class OBIDMS_column_char(OBIDMS_column) :
|
||||||
|
|
||||||
def get_item(self, line_nb, element_name):
|
def get_item(self, line_nb, element_name):
|
||||||
return (obi_column_get_char_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))).decode(encoding='utf-8')[:1]
|
return (obi_column_get_obichar_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))).decode(encoding='utf-8')[:1]
|
||||||
|
|
||||||
|
|
||||||
cdef class OBIDMS_column_char_read(OBIDMS_column_char) :
|
cdef class OBIDMS_column_char_read(OBIDMS_column_char) :
|
||||||
@ -22,7 +22,7 @@ cdef class OBIDMS_column_char_read(OBIDMS_column_char) :
|
|||||||
cdef class OBIDMS_column_char_writable(OBIDMS_column_char) :
|
cdef class OBIDMS_column_char_writable(OBIDMS_column_char) :
|
||||||
|
|
||||||
def set_item(self, line_nb, element_name, value):
|
def set_item(self, line_nb, element_name, value):
|
||||||
return obi_column_set_char_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value.encode('utf-8'))
|
return obi_column_set_obichar_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value.encode('utf-8'))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||||
|
@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
|
|||||||
|
|
||||||
cdef extern from "obidmscolumn_float.h" nogil:
|
cdef extern from "obidmscolumn_float.h" nogil:
|
||||||
|
|
||||||
int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value);
|
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value);
|
||||||
obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
@ -6,7 +6,7 @@ from .capidmscolumn_float cimport *
|
|||||||
cdef class OBIDMS_column_float(OBIDMS_column) :
|
cdef class OBIDMS_column_float(OBIDMS_column) :
|
||||||
|
|
||||||
def get_item(self, line_nb, element_name):
|
def get_item(self, line_nb, element_name):
|
||||||
return obi_column_get_float_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
return obi_column_get_obifloat_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
cdef class OBIDMS_column_float_read(OBIDMS_column_float) :
|
cdef class OBIDMS_column_float_read(OBIDMS_column_float) :
|
||||||
@ -22,7 +22,7 @@ cdef class OBIDMS_column_float_read(OBIDMS_column_float) :
|
|||||||
cdef class OBIDMS_column_float_writable(OBIDMS_column_float) :
|
cdef class OBIDMS_column_float_writable(OBIDMS_column_float) :
|
||||||
|
|
||||||
def set_item(self, line_nb, element_name, value):
|
def set_item(self, line_nb, element_name, value):
|
||||||
return obi_column_set_float_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
return obi_column_set_obifloat_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||||
|
@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
|
|||||||
|
|
||||||
cdef extern from "obidmscolumn_idx.h" nogil:
|
cdef extern from "obidmscolumn_idx.h" nogil:
|
||||||
|
|
||||||
int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value);
|
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value);
|
||||||
obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
@ -6,7 +6,7 @@ from .capidmscolumn_idx cimport *
|
|||||||
cdef class OBIDMS_column_idx(OBIDMS_column) :
|
cdef class OBIDMS_column_idx(OBIDMS_column) :
|
||||||
|
|
||||||
def get_item(self, line_nb, element_name):
|
def get_item(self, line_nb, element_name):
|
||||||
return obi_column_get_idx_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
return obi_column_get_obiidx_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
cdef class OBIDMS_column_idx_read(OBIDMS_column_idx) :
|
cdef class OBIDMS_column_idx_read(OBIDMS_column_idx) :
|
||||||
@ -22,7 +22,7 @@ cdef class OBIDMS_column_idx_read(OBIDMS_column_idx) :
|
|||||||
cdef class OBIDMS_column_idx_writable(OBIDMS_column_idx) :
|
cdef class OBIDMS_column_idx_writable(OBIDMS_column_idx) :
|
||||||
|
|
||||||
def set_item(self, line_nb, element_name, value):
|
def set_item(self, line_nb, element_name, value):
|
||||||
return obi_column_set_idx_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
return obi_column_set_obiidx_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||||
|
@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
|
|||||||
|
|
||||||
cdef extern from "obidmscolumn_int.h" nogil:
|
cdef extern from "obidmscolumn_int.h" nogil:
|
||||||
|
|
||||||
int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value);
|
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value);
|
||||||
obiint_t obi_column_get_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
@ -6,7 +6,7 @@ from .capidmscolumn_int cimport *
|
|||||||
cdef class OBIDMS_column_int(OBIDMS_column) :
|
cdef class OBIDMS_column_int(OBIDMS_column) :
|
||||||
|
|
||||||
def get_item(self, line_nb, element_name):
|
def get_item(self, line_nb, element_name):
|
||||||
return obi_column_get_int_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
return obi_column_get_obiint_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
cdef class OBIDMS_column_int_read(OBIDMS_column_int) :
|
cdef class OBIDMS_column_int_read(OBIDMS_column_int) :
|
||||||
@ -22,7 +22,7 @@ cdef class OBIDMS_column_int_read(OBIDMS_column_int) :
|
|||||||
cdef class OBIDMS_column_int_writable(OBIDMS_column_int) :
|
cdef class OBIDMS_column_int_writable(OBIDMS_column_int) :
|
||||||
|
|
||||||
def set_item(self, line_nb, element_name, value):
|
def set_item(self, line_nb, element_name, value):
|
||||||
return obi_column_set_int_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
return obi_column_set_obiint_with_elt_name(self.pointer, line_nb, element_name.encode('utf-8'), value)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||||
|
@ -600,7 +600,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
|||||||
int column_dir_file_descriptor;
|
int column_dir_file_descriptor;
|
||||||
size_t header_size;
|
size_t header_size;
|
||||||
size_t data_size;
|
size_t data_size;
|
||||||
size_t i, nb_elements;
|
|
||||||
|
|
||||||
new_column = NULL;
|
new_column = NULL;
|
||||||
|
|
||||||
@ -732,41 +731,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
|||||||
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
|
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
|
||||||
|
|
||||||
// Fill the data with NA values
|
// Fill the data with NA values
|
||||||
nb_elements = nb_lines*nb_elements_per_line;
|
obi_ini_to_NA_values (new_column, 0, nb_lines);
|
||||||
switch (type) {
|
|
||||||
case OBI_VOID: // TODO;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OBI_INT: for (i=0;i<nb_elements;i++)
|
|
||||||
{
|
|
||||||
*(((obiint_t*) (new_column->data)) + i) = OBIInt_NA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OBI_FLOAT: for (i=0;i<nb_elements;i++)
|
|
||||||
{
|
|
||||||
*(((obifloat_t*) (new_column->data)) + i) = OBIFloat_NA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OBI_BOOL: for (i=0;i<nb_elements;i++)
|
|
||||||
{
|
|
||||||
*(((obibool_t*) (new_column->data)) + i) = OBIBool_NA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OBI_CHAR: for (i=0;i<nb_elements;i++)
|
|
||||||
{
|
|
||||||
*(((obichar_t*) (new_column->data)) + i) = OBIChar_NA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OBI_IDX: for (i=0;i<nb_elements;i++)
|
|
||||||
{
|
|
||||||
*(((obiidx_t*) (new_column->data)) + i) = OBIIdx_NA;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(column_file_name);
|
free(column_file_name);
|
||||||
close(column_file_descriptor);
|
close(column_file_descriptor);
|
||||||
@ -1006,7 +971,7 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open the column file
|
// Open the column file
|
||||||
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDWR | O_CREAT);
|
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDWR);
|
||||||
if (column_file_descriptor < 0)
|
if (column_file_descriptor < 0)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
@ -1066,6 +1031,139 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int obi_enlarge_column(OBIDMS_column_p column)
|
||||||
|
{
|
||||||
|
size_t file_size;
|
||||||
|
size_t old_data_size;
|
||||||
|
size_t new_data_size;
|
||||||
|
size_t header_size;
|
||||||
|
size_t old_line_count;
|
||||||
|
size_t new_line_count;
|
||||||
|
int column_dir_file_descriptor;
|
||||||
|
int column_file_descriptor;
|
||||||
|
char* column_file_name;
|
||||||
|
|
||||||
|
// Get the file descriptor associated to the column directory
|
||||||
|
column_dir_file_descriptor = dirfd((column->column_directory)->directory);
|
||||||
|
if (column_dir_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError getting the file descriptor for a column directory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the column file name
|
||||||
|
column_file_name = build_column_file_name((column->header)->name, (column->header)->version);
|
||||||
|
if (column_file_name == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open the column file
|
||||||
|
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDWR | O_CREAT);
|
||||||
|
if (column_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError getting the file descriptor of a column file");
|
||||||
|
free(column_file_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the new file size
|
||||||
|
old_line_count = (column->header)->line_count;
|
||||||
|
new_line_count = old_line_count * GROWTH_FACTOR;
|
||||||
|
if (new_line_count > MAXIMUM_LINE_COUNT)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError enlarging a column file: new line count greater than the maximum allowed");
|
||||||
|
free(column_file_name);
|
||||||
|
close(column_file_descriptor);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
old_data_size = (column->header)->line_count * (column->header)->nb_elements_per_line * sizeof((column->header)->data_type);
|
||||||
|
new_data_size = old_data_size * GROWTH_FACTOR;
|
||||||
|
header_size = (column->header)->header_size;
|
||||||
|
file_size = header_size + new_data_size;
|
||||||
|
|
||||||
|
// Unmap the data
|
||||||
|
if (munmap(column->data, old_data_size) < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError munmapping the data of a column before enlarging");
|
||||||
|
free(column_file_name);
|
||||||
|
close(column_file_descriptor);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmap the header
|
||||||
|
if (munmap(column->header, header_size) < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError munmapping the header of a column before enlarging");
|
||||||
|
free(column_file_name);
|
||||||
|
close(column_file_descriptor);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlarge the file
|
||||||
|
if (ftruncate(column_file_descriptor, file_size) < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError enlarging a column file");
|
||||||
|
free(column_file_name);
|
||||||
|
close(column_file_descriptor);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remap the header (TODO not sure if necessary??)
|
||||||
|
column->header = mmap(NULL,
|
||||||
|
header_size,
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED,
|
||||||
|
column_file_descriptor,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (column->header == MAP_FAILED)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError mmapping the header of a column after enlarging file");
|
||||||
|
close(column_file_descriptor);
|
||||||
|
free(column_file_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remap the data
|
||||||
|
column->data = mmap(NULL,
|
||||||
|
new_data_size,
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED,
|
||||||
|
column_file_descriptor,
|
||||||
|
(column->header)->header_size
|
||||||
|
);
|
||||||
|
|
||||||
|
if (column->data == MAP_FAILED)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError re-mmapping the data of a column after enlarging the file");
|
||||||
|
free(column_file_name);
|
||||||
|
close(column_file_descriptor);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set new line count
|
||||||
|
(column->header)->line_count = new_line_count;
|
||||||
|
|
||||||
|
// Initialize new data lines to NA
|
||||||
|
obi_ini_to_NA_values(column, old_line_count, new_line_count - old_line_count);
|
||||||
|
|
||||||
|
free(column_file_name);
|
||||||
|
close(column_file_descriptor);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int obi_truncate_and_close_column(OBIDMS_column_p column)
|
int obi_truncate_and_close_column(OBIDMS_column_p column)
|
||||||
{
|
{
|
||||||
if (obi_truncate_column_to_lines_used(column) < 0)
|
if (obi_truncate_column_to_lines_used(column) < 0)
|
||||||
@ -1077,6 +1175,50 @@ int obi_truncate_and_close_column(OBIDMS_column_p column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void obi_ini_to_NA_values(OBIDMS_column_p column, size_t start, size_t nb_lines)
|
||||||
|
{
|
||||||
|
size_t i, end, nb_elements;
|
||||||
|
|
||||||
|
nb_elements = nb_lines*((column->header)->nb_elements_per_line);
|
||||||
|
end = start + nb_elements;
|
||||||
|
|
||||||
|
switch ((column->header)->data_type) {
|
||||||
|
case OBI_VOID: // TODO;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OBI_INT: for (i=start;i<end;i++)
|
||||||
|
{
|
||||||
|
*(((obiint_t*) (column->data)) + i) = OBIInt_NA;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OBI_FLOAT: for (i=start;i<end;i++)
|
||||||
|
{
|
||||||
|
*(((obifloat_t*) (column->data)) + i) = OBIFloat_NA;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OBI_BOOL: for (i=start;i<end;i++)
|
||||||
|
{
|
||||||
|
*(((obibool_t*) (column->data)) + i) = OBIBool_NA;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OBI_CHAR: for (i=start;i<end;i++)
|
||||||
|
{
|
||||||
|
*(((obichar_t*) (column->data)) + i) = OBIChar_NA;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OBI_IDX: for (i=start;i<end;i++)
|
||||||
|
{
|
||||||
|
*(((obiidx_t*) (column->data)) + i) = OBIIdx_NA;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void obi_column_make_unwritable(OBIDMS_column_p column)
|
void obi_column_make_unwritable(OBIDMS_column_p column)
|
||||||
{
|
{
|
||||||
column->writable = false;
|
column->writable = false;
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#define ELEMENTS_NAMES_MAX (2048)
|
#define ELEMENTS_NAMES_MAX (2048)
|
||||||
#define INITIAL_LINE_COUNT (1000)
|
#define INITIAL_LINE_COUNT (1000)
|
||||||
|
#define GROWTH_FACTOR (2)
|
||||||
|
#define MAXIMUM_LINE_COUNT (1000000)
|
||||||
|
|
||||||
|
|
||||||
typedef int32_t obiversion_t; /**< Used to store the column version number
|
typedef int32_t obiversion_t; /**< Used to store the column version number
|
||||||
@ -205,6 +207,20 @@ int obi_close_column(OBIDMS_column_p column);
|
|||||||
int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
|
int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enlarges a column file.
|
||||||
|
*
|
||||||
|
* @param column a pointer on an OBIDMS column
|
||||||
|
*
|
||||||
|
* @return 0 if the operation was successfully completed
|
||||||
|
* @return -1 if an error occurred
|
||||||
|
*
|
||||||
|
* @since August 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
int obi_enlarge_column(OBIDMS_column_p column);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Truncates a column file to the number of lines used and closes it.
|
* @brief Truncates a column file to the number of lines used and closes it.
|
||||||
*
|
*
|
||||||
@ -219,6 +235,19 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
|
|||||||
int obi_truncate_and_close_column(OBIDMS_column_p column);
|
int obi_truncate_and_close_column(OBIDMS_column_p column);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief Sets the data in a column to the NA value of the data type.
|
||||||
|
*
|
||||||
|
* @param column a pointer on an OBIDMS column
|
||||||
|
* @param start the first line number of the block that should be set
|
||||||
|
* @param nb_lines the number of lines that should be set
|
||||||
|
*
|
||||||
|
* @since August 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
void obi_ini_to_NA_values(OBIDMS_column_p column, size_t start, size_t nb_lines);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the 'writable' header attribute of an OBIDMS column to False.
|
* @brief Sets the 'writable' header attribute of an OBIDMS column to False.
|
||||||
*
|
*
|
||||||
|
@ -28,23 +28,47 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
int obi_column_set_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value)
|
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value)
|
||||||
{
|
{
|
||||||
|
// Check that the line number is not greater than the maximum allowed
|
||||||
|
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the file needs to be enlarged
|
||||||
|
while ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
// Enlarge the file
|
||||||
|
if (obi_enlarge_column(column) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Update lines used
|
// Update lines used
|
||||||
if ((line_nb+1) > (column->header)->lines_used)
|
if ((line_nb+1) > (column->header)->lines_used)
|
||||||
(column->header)->lines_used = line_nb+1;
|
(column->header)->lines_used = line_nb+1;
|
||||||
|
|
||||||
|
// Set the value
|
||||||
*(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
*(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obibool_t obi_column_get_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||||
{
|
{
|
||||||
|
if ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||||
|
return -1; // TODO return NA value?
|
||||||
|
}
|
||||||
return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value)
|
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -66,13 +90,13 @@ int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, ch
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
obi_column_set_bool_with_elt_idx(column, line_nb, element_idx, value);
|
obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obibool_t obi_column_get_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -94,5 +118,6 @@ obibool_t obi_column_get_bool_with_elt_name(OBIDMS_column_p column, size_t line_
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return obi_column_get_bool_with_elt_idx(column, line_nb, element_idx);
|
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value);
|
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +54,7 @@ int obi_column_set_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, siz
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obibool_t obi_column_get_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +78,7 @@ obibool_t obi_column_get_bool_with_elt_idx(OBIDMS_column_p column, size_t line_n
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value);
|
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,5 +97,5 @@ int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, ch
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obibool_t obi_column_get_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
|
||||||
|
@ -28,23 +28,47 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
int obi_column_set_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value)
|
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t value)
|
||||||
{
|
{
|
||||||
|
// Check that the line number is not greater than the maximum allowed
|
||||||
|
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the file needs to be enlarged
|
||||||
|
while ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
// Enlarge the file
|
||||||
|
if (obi_enlarge_column(column) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Update lines used
|
// Update lines used
|
||||||
if ((line_nb+1) > (column->header)->lines_used)
|
if ((line_nb+1) > (column->header)->lines_used)
|
||||||
(column->header)->lines_used = line_nb+1;
|
(column->header)->lines_used = line_nb+1;
|
||||||
*(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value[0];
|
|
||||||
|
// Set the value
|
||||||
|
*(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obichar_t* obi_column_get_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||||
{
|
{
|
||||||
return ((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx;
|
if ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||||
|
return '\0'; // TODO return NA value?
|
||||||
|
}
|
||||||
|
return *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value)
|
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t value)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -66,13 +90,13 @@ int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, ch
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
obi_column_set_char_with_elt_idx(column, line_nb, element_idx, value);
|
obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obichar_t* obi_column_get_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -84,15 +108,16 @@ obichar_t* obi_column_get_char_with_elt_name(OBIDMS_column_p column, size_t line
|
|||||||
{
|
{
|
||||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obidebug(1, "\nAn element name must be specified");
|
obidebug(1, "\nAn element name must be specified");
|
||||||
return NULL;
|
return '\0'; // TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||||
if (element_idx == -1)
|
if (element_idx == -1)
|
||||||
return NULL;
|
return '\0'; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
return obi_column_get_char_with_elt_idx(column, line_nb, element_idx);
|
return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value);
|
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +54,7 @@ int obi_column_set_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, siz
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obichar_t* obi_column_get_char_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
obichar_t* obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +78,7 @@ obichar_t* obi_column_get_char_with_elt_idx(OBIDMS_column_p column, size_t line_
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value);
|
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t* value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,5 +97,5 @@ int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, ch
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obichar_t* obi_column_get_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obichar_t* obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
|
||||||
|
@ -28,23 +28,47 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
int obi_column_set_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value)
|
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value)
|
||||||
{
|
{
|
||||||
|
// Check that the line number is not greater than the maximum allowed
|
||||||
|
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the file needs to be enlarged
|
||||||
|
while ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
// Enlarge the file
|
||||||
|
if (obi_enlarge_column(column) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Update lines used
|
// Update lines used
|
||||||
if ((line_nb+1) > (column->header)->lines_used)
|
if ((line_nb+1) > (column->header)->lines_used)
|
||||||
(column->header)->lines_used = line_nb+1;
|
(column->header)->lines_used = line_nb+1;
|
||||||
|
|
||||||
|
// Set the value
|
||||||
*(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
*(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obifloat_t obi_column_get_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||||
{
|
{
|
||||||
|
if ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||||
|
return -1; // TODO return NA value?
|
||||||
|
}
|
||||||
return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value)
|
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -66,13 +90,13 @@ int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, c
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
obi_column_set_float_with_elt_idx(column, line_nb, element_idx, value);
|
obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -94,5 +118,6 @@ obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t lin
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return obi_column_get_float_with_elt_idx(column, line_nb, element_idx);
|
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value);
|
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +54,7 @@ int obi_column_set_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, si
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obifloat_t obi_column_get_float_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +78,7 @@ obifloat_t obi_column_get_float_with_elt_idx(OBIDMS_column_p column, size_t line
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value);
|
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,5 +97,5 @@ int obi_column_set_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, c
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obifloat_t obi_column_get_float_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
|
||||||
|
@ -28,23 +28,47 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
int obi_column_set_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value)
|
int obi_column_set_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value)
|
||||||
{
|
{
|
||||||
|
// Check that the line number is not greater than the maximum allowed
|
||||||
|
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the file needs to be enlarged
|
||||||
|
while ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
// Enlarge the file
|
||||||
|
if (obi_enlarge_column(column) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Update lines used
|
// Update lines used
|
||||||
if ((line_nb+1) > (column->header)->lines_used)
|
if ((line_nb+1) > (column->header)->lines_used)
|
||||||
(column->header)->lines_used = line_nb+1;
|
(column->header)->lines_used = line_nb+1;
|
||||||
|
|
||||||
|
// Set the value
|
||||||
*(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
*(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obiidx_t obi_column_get_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
obiidx_t obi_column_get_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||||
{
|
{
|
||||||
|
if ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||||
|
return -1; // TODO return NA value?
|
||||||
|
}
|
||||||
return *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
return *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value)
|
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -66,13 +90,13 @@ int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, cha
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
obi_column_set_idx_with_elt_idx(column, line_nb, element_idx, value);
|
obi_column_set_obiidx_with_elt_idx(column, line_nb, element_idx, value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -94,5 +118,6 @@ obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return obi_column_get_idx_with_elt_idx(column, line_nb, element_idx);
|
return obi_column_get_obiidx_with_elt_idx(column, line_nb, element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value);
|
int obi_column_set_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +54,7 @@ int obi_column_set_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obiidx_t obi_column_get_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
obiidx_t obi_column_get_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +78,7 @@ obiidx_t obi_column_get_idx_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value);
|
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,5 +97,5 @@ int obi_column_set_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, cha
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obiidx_t obi_column_get_idx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
|
||||||
|
@ -28,23 +28,47 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
int obi_column_set_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value)
|
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value)
|
||||||
{
|
{
|
||||||
|
// Check that the line number is not greater than the maximum allowed
|
||||||
|
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the file needs to be enlarged
|
||||||
|
while ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
// Enlarge the file
|
||||||
|
if (obi_enlarge_column(column) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Update lines used
|
// Update lines used
|
||||||
if ((line_nb+1) > (column->header)->lines_used)
|
if ((line_nb+1) > (column->header)->lines_used)
|
||||||
(column->header)->lines_used = line_nb+1;
|
(column->header)->lines_used = line_nb+1;
|
||||||
|
|
||||||
|
// Set the value
|
||||||
*(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
*(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obiint_t obi_column_get_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||||
{
|
{
|
||||||
|
if ((line_nb+1) > (column->header)->line_count)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError trying to get a value that is beyond the current line count");
|
||||||
|
return -1; // TODO return NA value?
|
||||||
|
}
|
||||||
return *(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
return *(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value)
|
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -66,13 +90,13 @@ int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, cha
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
obi_column_set_int_with_elt_idx(column, line_nb, element_idx, value);
|
obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
obiint_t obi_column_get_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||||
{
|
{
|
||||||
size_t element_idx;
|
size_t element_idx;
|
||||||
|
|
||||||
@ -94,6 +118,6 @@ obiint_t obi_column_get_int_with_elt_name(OBIDMS_column_p column, size_t line_nb
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return obi_column_get_int_with_elt_idx(column, line_nb, element_idx);
|
return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value);
|
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +54,7 @@ int obi_column_set_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size
|
|||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obiint_t obi_column_get_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,7 +78,7 @@ obiint_t obi_column_get_int_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value);
|
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,5 +97,5 @@ int obi_column_set_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, cha
|
|||||||
* @since August 2015
|
* @since August 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
obiint_t obi_column_get_int_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user