functions to get data type as a character string

This commit is contained in:
celinemercier
2015-08-03 11:46:21 +02:00
parent 5f62cd8526
commit 1e01c9059c
4 changed files with 65 additions and 5 deletions

View File

@ -12,6 +12,8 @@ cdef extern from "obitypes.h" nogil:
ctypedef char obichar_t ctypedef char obichar_t
ctypedef size_t obiidx_t ctypedef size_t obiidx_t
char* name_data_type(int data_type)
cdef extern from "obidmscolumn.h" nogil: cdef extern from "obidmscolumn.h" nogil:
struct OBIDMS_column_t: struct OBIDMS_column_t:
@ -35,6 +37,6 @@ cdef extern from "obidmscolumn.h" nogil:
cdef class OBIDMS_column: cdef class OBIDMS_column:
cdef OBIDMS_column_p pointer cdef OBIDMS_column_p pointer
cdef OBIDMS_p dms cdef OBIDMS_p dms
cdef OBIType_t data_type cdef str data_type # keep as OBIType_t? both?
cdef str dms_name cdef str dms_name
cdef str column_name cdef str column_name

View File

@ -14,7 +14,7 @@ cdef class OBIDMS_column:
dms_name_b = dms_name.encode(encoding='UTF-8') dms_name_b = dms_name.encode(encoding='UTF-8')
self.dms_name = dms_name self.dms_name = dms_name
self.column_name = column_name self.column_name = column_name
self.data_type = type self.data_type = (name_data_type(type)).decode('UTF-8')
if create : if create :
dms = obi_dms(dms_name_b) dms = obi_dms(dms_name_b)
self.dms = dms self.dms = dms

View File

@ -5,7 +5,15 @@
* Author: coissac * Author: coissac
*/ */
#include <obitypes.h>
#include <string.h>
#include "obitypes.h"
#include "obidebug.h"
#include "obierrno.h"
#define DEBUG_LEVEL 0
size_t obi_sizeof(OBIType_t type) 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; 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;
}

View File

@ -17,10 +17,10 @@
#define OBIFloat_NA (NAN) #define OBIFloat_NA (NAN)
#define OBIIdx_NA (SIZE_MAX) #define OBIIdx_NA (SIZE_MAX)
/** /**
* @brief enum for the boolean OBIType. * @brief enum for the boolean OBIType.
*/ */
typedef enum { typedef enum {
FALSE = 0, FALSE = 0,
TRUE = 1, TRUE = 1,
@ -31,7 +31,6 @@ typedef enum {
/** /**
* @brief enum OBITypes for the data type of the OBIDMS columns. * @brief enum OBITypes for the data type of the OBIDMS columns.
*/ */
typedef enum OBIType { typedef enum OBIType {
OBI_VOID = 0, /**< data type not specified */ OBI_VOID = 0, /**< data type not specified */
OBI_INT, /**< a signed integer value (C type : int32_t) */ 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) */ OBI_IDX /**< an index in a data structure (C type : size_t) */
} OBIType_t, *OBIType_p; } OBIType_t, *OBIType_p;
typedef int32_t obiint_t; typedef int32_t obiint_t;
typedef double obifloat_t; typedef double obifloat_t;
typedef char obichar_t; typedef char obichar_t;
typedef size_t obiidx_t; typedef size_t obiidx_t;
/** /**
* @brief returns the memory size in bytes of an OBIType * @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); size_t obi_sizeof(OBIType_t type);
/** /**
* @brief returns the size requested to store an array of OBIType * @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); 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_ */ #endif /* OBITYPES_H_ */