obitypes.h 4.45 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
#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
25 26
#define OBISeq_NA (NULL)			/**< NA value for the type OBI_SEQ */  // TODO discuss
#define OBIStr_NA (NULL)			/**< NA value for the type OBI_STR */  // TODO discuss
Celine Mercier's avatar
Celine Mercier committed
27
#define OBIBlob_NA (NULL)			/**< NA value for the type Obiblobs */  // TODO discuss
Celine Mercier's avatar
Celine Mercier committed
28 29
#define OBIQual_char_NA (NULL)		/**< NA value for the type OBI_QUAL if the quality is in character string format */
#define OBIQual_int_NA (NULL)		/**< NA value for the type OBI_QUAL if the quality is in integer format */
Celine Mercier's avatar
Celine Mercier committed
30

31

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


/**
43
 * @brief enum OBITypes for the data type of the OBIDMS columns.
Celine Mercier's avatar
Celine Mercier committed
44 45 46
 */
typedef enum OBIType {
	OBI_VOID    = 0,     		/**< data type not specified */
47 48
	OBI_INT,			    	/**< a signed integer value (C type : int32_t) */
	OBI_FLOAT,					/**< a floating value (C type : double) */
49
	OBI_BOOL,					/**< a boolean true/false value, see obibool_t enum */
50
	OBI_CHAR,					/**< a character (C type : char) */
51
	OBI_QUAL,					/**< an index in a data structure (C type : int64_t) referring to a quality score array */
52 53
	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 */
54
	OBI_IDX					    /**< an index referring to a line in another column (C type : int64_t) */
Celine Mercier's avatar
Celine Mercier committed
55 56
} OBIType_t, *OBIType_p;

57

58 59 60
/**
 * Typedefs for the OBITypes.
 */
Celine Mercier's avatar
Celine Mercier committed
61 62 63
typedef int32_t obiint_t;
typedef double obifloat_t;
typedef char obichar_t;
64
typedef int64_t index_t;
65

66 67
typedef char byte_t;			/**< Defining byte type.
 	 	 	 	 	 	 	 	 */
68

69 70
typedef int32_t obiversion_t;	/**< Defining type for version numbers.
	 	 	 	 	 	 	 	 */
71 72


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


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


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

109

110
/**
111
 * @brief Returns the size required to store an array of elements with an OBIType.
112
 *
113
 * The returned size is large enough to store an array large enough
114
 * to store all the elements but rounded at a multiple of the memory page size.
115
 *
116 117 118
 * @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.
119
 *
120 121
 * @returns The size in bytes of the array.
 * @retval 0 if an error occurred (unknown type).
122 123 124 125
 *
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 */
126
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
127

128 129

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


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