obitypes.h 4.42 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
27
#define OBIQual_char_NA ("\0")		/**< NA value for the type OBI_QUAL if the quality is in character string format */  // TODO test and discuss
28
#define OBIQual_int_NA (NULL)		/**< NA value for the type OBI_QUAL if the quality is in integer format */  // TODO test and discuss
Celine Mercier's avatar
Celine Mercier committed
29

30

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


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

56

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

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

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


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


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


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

108

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

127 128

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


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