obitypes.h 3.53 KB
Newer Older
1 2 3 4
/****************************************************************************
 * Header file for OBITypes                                                 *
 ****************************************************************************/

Celine Mercier's avatar
Celine Mercier committed
5 6
/**
 * @file obitypes.h
7
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
Celine Mercier's avatar
Celine Mercier committed
8
 * @date 18 May 2015
9
 * @brief Header file for the handling of OBITypes.
Celine Mercier's avatar
Celine Mercier committed
10 11
 */

12

Celine Mercier's avatar
Celine Mercier committed
13 14 15 16
#ifndef OBITYPES_H_
#define OBITYPES_H_

#include <stdio.h>
17
#include <unistd.h>
Eric Coissac's avatar
Eric Coissac committed
18
#include <stdint.h>
Celine Mercier's avatar
Celine Mercier committed
19

20

21 22 23 24 25
#define OBIInt_NA (INT32_MIN)		/**< NA value for the type OBI_INT */
#define OBIIdx_NA (SIZE_MAX)		/**< NA value for the type OBI_IDX */
#define OBIFloat_NA (float_NA())	/**< NA value for the type OBI_FLOAT */
#define OBIChar_NA (0)				/**< NA value for the type OBI_CHAR */
										 // TODO not sure about this one as it can be impossible to distinguish from uninitialized values
Celine Mercier's avatar
Celine Mercier committed
26

27

Celine Mercier's avatar
Celine Mercier committed
28 29 30
/**
 * @brief enum for the boolean OBIType.
 */
31
typedef enum OBIBool {
Celine Mercier's avatar
Celine Mercier committed
32 33 34
    FALSE      = 0,
    TRUE       = 1,
    OBIBool_NA = 2
35
} obibool_t, *obibool_p; 		/**< a boolean true/false value */
Celine Mercier's avatar
Celine Mercier committed
36 37 38


/**
39
 * @brief enum OBITypes for the data type of the OBIDMS columns.
Celine Mercier's avatar
Celine Mercier committed
40 41 42
 */
typedef enum OBIType {
	OBI_VOID    = 0,     		/**< data type not specified */
43 44
	OBI_INT,			    	/**< a signed integer value (C type : int32_t) */
	OBI_FLOAT,					/**< a floating value (C type : double) */
45
	OBI_BOOL,					/**< a boolean true/false value, see obibool_t enum */
46 47
	OBI_CHAR,					/**< a character (C type : char) */
	OBI_IDX					    /**< an index in a data structure (C type : size_t) */
Celine Mercier's avatar
Celine Mercier committed
48 49
} OBIType_t, *OBIType_p;

50

Celine Mercier's avatar
Celine Mercier committed
51 52 53 54 55
typedef int32_t obiint_t;
typedef double obifloat_t;
typedef char obichar_t;
typedef size_t obiidx_t;

56

57 58 59
/**
 * @brief Union used to compute the NA value of the OBI_FLOAT OBIType.
 */
60 61 62 63 64 65 66
typedef union
{
    double value;
    unsigned int word[2];
} ieee_double;


67 68 69 70 71
/**
 * @brief Returns the NA value of the OBI_FLOAT OBIType.
 * This value corresponds to the float NA value as defined in R.
 */
static double float_NA(void)
72 73 74 75 76 77 78 79
{
    volatile ieee_double x;
    x.word[0] = 0x7ff00000;
    x.word[1] = 1954;
    return x.value;
}


80
/**
81
 * @brief Returns the memory size in bytes of an OBIType.
82
 *
83
 * @param type The OBIType code used as query.
84
 *
85 86
 * @returns The size in bytes of the type.
 * @retval 0 if an error occurred (unknown type).
87 88 89 90 91 92
 *
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 */
size_t obi_sizeof(OBIType_t type);

93

94
/**
95
 * @brief Returns the size required to store an array of elements with an OBIType.
96
 *
97 98
 * The returned size is large enough to store an array large enough
 * to store all the elements but rounded at a multiple of the memory page size.				// TODO this might be redundant but still a good thing
99
 *
100 101 102
 * @param data_type The OBIType of the elements.
 * @param nb_lines The number of lines to be stored.
 * @param nb_elements_per_line The number of elements per line.
103
 *
104 105
 * @returns The size in bytes of the array.
 * @retval 0 if an error occurred (unknown type).
106 107 108 109
 *
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 */
110
size_t obi_array_sizeof(OBIType_t data_type, size_t nb_lines, size_t nb_elements_per_line);
Celine Mercier's avatar
Celine Mercier committed
111

112 113

/**
114
 * @brief Returns the name in the form of a character string of an OBIType.
115 116
 *
 *
117
 * @param data_type The OBIType code used as query.
118
 *
119 120
 * @returns The name of the OBIType.
 * @retval NULL if an error occurred (unknown type or error allocating the memory for the character string).
121 122 123 124 125 126 127
 *
 * @since August 2015
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
char* name_data_type(int data_type);


Celine Mercier's avatar
Celine Mercier committed
128
#endif /* OBITYPES_H_ */