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

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

12

Celine Mercier committed
13 14 15 16
#ifndef OBITYPES_H_
#define OBITYPES_H_

#include <stdio.h>
17
#include <unistd.h>
Eric Coissac committed
18
#include <stdint.h>
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
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 committed
27
#define OBIBlob_NA (NULL)			/**< NA value for the type Obiblobs */  // TODO discuss
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 */
30
#define OBITuple_NA (NULL)			/**< NA value for tuples of any type */
31

32

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


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

58

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

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

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


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


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


97 98 99 100 101 102 103 104 105 106
/**
 * @brief Trick to suppress compilation warnings about unused
 *        float_NA function actually called in macro.
 */
static inline void suppress_warning(void) {
	(void)float_NA;
	(void)suppress_warning;
}


107
/**
108
 * @brief Returns the memory size in bytes of an OBIType.
109
 *
110
 * @param type The OBIType code used as query.
111
 *
112 113
 * @returns The size in bytes of the type.
 * @retval 0 if an error occurred (unknown type).
114 115 116 117 118 119
 *
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 */
size_t obi_sizeof(OBIType_t type);

120

121
/**
122
 * @brief Returns the size required to store an array of elements with an OBIType.
123
 *
124
 * The returned size is large enough to store an array large enough
125
 * to store all the elements but rounded at a multiple of the memory page size.
126
 *
127 128 129
 * @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.
130
 *
131 132
 * @returns The size in bytes of the array.
 * @retval 0 if an error occurred (unknown type).
133 134 135 136
 *
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 */
137
size_t obi_array_sizeof(OBIType_t data_type, index_t nb_lines, index_t nb_elements_per_line);
Celine Mercier committed
138

139 140

/**
141
 * @brief Returns the name in the form of a character string of an OBIType.
142 143
 *
 *
144
 * @param data_type The OBIType code used as query.
145
 *
146 147
 * @returns The name of the OBIType.
 * @retval NULL if an error occurred (unknown type or error allocating the memory for the character string).
148 149 150 151 152 153 154
 *
 * @since August 2015
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
char* name_data_type(int data_type);


Celine Mercier committed
155
#endif /* OBITYPES_H_ */