Commit 1e01c905 by celinemercier

functions to get data type as a character string

parent 5f62cd85
......@@ -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
......@@ -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
......
......@@ -5,7 +5,15 @@
* 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)
......@@ -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;
}
......@@ -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_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment