obitypes.h 4.05 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
#define OBIInt_NA (INT32_MIN)		/**< NA value for the type OBI_INT */
22
#define OBIIdx_NA (INT64_MIN)		/**< NA value for indices */
23
#define OBIFloat_NA (float_NA())	/**< NA value for the type OBI_FLOAT */
24 25 26
#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
#define OBISeq_NA ("\0")			/**< NA value for the type OBI_SEQ */  // TODO discuss
#define OBIStr_NA ("\0")			/**< NA value for the type OBI_STR */  // TODO discuss
Celine Mercier's avatar
Celine Mercier committed
27

28

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


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

53

54 55 56
/**
 * Typedefs for the OBITypes.
 */
Celine Mercier's avatar
Celine Mercier committed
57 58 59
typedef int32_t obiint_t;
typedef double obifloat_t;
typedef char obichar_t;
60
typedef int64_t index_t;
61

62 63
typedef char byte_t;			/**< Defining byte type.
 	 	 	 	 	 	 	 	 */
64

65 66
typedef int32_t obiversion_t;	/**< Defining type for version numbers.
	 	 	 	 	 	 	 	 */
67 68


69 70 71
/**
 * @brief Union used to compute the NA value of the OBI_FLOAT OBIType.
 */
72 73 74 75 76 77 78
typedef union
{
    double value;
    unsigned int word[2];
} ieee_double;


79 80 81 82 83
/**
 * @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)
84 85 86 87 88 89 90 91
{
    volatile ieee_double x;
    x.word[0] = 0x7ff00000;
    x.word[1] = 1954;
    return x.value;
}


92
/**
93
 * @brief Returns the memory size in bytes of an OBIType.
94
 *
95
 * @param type The OBIType code used as query.
96
 *
97 98
 * @returns The size in bytes of the type.
 * @retval 0 if an error occurred (unknown type).
99 100 101 102 103 104
 *
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 */
size_t obi_sizeof(OBIType_t type);

105

106
/**
107
 * @brief Returns the size required to store an array of elements with an OBIType.
108
 *
109
 * The returned size is large enough to store an array large enough
110
 * to store all the elements but rounded at a multiple of the memory page size.
111
 *
112 113 114
 * @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.
115
 *
116 117
 * @returns The size in bytes of the array.
 * @retval 0 if an error occurred (unknown type).
118 119 120 121
 *
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 */
122
size_t obi_array_sizeof(OBIType_t data_type, index_t nb_lines, index_t nb_elements_per_line);
Celine Mercier's avatar
Celine Mercier committed
123

124 125

/**
126
 * @brief Returns the name in the form of a character string of an OBIType.
127 128
 *
 *
129
 * @param data_type The OBIType code used as query.
130
 *
131 132
 * @returns The name of the OBIType.
 * @retval NULL if an error occurred (unknown type or error allocating the memory for the character string).
133 134 135 136 137 138 139
 *
 * @since August 2015
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
char* name_data_type(int data_type);


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