diff --git a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd index c7c2e59..d9d8fac 100644 --- a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd +++ b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd @@ -5,8 +5,11 @@ from libc.stdint cimport * cdef extern from "obitypes.h" nogil: enum OBIType: pass + enum OBIBool: + pass ctypedef OBIType OBIType_t + ctypedef OBIBool obibool_t ctypedef int32_t obiint_t ctypedef double obifloat_t ctypedef char obichar_t diff --git a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx index 24fc56d..737a0ce 100644 --- a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx +++ b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx @@ -3,6 +3,9 @@ from .capidmscolumn cimport * from obitools3.obidms.obidmscolumn.obidmscolumn_int.capidmscolumn_int import OBIDMS_column_int from obitools3.obidms.obidmscolumn.obidmscolumn_float.capidmscolumn_float import OBIDMS_column_float +from obitools3.obidms.obidmscolumn.obidmscolumn_bool.capidmscolumn_bool import OBIDMS_column_bool +#from obitools3.obidms.obidmscolumn.obidmscolumn_char.capidmscolumn_char import OBIDMS_column_char +from obitools3.obidms.obidmscolumn.obidmscolumn_idx.capidmscolumn_idx import OBIDMS_column_idx cdef class OBIDMS_column: @@ -100,6 +103,24 @@ cdef class OBIDMS_column: create, version_number, type, nb_elements, nb_elements_per_line, elements_names) + + elif type == 3 : + column = OBIDMS_column_bool(dms_name, column_name, + create, version_number, + type, nb_elements, + nb_elements_per_line, elements_names) + +# elif type == 4 : +# column = OBIDMS_column_char(dms_name, column_name, +# create, version_number, +# type, nb_elements, +# nb_elements_per_line, elements_names) + + elif type == 5 : + column = OBIDMS_column_idx(dms_name, column_name, + create, version_number, + type, nb_elements, + nb_elements_per_line, elements_names) else : "Problem with the data type" diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/__init__.py b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.cfiles b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.cfiles new file mode 100644 index 0000000..02b49a6 --- /dev/null +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.cfiles @@ -0,0 +1,16 @@ +../../../../../src/obidmscolumn_bool.c +../../../../../src/obidmscolumn_bool.h +../../../../../src/obidmscolumn.h +../../../../../src/obidmscolumn.c +../../../../../src/obidmscolumndir.h +../../../../../src/obidmscolumndir.c +../../../../../src/obidms.h +../../../../../src/obidms.c +../../../../../src/obierrno.h +../../../../../src/obierrno.c +../../../../../src/obilittlebigman.h +../../../../../src/obilittlebigman.c +../../../../../src/obitypes.h +../../../../../src/obitypes.c +../../../../../src/private_at_functions.h +../../../../../src/private_at_functions.c diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd new file mode 100644 index 0000000..77f1051 --- /dev/null +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd @@ -0,0 +1,7 @@ +from obitools3.obidms.obidmscolumn.capidmscolumn cimport * + + +cdef extern from "obidmscolumn_bool.h" nogil: + + int obi_column_set_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value) + obibool_t obi_column_get_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx) diff --git a/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx new file mode 100644 index 0000000..f657f36 --- /dev/null +++ b/python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx @@ -0,0 +1,30 @@ +#cython: language_level=3 + +from .capidmscolumn_bool cimport * + + +cdef class OBIDMS_column_bool(OBIDMS_column) : + + def set_item(self, line_nb, element_name, value): + if element_name != "" : + element_idx = self.get_element_index_from_name(element_name) + else : + if obi_column_get_nb_elements_per_line(self.pointer) == 1 : + element_idx = 0 + else : + print("An element name must be specified") + return -1 + return obi_column_set_bool(self.pointer, line_nb, element_idx, value) + + def get_item(self, line_nb, element_name): + if element_name != "" : + element_idx = self.get_element_index_from_name(element_name) + else : + if obi_column_get_nb_elements_per_line(self.pointer) == 1 : + element_idx = 0 + else : + print("An element name must be specified") + return -1 + return obi_column_get_bool(self.pointer, line_nb, element_idx) + + \ No newline at end of file diff --git a/src/obidmscolumn_bool.c b/src/obidmscolumn_bool.c new file mode 100644 index 0000000..0c07818 --- /dev/null +++ b/src/obidmscolumn_bool.c @@ -0,0 +1,41 @@ +/**************************************************************************** + * OBIDMS_column_bool functions * + ****************************************************************************/ + +/** + * @file obidsmcolumn_bool.c + * @author Celine Mercier + * @date August 10th 2015 + * @brief Functions handling OBIColumns containing data with the OBIType OBI_BOOL. + */ + + +#include +#include + +#include "obidmscolumn.h" +#include "obitypes.h" +#include "obierrno.h" +#include "obidebug.h" + + +/********************************************************************** + * + * 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 + * + **********************************************************************/ + +int obi_column_set_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value) +{ + // when/where check if can write? + // check if value in enum? + *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value; + return 0; +} + + +obibool_t obi_column_get_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx) +{ + return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx); +} + diff --git a/src/obidmscolumn_bool.h b/src/obidmscolumn_bool.h new file mode 100644 index 0000000..d26f0bb --- /dev/null +++ b/src/obidmscolumn_bool.h @@ -0,0 +1,59 @@ +/**************************************************************************** + * OBIDMS_column_bool header file * + ****************************************************************************/ + +/** + * @file obidsmcolumn_bool.h + * @author Celine Mercier + * @date August 10th 2015 + * @brief Header file for the functions handling OBIColumns containing data with the OBIType OBI_BOOL. + */ + + +#include +#include + +#include "obidmscolumn.h" +#include "obitypes.h" + + +/** + * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL. + * + * @param column a pointer as returned by obi_create_column() + * @warning Pointers returned by obi_open_column() don't allow writing. + * + * @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 + * + * @return an integer value indicating the success of the operation. + * + * @retvalue 0 on success + * @retvalue -1 on failure and the `obi_errno` variable is set. + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_column_set_bool(OBIDMS_column_p column, size_t line_nb, size_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 + * + * @return the recovered value + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +obibool_t obi_column_get_bool(OBIDMS_column_p column, size_t line_nb, size_t element_idx); + + diff --git a/src/obitypes.c b/src/obitypes.c index b273a9d..00e61f3 100644 --- a/src/obitypes.c +++ b/src/obitypes.c @@ -30,6 +30,9 @@ size_t obi_sizeof(OBIType_t type) case OBI_FLOAT: size = sizeof(obifloat_t); break; + case OBI_BOOL: size = sizeof(obibool_t); + break; + case OBI_CHAR: size = sizeof(obichar_t); break; @@ -77,6 +80,9 @@ char* name_data_type(int data_type) case OBI_FLOAT: name = strdup("OBI_FLOAT"); break; + case OBI_BOOL: name = strdup("OBI_BOOL"); + break; + case OBI_CHAR: name = strdup("OBI_CHAR"); break; diff --git a/src/obitypes.h b/src/obitypes.h index f6a09b3..92cd124 100644 --- a/src/obitypes.h +++ b/src/obitypes.h @@ -21,11 +21,11 @@ /** * @brief enum for the boolean OBIType. */ -typedef enum { +typedef enum OBIBool { FALSE = 0, TRUE = 1, OBIBool_NA = 2 -} OBIBool_t, *OBIBool_p; /**< a boolean true/false value */ +} obibool_t, *obibool_p; /**< a boolean true/false value */ /** @@ -35,6 +35,7 @@ typedef enum OBIType { OBI_VOID = 0, /**< data type not specified */ OBI_INT, /**< a signed integer value (C type : int32_t) */ OBI_FLOAT, /**< a floating value (C type : double) */ + OBI_BOOL, /**< a boolean true/false value, see obibool_t enum */ OBI_CHAR, /**< a character (C type : char) */ OBI_IDX /**< an index in a data structure (C type : size_t) */ } OBIType_t, *OBIType_p;