From 1e01c9059ce7f71358105ac44737f6003e2eb5b7 Mon Sep 17 00:00:00 2001 From: celinemercier Date: Mon, 3 Aug 2015 11:46:21 +0200 Subject: [PATCH] functions to get data type as a character string --- .../obidms/obidmscolumn/capidmscolumn.pxd | 4 +- .../obidms/obidmscolumn/capidmscolumn.pyx | 2 +- src/obitypes.c | 42 ++++++++++++++++++- src/obitypes.h | 22 +++++++++- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd index 9798927..c7c2e59 100644 --- a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd +++ b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pxd @@ -12,6 +12,8 @@ cdef extern from "obitypes.h" nogil: ctypedef char obichar_t ctypedef size_t obiidx_t + char* name_data_type(int data_type) + cdef extern from "obidmscolumn.h" nogil: struct OBIDMS_column_t: @@ -35,6 +37,6 @@ cdef extern from "obidmscolumn.h" nogil: cdef class OBIDMS_column: cdef OBIDMS_column_p pointer cdef OBIDMS_p dms - cdef OBIType_t data_type + cdef str data_type # keep as OBIType_t? both? cdef str dms_name cdef str column_name diff --git a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx index 17fcf9e..7d07fd4 100644 --- a/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx +++ b/python/obitools3/obidms/obidmscolumn/capidmscolumn.pyx @@ -14,7 +14,7 @@ cdef class OBIDMS_column: dms_name_b = dms_name.encode(encoding='UTF-8') self.dms_name = dms_name self.column_name = column_name - self.data_type = type + self.data_type = (name_data_type(type)).decode('UTF-8') if create : dms = obi_dms(dms_name_b) self.dms = dms diff --git a/src/obitypes.c b/src/obitypes.c index d7927c2..b273a9d 100644 --- a/src/obitypes.c +++ b/src/obitypes.c @@ -5,7 +5,15 @@ * Author: coissac */ -#include + +#include + +#include "obitypes.h" +#include "obidebug.h" +#include "obierrno.h" + + +#define DEBUG_LEVEL 0 size_t obi_sizeof(OBIType_t type) @@ -53,3 +61,35 @@ size_t obi_array_sizeof(OBIType_t type, size_t nb_elements, size_t nb_elements_p return size; } + +char* name_data_type(int data_type) +{ + char* name = NULL; + + switch (data_type) + { + case OBI_VOID: name = strdup("OBI_VOID"); + break; + + case OBI_INT: name = strdup("OBI_INT"); + break; + + case OBI_FLOAT: name = strdup("OBI_FLOAT"); + break; + + case OBI_CHAR: name = strdup("OBI_CHAR"); + break; + + case OBI_IDX: name = strdup("OBI_IDX"); + break; + } + + if (name == NULL) + obidebug(1, "Problem with the data type"); + + return name; +} + + + + diff --git a/src/obitypes.h b/src/obitypes.h index 0f13cd2..f6a09b3 100644 --- a/src/obitypes.h +++ b/src/obitypes.h @@ -17,10 +17,10 @@ #define OBIFloat_NA (NAN) #define OBIIdx_NA (SIZE_MAX) + /** * @brief enum for the boolean OBIType. */ - typedef enum { FALSE = 0, TRUE = 1, @@ -31,7 +31,6 @@ typedef enum { /** * @brief enum OBITypes for the data type of the OBIDMS columns. */ - typedef enum OBIType { OBI_VOID = 0, /**< data type not specified */ OBI_INT, /**< a signed integer value (C type : int32_t) */ @@ -40,11 +39,13 @@ typedef enum OBIType { OBI_IDX /**< an index in a data structure (C type : size_t) */ } OBIType_t, *OBIType_p; + typedef int32_t obiint_t; typedef double obifloat_t; typedef char obichar_t; typedef size_t obiidx_t; + /** * @brief returns the memory size in bytes of an OBIType * @@ -58,6 +59,7 @@ typedef size_t obiidx_t; */ size_t obi_sizeof(OBIType_t type); + /** * @brief returns the size requested to store an array of OBIType * @@ -75,4 +77,20 @@ size_t obi_sizeof(OBIType_t type); */ size_t obi_array_sizeof(OBIType_t type, size_t nbelements, size_t nb_elements_per_line); + +/** + * @brief returns the name in the form of a character string of an OBIType + * + * + * @param data_type the OBIType code used as query + * + * @return the name of the OBIType + * @retval NULL on error (unknown type or error allocating the memory for the character string) + * + * @since August 2015 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* name_data_type(int data_type); + + #endif /* OBITYPES_H_ */