2015-09-30 12:03:46 +02:00
/****************************************************************************
* Header file for OBITypes *
****************************************************************************/
2015-05-22 17:54:34 +02:00
/**
* @file obitypes.h
2015-09-30 12:03:46 +02:00
* @author Celine Mercier (celine.mercier@metabarcoding.org)
2015-05-22 17:54:34 +02:00
* @date 18 May 2015
2015-09-30 12:03:46 +02:00
* @brief Header file for the handling of OBITypes.
2015-05-22 17:54:34 +02:00
*/
2015-09-30 12:03:46 +02:00
2015-05-22 17:54:34 +02:00
#ifndef OBITYPES_H_
#define OBITYPES_H_
#include <stdio.h>
2015-05-23 16:50:49 +03:00
#include <unistd.h>
2015-05-26 10:38:56 +02:00
#include <stdint.h>
2015-05-22 17:54:34 +02:00
2015-06-10 15:19:02 +02:00
2015-09-30 12:03:46 +02:00
#define OBIInt_NA (INT32_MIN) /**< NA value for the type OBI_INT */
2015-11-06 17:55:15 +01:00
#define OBIIdx_NA (INT64_MIN) /**< NA value for indices */
2015-09-30 12:03:46 +02:00
#define OBIFloat_NA (float_NA()) /**< NA value for the type OBI_FLOAT */
2016-04-25 10:33:01 +02:00
#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
2016-06-03 18:54:25 +02:00
#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
2016-11-10 15:01:29 +01:00
#define OBIBlob_NA (NULL) /**< NA value for the type Obiblobs */ // TODO discuss
2016-06-03 18:54:25 +02:00
#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 */
2017-11-15 13:48:59 +01:00
#define OBITuple_NA (NULL) /**< NA value for tuples of any type */
2015-08-03 11:46:21 +02:00
2018-10-17 13:13:23 +02:00
2015-05-22 17:54:34 +02:00
/**
* @brief enum for the boolean OBIType.
*/
2015-08-11 11:00:59 +02:00
typedef enum OBIBool {
2015-05-22 17:54:34 +02:00
FALSE = 0 ,
TRUE = 1 ,
OBIBool_NA = 2
2016-02-18 10:38:51 +01:00
} obibool_t , * obibool_p ; /**< a boolean true/false value */ // TODO check name convention?
2015-05-22 17:54:34 +02:00
/**
2015-06-10 15:19:02 +02:00
* @brief enum OBITypes for the data type of the OBIDMS columns.
2015-05-22 17:54:34 +02:00
*/
typedef enum OBIType {
OBI_VOID = 0 , /**< data type not specified */
2015-05-23 16:50:49 +03:00
OBI_INT , /**< a signed integer value (C type : int32_t) */
OBI_FLOAT , /**< a floating value (C type : double) */
2015-08-11 11:00:59 +02:00
OBI_BOOL , /**< a boolean true/false value, see obibool_t enum */
2015-05-23 16:50:49 +03:00
OBI_CHAR , /**< a character (C type : char) */
2016-05-11 16:38:14 +02:00
OBI_QUAL , /**< an index in a data structure (C type : int64_t) referring to a quality score array */
2015-11-29 11:57:07 +01:00
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 */
2016-04-25 10:33:01 +02:00
OBI_IDX /**< an index referring to a line in another column (C type : int64_t) */
2015-05-22 17:54:34 +02:00
} OBIType_t , * OBIType_p ;
2015-08-03 11:46:21 +02:00
2016-04-25 10:33:01 +02:00
/**
* Typedefs for the OBITypes.
*/
2015-05-22 17:54:34 +02:00
typedef int32_t obiint_t ;
typedef double obifloat_t ;
typedef char obichar_t ;
2016-04-25 10:33:01 +02:00
typedef int64_t index_t ;
2015-08-03 11:46:21 +02:00
2016-04-25 10:33:01 +02:00
typedef char byte_t ; /**< Defining byte type.
*/
2015-12-11 17:24:44 +01:00
2016-04-25 10:33:01 +02:00
typedef int32_t obiversion_t ; /**< Defining type for version numbers.
*/
2015-12-11 17:24:44 +01:00
2015-09-30 12:03:46 +02:00
/**
* @brief Union used to compute the NA value of the OBI_FLOAT OBIType.
*/
2015-08-26 12:00:38 +02:00
typedef union
{
double value ;
unsigned int word [ 2 ];
} ieee_double ;
2015-09-30 12:03:46 +02:00
/**
* @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 )
2015-08-26 12:00:38 +02:00
{
volatile ieee_double x ;
x . word [ 0 ] = 0x7ff00000 ;
x . word [ 1 ] = 1954 ;
return x . value ;
}
2018-10-17 13:13:23 +02:00
/**
* @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 ;
}
2015-05-23 16:50:49 +03:00
/**
2015-09-30 12:03:46 +02:00
* @brief Returns the memory size in bytes of an OBIType.
2015-05-23 16:50:49 +03:00
*
2015-09-30 12:03:46 +02:00
* @param type The OBIType code used as query.
2015-05-23 16:50:49 +03:00
*
2015-09-30 12:03:46 +02:00
* @returns The size in bytes of the type.
* @retval 0 if an error occurred (unknown type).
2015-05-23 16:50:49 +03:00
*
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
size_t obi_sizeof ( OBIType_t type );
2015-08-03 11:46:21 +02:00
2015-05-23 16:50:49 +03:00
/**
2015-09-30 12:03:46 +02:00
* @brief Returns the size required to store an array of elements with an OBIType.
2015-05-23 16:50:49 +03:00
*
2015-09-30 12:03:46 +02:00
* The returned size is large enough to store an array large enough
2016-04-25 10:33:01 +02:00
* to store all the elements but rounded at a multiple of the memory page size.
2015-05-23 16:50:49 +03:00
*
2015-09-30 12:03:46 +02:00
* @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.
2015-05-23 16:50:49 +03:00
*
2015-09-30 12:03:46 +02:00
* @returns The size in bytes of the array.
* @retval 0 if an error occurred (unknown type).
2015-05-23 16:50:49 +03:00
*
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
2015-11-06 17:55:15 +01:00
size_t obi_array_sizeof ( OBIType_t data_type , index_t nb_lines , index_t nb_elements_per_line );
2015-05-22 17:54:34 +02:00
2015-08-03 11:46:21 +02:00
/**
2015-09-30 12:03:46 +02:00
* @brief Returns the name in the form of a character string of an OBIType.
2015-08-03 11:46:21 +02:00
*
*
2015-09-30 12:03:46 +02:00
* @param data_type The OBIType code used as query.
2015-08-03 11:46:21 +02:00
*
2015-09-30 12:03:46 +02:00
* @returns The name of the OBIType.
* @retval NULL if an error occurred (unknown type or error allocating the memory for the character string).
2015-08-03 11:46:21 +02:00
*
* @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
char * name_data_type ( int data_type );
2015-05-22 17:54:34 +02:00
#endif /* OBITYPES_H_ */