diff --git a/python/obitools3/obidms/_obidms.cfiles b/python/obitools3/obidms/_obidms.cfiles index 8a385f6..da82237 100644 --- a/python/obitools3/obidms/_obidms.cfiles +++ b/python/obitools3/obidms/_obidms.cfiles @@ -37,3 +37,15 @@ ../../../src/obiview.c ../../../src/utils.h ../../../src/utils.c +../../../src/obidmscolumn_bool.c +../../../src/obidmscolumn_bool.h +../../../src/obidmscolumn_char.c +../../../src/obidmscolumn_char.h +../../../src/obidmscolumn_float.c +../../../src/obidmscolumn_float.h +../../../src/obidmscolumn_int.c +../../../src/obidmscolumn_int.h +../../../src/obidmscolumn_seq.c +../../../src/obidmscolumn_seq.h +../../../src/obidmscolumn_str.c +../../../src/obidmscolumn_str.h diff --git a/python/obitools3/obidms/_obidmscolumn_bool.pyx b/python/obitools3/obidms/_obidmscolumn_bool.pyx index b0fe60c..2133af0 100644 --- a/python/obitools3/obidms/_obidmscolumn_bool.pyx +++ b/python/obitools3/obidms/_obidmscolumn_bool.pyx @@ -1,7 +1,7 @@ #cython: language_level=3 -from .capi.obidmscolumn cimport obi_truncate_and_close_column, \ - obi_column_get_obibool_with_elt_name_in_view, \ +from .capi.obidmscolumn cimport obi_truncate_and_close_column +from .capi.obiview cimport obi_column_get_obibool_with_elt_name_in_view, \ obi_column_get_obibool_with_elt_idx_in_view, \ obi_column_set_obibool_with_elt_name_in_view, \ obi_column_set_obibool_with_elt_idx_in_view diff --git a/python/obitools3/obidms/_obidmscolumn_char.pyx b/python/obitools3/obidms/_obidmscolumn_char.pyx index 391cbcb..7adbe7c 100644 --- a/python/obitools3/obidms/_obidmscolumn_char.pyx +++ b/python/obitools3/obidms/_obidmscolumn_char.pyx @@ -1,7 +1,7 @@ #cython: language_level=3 -from .capi.obidmscolumn cimport obi_truncate_and_close_column, \ - obi_column_get_obichar_with_elt_name_in_view, \ +from .capi.obidmscolumn cimport obi_truncate_and_close_column +from .capi.obiview cimport obi_column_get_obichar_with_elt_name_in_view, \ obi_column_get_obichar_with_elt_idx_in_view, \ obi_column_set_obichar_with_elt_name_in_view, \ obi_column_set_obichar_with_elt_idx_in_view diff --git a/python/obitools3/obidms/_obidmscolumn_float.pyx b/python/obitools3/obidms/_obidmscolumn_float.pyx index 2783e76..608a2d1 100644 --- a/python/obitools3/obidms/_obidmscolumn_float.pyx +++ b/python/obitools3/obidms/_obidmscolumn_float.pyx @@ -1,7 +1,7 @@ #cython: language_level=3 -from .capi.obidmscolumn cimport obi_truncate_and_close_column,\ - obi_column_get_obifloat_with_elt_name_in_view, \ +from .capi.obidmscolumn cimport obi_truncate_and_close_column +from .capi.obiview cimport obi_column_get_obifloat_with_elt_name_in_view, \ obi_column_get_obifloat_with_elt_idx_in_view, \ obi_column_set_obifloat_with_elt_name_in_view, \ obi_column_set_obifloat_with_elt_idx_in_view diff --git a/python/obitools3/obidms/_obidmscolumn_int.pyx b/python/obitools3/obidms/_obidmscolumn_int.pyx index 4fcfaa5..faa9f2b 100644 --- a/python/obitools3/obidms/_obidmscolumn_int.pyx +++ b/python/obitools3/obidms/_obidmscolumn_int.pyx @@ -1,7 +1,7 @@ #cython: language_level=3 -from .capi.obidmscolumn cimport obi_truncate_and_close_column, \ - obi_column_get_obiint_with_elt_name_in_view, \ +from .capi.obidmscolumn cimport obi_truncate_and_close_column +from .capi.obiview cimport obi_column_get_obiint_with_elt_name_in_view, \ obi_column_get_obiint_with_elt_idx_in_view, \ obi_column_set_obiint_with_elt_name_in_view, \ obi_column_set_obiint_with_elt_idx_in_view diff --git a/python/obitools3/obidms/_obidmscolumn_seq.pyx b/python/obitools3/obidms/_obidmscolumn_seq.pyx index 6d9a55e..3e3f342 100644 --- a/python/obitools3/obidms/_obidmscolumn_seq.pyx +++ b/python/obitools3/obidms/_obidmscolumn_seq.pyx @@ -1,7 +1,7 @@ #cython: language_level=3 -from .capi.obidmscolumn cimport obi_truncate_and_close_column, \ - obi_column_get_obiseq_with_elt_name_in_view, \ +from .capi.obidmscolumn cimport obi_truncate_and_close_column +from .capi.obiview cimport obi_column_get_obiseq_with_elt_name_in_view, \ obi_column_get_obiseq_with_elt_idx_in_view, \ obi_column_set_obiseq_with_elt_name_in_view, \ obi_column_set_obiseq_with_elt_idx_in_view diff --git a/python/obitools3/obidms/_obidmscolumn_str.pyx b/python/obitools3/obidms/_obidmscolumn_str.pyx index e1636f9..50c3a9e 100644 --- a/python/obitools3/obidms/_obidmscolumn_str.pyx +++ b/python/obitools3/obidms/_obidmscolumn_str.pyx @@ -1,7 +1,7 @@ #cython: language_level=3 -from .capi.obidmscolumn cimport obi_truncate_and_close_column, \ - obi_column_get_obistr_with_elt_name_in_view, \ +from .capi.obidmscolumn cimport obi_truncate_and_close_column +from .capi.obiview cimport obi_column_get_obistr_with_elt_name_in_view, \ obi_column_get_obistr_with_elt_idx_in_view, \ obi_column_set_obistr_with_elt_name_in_view, \ obi_column_set_obistr_with_elt_idx_in_view @@ -16,8 +16,8 @@ from libc.string cimport strcmp cdef class OBIDMS_column_str(OBIDMS_column): cpdef object get_line(self, index_t line_nb): - cdef char* value - cdef object result + cdef const_char_p value + cdef object result value = obi_column_get_obistr_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) @@ -41,8 +41,8 @@ cdef class OBIDMS_column_str(OBIDMS_column): cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts): cpdef object get_item(self, index_t line_nb, str element_name): - cdef char* value - cdef object result + cdef const_char_p value + cdef object result value = obi_column_get_obistr_with_elt_name_in_view(self.view, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) @@ -54,11 +54,11 @@ cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts): return result cpdef object get_line(self, index_t line_nb) : - cdef char* value - cdef object value_in_result - cdef dict result - cdef index_t i - cdef bint all_NA + cdef const_char_p value + cdef object value_in_result + cdef dict result + cdef index_t i + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : diff --git a/python/obitools3/obidms/capi/obidmscolumn.pxd b/python/obitools3/obidms/capi/obidmscolumn.pxd index baa593e..1f0b0f5 100644 --- a/python/obitools3/obidms/capi/obidmscolumn.pxd +++ b/python/obitools3/obidms/capi/obidmscolumn.pxd @@ -76,30 +76,7 @@ cdef extern from "obidmscolumn.h" nogil: int obi_select(OBIDMS_column_p line_selection_column, index_t line_to_grep) -from ..capi.obiview cimport Obiview_p # TODO - cdef extern from "obidmscolumn_int.h" nogil: - int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name, - obiint_t value) - - int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx, - obiint_t value) - - obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name) - - obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, @@ -121,28 +98,6 @@ cdef extern from "obidmscolumn_int.h" nogil: cdef extern from "obidmscolumn_bool.h" nogil: - int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name, - obibool_t value) - - int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx, - obibool_t value) - - obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name) - - obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) - int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const_char_p element_name, @@ -163,28 +118,6 @@ cdef extern from "obidmscolumn_bool.h" nogil: cdef extern from "obidmscolumn_char.h" nogil: - int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name, - obichar_t value) - - int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx, - obichar_t value) - - obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name) - - obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) - int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const_char_p element_name, @@ -205,83 +138,39 @@ cdef extern from "obidmscolumn_char.h" nogil: cdef extern from "obidmscolumn_float.h" nogil: - int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name, - obifloat_t value) - - int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx, - obifloat_t value) - - obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name) - - obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) - int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name, - obifloat_t value) + index_t line_nb, + const_char_p element_name, + 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) + index_t line_nb, + index_t element_idx, + obifloat_t value) obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name) + index_t line_nb, + const_char_p element_name) obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) + index_t line_nb, + index_t element_idx) cdef extern from "obidmscolumn_str.h" nogil: - int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name, - char* value) - - int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx, - char* value) - - const_char_p obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name) - - const_char_p obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) - int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const_char_p element_name, - char* value) + const_char_p value) int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, - char* value) + const_char_p value) const_char_p obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, - index_t line_nb, - char* element_name) + index_t line_nb, + const_char_p element_name) const_char_p obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, @@ -289,43 +178,21 @@ cdef extern from "obidmscolumn_str.h" nogil: cdef extern from "obidmscolumn_seq.h" nogil: - int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name, - char* value) - - int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx, - char* value) - - const_char_p obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - const_char_p element_name) - - const_char_p obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) - int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const_char_p element_name, - char* value) + const_char_p value) int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, - char* value) + const_char_p value) - const_char_p obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, - index_t line_nb, - char* element_name) + char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name) - const_char_p obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, - index_t line_nb, - index_t element_idx) + char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, + index_t line_nb, + index_t element_idx) diff --git a/python/obitools3/obidms/capi/obiview.pxd b/python/obitools3/obidms/capi/obiview.pxd index 3af90ba..a490d67 100644 --- a/python/obitools3/obidms/capi/obiview.pxd +++ b/python/obitools3/obidms/capi/obiview.pxd @@ -3,6 +3,10 @@ from .obitypes cimport const_char_p, \ OBIType_t, \ obiversion_t, \ + obiint_t, \ + obibool_t, \ + obichar_t, \ + obifloat_t, \ index_t, \ time_t from ..capi.obidms cimport OBIDMS_p @@ -111,4 +115,136 @@ cdef extern from "obiview.h" nogil: int obi_close_view(Obiview_p view) int obi_save_and_close_view(Obiview_p view) + + int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name, + obiint_t value) + + int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx, + obiint_t value) + + obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name) + + obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx) + + int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name, + obibool_t value) + + int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx, + obibool_t value) + + obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name) + + obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx) + + int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name, + obichar_t value) + + int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx, + obichar_t value) + + obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name) + + obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx) + + int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name, + obifloat_t value) + + int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx, + obifloat_t value) + + obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name) + + obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx) + + int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name, + const_char_p value) + + int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx, + const_char_p value) + + const_char_p obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name) + + const_char_p obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx) + + int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name, + const_char_p value) + + int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx, + const_char_p value) + + char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + const_char_p element_name) + + char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, + OBIDMS_column_p column, + index_t line_nb, + index_t element_idx) diff --git a/python/obitools3/obiimport.py b/python/obitools3/obiimport.py index f0d7ff5..a07362a 100644 --- a/python/obitools3/obiimport.py +++ b/python/obitools3/obiimport.py @@ -26,16 +26,16 @@ if __name__ == '__main__': view = d.new_view('uniq view', view_type="NUC_SEQS_VIEW") - for i in range(35000000) : - if (not (i%500000)) : - print(str(time.time())+'\t'+str(i)) - id = "@HWI-D00405:142:C71BAANXX:4:1101:1234:2234_CONS_SUB_SUB_"+str(i) - view[i].set_id(id) - if id != view[i]["ID"] : - print("nope", id, view[i]["ID"]) +# for i in range(35000000) : +# if (not (i%500000)) : +# print(str(time.time())+'\t'+str(i)) +# id = "@HWI-D00405:142:C71BAANXX:4:1101:1234:2234_CONS_SUB_SUB_"+str(i) +# view[i].set_id(id) +# if id != view[i]["ID"] : +# print("nope", id, view[i]["ID"]) -# input_file = open(args.input_file, 'r') -# input_file_buffered = bufferedRead(input_file) + input_file = open(args.input_file, 'r') + input_file_buffered = bufferedRead(input_file) # # if args.input_file[-1:] == "a" : @@ -113,32 +113,32 @@ if __name__ == '__main__': # l = 0 # next = False # -# l=0 -# i=0 + l=0 + i=0 # while (True): # l+=1 # line = input_file.readline() # if line=="": # break -# for line in input_file_buffered : + for line in input_file_buffered : # -# #if i > 1E7 : + #if i > 1E7 : # # print('hmm?') # # if i == 6000000 : # break # -# if l%4 == 0 : + if l%4 == 0 : # -# if (not (i%500000)) : -# print(str(time.time())+'\t'+str(i)) + if (not (i%500000)) : + print(str(time.time())+'\t'+str(i)) # # # # #print("header", line) # # -# id = line.split(" ", 1)[0][1:] + id = line.split(" ", 1)[0][1:] # print(id) # # #rest = (line[:-1].split(" ", 1)[1]).split(";") -# view[i].set_id(id) + view[i].set_id(id) # print(view[i]["ID"]) # # i+=1 @@ -178,17 +178,17 @@ if __name__ == '__main__': # # description = description.strip() # # view[i].set_description(description) # -# # elif l%4 == 1 : + elif l%4 == 1 : # # -# # seq = line[:-1] + seq = line[:-1] # #print("seq", seq) -# # view[i].set_sequence(seq) -# # i+=1 + view[i].set_sequence(seq) + i+=1 # -# l+=1 + l+=1 # # -# input_file.close() + input_file.close() #print(view) print(view.__repr__()) diff --git a/src/obidmscolumn.c b/src/obidmscolumn.c index 23ab0dd..3ef7bc6 100644 --- a/src/obidmscolumn.c +++ b/src/obidmscolumn.c @@ -1418,7 +1418,53 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha } -char* obi_column_format_date(time_t date) +int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb) +{ + // Check if the column is read-only + if (!(column->writable)) + { + obi_set_errno(OBICOL_UNKNOWN_ERROR); + obidebug(1, "\nError trying to set a value in a read-only column"); + return -1; + } + + // Check that the line number is not greater than the maximum allowed + if (line_nb >= MAXIMUM_LINE_COUNT) + { + obi_set_errno(OBICOL_UNKNOWN_ERROR); + obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); + return -1; + } + + // Check if the file needs to be enlarged + while ((line_nb+1) > (column->header)->line_count) + { + // Enlarge the file + if (obi_enlarge_column(column) < 0) + return -1; + } + + // Update lines used + if ((line_nb+1) > (column->header)->lines_used) + (column->header)->lines_used = line_nb+1; + + return 0; +} + + +int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb) +{ + if ((line_nb+1) > ((column->header)->line_count)) + { + obi_set_errno(OBICOL_UNKNOWN_ERROR); + obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); + return -1; + } + return 0; +} + + +char* obi_column_format_date(time_t date) // TODO put in utils.c { char* formatted_time; struct tm* tmp; diff --git a/src/obidmscolumn.h b/src/obidmscolumn.h index 131dec9..443091f 100644 --- a/src/obidmscolumn.h +++ b/src/obidmscolumn.h @@ -344,7 +344,15 @@ int obi_unmap_header(OBIDMS_column_header_p header); index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name); -/** +// TODO doc +int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb); + + +// TODO doc +int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb); + + +/** TODO put in utils.c * @brief Formats a date in a way that is easy to read. * * @warning The pointer returned must be freed by the caller. diff --git a/src/obidmscolumn_bool.c b/src/obidmscolumn_bool.c index a781311..ae1f862 100644 --- a/src/obidmscolumn_bool.c +++ b/src/obidmscolumn_bool.c @@ -14,7 +14,6 @@ #include #include "obidmscolumn.h" -#include "obiview.h" #include "obitypes.h" #include "obierrno.h" #include "obidebug.h" @@ -32,25 +31,8 @@ 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 - if (line_nb >= MAXIMUM_LINE_COUNT) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); - return -1; - } - - // Check if the file needs to be enlarged - while ((line_nb+1) > (column->header)->line_count) - { - // Enlarge the file - if (obi_enlarge_column(column) < 0) - return -1; - } - - // Update lines used - if ((line_nb+1) > (column->header)->lines_used) - (column->header)->lines_used = line_nb+1; + if (obi_column_prepare_to_set_value(column, line_nb) < 0) + return -1; // Set the value *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; @@ -59,111 +41,31 @@ int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, } -int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value) -{ - // Check that the view is not read-only - if (view->read_only) - { - obi_set_errno(OBIVIEW_ERROR); - obidebug(1, "\nError trying to set a value in a column in a read-only view"); - return -1; - } - - if ((view->line_selection != NULL) || (!(column->writable))) - { - // Get the right line number - if (column->writable) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - column = obi_view_clone_column(view, (column->header)->name); - if (column == NULL) - { - obidebug(1, "\nError trying to clone a column to modify it"); - return -1; - } - } - - if ((line_nb+1) > view->line_count) - { - if (obi_view_update_lines(view, (line_nb+1)) < 0) - return -1; - } - - if (obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value) < 0) - return -1; - - return 0; -} - - 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)->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); + if (obi_column_prepare_to_get_value(column, line_nb) < 0) return OBIBool_NA; - } return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); } -obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) -{ - if ((line_nb+1) > (view->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current line count of the view"); - return OBIBool_NA; - } - - if (view->line_selection) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx); -} - - int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value) { - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value); - return 0; -} - -int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value) -{ - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return -1; - obi_column_set_obibool_with_elt_idx_in_view(view, column, line_nb, element_idx, value); - return 0; + return obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value); } obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) { - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIBool_NA; + return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx); } - -obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) -{ - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return OBIBool_NA; - return obi_column_get_obibool_with_elt_idx_in_view(view, column, line_nb, element_idx); -} diff --git a/src/obidmscolumn_bool.h b/src/obidmscolumn_bool.h index 254d43b..a660d69 100644 --- a/src/obidmscolumn_bool.h +++ b/src/obidmscolumn_bool.h @@ -19,7 +19,6 @@ #include "obidmscolumn.h" #include "obitypes.h" -#include "obiview.h" /** @@ -96,79 +95,5 @@ int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); -/** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line. - * - * @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 line_nb The number of the line where the value should be set. - * @param element_idx The index of the element that should be set in the line. - * @param value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL. - * - * @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 element_idx The index of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, 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_BOOL, - * using the name of the element in the line. - * - * @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 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 value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL, - * using the name of the element in the line. - * - * @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 element_name The name of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); - - #endif /* OBIDMSCOLUMN_BOOL_H_ */ diff --git a/src/obidmscolumn_char.c b/src/obidmscolumn_char.c index 361fb95..928ef82 100644 --- a/src/obidmscolumn_char.c +++ b/src/obidmscolumn_char.c @@ -14,7 +14,6 @@ #include #include "obidmscolumn.h" -#include "obiview.h" #include "obitypes.h" #include "obierrno.h" #include "obidebug.h" @@ -32,25 +31,8 @@ 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 - if (line_nb >= MAXIMUM_LINE_COUNT) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); - return -1; - } - - // Check if the file needs to be enlarged - while ((line_nb+1) > (column->header)->line_count) - { - // Enlarge the file - if (obi_enlarge_column(column) < 0) - return -1; - } - - // Update lines used - if ((line_nb+1) > (column->header)->lines_used) - (column->header)->lines_used = line_nb+1; + if (obi_column_prepare_to_set_value(column, line_nb) < 0) + return -1; // Set the value *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; @@ -59,111 +41,30 @@ int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, } -int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value) -{ - // Check that the view is not read-only - if (view->read_only) - { - obi_set_errno(OBIVIEW_ERROR); - obidebug(1, "\nError trying to set a value in a column in a read-only view"); - return -1; - } - - if ((view->line_selection != NULL) || (!(column->writable))) - { - // Get the right line number - if (column->writable) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - column = obi_view_clone_column(view, (column->header)->name); - if (column == NULL) - { - obidebug(1, "\nError trying to clone a column to modify it"); - return -1; - } - } - - if ((line_nb+1) > view->line_count) - { - if (obi_view_update_lines(view, (line_nb+1)) < 0) - return -1; - } - - if (obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value) < 0) - return -1; - - return 0; -} - - 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)->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); + if (obi_column_prepare_to_get_value(column, line_nb) < 0) return OBIChar_NA; - } return *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); } -obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) -{ - if ((line_nb+1) > (view->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current line count of the view"); - return OBIChar_NA; - } - - if (view->line_selection) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx); -} - - int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value) { - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value); - return 0; -} - -int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value) -{ - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return -1; - obi_column_set_obichar_with_elt_idx_in_view(view, column, line_nb, element_idx, value); - return 0; + return obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value); } obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) { - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIChar_NA; + return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx); } - - -obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) -{ - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return OBIChar_NA; - return obi_column_get_obichar_with_elt_idx_in_view(view, column, line_nb, element_idx); -} diff --git a/src/obidmscolumn_char.h b/src/obidmscolumn_char.h index 639023e..387a5f0 100644 --- a/src/obidmscolumn_char.h +++ b/src/obidmscolumn_char.h @@ -19,7 +19,6 @@ #include "obidmscolumn.h" #include "obitypes.h" -#include "obiview.h" /** @@ -96,79 +95,5 @@ int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); -/** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the index of the element in the line. - * - * @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 line_nb The number of the line where the value should be set. - * @param element_idx The index of the element that should be set in the line. - * @param value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR. - * - * @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 element_idx The index of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, 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_CHAR, - * using the name of the element in the line. - * - * @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 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 value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR, - * using the name of the element in the line. - * - * @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 element_name The name of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); - - #endif /* OBIDMSCOLUMN_CHAR_H_ */ diff --git a/src/obidmscolumn_float.c b/src/obidmscolumn_float.c index 6ecfe3c..030bdd6 100644 --- a/src/obidmscolumn_float.c +++ b/src/obidmscolumn_float.c @@ -14,7 +14,6 @@ #include #include "obidmscolumn.h" -#include "obiview.h" #include "obitypes.h" #include "obierrno.h" #include "obidebug.h" @@ -31,25 +30,8 @@ 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 - if (line_nb >= MAXIMUM_LINE_COUNT) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); - return -1; - } - - // Check if the file needs to be enlarged - while ((line_nb+1) > (column->header)->line_count) - { - // Enlarge the file - if (obi_enlarge_column(column) < 0) - return -1; - } - - // Update lines used - if ((line_nb+1) > (column->header)->lines_used) - (column->header)->lines_used = line_nb+1; + if (obi_column_prepare_to_set_value(column, line_nb) < 0) + return -1; // Set the value *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; @@ -58,111 +40,31 @@ int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb } -int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value) -{ - // Check that the view is not read-only - if (view->read_only) - { - obi_set_errno(OBIVIEW_ERROR); - obidebug(1, "\nError trying to set a value in a column in a read-only view"); - return -1; - } - - if ((view->line_selection != NULL) || (!(column->writable))) - { - // Get the right line number - if (column->writable) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - column = obi_view_clone_column(view, (column->header)->name); - if (column == NULL) - { - obidebug(1, "\nError trying to clone a column to modify it"); - return -1; - } - } - - if ((line_nb+1) > view->line_count) - { - if (obi_view_update_lines(view, (line_nb+1)) < 0) - return -1; - } - - if (obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value) < 0) - return -1; - - return 0; -} - - 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)->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); + if (obi_column_prepare_to_get_value(column, line_nb) < 0) return OBIFloat_NA; - } return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); } -obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) -{ - if ((line_nb+1) > (view->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current line count of the view"); - return OBIFloat_NA; - } - - if (view->line_selection) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx); -} - - int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value) { - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value); - return 0; -} - -int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value) -{ - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return -1; - obi_column_set_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx, value); - return 0; + return obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value); } obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) { - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIFloat_NA; + return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx); } - -obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) -{ - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return OBIFloat_NA; - return obi_column_get_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx); -} diff --git a/src/obidmscolumn_float.h b/src/obidmscolumn_float.h index 5a03b2e..51b7476 100644 --- a/src/obidmscolumn_float.h +++ b/src/obidmscolumn_float.h @@ -19,7 +19,6 @@ #include "obidmscolumn.h" #include "obitypes.h" -#include "obiview.h" /** @@ -96,79 +95,5 @@ int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_n obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); -/** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the index of the element in the line. - * - * @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 line_nb The number of the line where the value should be set. - * @param element_idx The index of the element that should be set in the line. - * @param value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT. - * - * @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 element_idx The index of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, 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_FLOAT, - * using the name of the element in the line. - * - * @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 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 value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT, - * using the name of the element in the line. - * - * @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 element_name The name of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); - - #endif /* OBIDMSCOLUMN_FLOAT_H_ */ diff --git a/src/obidmscolumn_idx.c b/src/obidmscolumn_idx.c index 95ddadb..89f5505 100644 --- a/src/obidmscolumn_idx.c +++ b/src/obidmscolumn_idx.c @@ -31,25 +31,8 @@ int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value) { - // Check that the line number is not greater than the maximum allowed - if (line_nb >= MAXIMUM_LINE_COUNT) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); - return -1; - } - - // Check if the file needs to be enlarged - while ((line_nb+1) > (column->header)->line_count) - { - // Enlarge the file - if (obi_enlarge_column(column) < 0) - return -1; - } - - // Update lines used - if ((line_nb+1) > (column->header)->lines_used) - (column->header)->lines_used = line_nb+1; + if (obi_column_prepare_to_set_value(column, line_nb) < 0) + return -1; // Set the value *(((index_t*) (column->data)) + line_nb) = value; @@ -60,12 +43,8 @@ int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value) index_t obi_column_get_index(OBIDMS_column_p column, index_t line_nb) { - if ((line_nb+1) > ((column->header)->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); + if (obi_column_prepare_to_get_value(column, line_nb) < 0) return OBIIdx_NA; - } return *(((index_t*) (column->data)) + line_nb); } diff --git a/src/obidmscolumn_idx.h b/src/obidmscolumn_idx.h index 326318a..59f87f7 100644 --- a/src/obidmscolumn_idx.h +++ b/src/obidmscolumn_idx.h @@ -20,6 +20,7 @@ #include "obidmscolumn.h" #include "obitypes.h" +// TODO doc int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value); diff --git a/src/obidmscolumn_int.c b/src/obidmscolumn_int.c index 93e66b2..60bfd7e 100644 --- a/src/obidmscolumn_int.c +++ b/src/obidmscolumn_int.c @@ -14,7 +14,6 @@ #include #include "obidmscolumn.h" -#include "obiview.h" #include "obitypes.h" #include "obierrno.h" #include "obidebug.h" @@ -29,28 +28,10 @@ * **********************************************************************/ - 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 - if (line_nb >= MAXIMUM_LINE_COUNT) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); - return -1; - } - - // Check if the file needs to be enlarged - while ((line_nb+1) > (column->header)->line_count) - { - // Enlarge the file - if (obi_enlarge_column(column) < 0) - return -1; - } - - // Update lines used - if ((line_nb+1) > (column->header)->lines_used) - (column->header)->lines_used = line_nb+1; + if (obi_column_prepare_to_set_value(column, line_nb) < 0) + return -1; // Set the value *(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; @@ -59,112 +40,31 @@ int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, } -int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value) -{ - // Check that the view is not read-only - if (view->read_only) - { - obi_set_errno(OBIVIEW_ERROR); - obidebug(1, "\nError trying to set a value in a column in a read-only view"); - return -1; - } - - if ((view->line_selection != NULL) || (!(column->writable))) - { - // Get the right line number - if (column->writable) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - column = obi_view_clone_column(view, (column->header)->name); - if (column == NULL) - { - obidebug(1, "\nError trying to clone a column to modify it"); - return -1; - } - } - - if ((line_nb+1) > view->line_count) - { - if (obi_view_update_lines(view, (line_nb+1)) < 0) - return -1; - } - - if (obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value) < 0) - return -1; - - return 0; -} - - 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)->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); + if (obi_column_prepare_to_get_value(column, line_nb) < 0) return OBIInt_NA; - } return *(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); } -obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) -{ - if ((line_nb+1) > (view->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current line count of the view"); - return OBIInt_NA; - } - - if (view->line_selection) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx); -} - - int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value) { - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value); - return 0; -} - -int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value) -{ - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return -1; - obi_column_set_obiint_with_elt_idx_in_view(view, column, line_nb, element_idx, value); - return 0; + return obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value); } obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) { - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIInt_NA; + return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx); } - -obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) -{ - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return OBIInt_NA; - return obi_column_get_obiint_with_elt_idx_in_view(view, column, line_nb, element_idx); -} - diff --git a/src/obidmscolumn_int.h b/src/obidmscolumn_int.h index afe52ee..3e6f600 100644 --- a/src/obidmscolumn_int.h +++ b/src/obidmscolumn_int.h @@ -19,7 +19,6 @@ #include "obidmscolumn.h" #include "obitypes.h" -#include "obiview.h" /** @@ -96,79 +95,5 @@ int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); -/** - * @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the index of the element in the line. - * - * @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 line_nb The number of the line where the value should be set. - * @param element_idx The index of the element that should be set in the line. - * @param value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT. - * - * @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 element_idx The index of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, 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_INT, - * using the name of the element in the line. - * - * @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 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 value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT, - * using the name of the element in the line. - * - * @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 element_name The name of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); - - #endif /* OBIDMSCOLUMN_INT_H_ */ diff --git a/src/obidmscolumn_seq.c b/src/obidmscolumn_seq.c index fe099b9..fc9b3f2 100644 --- a/src/obidmscolumn_seq.c +++ b/src/obidmscolumn_seq.c @@ -14,7 +14,6 @@ #include #include "obidmscolumn.h" -#include "obiview.h" #include "obitypes.h" #include "obierrno.h" #include "obidebug.h" @@ -30,31 +29,14 @@ * **********************************************************************/ - -int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value) +int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) { index_t idx; - // Check that the line number is not greater than the maximum allowed - if (line_nb >= MAXIMUM_LINE_COUNT) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); - return -1; - } - - // Check if the file needs to be enlarged - while ((line_nb+1) > (column->header)->line_count) - { - // Enlarge the file - if (obi_enlarge_column(column) < 0) - return -1; - } - - // Update lines used - if ((line_nb+1) > (column->header)->lines_used) - (column->header)->lines_used = line_nb+1; + if (obi_column_prepare_to_set_value(column, line_nb) < 0) + return -1; + // Add the value in the indexer idx = obi_index_dna_seq(column->indexer, value); if (idx == -1) return -1; @@ -66,50 +48,12 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, } -int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value) -{ - // Check that the view is not read-only - if (view->read_only) - { - obi_set_errno(OBIVIEW_ERROR); - obidebug(1, "\nError trying to set a value in a column in a read-only view"); - return -1; - } - - if ((view->line_selection != NULL) || (!(column->writable))) - { - // Get the right line number - if (column->writable) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - column = obi_view_clone_column(view, (column->header)->name); - if (column == NULL) - { - obidebug(1, "\nError trying to clone a column to modify it"); - return -1; - } - } - - if ((line_nb+1) > view->line_count) - { - if (obi_view_update_lines(view, (line_nb+1)) < 0) - return -1; - } - - return obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value); -} - - -const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx) +char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx) { index_t idx; - if ((line_nb+1) > ((column->header)->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); + if (obi_column_prepare_to_get_value(column, line_nb) < 0) return OBISeq_NA; - } idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); @@ -121,60 +65,22 @@ const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t l } -const char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) { - if ((line_nb+1) > (view->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current line count of the view"); - return OBISeq_NA; - } - - if (view->line_selection) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - return obi_column_get_obiseq_with_elt_idx(column, line_nb, element_idx); -} - - -int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value) -{ - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; + return obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value); } -int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value) +char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) { - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return -1; - return obi_column_set_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx, value); -} - - -const char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) -{ - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBISeq_NA; + return obi_column_get_obiseq_with_elt_idx(column, line_nb, element_idx); } - -const char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) -{ - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return OBISeq_NA; - return obi_column_get_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx); -} - diff --git a/src/obidmscolumn_seq.h b/src/obidmscolumn_seq.h index a948b06..55f3b03 100644 --- a/src/obidmscolumn_seq.h +++ b/src/obidmscolumn_seq.h @@ -40,7 +40,7 @@ * @since November 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value); +int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value); /** @@ -57,7 +57,7 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, * @since November 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx); +char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx); /** @@ -78,7 +78,7 @@ const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t l * @since November 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value); +int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value); /** @@ -95,83 +95,7 @@ int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, * @since November 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -const char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); - - -/** - * @brief Sets a value in an OBIDMS column containing data in the form of indices referring - * to DNA sequences handled by an indexer, using the index of the element in the line. - * - * @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 line_nb The number of the line where the value should be set. - * @param element_idx The index of the element that should be set in the line. - * @param value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring - * to DNA sequences handled by an indexer, using the index of the element in the line. - * - * @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 element_idx The index of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -const char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); - - -/** - * @brief Sets a value in an OBIDMS column containing data in the form of indices referring - * to DNA sequences handled by an indexer, using the name of the element in the line. - * - * @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 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 value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring - * to DNA sequences handled by an indexer, using the name of the element in the line. - * - * @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 element_name The name of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -const char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); #endif /* OBIDMSCOLUMN_SEQ_H_ */ diff --git a/src/obidmscolumn_str.c b/src/obidmscolumn_str.c index ee1a429..6a9c19b 100644 --- a/src/obidmscolumn_str.c +++ b/src/obidmscolumn_str.c @@ -14,7 +14,6 @@ #include #include "obidmscolumn.h" -#include "obiview.h" #include "obitypes.h" #include "obierrno.h" #include "obidebug.h" @@ -30,31 +29,14 @@ * **********************************************************************/ -int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_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, const char* value) { - index_t idx; + index_t idx; - // Check that the line number is not greater than the maximum allowed - if (line_nb >= MAXIMUM_LINE_COUNT) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed"); - return -1; - } + if (obi_column_prepare_to_set_value(column, line_nb) < 0) + return -1; - // Check if the file needs to be enlarged - while ((line_nb+1) > (column->header)->line_count) - { - // Enlarge the file - if (obi_enlarge_column(column) < 0) - return -1; - } - - // Update lines used - if ((line_nb+1) > (column->header)->lines_used) - (column->header)->lines_used = line_nb+1; - - // Add in the indexer + // Add the value in the indexer idx = obi_index_char_str(column->indexer, value); if (idx == -1) return -1; @@ -66,50 +48,12 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, } -int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value) -{ - // Check that the view is not read-only - if (view->read_only) - { - obi_set_errno(OBIVIEW_ERROR); - obidebug(1, "\nError trying to set a value in a column in a read-only view"); - return -1; - } - - if ((view->line_selection != NULL) || (!(column->writable))) // TODO why check here writable? - { - // Get the right line number - if (column->writable) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - column = obi_view_clone_column(view, (column->header)->name); - if (column == NULL) - { - obidebug(1, "\nError trying to clone a column to modify it"); - return -1; - } - } - - if ((line_nb+1) > view->line_count) - { - if (obi_view_update_lines(view, (line_nb+1)) < 0) - return -1; - } - - return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value); -} - - 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; - if ((line_nb+1) > ((column->header)->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column"); - return OBIStr_NA; - } + if (obi_column_prepare_to_get_value(column, line_nb) < 0) + return OBISeq_NA; idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); @@ -121,60 +65,22 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t l } -const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) { - if ((line_nb+1) > (view->line_count)) - { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current line count of the view"); - return OBIStr_NA; - } - - if (view->line_selection) - line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb); - - return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx); -} - - -int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value) -{ - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; + return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value); } -int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value) -{ - index_t element_idx; - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return -1; - return obi_column_set_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx, value); -} - - const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) { - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIStr_NA; + return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx); } - -const char* obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) -{ - index_t element_idx; - - element_idx = obi_column_get_element_index_from_name(column, element_name); - if (element_idx == OBIIdx_NA) - return OBIStr_NA; - return obi_column_get_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx); -} - diff --git a/src/obidmscolumn_str.h b/src/obidmscolumn_str.h index 7689c44..1cd98df 100644 --- a/src/obidmscolumn_str.h +++ b/src/obidmscolumn_str.h @@ -40,7 +40,7 @@ * @since October 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_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, const char* value); /** @@ -78,7 +78,7 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t l * @since October 2015 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_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, const char* value); /** @@ -98,81 +98,5 @@ int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); -/** - * @brief Sets a value in an OBIDMS column containing data in the form of indices referring - * to character strings handled by an indexer, using the index of the element in the line. - * - * @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 line_nb The number of the line where the value should be set. - * @param element_idx The index of the element that should be set in the line. - * @param value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring - * to character strings handled by an indexer, using the index of the element in the line. - * - * @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 element_idx The index of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); - - -/** - * @brief Sets a value in an OBIDMS column containing data in the form of indices referring - * to character strings handled by an indexer, using the name of the element in the line. - * - * @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 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 value The value that should be set. - * - * @returns An integer value indicating the success of the operation. - * @retval 0 on success. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value); - - -/** - * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring - * to character strings handled by an indexer, using the name of the element in the line. - * - * @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 element_name The name of the element that should be recovered in the line. - * - * @returns The recovered value. - * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -const char* obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); - - #endif /* OBIDMSCOLUMN_STR_H_ */ diff --git a/src/obiview.c b/src/obiview.c index 47ab071..a383182 100644 --- a/src/obiview.c +++ b/src/obiview.c @@ -25,6 +25,12 @@ #include "utils.h" #include "obilittlebigman.h" #include "obidmscolumn_idx.h" +#include "obidmscolumn_bool.h" +#include "obidmscolumn_char.h" +#include "obidmscolumn_float.h" +#include "obidmscolumn_int.h" +#include "obidmscolumn_seq.h" +#include "obidmscolumn_str.h" #define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?) @@ -73,6 +79,14 @@ static char* build_obiview_file_name(); int create_obiview_file(int dms_file_descriptor); +// TODO doc +int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, index_t* line_nb_p); + + +// TODO doc +int prepare_to_get_value_in_column(Obiview_p view, OBIDMS_column_p column, index_t* line_nb_p); + + /************************************************************************ * * D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S @@ -203,6 +217,58 @@ int create_obiview_file(int dms_file_descriptor) } +int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, index_t* line_nb_p) +{ + // Check that the view is not read-only + if (view->read_only) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError trying to set a value in a column in a read-only view"); + return -1; + } + + // If there is a line selection associated with the view or if the column + // is read-only, all columns or this column respectively must be cloned + if ((view->line_selection != NULL) || (!((*column_pp)->writable))) + { + // Get the right line number + if (view->line_selection != NULL) + (*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p)); + + (*column_pp) = obi_view_clone_column(view, ((*column_pp)->header)->name); + if ((*column_pp) == NULL) + { + obidebug(1, "\nError trying to clone a column to modify it"); + return -1; + } + } + + if (((*line_nb_p)+1) > view->line_count) + { + if (obi_view_update_lines(view, ((*line_nb_p)+1)) < 0) + return -1; + } + + return 0; +} + + +int prepare_to_get_value_from_column(Obiview_p view, OBIDMS_column_p column, index_t* line_nb_p) +{ + if (((*line_nb_p)+1) > (view->line_count)) + { + obi_set_errno(OBICOL_UNKNOWN_ERROR); + obidebug(1, "\nError trying to get a value that is beyond the current line count of the view"); + return -1; + } + + if (view->line_selection) + (*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p)); + + return 0; +} + + /********************************************************************** * * D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S @@ -1148,3 +1214,231 @@ int obi_save_and_close_view(Obiview_p view) return 0; } + +/*********** FOR BOOL COLUMNS ***********/ + +int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value) +{ + if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) + return -1; + return obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value); +} + + +obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +{ + if (prepare_to_get_value_from_column(view, column, &line_nb) < 0) + return OBIBool_NA; + return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx); +} + + +int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return -1; + return obi_column_set_obibool_with_elt_idx_in_view(view, column, line_nb, element_idx, value); +} + + +obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return OBIBool_NA; + return obi_column_get_obibool_with_elt_idx_in_view(view, column, line_nb, element_idx); +} + +/****************************************/ + + +/*********** FOR CHAR COLUMNS ***********/ + +int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value) +{ + if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) + return -1; + return obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value); +} + + +obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +{ + if (prepare_to_get_value_from_column(view, column, &line_nb) < 0) + return OBIChar_NA; + return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx); +} + + +int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return -1; + return obi_column_set_obichar_with_elt_idx_in_view(view, column, line_nb, element_idx, value); +} + + +obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return OBIChar_NA; + return obi_column_get_obichar_with_elt_idx_in_view(view, column, line_nb, element_idx); +} + +/****************************************/ + + +/*********** FOR FLOAT COLUMNS ***********/ + +int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value) +{ + if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) + return -1; + return obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value); +} + + +obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +{ + if (prepare_to_get_value_from_column(view, column, &line_nb) < 0) + return OBIFloat_NA; + return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx); +} + + +int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return -1; + return obi_column_set_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx, value); +} + + +obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return OBIFloat_NA; + return obi_column_get_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx); +} + +/****************************************/ + + +/*********** FOR INT COLUMNS ***********/ + +int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value) +{ + if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) + return -1; + return obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value); +} + + +obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +{ + if (prepare_to_get_value_from_column(view, column, &line_nb) < 0) + return OBIInt_NA; + return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx); +} + + +int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return -1; + return obi_column_set_obiint_with_elt_idx_in_view(view, column, line_nb, element_idx, value); +} + + +obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return OBIInt_NA; + return obi_column_get_obiint_with_elt_idx_in_view(view, column, line_nb, element_idx); +} + +/****************************************/ + + +/*********** FOR SEQ COLUMNS ***********/ + +int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) +{ + if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) + return -1; + return obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value); +} + + +char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +{ + if (prepare_to_get_value_from_column(view, column, &line_nb) < 0) + return OBISeq_NA; + return obi_column_get_obiseq_with_elt_idx(column, line_nb, element_idx); +} + + +int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return -1; + return obi_column_set_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx, value); +} + + +char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return OBISeq_NA; + return obi_column_get_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx); +} + +/****************************************/ + + +/*********** FOR STR COLUMNS ***********/ + +int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) +{ + if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) + return -1; + return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value); +} + + +const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +{ + if (prepare_to_get_value_from_column(view, column, &line_nb) < 0) + return OBIStr_NA; + return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx); +} + + +int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return -1; + return obi_column_set_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx, value); +} + + +const char* obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +{ + index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + if (element_idx == OBIIdx_NA) + return OBIStr_NA; + return obi_column_get_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx); +} + +/****************************************/ + diff --git a/src/obiview.h b/src/obiview.h index 5ff7bb5..207c501 100644 --- a/src/obiview.h +++ b/src/obiview.h @@ -186,4 +186,455 @@ int obi_close_view(Obiview_p view); int obi_save_and_close_view(Obiview_p view); +int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line. + * + * @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 line_nb The number of the line where the value should be set. + * @param element_idx The index of the element that should be set in the line. + * @param value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL. + * + * @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 element_idx The index of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, 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_BOOL, + * using the name of the element in the line. + * + * @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 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 value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL, + * using the name of the element in the line. + * + * @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 element_name The name of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the index of the element in the line. + * + * @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 line_nb The number of the line where the value should be set. + * @param element_idx The index of the element that should be set in the line. + * @param value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR. + * + * @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 element_idx The index of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, 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_CHAR, + * using the name of the element in the line. + * + * @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 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 value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR, + * using the name of the element in the line. + * + * @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 element_name The name of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the index of the element in the line. + * + * @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 line_nb The number of the line where the value should be set. + * @param element_idx The index of the element that should be set in the line. + * @param value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT. + * + * @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 element_idx The index of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, 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_FLOAT, + * using the name of the element in the line. + * + * @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 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 value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT, + * using the name of the element in the line. + * + * @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 element_name The name of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the index of the element in the line. + * + * @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 line_nb The number of the line where the value should be set. + * @param element_idx The index of the element that should be set in the line. + * @param value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT. + * + * @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 element_idx The index of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, 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_INT, + * using the name of the element in the line. + * + * @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 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 value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT, + * using the name of the element in the line. + * + * @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 element_name The name of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); + + +/** + * @brief Sets a value in an OBIDMS column containing data in the form of indices referring + * to DNA sequences handled by an indexer, using the index of the element in the line. + * + * @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 line_nb The number of the line where the value should be set. + * @param element_idx The index of the element that should be set in the line. + * @param value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring + * to DNA sequences handled by an indexer, using the index of the element in the line. + * + * @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 element_idx The index of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); + + +/** + * @brief Sets a value in an OBIDMS column containing data in the form of indices referring + * to DNA sequences handled by an indexer, using the name of the element in the line. + * + * @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 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 value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring + * to DNA sequences handled by an indexer, using the name of the element in the line. + * + * @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 element_name The name of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); + + +/** + * @brief Sets a value in an OBIDMS column containing data in the form of indices referring + * to character strings handled by an indexer, using the index of the element in the line. + * + * @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 line_nb The number of the line where the value should be set. + * @param element_idx The index of the element that should be set in the line. + * @param value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring + * to character strings handled by an indexer, using the index of the element in the line. + * + * @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 element_idx The index of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); + + +/** + * @brief Sets a value in an OBIDMS column containing data in the form of indices referring + * to character strings handled by an indexer, using the name of the element in the line. + * + * @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 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 value The value that should be set. + * + * @returns An integer value indicating the success of the operation. + * @retval 0 on success. + * @retval -1 if an error occurred. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value); + + +/** + * @brief Recovers a value in an OBIDMS column containing data in the form of indices referring + * to character strings handled by an indexer, using the name of the element in the line. + * + * @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 element_name The name of the element that should be recovered in the line. + * + * @returns The recovered value. + * @retval '\0' the NA value of the type if an error occurred and obi_errno is set. + * + * @since February 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +const char* obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); + + #endif /* OBIVIEW_H_ */