Major update: obiarrays with columns containing indices referring to

character strings.
This commit is contained in:
Celine Mercier
2015-11-06 17:55:15 +01:00
parent 456551ffeb
commit 9b066f4327
35 changed files with 632 additions and 532 deletions

View File

@ -2,7 +2,7 @@
from .capi.obidms cimport OBIDMS_p from .capi.obidms cimport OBIDMS_p
from .capi.obidmscolumn cimport OBIDMS_column_p from .capi.obidmscolumn cimport OBIDMS_column_p
from .capi.obitypes cimport obiversion_t, OBIType_t from .capi.obitypes cimport obiversion_t, OBIType_t, index_t
cdef class OBIDMS_column cdef class OBIDMS_column
@ -21,8 +21,8 @@ cdef class OBIDMS:
bint clone=*, bint clone_data=*, bint clone=*, bint clone_data=*,
obiversion_t version_number=*, obiversion_t version_number=*,
OBIType_t data_type=*, OBIType_t data_type=*,
size_t nb_lines=*, index_t nb_lines=*,
size_t nb_elements_per_line=*, index_t nb_elements_per_line=*,
list elements_names=*, list elements_names=*,
str array_name=*) str array_name=*)
@ -34,14 +34,14 @@ cdef class OBIDMS_column:
cdef str data_type # TODO keep as OBIType_t? both? cdef str data_type # TODO keep as OBIType_t? both?
cdef str dms_name cdef str dms_name
cdef str column_name cdef str column_name
cdef size_t nb_elements_per_line cdef index_t nb_elements_per_line
cdef list elements_names cdef list elements_names
# cpdef object get_item(self, size_t line_nb, str element_name) TODO can't declare because not the same in all subclasses # cpdef object get_item(self, index_t line_nb, str element_name) TODO can't declare because not the same in all subclasses
# cpdef set_item(self, size_t line_nb, str element_name, object value) TODO can't declare because object value # cpdef set_item(self, index_t line_nb, str element_name, object value) TODO can't declare because object value
cpdef list get_elements_names(self) cpdef list get_elements_names(self)
cpdef str get_data_type(self) cpdef str get_data_type(self)
cpdef size_t get_nb_lines_used(self) cpdef index_t get_nb_lines_used(self)
cpdef str get_creation_date(self) cpdef str get_creation_date(self)
cpdef close(self) cpdef close(self)

View File

@ -80,7 +80,7 @@ cdef class OBIDMS :
cdef str data_type cdef str data_type
cdef str creation_date cdef str creation_date
cdef obiversion_t latest_version cdef obiversion_t latest_version
cdef size_t line_count cdef index_t line_count
cdef OBIDMS_column_header_p header cdef OBIDMS_column_header_p header
p = Path(self.dms_name+'.obidms') p = Path(self.dms_name+'.obidms')
@ -117,8 +117,8 @@ cdef class OBIDMS :
bint clone=False, bint clone_data=True, bint clone=False, bint clone_data=True,
obiversion_t version_number=-1, obiversion_t version_number=-1,
OBIType_t data_type= <OBIType_t> 0, OBIType_t data_type= <OBIType_t> 0,
size_t nb_lines=0, index_t nb_lines=0,
size_t nb_elements_per_line=0, index_t nb_elements_per_line=0,
list elements_names=None, list elements_names=None,
str array_name="default_obiarray"): str array_name="default_obiarray"):
@ -222,7 +222,7 @@ cdef class OBIDMS :
version_number, data_type, version_number, data_type,
nb_lines, nb_elements_per_line, nb_lines, nb_elements_per_line,
elements_names, array_name) elements_names, array_name)
return column return column
@ -237,8 +237,8 @@ cdef class OBIDMS_column :
bint clone, bint clone_data, bint clone, bint clone_data,
obiversion_t version_number, obiversion_t version_number,
OBIType_t type, OBIType_t type,
size_t nb_lines, index_t nb_lines,
size_t nb_elements_per_line, index_t nb_elements_per_line,
list elements_names, list elements_names,
str array_name): str array_name):
@ -279,8 +279,8 @@ cdef class OBIDMS_column :
def __iter__(self): def __iter__(self):
# Declarations # Declarations
cdef size_t lines_used cdef index_t lines_used
cdef size_t line_nb cdef index_t line_nb
# Yield each line # Yield each line
lines_used = self.pointer.header.lines_used lines_used = self.pointer.header.lines_used
@ -288,19 +288,19 @@ cdef class OBIDMS_column :
yield self.get_line(line_nb) yield self.get_line(line_nb)
def __setitem__(self, size_t line_nb, object value): def __setitem__(self, index_t line_nb, object value):
self.set_line(line_nb, value) self.set_line(line_nb, value)
def __getitem__(self, size_t line_nb): def __getitem__(self, index_t line_nb):
return self.get_line(line_nb) return self.get_line(line_nb)
# cpdef object get_item(self, size_t line_nb, str element_name): TODO # cpdef object get_item(self, index_t line_nb, str element_name): TODO
# raise NotImplementedError # raise NotImplementedError
# cpdef set_item(self, size_t line_nb, str element_name, object value): TODO # cpdef set_item(self, index_t line_nb, str element_name, object value): TODO
# raise NotImplementedError # raise NotImplementedError
@ -312,7 +312,7 @@ cdef class OBIDMS_column :
return self.data_type return self.data_type
cpdef size_t get_nb_lines_used(self): cpdef index_t get_nb_lines_used(self):
return self.pointer.header.lines_used return self.pointer.header.lines_used

View File

@ -1,25 +1,25 @@
#cython: language_level=3 #cython: language_level=3
from .capi.obitypes cimport obibool_t from .capi.obitypes cimport obibool_t, index_t
from ._obidms cimport OBIDMS_column from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_bool(OBIDMS_column): cdef class OBIDMS_column_bool(OBIDMS_column):
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool): cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool): cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
cpdef object get_item(self, size_t line_nb, str element_name) cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value) cpdef set_item(self, index_t line_nb, str element_name, obibool_t value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts): cdef class OBIDMS_column_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value) cpdef set_item(self, index_t line_nb, str element_name, obibool_t value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cpdef close(self) cpdef close(self)

View File

@ -16,7 +16,7 @@ from cpython.bool cimport PyBool_FromLong
cdef class OBIDMS_column_bool(OBIDMS_column): cdef class OBIDMS_column_bool(OBIDMS_column):
cpdef object get_line(self, size_t line_nb): cpdef object get_line(self, index_t line_nb):
cdef obibool_t value cdef obibool_t value
cdef object result cdef object result
value = obi_column_get_obibool_with_elt_idx(self.pointer, line_nb, 0) value = obi_column_get_obibool_with_elt_idx(self.pointer, line_nb, 0)
@ -28,7 +28,7 @@ cdef class OBIDMS_column_bool(OBIDMS_column):
result = PyBool_FromLong(value) result = PyBool_FromLong(value)
return result return result
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef close(self): cpdef close(self):
@ -38,7 +38,7 @@ cdef class OBIDMS_column_bool(OBIDMS_column):
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool): cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obibool_with_elt_idx(self.pointer, line_nb, 0, <obibool_t> value) < 0: if obi_column_set_obibool_with_elt_idx(self.pointer, line_nb, 0, <obibool_t> value) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
@ -49,7 +49,7 @@ cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool): cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
cpdef object get_item(self, size_t line_nb, str element_name): cpdef object get_item(self, index_t line_nb, str element_name):
cdef obibool_t value cdef obibool_t value
cdef object result cdef object result
value = obi_column_get_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name)) value = obi_column_get_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
@ -61,10 +61,10 @@ cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
result = PyBool_FromLong(value) result = PyBool_FromLong(value)
return result return result
cpdef object get_line(self, size_t line_nb) : cpdef object get_line(self, index_t line_nb) :
cdef obibool_t value cdef obibool_t value
cdef object result cdef object result
cdef size_t i cdef index_t i
cdef bint all_NA cdef bint all_NA
result = {} result = {}
all_NA = True all_NA = True
@ -79,20 +79,20 @@ cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
result = None result = None
return result return result
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value): cpdef set_item(self, index_t line_nb, str element_name, obibool_t value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cdef class OBIDMS_column_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts): cdef class OBIDMS_column_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value): cpdef set_item(self, index_t line_nb, str element_name, obibool_t value):
if obi_column_set_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0: if obi_column_set_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
cdef obibool_t value cdef obibool_t value
for element_name in values : for element_name in values :
value = <obibool_t> values[element_name] value = <obibool_t> values[element_name]

View File

@ -1,25 +1,25 @@
#cython: language_level=3 #cython: language_level=3
from .capi.obitypes cimport obichar_t from .capi.obitypes cimport obichar_t, index_t
from ._obidms cimport OBIDMS_column from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_char(OBIDMS_column): cdef class OBIDMS_column_char(OBIDMS_column):
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_char_writable(OBIDMS_column_char): cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char): cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
cpdef object get_item(self, size_t line_nb, str element_name) cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, bytes value) cpdef set_item(self, index_t line_nb, str element_name, bytes value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts): cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, bytes value) cpdef set_item(self, index_t line_nb, str element_name, bytes value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cpdef close(self) cpdef close(self)

View File

@ -14,7 +14,7 @@ from obitools3.utils cimport str2bytes
cdef class OBIDMS_column_char(OBIDMS_column): cdef class OBIDMS_column_char(OBIDMS_column):
cpdef object get_line(self, size_t line_nb): cpdef object get_line(self, index_t line_nb):
cdef obichar_t value cdef obichar_t value
cdef object result cdef object result
value = obi_column_get_obichar_with_elt_idx(self.pointer, line_nb, 0) value = obi_column_get_obichar_with_elt_idx(self.pointer, line_nb, 0)
@ -26,7 +26,7 @@ cdef class OBIDMS_column_char(OBIDMS_column):
result = <bytes> value result = <bytes> value
return result return result
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef close(self): cpdef close(self):
@ -36,7 +36,7 @@ cdef class OBIDMS_column_char(OBIDMS_column):
cdef class OBIDMS_column_char_writable(OBIDMS_column_char): cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obichar_with_elt_idx(self.pointer, line_nb, 0, <bytes> value[0]) < 0: if obi_column_set_obichar_with_elt_idx(self.pointer, line_nb, 0, <bytes> value[0]) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
@ -47,7 +47,7 @@ cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char): cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
cpdef object get_item(self, size_t line_nb, str element_name): cpdef object get_item(self, index_t line_nb, str element_name):
cdef obichar_t value cdef obichar_t value
cdef object result cdef object result
value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name)) value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
@ -59,10 +59,10 @@ cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
result = <bytes> value result = <bytes> value
return result return result
cpdef object get_line(self, size_t line_nb) : cpdef object get_line(self, index_t line_nb) :
cdef obichar_t value cdef obichar_t value
cdef object result cdef object result
cdef size_t i cdef index_t i
cdef bint all_NA cdef bint all_NA
result = {} result = {}
all_NA = True all_NA = True
@ -77,20 +77,20 @@ cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
result = None result = None
return result return result
cpdef set_item(self, size_t line_nb, str element_name, bytes value): cpdef set_item(self, index_t line_nb, str element_name, bytes value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts): cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, bytes value): cpdef set_item(self, index_t line_nb, str element_name, bytes value):
if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 0: if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
cdef bytes value cdef bytes value
for element_name in values : for element_name in values :
value = <bytes> values[element_name] value = <bytes> values[element_name]
@ -106,7 +106,7 @@ cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts)
# cdef class OBIDMS_column_char(OBIDMS_column) : # cdef class OBIDMS_column_char(OBIDMS_column) :
# #
# cpdef object get_item(self, size_t line_nb, str element_name): # cpdef object get_item(self, index_t line_nb, str element_name):
# cdef char value # cdef char value
# cdef object result # cdef object result
# value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name)) # value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
@ -118,7 +118,7 @@ cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts)
# result = <bytes> value # result = <bytes> value
# return result # return result
# #
# cpdef set_item(self, size_t line_nb, str element_name, bytes value): # cpdef set_item(self, index_t line_nb, str element_name, bytes value):
# raise Exception("Column is read-only") # raise Exception("Column is read-only")
# #
# cpdef close(self): # cpdef close(self):
@ -128,7 +128,7 @@ cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts)
# #
# cdef class OBIDMS_column_char_writable(OBIDMS_column_char) : # cdef class OBIDMS_column_char_writable(OBIDMS_column_char) :
# #
# cpdef set_item(self, size_t line_nb, str element_name, bytes value): # cpdef set_item(self, index_t line_nb, str element_name, bytes value):
# if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 0: # if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 0:
# raise Exception("Problem setting a value in a column") # raise Exception("Problem setting a value in a column")
# #

View File

@ -1,25 +1,25 @@
#cython: language_level=3 #cython: language_level=3
from .capi.obitypes cimport obifloat_t from .capi.obitypes cimport obifloat_t, index_t
from ._obidms cimport OBIDMS_column from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_float(OBIDMS_column): cdef class OBIDMS_column_float(OBIDMS_column):
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_float_writable(OBIDMS_column_float): cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float): cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
cpdef object get_item(self, size_t line_nb, str element_name) cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value) cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_float_multi_elts_writable(OBIDMS_column_float_multi_elts): cdef class OBIDMS_column_float_multi_elts_writable(OBIDMS_column_float_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value) cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cpdef close(self) cpdef close(self)

View File

@ -14,7 +14,7 @@ from obitools3.utils cimport str2bytes
cdef class OBIDMS_column_float(OBIDMS_column): cdef class OBIDMS_column_float(OBIDMS_column):
cpdef object get_line(self, size_t line_nb): cpdef object get_line(self, index_t line_nb):
cdef obifloat_t value cdef obifloat_t value
cdef object result cdef object result
value = obi_column_get_obifloat_with_elt_idx(self.pointer, line_nb, 0) value = obi_column_get_obifloat_with_elt_idx(self.pointer, line_nb, 0)
@ -26,7 +26,7 @@ cdef class OBIDMS_column_float(OBIDMS_column):
result = <double> value result = <double> value
return result return result
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef close(self): cpdef close(self):
@ -36,7 +36,7 @@ cdef class OBIDMS_column_float(OBIDMS_column):
cdef class OBIDMS_column_float_writable(OBIDMS_column_float): cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obifloat_with_elt_idx(self.pointer, line_nb, 0, <obifloat_t> value) < 0: if obi_column_set_obifloat_with_elt_idx(self.pointer, line_nb, 0, <obifloat_t> value) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
@ -47,7 +47,7 @@ cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float): cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
cpdef object get_item(self, size_t line_nb, str element_name): cpdef object get_item(self, index_t line_nb, str element_name):
cdef obifloat_t value cdef obifloat_t value
cdef object result cdef object result
value = obi_column_get_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name)) value = obi_column_get_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
@ -59,10 +59,10 @@ cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
result = <double> value result = <double> value
return result return result
cpdef object get_line(self, size_t line_nb) : cpdef object get_line(self, index_t line_nb) :
cdef obifloat_t value cdef obifloat_t value
cdef object result cdef object result
cdef size_t i cdef index_t i
cdef bint all_NA cdef bint all_NA
result = {} result = {}
all_NA = True all_NA = True
@ -77,20 +77,20 @@ cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
result = None result = None
return result return result
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value): cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cdef class OBIDMS_column_float_multi_elts_writable(OBIDMS_column_float_multi_elts): cdef class OBIDMS_column_float_multi_elts_writable(OBIDMS_column_float_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value): cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value):
if obi_column_set_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0: if obi_column_set_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
cdef obifloat_t value cdef obifloat_t value
for element_name in values : for element_name in values :
value = <obifloat_t> values[element_name] value = <obifloat_t> values[element_name]

View File

@ -1,25 +1,25 @@
#cython: language_level=3 #cython: language_level=3
from .capi.obitypes cimport obiint_t from .capi.obitypes cimport obiint_t, index_t
from ._obidms cimport OBIDMS_column from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_int(OBIDMS_column): cdef class OBIDMS_column_int(OBIDMS_column):
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_int_writable(OBIDMS_column_int): cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int): cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
cpdef object get_item(self, size_t line_nb, str element_name) cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value) cpdef set_item(self, index_t line_nb, str element_name, obiint_t value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts): cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value) cpdef set_item(self, index_t line_nb, str element_name, obiint_t value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cpdef close(self) cpdef close(self)

View File

@ -16,7 +16,7 @@ from cpython.int cimport PyInt_FromLong
cdef class OBIDMS_column_int(OBIDMS_column): cdef class OBIDMS_column_int(OBIDMS_column):
cpdef object get_line(self, size_t line_nb): cpdef object get_line(self, index_t line_nb):
cdef obiint_t value cdef obiint_t value
cdef object result cdef object result
value = obi_column_get_obiint_with_elt_idx(self.pointer, line_nb, 0) value = obi_column_get_obiint_with_elt_idx(self.pointer, line_nb, 0)
@ -28,7 +28,7 @@ cdef class OBIDMS_column_int(OBIDMS_column):
result = PyInt_FromLong(value) result = PyInt_FromLong(value)
return result return result
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef close(self): cpdef close(self):
@ -38,7 +38,7 @@ cdef class OBIDMS_column_int(OBIDMS_column):
cdef class OBIDMS_column_int_writable(OBIDMS_column_int): cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obiint_with_elt_idx(self.pointer, line_nb, 0, <obiint_t> value) < 0: if obi_column_set_obiint_with_elt_idx(self.pointer, line_nb, 0, <obiint_t> value) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
@ -49,7 +49,7 @@ cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int): cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
cpdef object get_item(self, size_t line_nb, str element_name): cpdef object get_item(self, index_t line_nb, str element_name):
cdef obiint_t value cdef obiint_t value
cdef object result cdef object result
value = obi_column_get_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name)) value = obi_column_get_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
@ -61,10 +61,10 @@ cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
result = PyInt_FromLong(value) result = PyInt_FromLong(value)
return result return result
cpdef object get_line(self, size_t line_nb) : cpdef object get_line(self, index_t line_nb) :
cdef obiint_t value cdef obiint_t value
cdef object result cdef object result
cdef size_t i cdef index_t i
cdef bint all_NA cdef bint all_NA
result = {} result = {}
all_NA = True all_NA = True
@ -79,20 +79,20 @@ cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
result = None result = None
return result return result
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value): cpdef set_item(self, index_t line_nb, str element_name, obiint_t value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts): cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value): cpdef set_item(self, index_t line_nb, str element_name, obiint_t value):
if obi_column_set_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0: if obi_column_set_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
cdef obiint_t value cdef obiint_t value
for element_name in values : for element_name in values :
value = <obiint_t> values[element_name] value = <obiint_t> values[element_name]

View File

@ -1,24 +1,25 @@
#cython: language_level=3 #cython: language_level=3
from .capi.obitypes cimport index_t
from ._obidms cimport OBIDMS_column from ._obidms cimport OBIDMS_column
cdef class OBIDMS_column_str(OBIDMS_column): cdef class OBIDMS_column_str(OBIDMS_column):
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_str_writable(OBIDMS_column_str): cdef class OBIDMS_column_str_writable(OBIDMS_column_str):
cpdef set_line(self, size_t line_nb, object value) cpdef set_line(self, index_t line_nb, object value)
cpdef close(self) cpdef close(self)
cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str): cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
cpdef object get_item(self, size_t line_nb, str element_name) cpdef object get_item(self, index_t line_nb, str element_name)
cpdef object get_line(self, size_t line_nb) cpdef object get_line(self, index_t line_nb)
cpdef set_item(self, size_t line_nb, str element_name, str value) cpdef set_item(self, index_t line_nb, str element_name, str value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cdef class OBIDMS_column_str_multi_elts_writable(OBIDMS_column_str_multi_elts): cdef class OBIDMS_column_str_multi_elts_writable(OBIDMS_column_str_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, str value) cpdef set_item(self, index_t line_nb, str element_name, str value)
cpdef set_line(self, size_t line_nb, object values) cpdef set_line(self, index_t line_nb, object values)
cpdef close(self) cpdef close(self)

View File

@ -9,42 +9,24 @@ from .capi.obidmscolumn cimport obi_close_column,\
from .capi.obierrno cimport obi_errno from .capi.obierrno cimport obi_errno
from .capi.obitypes cimport OBIIdx_NA, const_char_p from .capi.obitypes cimport OBIIdx_NA, const_char_p
from libc.string cimport strlen
from obitools3.utils cimport str2bytes, bytes2str from obitools3.utils cimport str2bytes, bytes2str
from cpython.int cimport PyInt_FromSsize_t
cdef class OBIDMS_column_str(OBIDMS_column): cdef class OBIDMS_column_str(OBIDMS_column):
cpdef object get_line(self, size_t line_nb): cpdef object get_line(self, index_t line_nb):
cdef const_char_p cvalue
cdef bytes value cdef bytes value
cdef object result cdef object result
value = <bytes> obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, 0)
cvalue = obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, 0)
print('test 1')
print(hex(<int> cvalue))
print(strlen(cvalue))
print("test")
value = <bytes> cvalue
print(value)
if obi_errno > 0 : if obi_errno > 0 :
raise IndexError(line_nb) raise IndexError(line_nb)
if value == OBIIdx_NA : if value == OBIIdx_NA :
result = None result = None
else : else :
print(value)
result = bytes2str(value) result = bytes2str(value)
return result return result
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef close(self): cpdef close(self):
@ -54,7 +36,7 @@ cdef class OBIDMS_column_str(OBIDMS_column):
cdef class OBIDMS_column_str_writable(OBIDMS_column_str): cdef class OBIDMS_column_str_writable(OBIDMS_column_str):
cpdef set_line(self, size_t line_nb, object value): cpdef set_line(self, index_t line_nb, object value):
if obi_column_set_obistr_with_elt_idx(self.pointer, line_nb, 0, str2bytes(value)) < 0: if obi_column_set_obistr_with_elt_idx(self.pointer, line_nb, 0, str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
@ -65,10 +47,10 @@ cdef class OBIDMS_column_str_writable(OBIDMS_column_str):
cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str): cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
cpdef object get_item(self, size_t line_nb, str element_name): cpdef object get_item(self, index_t line_nb, str element_name):
cdef bytes value cdef bytes value
cdef object result cdef object result
value = obi_column_get_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name)) value = <bytes> obi_column_get_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
if obi_errno > 0 : if obi_errno > 0 :
raise IndexError(line_nb, element_name) raise IndexError(line_nb, element_name)
if value == OBIIdx_NA : if value == OBIIdx_NA :
@ -77,15 +59,15 @@ cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
result = bytes2str(value) result = bytes2str(value)
return result return result
cpdef object get_line(self, size_t line_nb) : cpdef object get_line(self, index_t line_nb) :
cdef bytes value cdef bytes value
cdef object result cdef object result
cdef size_t i cdef index_t i
cdef bint all_NA cdef bint all_NA
result = {} result = {}
all_NA = True all_NA = True
for i in range(self.nb_elements_per_line) : for i in range(self.nb_elements_per_line) :
value = obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, i) value = <bytes> obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, i)
if obi_errno > 0 : if obi_errno > 0 :
raise IndexError(line_nb) raise IndexError(line_nb)
result[self.elements_names[i]] = bytes2str(value) result[self.elements_names[i]] = bytes2str(value)
@ -95,20 +77,20 @@ cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
result = None result = None
return result return result
cpdef set_item(self, size_t line_nb, str element_name, str value): cpdef set_item(self, index_t line_nb, str element_name, str value):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
raise Exception("Column is read-only") raise Exception("Column is read-only")
cdef class OBIDMS_column_str_multi_elts_writable(OBIDMS_column_str_multi_elts): cdef class OBIDMS_column_str_multi_elts_writable(OBIDMS_column_str_multi_elts):
cpdef set_item(self, size_t line_nb, str element_name, str value): cpdef set_item(self, index_t line_nb, str element_name, str value):
if obi_column_set_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name), str2bytes(value)) < 0: if obi_column_set_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name), str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column") raise Exception("Problem setting a value in a column")
cpdef set_line(self, size_t line_nb, object values): cpdef set_line(self, index_t line_nb, object values):
cdef str value cdef str value
for element_name in values : for element_name in values :
value = values[element_name] value = values[element_name]

View File

@ -8,6 +8,7 @@ from ..capi.obitypes cimport const_char_p, \
obibool_t, \ obibool_t, \
obichar_t, \ obichar_t, \
obifloat_t, \ obifloat_t, \
index_t, \
time_t time_t
@ -16,9 +17,9 @@ cdef extern from "obidmscolumn.h" nogil:
struct OBIDMS_column_header_t: struct OBIDMS_column_header_t:
bint little_endian bint little_endian
int header_size int header_size
size_t line_count index_t line_count
size_t lines_used index_t lines_used
size_t nb_elements_per_line index_t nb_elements_per_line
const_char_p elements_names const_char_p elements_names
OBIType_t data_type OBIType_t data_type
time_t creation_date time_t creation_date
@ -38,8 +39,8 @@ cdef extern from "obidmscolumn.h" nogil:
OBIDMS_column_p obi_create_column(OBIDMS_p dms, OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const_char_p column_name, const_char_p column_name,
OBIType_t type, OBIType_t type,
size_t nb_lines, index_t nb_lines,
size_t nb_elements_per_line, index_t nb_elements_per_line,
const_char_p elements_names, const_char_p elements_names,
const_char_p array_name) const_char_p array_name)
@ -69,101 +70,101 @@ cdef extern from "obidmscolumn.h" nogil:
cdef extern from "obidmscolumn_int.h" nogil: cdef extern from "obidmscolumn_int.h" nogil:
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name, const_char_p element_name,
obiint_t value) obiint_t value)
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx, index_t element_idx,
obiint_t value) obiint_t value)
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name) const_char_p element_name)
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx) index_t element_idx)
cdef extern from "obidmscolumn_bool.h" nogil: cdef extern from "obidmscolumn_bool.h" nogil:
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name, const_char_p element_name,
obibool_t value) obibool_t value)
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx, index_t element_idx,
obibool_t value) obibool_t value)
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name) const_char_p element_name)
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx) index_t element_idx)
cdef extern from "obidmscolumn_char.h" nogil: cdef extern from "obidmscolumn_char.h" nogil:
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name, const_char_p element_name,
obichar_t value) obichar_t value)
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx, index_t element_idx,
obichar_t value) obichar_t value)
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name) const_char_p element_name)
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx) index_t element_idx)
cdef extern from "obidmscolumn_float.h" nogil: cdef extern from "obidmscolumn_float.h" nogil:
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name, const_char_p element_name,
obifloat_t value) obifloat_t value)
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx, index_t element_idx,
obifloat_t value) obifloat_t value)
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name) const_char_p element_name)
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx) index_t element_idx)
cdef extern from "obidmscolumn_str.h" nogil: cdef extern from "obidmscolumn_str.h" nogil:
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name, const_char_p element_name,
char* value) char* value)
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx, index_t element_idx,
char* value) char* value)
const_char_p obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, const_char_p obi_column_get_obistr_with_elt_name(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
const_char_p element_name) const_char_p element_name)
const_char_p obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, const_char_p obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column,
size_t line_nb, index_t line_nb,
size_t element_idx) index_t element_idx)

View File

@ -1,7 +1,7 @@
#cython: language_level=3 #cython: language_level=3
from libc.stdint cimport int32_t from libc.stdint cimport int32_t, int64_t
from posix.types cimport time_t from posix.types cimport time_t
@ -33,10 +33,10 @@ cdef extern from "obitypes.h" nogil:
ctypedef int32_t obiint_t ctypedef int32_t obiint_t
ctypedef double obifloat_t ctypedef double obifloat_t
ctypedef char obichar_t ctypedef char obichar_t
ctypedef size_t obiidx_t ctypedef int64_t index_t
extern obiint_t OBIInt_NA extern obiint_t OBIInt_NA
extern obiidx_t OBIIdx_NA extern index_t OBIIdx_NA
extern obifloat_t OBIFloat_NA extern obifloat_t OBIFloat_NA
extern obichar_t OBIChar_NA extern obichar_t OBIChar_NA
extern obibool_t OBIBool_NA extern obibool_t OBIBool_NA

View File

@ -2,16 +2,17 @@ import os
import sys import sys
import shutil import shutil
import unittest import unittest
from random import randint, uniform from random import randint, uniform, choice
import string
from obitools3.obidms._obidms import OBIDMS from obitools3.obidms._obidms import OBIDMS
LINE_COUNT_FOR_TEST_COLUMN = 100000 # TODO randomize? LINE_COUNT_FOR_TEST_COLUMN = 10000 # TODO randomize?
SMALLER_LINE_COUNT_FOR_TEST_COLUMN = 10000 # TODO randomize? SMALLER_LINE_COUNT_FOR_TEST_COLUMN = 1000 # TODO randomize?
NB_ELEMENTS_PER_LINE = 50 # TODO randomize? NB_ELEMENTS_PER_LINE = 20 # TODO randomize?
DMS_NAME = "unit_test_dms" DMS_NAME = "unit_test_dms"
DATA_TYPES = ['OBI_INT', 'OBI_FLOAT', 'OBI_BOOL', 'OBI_CHAR'] DATA_TYPES = ['OBI_INT', 'OBI_FLOAT', 'OBI_BOOL', 'OBI_CHAR', 'OBI_IDX']
def create_test_obidms(): def create_test_obidms():
@ -26,7 +27,7 @@ def create_test_column(dms, data_type_code, multiple_elements_per_line=False):
data_type_code = data_type_code data_type_code = data_type_code
data_type_str = data_types[data_type_code-1] data_type_str = data_types[data_type_code-1]
col_name = "unit_test_"+data_type_str col_name = "unit_test_"+data_type_str
if multiple_elements_per_line : if multiple_elements_per_line :
elts_names = elements_names() elts_names = elements_names()
col = dms.open_column(col_name, col = dms.open_column(col_name,
@ -41,7 +42,7 @@ def create_test_column(dms, data_type_code, multiple_elements_per_line=False):
create=True, create=True,
data_type=data_type_code) data_type=data_type_code)
return (col, col_name, data_type_str) return (col, col_name, data_type_str)
def elements_names(): def elements_names():
names = [str(i) for i in range(NB_ELEMENTS_PER_LINE)] names = [str(i) for i in range(NB_ELEMENTS_PER_LINE)]
@ -60,8 +61,9 @@ def random_obivalue(data_type):
nucs = 'atgc' nucs = 'atgc'
return bytes(nucs[randint(0,3)], 'utf-8') return bytes(nucs[randint(0,3)], 'utf-8')
elif data_type == "OBI_IDX" : elif data_type == "OBI_IDX" :
return randint(0,r) length = randint(1,500)
randoms = ''.join(choice(string.ascii_lowercase) for i in range(length))
return randoms
class OBIDMS_Column_TestCase(unittest.TestCase): class OBIDMS_Column_TestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
@ -228,14 +230,42 @@ class OBIDMS_Column_OBI_CHAR_multiple_elements_TestCase(OBIDMS_Column_multiple_e
multiple_elements_per_line=True) multiple_elements_per_line=True)
class OBIDMS_Column_OBI_STR_TestCase(OBIDMS_Column_TestCase):
def setUp(self):
self.data_type_code = 5
self.dms, \
self.dms_name, \
self.dms_dir_name = create_test_obidms()
self.col, \
self.col_name, \
self.data_type_str = create_test_column(self.dms,
self.data_type_code)
class OBIDMS_Column_OBI_STR_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase):
def setUp(self):
self.data_type_code = 5
self.dms, \
self.dms_name, \
self.dms_dir_name = create_test_obidms()
self.col, \
self.col_name, \
self.elts_names, \
self.data_type_str = create_test_column(self.dms,
self.data_type_code,
multiple_elements_per_line=True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(verbosity=2, defaultTest=["OBIDMS_Column_OBI_INT_TestCase", unittest.main(verbosity=2, defaultTest=["OBIDMS_Column_OBI_INT_TestCase",
"OBIDMS_Column_OBI_INT_multiple_elements_TestCase", "OBIDMS_Column_OBI_INT_multiple_elements_TestCase",
"OBIDMS_Column_OBI_FLOAT_TestCase", "OBIDMS_Column_OBI_FLOAT_TestCase",
"OBIDMS_Column_OBI_FLOAT_multiple_elements_TestCase", "OBIDMS_Column_OBI_FLOAT_multiple_elements_TestCase",
"OBIDMS_Column_OBI_BOOL_TestCase", "OBIDMS_Column_OBI_BOOL_TestCase",
"OBIDMS_Column_OBI_BOOL_multiple_elements_TestCase", "OBIDMS_Column_OBI_BOOL_multiple_elements_TestCase",
"OBIDMS_Column_OBI_CHAR_TestCase", "OBIDMS_Column_OBI_CHAR_TestCase",
"OBIDMS_Column_OBI_CHAR_multiple_elements_TestCase"]) "OBIDMS_Column_OBI_CHAR_multiple_elements_TestCase",
"OBIDMS_Column_OBI_STR_TestCase",
"OBIDMS_Column_OBI_STR_multiple_elements_TestCase"])

View File

@ -2,4 +2,4 @@ major = 1
minor = 1 minor = 1
serial= '16' serial= '16'
version ="%2d.%02d.%s" % (major,minor,serial) version ="%d.%02d.%s" % (major,minor,serial)

View File

@ -13,6 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <time.h> #include <time.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <fcntl.h> #include <fcntl.h>
@ -20,7 +21,9 @@
#include "obiarray.h" #include "obiarray.h"
#include "obierrno.h" #include "obierrno.h"
#include "obitypes.h"
#include "obidebug.h" #include "obidebug.h"
#include "private_at_functions.h"
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?) #define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
@ -37,7 +40,7 @@
* *
* @warning The returned pointer has to be freed by the caller. * @warning The returned pointer has to be freed by the caller.
* *
* @param name The name of the array. * @param array_name The name of the array.
* *
* @returns A pointer to the array file name. * @returns A pointer to the array file name.
* @retval NULL if an error occurred. * @retval NULL if an error occurred.
@ -53,7 +56,7 @@ static char* build_array_file_name(const char* array_name);
* *
* @warning The returned pointer has to be freed by the caller. * @warning The returned pointer has to be freed by the caller.
* *
* @param name The name of the array. * @param array_name The name of the array.
* *
* @returns A pointer to the array data file name. * @returns A pointer to the array data file name.
* @retval NULL if an error occurred. * @retval NULL if an error occurred.
@ -65,62 +68,121 @@ static char* build_array_data_file_name(const char* array_name);
/** /**
* PRIVATE * @brief Internal function returning the size of an array header on this platform.
*/ *
static char* build_array_file_path(OBIDMS_p dms, const char* array_name); * @returns The size of an array header in bytes.
*
* @since October 2015
/** * @author Celine Mercier (celine.mercier@metabarcoding.org)
* PRIVATE
*/ */
size_t get_array_header_size(); size_t get_array_header_size();
/** /**
* PRIVATE * @brief Internal function returning the initial size of an array on this platform.
*
* @returns The initial size of an array in bytes.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
size_t get_initial_array_size(); size_t get_initial_array_size();
/** /**
* PRIVATE * @brief Internal function returning the size of a data array header on this platform.
*
* @returns The size of a data array header in bytes.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
size_t get_array_data_header_size(); size_t get_array_data_header_size();
/** /**
* PRIVATE * @brief Internal function returning the initial size of a data array on this platform.
*
* @returns The initial size of a data array in bytes.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
size_t get_initial_array_data_size(); size_t get_initial_array_data_size();
/** /**
* PRIVATE * @brief Internal function closing a data array structure.
*
* @param array_data A pointer to the data array.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int close_array_data(OBIDMS_array_data_p array_data); int close_array_data(OBIDMS_array_data_p array_data);
/** /**
* PRIVATE * @brief Internal function enlarging an array.
*
* @param array A pointer to the array structure.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int grow_array(OBIDMS_array_p array); int grow_array(OBIDMS_array_p array);
/** /**
* PRIVATE * @brief Internal function enlarging a data array.
*
* @param array A pointer to the array structure.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int grow_array_data(OBIDMS_array_p array); int grow_array_data(OBIDMS_array_p array);
/** /**
* PRIVATE * @brief Internal function comparing two byte arrays.
*
* The encoding is compared first, then the length of the
* values, then the values themselves.
*
* @param value_1 A pointer to the first byte array.
* @param value_2 A pointer to the second byte array.
*
* @returns A value < 0 if value_1 < value_2,
* a value > 0 if value_1 > value_2,
* and 0 if value_1 == value_2.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int array_compare(byte_t* value_1, byte_t* value_2); int array_compare(byte_t* value_1, byte_t* value_2);
/** /**
* PRIVATE * @brief Internal function calculating the size in bytes of a byte array.
*
* @param value A pointer to the byte array.
*
* @returns The size of the byte array in bytes.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int32_t array_sizeof(byte_t* value); // TODO not sure about type size_t array_sizeof(byte_t* value); // TODO not sure about type
/************************************************************************ /************************************************************************
@ -170,33 +232,6 @@ static char* build_array_data_file_name(const char* array_name)
} }
static char* build_array_file_path(OBIDMS_p dms, const char* array_name) // TODO store DIR in dms structure
{
char* array_file_path;
char* array_file_name;
// Build the array file name
array_file_name = build_array_file_name(array_name);
if (array_file_name == NULL)
return NULL;
// TODO use get_full_path(int directory_file_descriptor, const char* path_name)
array_file_path = (char*) malloc((strlen(dms->directory_name) + strlen("/arrays/") + strlen(array_file_name) + 1) * sizeof(char));
if (array_file_path == NULL)
{
obi_set_errno(OBI_ARRAY_ERROR);
obidebug(1, "\nError building an array file path");
return NULL;
}
strcpy(array_file_path, dms->directory_name);
strcat(array_file_path, "/arrays/");
strcat(array_file_path, array_file_name);
return array_file_path;
}
size_t get_array_header_size() size_t get_array_header_size()
{ {
return getpagesize() * 1; return getpagesize() * 1;
@ -272,7 +307,7 @@ int grow_array(OBIDMS_array_p array) // TODO Lock when needed
return -1; return -1;
} }
// Open the array data file // Open the array file
array_file_descriptor = openat(array_dir_file_descriptor, array_file_name, O_RDWR); array_file_descriptor = openat(array_dir_file_descriptor, array_file_name, O_RDWR);
if (array_file_descriptor < 0) if (array_file_descriptor < 0)
{ {
@ -285,7 +320,7 @@ int grow_array(OBIDMS_array_p array) // TODO Lock when needed
free(array_file_name); free(array_file_name);
// Calculate the new file size // Calculate the new file size
old_data_size = ((array->header)->nb_items_max) * sizeof(index_t); old_data_size = (array->header)->array_size;
new_data_size = old_data_size * ARRAY_GROWTH_FACTOR; new_data_size = old_data_size * ARRAY_GROWTH_FACTOR;
header_size = (array->header)->header_size; header_size = (array->header)->header_size;
file_size = header_size + new_data_size; file_size = header_size + new_data_size;
@ -331,8 +366,11 @@ int grow_array(OBIDMS_array_p array) // TODO Lock when needed
// Set new maximum number of items // Set new maximum number of items
(array->header)->nb_items_max = ceil(((double) new_data_size) / ((double) sizeof(index_t))); (array->header)->nb_items_max = ceil(((double) new_data_size) / ((double) sizeof(index_t)));
// Set the new array size
(array->header)->array_size = new_data_size;
// Initialize new data to 0 // Initialize new data to 0
memset((array->first)+old_data_size, 0, new_data_size - old_data_size); memset(((uint8_t*)(array->first))+old_data_size, 0, (new_data_size-old_data_size));
close(array_file_descriptor); close(array_file_descriptor);
@ -343,8 +381,8 @@ int grow_array(OBIDMS_array_p array) // TODO Lock when needed
int grow_array_data(OBIDMS_array_p array) // TODO Lock when needed int grow_array_data(OBIDMS_array_p array) // TODO Lock when needed
{ {
size_t file_size; size_t file_size;
size_t old_data_size; index_t old_data_size;
size_t new_data_size; index_t new_data_size;
size_t header_size; size_t header_size;
int array_dir_file_descriptor; int array_dir_file_descriptor;
int array_data_file_descriptor; int array_data_file_descriptor;
@ -444,7 +482,7 @@ int array_compare(byte_t* value_1, byte_t* value_2)
int32_t len_2; int32_t len_2;
int32_t b; int32_t b;
obidebug(1, "\nCOMPARING 1=%d,%.*s; 2=%d,%.*s", (int32_t) *(value_1+1), (int32_t) *(value_1+1), value_1+5, (int32_t) *(value_2+1), (int32_t) *(value_2+1), value_2+5); //obidebug(1, "\nCOMPARING 1=%d,%.*s; 2=%d,%.*s", *((int32_t*)(value_1+1)), *((int32_t*)(value_1+1)), value_1+BYTE_ARRAY_HEADER_SIZE, *((int32_t*)(value_2+1)), *((int32_t*)(value_2+1)), value_2+BYTE_ARRAY_HEADER_SIZE);
size_1 = (uint8_t) *(value_1); size_1 = (uint8_t) *(value_1);
size_2 = (uint8_t) *(value_2); size_2 = (uint8_t) *(value_2);
@ -452,31 +490,26 @@ int array_compare(byte_t* value_1, byte_t* value_2)
if (size_1 != size_2) if (size_1 != size_2)
return (size_1 - size_2); return (size_1 - size_2);
len_1 = (int32_t) *(value_1+1); len_1 = *((int32_t*)(value_1+1));
len_2 = (int32_t) *(value_2+1); len_2 = *((int32_t*)(value_2+1));
obidebug(1, "\ncomp length = %d - %d = %d", len_1, len_2, (len_1 - len_2));
if (len_1 != len_2) if (len_1 != len_2)
return (len_1 - len_2); return (len_1 - len_2);
b = 0; b = BYTE_ARRAY_HEADER_SIZE;
comp = 0; comp = 0;
while (!comp && (b < len_1)) while (!comp && (b < len_1+BYTE_ARRAY_HEADER_SIZE))
{ {
comp = *(value_1+b) - *(value_2+b); comp = *(value_1+b) - *(value_2+b);
b++; b++;
} }
obidebug(1, "\ncomp = %d", comp);
return comp; return comp;
} }
int32_t array_sizeof(byte_t* value) size_t array_sizeof(byte_t* value)
{ {
return (6 + (int32_t) *(value+1)); return (BYTE_ARRAY_HEADER_SIZE + *((int32_t*)(value+1)) + 1);
} }
@ -490,14 +523,39 @@ int obi_array_exists(OBIDMS_p dms, const char* array_name)
{ {
struct stat buffer; struct stat buffer;
char* array_file_path; char* array_file_path;
char* array_file_name;
int check_dir; int check_dir;
int array_dir_file_descriptor;
// Get the file descriptor of the array directory
array_dir_file_descriptor = dirfd(dms->array_directory);
if (array_dir_file_descriptor < 0)
{
obi_set_errno(OBI_ARRAY_ERROR);
obidebug(1, "\nError getting the file descriptor for an array directory");
return -1;
}
// Build file name
array_file_name = build_array_file_name(array_name);
if (array_file_name == NULL)
{
close(array_dir_file_descriptor);
return -1;
}
// Build the array file path // Build the array file path
array_file_path = build_array_file_path(dms, array_name); array_file_path = get_full_path(array_dir_file_descriptor, array_file_name);
if (array_file_path == NULL)
{
obidebug(1, "\nError getting the file path for an array file");
return -1;
}
check_dir = stat(array_file_path, &buffer); check_dir = stat(array_file_path, &buffer);
free(array_file_path); free(array_file_path);
free(array_file_name);
if (check_dir == 0) if (check_dir == 0)
return 1; return 1;
@ -549,8 +607,6 @@ OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name)
return NULL; return NULL;
} }
obidebug(1, "\nboom");
// Build file name // Build file name
array_data_file_name = build_array_data_file_name(array_name); array_data_file_name = build_array_data_file_name(array_name);
if (array_data_file_name == NULL) if (array_data_file_name == NULL)
@ -559,8 +615,6 @@ OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name)
return NULL; return NULL;
} }
obidebug(1, "\nboom");
// Create file // Create file
array_data_file_descriptor = openat(array_dir_file_descriptor, array_data_file_name, O_RDWR | O_CREAT | O_EXCL, 0777); array_data_file_descriptor = openat(array_dir_file_descriptor, array_data_file_name, O_RDWR | O_CREAT | O_EXCL, 0777);
if (array_data_file_descriptor < 0) if (array_data_file_descriptor < 0)
@ -719,7 +773,7 @@ OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name)
return NULL; return NULL;
} }
array->first = mmap(NULL, array->first = mmap(NULL,
data_size, data_size,
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED, MAP_SHARED,
@ -742,6 +796,7 @@ OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name)
array->directory = dms->array_directory; array->directory = dms->array_directory;
(array->header)->header_size = header_size; (array->header)->header_size = header_size;
(array->header)->array_size = data_size;
(array->header)->nb_items = 0; (array->header)->nb_items = 0;
(array->header)->nb_items_max = (index_t) ceil(((double) get_initial_array_size()) / ((double) sizeof(index_t))); (array->header)->nb_items_max = (index_t) ceil(((double) get_initial_array_size()) / ((double) sizeof(index_t)));
(array->header)->creation_date = time(NULL); (array->header)->creation_date = time(NULL);
@ -751,7 +806,6 @@ OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name)
memset(array->first, 0, data_size); memset(array->first, 0, data_size);
close(array_file_descriptor); close(array_file_descriptor);
//close(array_dir_file_descriptor); TODO
return array; return array;
} }
@ -929,7 +983,6 @@ OBIDMS_array_p obi_open_array(OBIDMS_p dms, const char* array_name)
array->directory = dms->array_directory; array->directory = dms->array_directory;
close(array_file_descriptor); close(array_file_descriptor);
//close(array_dir_file_descriptor); TODO
return array; return array;
} }
@ -961,29 +1014,17 @@ int obi_close_array(OBIDMS_array_p array)
} }
//int obi_delete_array(const char* array_name)
//{
//
//}
index_t obi_array_add(OBIDMS_array_p array, byte_t* value) index_t obi_array_add(OBIDMS_array_p array, byte_t* value)
{ {
index_t idx; index_t idx;
index_t nb_items; index_t nb_items;
index_t nb_items_max; index_t nb_items_max;
index_t* a; index_t data_size_used;
byte_t* data; index_t* data_size_max_p;
int64_t data_size_used; size_t value_size;
int64_t* data_size_max_p;
int32_t value_size;
obidebug(1, "\n");
nb_items = (array->header)->nb_items; nb_items = (array->header)->nb_items;
nb_items_max = (array->header)->nb_items_max; nb_items_max = (array->header)->nb_items_max;
a = array->first;
data = (array->data)->data;
data_size_used = ((array->data)->header)->data_size_used; data_size_used = ((array->data)->header)->data_size_used;
data_size_max_p = &(((array->data)->header)->data_size_max); data_size_max_p = &(((array->data)->header)->data_size_max);
@ -999,8 +1040,6 @@ index_t obi_array_add(OBIDMS_array_p array, byte_t* value)
else // First item else // First item
idx = 0; idx = 0;
obidebug(1, "\n");
// Grow the array if needed // Grow the array if needed
if (nb_items == nb_items_max) if (nb_items == nb_items_max)
{ {
@ -1008,37 +1047,22 @@ index_t obi_array_add(OBIDMS_array_p array, byte_t* value)
return -1; return -1;
} }
obidebug(1, "\n");
// Grow the data if needed // Grow the data if needed
value_size = array_sizeof(value); value_size = array_sizeof(value);
while (*data_size_max_p < (data_size_used + value_size)) while (*data_size_max_p < (data_size_used + value_size)) // TODO problem with types
{ {
if (grow_array_data(array) < 0) if (grow_array_data(array) < 0)
return -1; return -1;
} }
obidebug(1, "\nidx = %d", idx); // Store the index of the value in the array
// Add the index of the value in the array if (nb_items > 0)
memmove((a+idx+1), (a+idx), ((nb_items - idx) * sizeof(index_t))); memmove(((array->first)+idx+1), ((array->first)+idx), ((nb_items - idx) * sizeof(index_t)));
a[idx] = data_size_used; (array->first)[idx] = data_size_used;
int i;
for (i=0; i<nb_items; i++)
fprintf(stderr, "\narray[%d] = %d\n", i, a[i]);
//fprintf(stderr, "\nBEFORE COPY DATA+5=%.5s, DATA+14=%.5s\n", data+5, data+14);
//fprintf(stderr, "\nBEFORE COPY DATA+8=%s\n", data+8);
fprintf(stderr, "\ndata size used = %lld, value size = %d", data_size_used, value_size);
// Store the value itself at the end of the data // Store the value itself at the end of the data
memcpy((data+data_size_used), value, value_size); memcpy((((array->data)->data)+data_size_used), value, value_size);
//fprintf(stderr, "\nAFTER COPY DATA+8=%s\n", data+8);
//fprintf(stderr, "\nAFTER COPY DATA+5=%.4s, DATA+14=%.5s\n", data+5, data+14);
// Update the data size // Update the data size
((array->data)->header)->data_size_used = data_size_used + value_size; ((array->data)->header)->data_size_used = data_size_used + value_size;
@ -1047,18 +1071,18 @@ index_t obi_array_add(OBIDMS_array_p array, byte_t* value)
((array->header)->nb_items)++; ((array->header)->nb_items)++;
(((array->data)->header)->nb_items)++; (((array->data)->header)->nb_items)++;
//obidebug(1, "\nSHOULD ++ : %d", (array->header)->nb_items); // PRINT ARRAY
// fprintf(stderr, "\nARRAY:");
for (i=0; i<(array->header)->nb_items; i++) // int i;
fprintf(stderr, "\narray[%d] = %d\n", i, a[i]); // for (i=0; i<=nb_items; i++)
// fprintf(stderr, "\narray[%d] = %d -> %s", i, a[i], data+a[i]+BYTE_ARRAY_HEADER_SIZE);
fprintf(stderr, "\nreturning %lld\n", data_size_used);
// Return the data index of the value
return data_size_used; return data_size_used;
} }
byte_t* obi_array_get(OBIDMS_array_p array, index_t idx) // TODO copy? byte_t* obi_array_get(OBIDMS_array_p array, index_t idx)
{ {
return (((array->data)->data)+idx); return (((array->data)->data)+idx);
} }
@ -1080,48 +1104,37 @@ index_t obi_array_search(OBIDMS_array_p array, byte_t* value)
data = (array->data)->data; data = (array->data)->data;
a = array->first; a = array->first;
obidebug(1, "\nnb items = %d", nb_items);
if (nb_items == 0) if (nb_items == 0)
return 0; return -1;
idx_max = nb_items; idx_max = nb_items-1;
idx_min = 0; idx_min = 0;
obidebug(1, "\n"); while (idx_min <= idx_max)
while (idx_min < idx_max)
{ {
idx_mid = nb_items/2; idx_mid = (idx_min+idx_max)/2;
obidebug(1, "\ncomparing with idx = %d, data idx %d", idx_mid, a[idx_mid]);
//fprintf(stderr, "\ndata+14=%.5s\n", data+14);
to_compare = obi_array_get(array, a[idx_mid]); to_compare = obi_array_get(array, a[idx_mid]);
//fprintf(stderr, "\nto_compare=%.5s\n", to_compare+5);
comp = array_compare(to_compare, value); comp = array_compare(to_compare, value);
obidebug(1, "\nCOMP = %d", comp);
if (!comp) if (!comp)
{
// Found
return a[idx_mid]; return a[idx_mid];
}
else if (comp < 0) else if (comp < 0)
{ {
idx = idx_mid + 1;
// Search in upper half // Search in upper half
idx = idx_mid + 1;
idx_min = idx_mid + 1; idx_min = idx_mid + 1;
} }
else else
idx = idx_mid; {
// Search in lower half // Search in lower half
idx = idx_mid;
idx_max = idx_mid - 1; idx_max = idx_mid - 1;
}
} }
obidebug(1, "\nNOT FOUND, idx=%d", idx); // Not found: return where the value should be in the array
// Not found: return where the value should be
return -(idx+1); return -(idx+1);
} }
@ -1134,7 +1147,7 @@ byte_t* obi_str_to_obibytes(char* value)
size = 8; size = 8;
length = strlen(value); length = strlen(value);
value_b = (byte_t*) malloc(length + 6); value_b = (byte_t*) malloc(length + BYTE_ARRAY_HEADER_SIZE + 1);
if (value_b == NULL) if (value_b == NULL)
{ {
obi_set_errno(OBI_ARRAY_ERROR); obi_set_errno(OBI_ARRAY_ERROR);
@ -1143,11 +1156,10 @@ byte_t* obi_str_to_obibytes(char* value)
} }
*(value_b) = size; *(value_b) = size;
*(value_b+1) = length;
strcpy(value_b+5, value); *((int32_t*)(value_b+1)) = length;
// TODO 5 as macro strcpy(value_b+BYTE_ARRAY_HEADER_SIZE, value);
return value_b; return value_b;
} }
@ -1157,17 +1169,8 @@ const char* obi_obibytes_to_str(byte_t* value_b)
{ {
const char* value; const char* value;
value = value_b+5; value = value_b+BYTE_ARRAY_HEADER_SIZE;
obidebug(1, "\nvalue = %s", value);
// TODO 5 as macro
return value; return value;
} }

View File

@ -3,15 +3,15 @@
****************************************************************************/ ****************************************************************************/
/** /**
* @file array.h * @file obiarray.h
* @author Celine Mercier * @author Celine Mercier
* @date October 19th 2015 * @date October 19th 2015
* @brief Header file for handling arrays for storing and retrieving data arrays (i.e. character strings). * @brief Header file for handling arrays for storing and retrieving byte arrays (i.e. coding for character strings).
*/ */
#ifndef ARRAY_H_ #ifndef OBIARRAY_H_
#define ARRAY_H_ #define OBIARRAY_H_
#include <stdlib.h> #include <stdlib.h>
@ -29,9 +29,10 @@
*/ */
#define ARRAY_GROWTH_FACTOR (2) /**< The growth factor when an array is enlarged. #define ARRAY_GROWTH_FACTOR (2) /**< The growth factor when an array is enlarged.
*/ */
#define BYTE_ARRAY_HEADER_SIZE (5) /**< The size of the header of a byte array.
*/
typedef int32_t index_t; /**< Type of the array indices.
*/
typedef char byte_t; /**< Defining byte type since data is stored in bits typedef char byte_t; /**< Defining byte type since data is stored in bits
* and char (stored on one byte) is the smallest addressable unit. * and char (stored on one byte) is the smallest addressable unit.
*/ */
@ -43,9 +44,9 @@ typedef char byte_t; /**< Defining byte type since data is stored in bits
typedef struct OBIDMS_array_data_header { typedef struct OBIDMS_array_data_header {
int header_size; /**< Size of the header in bytes. int header_size; /**< Size of the header in bytes.
*/ */
int64_t data_size_used; /**< Size of the data used in bytes. // TODO not sure about type index_t data_size_used; /**< Size of the data used in bytes.
*/ */
int64_t data_size_max; /**< Max size of the data in bytes. // TODO not sure about type index_t data_size_max; /**< Max size of the data in bytes.
*/ */
index_t nb_items; /**< Number of items. index_t nb_items; /**< Number of items.
*/ */
@ -73,6 +74,8 @@ typedef struct OBIDMS_array_data {
typedef struct OBIDMS_array_header { typedef struct OBIDMS_array_header {
int header_size; /**< Size of the header in bytes. int header_size; /**< Size of the header in bytes.
*/ */
size_t array_size; /**< Size of the array in bytes.
*/
index_t nb_items; /**< Number of items in the array. index_t nb_items; /**< Number of items in the array.
*/ */
index_t nb_items_max; /**< Maximum number of items in the array before it has to be enlarged. index_t nb_items_max; /**< Maximum number of items in the array before it has to be enlarged.
@ -102,76 +105,181 @@ typedef struct OBIDMS_array {
/** /**
* @brief Checks if an obiarray already exists or not.
* *
* @param dms The OBIDMS to which the obiarray belongs.
* @param array_name The name of the obiarray.
*
* @returns A value indicating whether the obiarray exists or not.
* @retval 1 if the obiarray exists.
* @retval 0 if the obiarray does not exist.
* @retval -1 if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int obi_array_exists(OBIDMS_p dms, const char* array_name); int obi_array_exists(OBIDMS_p dms, const char* array_name);
/** /**
* @brief Opens an obiarray and creates it if it does not already exist.
* *
* Note: An obiarray is made of two files (referred to by two structures).
* One file contains the indices referring to the data, and the other
* file contains the data itself. The obiarray as a whole is referred
* to via the OBIDMS_array structure.
*
* @param dms The OBIDMS to which the obiarray belongs.
* @param array_name The name of the obiarray.
*
* @returns A pointer to the obiarray structure.
* @retval NULL if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
OBIDMS_array_p obi_array(OBIDMS_p dms, const char* array_name); OBIDMS_array_p obi_array(OBIDMS_p dms, const char* array_name);
/** /**
* @brief Creates an obiarray. Fails if it already exists.
* *
* Note: An obiarray is made of two files (referred to by two structures).
* One file contains the indices referring to the data, and the other
* file contains the data itself. The obiarray as a whole is referred
* to via the OBIDMS_array structure.
*
* @param dms The OBIDMS to which the obiarray belongs.
* @param array_name The name of the obiarray.
*
* @returns A pointer to the newly created obiarray structure.
* @retval NULL if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name); OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name);
/** /**
* @brief Opens an obiarray. Fails if it does not already exist.
* *
* Note: An obiarray is made of two files (referred to by two structures).
* One file contains the indices referring to the data, and the other
* file contains the data itself. The obiarray as a whole is referred
* to via the OBIDMS_array structure.
*
* @param dms The OBIDMS to which the obiarray belongs.
* @param array_name The name of the obiarray.
*
* @returns A pointer to the obiarray structure.
* @retval NULL if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
OBIDMS_array_p obi_open_array(OBIDMS_p dms, const char* array_name); OBIDMS_array_p obi_open_array(OBIDMS_p dms, const char* array_name);
/** /**
* @brief Closes an obiarray.
* *
* Note: An obiarray is made of two files (referred to by two structures).
* One file contains the indices referring to the data, and the other
* file contains the data itself. The obiarray as a whole is referred
* to via the OBIDMS_array structure.
*
* @param array A pointer to the obiarray structure to close and free.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int obi_close_array(OBIDMS_array_p array); int obi_close_array(OBIDMS_array_p array);
/** /**
* @brief Adds a value (byte array) in an obiarray, checking first if it is already in it.
* *
*/ * @warning The byte array to add must already be encoded and contain its header.
//int obi_delete_array(OBIDMS_p dms, const char* array_name); *
* @param array A pointer to the obiarray.
* @param value The byte array to add in the obiarray.
/** *
* The header is already in the byte array * @returns The index of the value, whether it was added or already in the obiarray.
* @retval -1 if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
index_t obi_array_add(OBIDMS_array_p array, byte_t* value); index_t obi_array_add(OBIDMS_array_p array, byte_t* value);
/** /**
* Returns the entire array including the header * @brief Recovers a value (byte array) in an obiarray.
*
* @warning The byte array recovered is encoded and contains its header.
*
* @param array A pointer to the obiarray.
* @param index The index of the value in the data array.
*
* @returns A pointer to the byte array recovered.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
byte_t* obi_array_get(OBIDMS_array_p array, index_t index); byte_t* obi_array_get(OBIDMS_array_p array, index_t index);
/** /**
* @brief Searches a value (byte array) in an obiarray performing a binary search.
* *
* @warning The byte array to search must already be encoded and contain its header.
*
* @param array A pointer to the obiarray.
* @param value The byte array to add in the obiarray.
*
* @returns If the value is found, its data index is returned.
* If the value is not found, the array index indicating where the value's data index
* should be in the array is returned in the form (- (index + 1)), as data indices in an
* obiarray are sorted according to the ascending order of the values (byte arrays) themselves.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
index_t obi_array_search(OBIDMS_array_p array, byte_t* value); index_t obi_array_search(OBIDMS_array_p array, byte_t* value);
/** /**
* @brief Converts a character string to a byte array with a header.
* *
* @warning The byte array must be freed by the caller.
*
* @param value The character string to convert.
*
* @returns A pointer to the byte array created.
* @retval NULL if an error occurred.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
byte_t* obi_str_to_obibytes(char* value); byte_t* obi_str_to_obibytes(char* value);
/** /**
* @brief Converts a byte array to a character string.
* *
* @param value_b The byte array to convert.
*
* @returns A pointer to the character string contained in the byte array.
*
* @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
const char* obi_obibytes_to_str(byte_t* value_b); const char* obi_obibytes_to_str(byte_t* value_b);
/** #endif /* OBIARRAY_H_ */
* TODO LATER
*/
// OBIDMS_array_p obi_column_arrayify(FILE, encoding);
#endif /* ARRAY_H_ */

View File

@ -163,8 +163,6 @@ OBIDMS_p obi_create_dms(const char* dms_name)
return NULL; return NULL;
} }
// TODO close file descriptor?
free(directory_name); free(directory_name);
return obi_open_dms(dms_name); return obi_open_dms(dms_name);
@ -247,8 +245,6 @@ OBIDMS_p obi_open_dms(const char* dms_name)
free(directory_name); free(directory_name);
// TODO test if close file descriptor
return dms; return dms;
} }

View File

@ -72,6 +72,8 @@ int obi_dms_exists(const char* dms_name);
* if a directory with this name does not already exist * if a directory with this name does not already exist
* before creating the new database. * before creating the new database.
* *
* A directory to store obiarrays is also created.
*
* @param dms_name A pointer to a C string containing the name of the database. * @param dms_name A pointer to a C string containing the name of the database.
* The actual directory name used to store the DMS will be * The actual directory name used to store the DMS will be
* `<dms_name>.obidms`. * `<dms_name>.obidms`.

View File

@ -143,7 +143,7 @@ static int obi_column_set_elements_names(OBIDMS_column_p column, const char* ele
* @since September 2015 * @since September 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
static size_t get_line_count_per_page(OBIType_t data_type, size_t nb_elements_per_line); static index_t get_line_count_per_page(OBIType_t data_type, index_t nb_elements_per_line);
/************************************************************************ /************************************************************************
@ -463,7 +463,7 @@ int obi_column_set_elements_names(OBIDMS_column_p column, const char* elements_n
return 0; return 0;
} }
size_t get_line_count_per_page(OBIType_t data_type, size_t nb_elements_per_line) 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); return getpagesize() / (obi_sizeof(data_type) * nb_elements_per_line);
} }
@ -595,15 +595,15 @@ obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms, const char* c
size_t obi_get_platform_header_size() size_t obi_get_platform_header_size()
{ {
return getpagesize() * 1; return getpagesize() * 2;
} }
OBIDMS_column_p obi_create_column(OBIDMS_p dms, OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const char* column_name, const char* column_name,
OBIType_t data_type, OBIType_t data_type,
size_t nb_lines, index_t nb_lines,
size_t nb_elements_per_line, index_t nb_elements_per_line,
const char* elements_names, const char* elements_names,
const char* array_name) const char* array_name)
{ {
@ -618,7 +618,7 @@ 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 minimum_line_count; index_t minimum_line_count;
new_column = NULL; new_column = NULL;
@ -664,7 +664,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
else if ((elements_names != NULL) && (nb_elements_per_line > 1)) else if ((elements_names != NULL) && (nb_elements_per_line > 1))
{ {
char* token; char* token;
size_t n = 0; index_t n = 0;
token = strdup(elements_names); token = strdup(elements_names);
token = strtok(token, ";"); token = strtok(token, ";");
while (token != NULL) while (token != NULL)
@ -989,8 +989,8 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
{ {
OBIDMS_column_p column_to_clone; OBIDMS_column_p column_to_clone;
OBIDMS_column_p new_column; OBIDMS_column_p new_column;
size_t nb_lines; index_t nb_lines;
size_t nb_elements_per_line; index_t nb_elements_per_line;
size_t data_size; size_t data_size;
OBIType_t data_type; OBIType_t data_type;
@ -1083,7 +1083,7 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
{ {
size_t file_size; size_t file_size;
size_t data_size; size_t data_size;
size_t new_line_count; index_t new_line_count;
double multiple; double multiple;
int column_dir_file_descriptor; int column_dir_file_descriptor;
int column_file_descriptor; int column_file_descriptor;
@ -1180,8 +1180,8 @@ int obi_enlarge_column(OBIDMS_column_p column)
size_t old_data_size; size_t old_data_size;
size_t new_data_size; size_t new_data_size;
size_t header_size; size_t header_size;
size_t old_line_count; index_t old_line_count;
size_t new_line_count; index_t new_line_count;
int column_dir_file_descriptor; int column_dir_file_descriptor;
int column_file_descriptor; int column_file_descriptor;
char* column_file_name; char* column_file_name;
@ -1316,10 +1316,10 @@ int obi_truncate_and_close_column(OBIDMS_column_p column)
void obi_ini_to_NA_values(OBIDMS_column_p column, void obi_ini_to_NA_values(OBIDMS_column_p column,
size_t first_line_nb, index_t first_line_nb,
size_t nb_lines) index_t nb_lines)
{ {
size_t i, start, end, nb_elements; index_t i, start, end, nb_elements;
nb_elements = nb_lines*((column->header)->nb_elements_per_line); nb_elements = nb_lines*((column->header)->nb_elements_per_line);
start = first_line_nb*((column->header)->nb_elements_per_line); start = first_line_nb*((column->header)->nb_elements_per_line);
@ -1355,14 +1355,14 @@ void obi_ini_to_NA_values(OBIDMS_column_p column,
case OBI_IDX: for (i=start;i<end;i++) case OBI_IDX: for (i=start;i<end;i++)
{ {
*(((obiidx_t*) (column->data)) + i) = OBIIdx_NA; *(((index_t*) (column->data)) + i) = OBIIdx_NA;
} }
break; break;
} }
} }
OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char* column_name) // ADD VERSION ARGUMENT OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char* column_name) // TODO ADD VERSION ARGUMENT
{ {
OBIDMS_column_header_p header; OBIDMS_column_header_p header;
OBIDMS_column_directory_p column_directory; OBIDMS_column_directory_p column_directory;
@ -1391,7 +1391,7 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
} }
// Calculate the header size // Calculate the header size
header_size = obi_get_platform_header_size(); header_size = obi_get_platform_header_size(); // TODO read in header itself
// Get the latest version number // Get the latest version number
version_number = obi_get_latest_version_number(column_directory); version_number = obi_get_latest_version_number(column_directory);
@ -1458,17 +1458,17 @@ int obi_unmap_header(OBIDMS_column_header_p header)
// TODO to be rewritten in an optimized and safe way // TODO to be rewritten in an optimized and safe way
size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name) index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name)
{ {
char* elements_names; char* elements_names;
char* name; char* name;
size_t element_index; index_t element_index;
elements_names = strdup((column->header)->elements_names); elements_names = strdup((column->header)->elements_names);
if (elements_names == NULL) if (elements_names == NULL)
{ {
obidebug(1, "\nError strdup-ing the elements names"); obidebug(1, "\nError strdup-ing the elements names");
return SIZE_MAX; //TODO return OBIIdx_NA;
} }
element_index = 0; element_index = 0;
@ -1494,7 +1494,7 @@ size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char
obidebug(1, "\nCan't find an element name"); obidebug(1, "\nCan't find an element name");
free(elements_names); free(elements_names);
return SIZE_MAX; //TODO return OBIIdx_NA;
} }

View File

@ -53,13 +53,13 @@ typedef struct OBIDMS_column_header {
* - `false` on big endian platforms * - `false` on big endian platforms
* @see obi_is_little_endian() * @see obi_is_little_endian()
*/ */
int header_size; /**< Size of the header in bytes. size_t header_size; /**< Size of the header in bytes.
*/ */
size_t line_count; /**< Number of lines of data allocated. index_t line_count; /**< Number of lines of data allocated.
*/ */
size_t lines_used; /**< Number of lines of data used. index_t lines_used; /**< Number of lines of data used.
*/ */
size_t nb_elements_per_line; /**< Number of elements per line (default: 1). index_t nb_elements_per_line; /**< Number of elements per line (default: 1).
*/ */
char elements_names[ELEMENTS_NAMES_MAX+1]; /**< Names of the line elements with ';' as separator char elements_names[ELEMENTS_NAMES_MAX+1]; /**< Names of the line elements with ';' as separator
* (should be the column name if one element per line). * (should be the column name if one element per line).
@ -149,7 +149,7 @@ obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms, const char* c
* The header size is defined as a multiple of the memory page size. * The header size is defined as a multiple of the memory page size.
* As of now the header size is defined as one time the page size. * As of now the header size is defined as one time the page size.
* *
* @returns a `size_t` value corresponding to the header size in bytes. * @returns The header size in bytes.
* *
* @since May 2015 * @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org) * @author Eric Coissac (eric.coissac@metabarcoding.org)
@ -161,6 +161,7 @@ size_t obi_get_platform_header_size();
* @brief Creates a column. * @brief Creates a column.
* *
* The minimum data size allocated is one memory page, and the data is initialized to the NA value of the OBIType. * The minimum data size allocated is one memory page, and the data is initialized to the NA value of the OBIType.
* If there is an array associated with the column, it is opened or created if it does not already exist.
* *
* @warning If there is one element per line, elements_names should be equal to column_name. // TODO change this condition? * @warning If there is one element per line, elements_names should be equal to column_name. // TODO change this condition?
* *
@ -170,6 +171,7 @@ size_t obi_get_platform_header_size();
* @param nb_lines The number of lines to be stored. * @param nb_lines The number of lines to be stored.
* @param nb_elements_per_line The number of elements per line. * @param nb_elements_per_line The number of elements per line.
* @param elements_names The names of the elements with ';' as separator. * @param elements_names The names of the elements with ';' as separator.
* @param array_name The name of the array if there is one associated with the column.
* *
* @returns A pointer on the newly created column structure. * @returns A pointer on the newly created column structure.
* @retval NULL if an error occurred. * @retval NULL if an error occurred.
@ -180,8 +182,8 @@ size_t obi_get_platform_header_size();
OBIDMS_column_p obi_create_column(OBIDMS_p dms, OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const char* column_name, const char* column_name,
OBIType_t data_type, OBIType_t data_type,
size_t nb_lines, index_t nb_lines,
size_t nb_elements_per_line, index_t nb_elements_per_line,
const char* elements_names, const char* elements_names,
const char* array_name); const char* array_name);
@ -287,7 +289,7 @@ int obi_truncate_and_close_column(OBIDMS_column_p column);
* @since August 2015 * @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
void obi_ini_to_NA_values(OBIDMS_column_p column, size_t first_line_nb, size_t nb_lines); // TO make private? void obi_ini_to_NA_values(OBIDMS_column_p column, index_t first_line_nb, index_t nb_lines); // TO make private?
/** /**
@ -333,7 +335,7 @@ int obi_unmap_header(OBIDMS_column_header_p header);
* @since July 2015 * @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name); index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name);
/** /**

View File

@ -28,7 +28,7 @@
* *
**********************************************************************/ **********************************************************************/
int obi_column_set_obibool_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, index_t line_nb, index_t element_idx, obibool_t value)
{ {
// Check that the line number is not greater than the maximum allowed // Check that the line number is not greater than the maximum allowed
if (line_nb >= MAXIMUM_LINE_COUNT) if (line_nb >= MAXIMUM_LINE_COUNT)
@ -57,7 +57,7 @@ int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
} }
obibool_t obi_column_get_obibool_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, index_t line_nb, index_t element_idx)
{ {
if ((line_nb+1) > (column->header)->lines_used) if ((line_nb+1) > (column->header)->lines_used)
{ {
@ -69,23 +69,23 @@ obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t lin
} }
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obibool_t value) int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return -1; return -1;
obi_column_set_obibool_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_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name) obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return OBIBool_NA; return OBIBool_NA;
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx); return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
} }

View File

@ -38,7 +38,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_obibool_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, index_t line_nb, size_t element_idx, obibool_t value);
/** /**
@ -54,7 +54,7 @@ int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
* @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_obibool_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, index_t line_nb, size_t element_idx);
/** /**
@ -66,7 +66,6 @@ obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t lin
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be set. * @param line_nb The number of the line where the value should be set.
* @param element_name The name of the element that should be set in the line. * @param element_name The name of the element that should be set in the line.
* If empty, it is checked that there is only one element per line.
* @param value The value that should be set. * @param value The value that should be set.
* *
* @returns An integer value indicating the success of the operation. * @returns An integer value indicating the success of the operation.
@ -76,7 +75,7 @@ obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t lin
* @since August 2015 * @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obibool_t value); int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value);
/** /**
@ -86,7 +85,6 @@ int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb,
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be recovered. * @param line_nb The number of the line where the value should be recovered.
* @param element_name The name of the element that should be recovered in the line. * @param element_name The name of the element that should be recovered in the line.
* If empty, it is checked that there is only one element per line.
* *
* @returns The recovered value. * @returns The recovered value.
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
@ -94,7 +92,7 @@ int obi_column_set_obibool_with_elt_name(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)
*/ */
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name); obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
#endif /* OBIDMSCOLUMN_BOOL_H_ */ #endif /* OBIDMSCOLUMN_BOOL_H_ */

View File

@ -28,7 +28,7 @@
* *
**********************************************************************/ **********************************************************************/
int obi_column_set_obichar_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, index_t line_nb, index_t element_idx, obichar_t value)
{ {
// Check that the line number is not greater than the maximum allowed // Check that the line number is not greater than the maximum allowed
if (line_nb >= MAXIMUM_LINE_COUNT) if (line_nb >= MAXIMUM_LINE_COUNT)
@ -57,7 +57,7 @@ int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
} }
obichar_t obi_column_get_obichar_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, index_t line_nb, index_t element_idx)
{ {
if ((line_nb+1) > (column->header)->lines_used) if ((line_nb+1) > (column->header)->lines_used)
{ {
@ -69,23 +69,23 @@ obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t lin
} }
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obichar_t value) int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return -1; return -1;
obi_column_set_obichar_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_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name) obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return OBIChar_NA; return OBIChar_NA;
return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx); return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx);
} }

View File

@ -38,7 +38,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_obichar_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, index_t line_nb, index_t element_idx, obichar_t value);
/** /**
@ -54,7 +54,7 @@ int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
* @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_obichar_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, index_t line_nb, index_t element_idx);
/** /**
@ -66,7 +66,6 @@ obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t lin
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be set. * @param line_nb The number of the line where the value should be set.
* @param element_name The name of the element that should be set in the line. * @param element_name The name of the element that should be set in the line.
* If empty, it is checked that there is only one element per line.
* @param value The value that should be set. * @param value The value that should be set.
* *
* @returns An integer value indicating the success of the operation. * @returns An integer value indicating the success of the operation.
@ -76,7 +75,7 @@ obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t lin
* @since August 2015 * @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obichar_t value); int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value);
/** /**
@ -86,7 +85,6 @@ int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb,
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be recovered. * @param line_nb The number of the line where the value should be recovered.
* @param element_name The name of the element that should be recovered in the line. * @param element_name The name of the element that should be recovered in the line.
* If empty, it is checked that there is only one element per line.
* *
* @returns The recovered value. * @returns The recovered value.
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
@ -94,7 +92,7 @@ int obi_column_set_obichar_with_elt_name(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)
*/ */
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name); obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
#endif /* OBIDMSCOLUMN_CHAR_H_ */ #endif /* OBIDMSCOLUMN_CHAR_H_ */

View File

@ -28,7 +28,7 @@
* *
**********************************************************************/ **********************************************************************/
int obi_column_set_obifloat_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, index_t line_nb, index_t element_idx, obifloat_t value)
{ {
// Check that the line number is not greater than the maximum allowed // Check that the line number is not greater than the maximum allowed
if (line_nb >= MAXIMUM_LINE_COUNT) if (line_nb >= MAXIMUM_LINE_COUNT)
@ -57,7 +57,7 @@ int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
} }
obifloat_t obi_column_get_obifloat_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, index_t line_nb, index_t element_idx)
{ {
if ((line_nb+1) > (column->header)->lines_used) if ((line_nb+1) > (column->header)->lines_used)
{ {
@ -69,23 +69,23 @@ obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t l
} }
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obifloat_t value) int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return -1; return -1;
obi_column_set_obifloat_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_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name) obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return OBIFloat_NA; return OBIFloat_NA;
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx); return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
} }

View File

@ -38,7 +38,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_obifloat_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, index_t line_nb, index_t element_idx, obifloat_t value);
/** /**
@ -54,7 +54,7 @@ int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
* @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_obifloat_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, index_t line_nb, index_t element_idx);
/** /**
@ -66,7 +66,6 @@ obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t l
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be set. * @param line_nb The number of the line where the value should be set.
* @param element_name The name of the element that should be set in the line. * @param element_name The name of the element that should be set in the line.
* If empty, it is checked that there is only one element per line.
* @param value The value that should be set. * @param value The value that should be set.
* *
* @returns An integer value indicating the success of the operation. * @returns An integer value indicating the success of the operation.
@ -76,7 +75,7 @@ obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t l
* @since August 2015 * @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obifloat_t value); int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value);
/** /**
@ -86,7 +85,6 @@ int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be recovered. * @param line_nb The number of the line where the value should be recovered.
* @param element_name The name of the element that should be recovered in the line. * @param element_name The name of the element that should be recovered in the line.
* If empty, it is checked that there is only one element per line.
* *
* @returns The recovered value. * @returns The recovered value.
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
@ -94,7 +92,7 @@ int obi_column_set_obifloat_with_elt_name(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)
*/ */
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name); obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
#endif /* OBIDMSCOLUMN_FLOAT_H_ */ #endif /* OBIDMSCOLUMN_FLOAT_H_ */

View File

@ -28,7 +28,7 @@
* *
**********************************************************************/ **********************************************************************/
int obi_column_set_obiint_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, index_t line_nb, index_t element_idx, obiint_t value)
{ {
// Check that the line number is not greater than the maximum allowed // Check that the line number is not greater than the maximum allowed
if (line_nb >= MAXIMUM_LINE_COUNT) if (line_nb >= MAXIMUM_LINE_COUNT)
@ -57,7 +57,7 @@ int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, s
} }
obiint_t obi_column_get_obiint_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, index_t line_nb, index_t element_idx)
{ {
if ((line_nb+1) > (column->header)->lines_used) if ((line_nb+1) > (column->header)->lines_used)
{ {
@ -69,23 +69,23 @@ obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_
} }
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obiint_t value) int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return -1; return -1;
obi_column_set_obiint_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_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name) obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return OBIInt_NA; return OBIInt_NA;
return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx); return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx);
} }

View File

@ -38,7 +38,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_obiint_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, index_t line_nb, index_t element_idx, obiint_t value);
/** /**
@ -54,7 +54,7 @@ int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, s
* @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_obiint_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, index_t line_nb, index_t element_idx);
/** /**
@ -66,7 +66,6 @@ obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be set. * @param line_nb The number of the line where the value should be set.
* @param element_name The name of the element that should be set in the line. * @param element_name The name of the element that should be set in the line.
* If empty, it is checked that there is only one element per line.
* @param value The value that should be set. * @param value The value that should be set.
* *
* @returns An integer value indicating the success of the operation. * @returns An integer value indicating the success of the operation.
@ -76,7 +75,7 @@ obiint_t obi_column_get_obiint_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_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obiint_t value); int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value);
/** /**
@ -86,7 +85,6 @@ int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb,
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be recovered. * @param line_nb The number of the line where the value should be recovered.
* @param element_name The name of the element that should be recovered in the line. * @param element_name The name of the element that should be recovered in the line.
* If empty, it is checked that there is only one element per line.
* *
* @returns The recovered value. * @returns The recovered value.
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
@ -94,7 +92,7 @@ int obi_column_set_obiint_with_elt_name(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)
*/ */
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name); obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
#endif /* OBIDMSCOLUMN_INT_H_ */ #endif /* OBIDMSCOLUMN_INT_H_ */

View File

@ -6,7 +6,7 @@
* @file obidsmcolumn_str.c * @file obidsmcolumn_str.c
* @author Celine Mercier * @author Celine Mercier
* @date October 28th 2015 * @date October 28th 2015
* @brief Functions handling OBIColumns containing data with the OBIType OBI_IDX. * @brief Functions handling OBIColumns containing data in the form of indices referring to character strings.
*/ */
@ -29,7 +29,7 @@
* *
**********************************************************************/ **********************************************************************/
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, char* value) int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
{ {
byte_t* value_b; byte_t* value_b;
index_t idx; index_t idx;
@ -59,31 +59,24 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, size_t line_nb, s
if (value_b == NULL) if (value_b == NULL)
return -1; return -1;
obidebug(1, "\nvalue=%s", value);
//obidebug(1, "\nbytes=%s", value_b+5);
// Add in the obiarray // Add in the obiarray
idx = obi_array_add(column->array, value_b); idx = obi_array_add(column->array, value_b);
if (idx == -1) if (idx == -1)
return -1; return -1;
obidebug(1, "\nidx=%d", idx);
//obidebug(1, "\nbytes 2=%s", obi_array_get(column->array, idx)+5);
// Add the value's index in the column // Add the value's index in the column
*(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx; *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
// TODO free value_b probably free(value_b);
return 0; return 0;
} }
const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx) const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
{ {
index_t idx; index_t idx;
byte_t* value_b; byte_t* value_b;
const char* value;
if ((line_nb+1) > (column->header)->lines_used) if ((line_nb+1) > (column->header)->lines_used)
{ {
@ -92,32 +85,22 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, size_t li
return "\0"; // TODO return "\0"; // TODO
} }
idx = *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
// Check NA // Check NA
if (idx == OBIIdx_NA) if (idx == OBIIdx_NA)
return "\0"; // TODO return "\0"; // TODO
obidebug(1, "\nwhy, idx = %d", idx);
value_b = obi_array_get(column->array, idx); value_b = obi_array_get(column->array, idx);
return obi_obibytes_to_str(value_b);
obidebug(1, "\nwhyyyy");
value = obi_obibytes_to_str(value_b);
obidebug(1, "\nwhyyyyyyyyyyyy, value=%s %p", value, value);
obidebug(1, "\nwhyyyyyyyyyyyy, len value=%d", strlen(value));
return value;
} }
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, char* value) int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return -1; return -1;
if (obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value) < 0) if (obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value) < 0)
return -1; return -1;
@ -125,12 +108,12 @@ int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, size_t line_nb,
} }
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name) const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
{ {
size_t element_idx; index_t element_idx;
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 == SIZE_MAX) //TODO if (element_idx == OBIIdx_NA)
return "\0"; return "\0";
return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx); return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
} }

View File

@ -1,17 +1,17 @@
/**************************************************************************** /****************************************************************************
* OBIDMS_column_idx header file * * OBIDMS_column_str header file *
****************************************************************************/ ****************************************************************************/
/** /**
* @file obidsmcolumn_idx.h * @file obidsmcolumn_str.h
* @author Celine Mercier * @author Celine Mercier
* @date August 10th 2015 * @date October 28th 2015
* @brief Header file for the functions handling OBIColumns containing data with the OBIType OBI_IDX. * @brief Header file for the functions handling OBIColumns containing data in the form of indices referring to character strings.
*/ */
#ifndef OBIDMSCOLUMN_IDX_H_ #ifndef OBIDMSCOLUMN_STR_H_
#define OBIDMSCOLUMN_IDX_H_ #define OBIDMSCOLUMN_STR_H_
#include <stdlib.h> #include <stdlib.h>
@ -22,7 +22,8 @@
/** /**
* @brief Sets a value in an OBIDMS column containing data with the type OBI_IDX, using the index of the element in the line. * @brief Sets a value in an OBIDMS column containing data in the form of indices referring
* to character strings in an obiarray, using the index of the element in the line.
* *
* @warning Pointers returned by obi_open_column() don't allow writing. * @warning Pointers returned by obi_open_column() don't allow writing.
* *
@ -35,66 +36,65 @@
* @retval 0 on success. * @retval 0 on success.
* @retval -1 if an error occurred. * @retval -1 if an error occurred.
* *
* @since July 2015 * @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int obi_column_set_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, void* value); int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value);
/** /**
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX. * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
* to character strings in an obiarray, using the index of the element in the line.
* *
* @param column A pointer as returned by obi_create_column(). * @param column A pointer as returned by obi_create_column().
* @param line_nb The number of the line where the value should be recovered. * @param line_nb The number of the line where the value should be recovered.
* @param element_idx The index of the element that should be recovered in the line. * @param element_idx The index of the element that should be recovered in the line.
* *
* @returns The recovered value. * @returns The recovered value.
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. * @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
* *
* @since July 2015 * @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
const char* obi_column_get_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx); const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
/** /**
* @brief Sets a value in an OBIDMS column containing data with the type OBI_IDX, * @brief Sets a value in an OBIDMS column containing data in the form of indices referring
* using the name of the element in the line. * to character strings in an obiarray, using the name of the element in the line.
* *
* @warning Pointers returned by obi_open_column() don't allow writing. * @warning Pointers returned by obi_open_column() don't allow writing.
* *
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be set. * @param line_nb The number of the line where the value should be set.
* @param element_name The name of the element that should be set in the line. * @param element_name The name of the element that should be set in the line.
* If empty, it is checked that there is only one element per line.
* @param value The value that should be set. * @param value The value that should be set.
* *
* @returns An integer value indicating the success of the operation. * @returns An integer value indicating the success of the operation.
* @retval 0 on success. * @retval 0 on success.
* @retval -1 if an error occurred. * @retval -1 if an error occurred.
* *
* @since August 2015 * @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, void* value); int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value);
/** /**
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX, * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
* using the name of the element in the line. * to character strings in an obiarray, using the name of the element in the line.
* *
* @param column A pointer as returned by obi_create_column() or obi_clone_column(). * @param column A pointer as returned by obi_create_column() or obi_clone_column().
* @param line_nb The number of the line where the value should be recovered. * @param line_nb The number of the line where the value should be recovered.
* @param element_name The name of the element that should be recovered in the line. * @param element_name The name of the element that should be recovered in the line.
* If empty, it is checked that there is only one element per line.
* *
* @returns The recovered value. * @returns The recovered value.
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. * @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
* *
* @since August 2015 * @since October 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org) * @author Celine Mercier (celine.mercier@metabarcoding.org)
*/ */
const char* obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name); const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
#endif /* OBIDMSCOLUMN_IDX_H_ */ #endif /* OBIDMSCOLUMN_IDX_H_ */

View File

@ -98,7 +98,7 @@ extern int obi_errno;
*/ */
#define OBICOL_ACCESS_ERROR (19) /**< Permission error trying to access an OBIDSM column directory #define OBICOL_ACCESS_ERROR (19) /**< Permission error trying to access an OBIDSM column directory
*/ */
#define OBI_ARRAY_ERROR (20) /** Error while handling a heap #define OBI_ARRAY_ERROR (20) /** Error while handling an array
*/ */
/**@}*/ /**@}*/

View File

@ -40,7 +40,7 @@ size_t obi_sizeof(OBIType_t type)
case OBI_CHAR: size = sizeof(obichar_t); case OBI_CHAR: size = sizeof(obichar_t);
break; break;
case OBI_IDX: size = sizeof(obiidx_t); case OBI_IDX: size = sizeof(index_t);
break; break;
default: size = 0; default: size = 0;
@ -50,7 +50,7 @@ size_t obi_sizeof(OBIType_t type)
} }
size_t obi_array_sizeof(OBIType_t type, size_t nb_lines, size_t nb_elements_per_line) size_t obi_array_sizeof(OBIType_t type, index_t nb_lines, index_t nb_elements_per_line)
{ {
size_t size; size_t size;
size_t rsize; size_t rsize;

View File

@ -19,7 +19,7 @@
#define OBIInt_NA (INT32_MIN) /**< NA value for the type OBI_INT */ #define OBIInt_NA (INT32_MIN) /**< NA value for the type OBI_INT */
#define OBIIdx_NA (SIZE_MAX) /**< NA value for the type OBI_IDX */ #define OBIIdx_NA (INT64_MIN) /**< NA value for indices */
#define OBIFloat_NA (float_NA()) /**< NA value for the type OBI_FLOAT */ #define OBIFloat_NA (float_NA()) /**< NA value for the type OBI_FLOAT */
#define OBIChar_NA (0) /**< NA value for the type OBI_CHAR */ #define OBIChar_NA (0) /**< NA value for the type OBI_CHAR */
// TODO not sure about this one as it can be impossible to distinguish from uninitialized values // TODO not sure about this one as it can be impossible to distinguish from uninitialized values
@ -44,14 +44,14 @@ typedef enum OBIType {
OBI_FLOAT, /**< a floating value (C type : double) */ OBI_FLOAT, /**< a floating value (C type : double) */
OBI_BOOL, /**< a boolean true/false value, see obibool_t enum */ OBI_BOOL, /**< a boolean true/false value, see obibool_t enum */
OBI_CHAR, /**< a character (C type : char) */ OBI_CHAR, /**< a character (C type : char) */
OBI_IDX /**< an index in a data structure (C type : size_t) */ OBI_IDX /**< an index in a data structure (C type : int64_t) */
} OBIType_t, *OBIType_p; } OBIType_t, *OBIType_p;
typedef int64_t index_t;
typedef int32_t obiint_t; typedef int32_t obiint_t;
typedef double obifloat_t; typedef double obifloat_t;
typedef char obichar_t; typedef char obichar_t;
typedef size_t obiidx_t;
/** /**
@ -107,7 +107,7 @@ size_t obi_sizeof(OBIType_t type);
* @since May 2015 * @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org) * @author Eric Coissac (eric.coissac@metabarcoding.org)
*/ */
size_t obi_array_sizeof(OBIType_t data_type, size_t nb_lines, size_t nb_elements_per_line); size_t obi_array_sizeof(OBIType_t data_type, index_t nb_lines, index_t nb_elements_per_line);
/** /**