obidmscolumn_bool.c 2.01 KB
Newer Older
1
/****************************************************************************
2
 * OBIDMS_column_bool functions                                             *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 ****************************************************************************/

/**
 * @file obidsmcolumn_bool.c
 * @author Celine Mercier
 * @date August 10th 2015
 * @brief Functions handling OBIColumns containing data with the OBIType OBI_BOOL.
 */


#include <stdlib.h>
#include <stdio.h>

#include "obidmscolumn.h"
#include "obitypes.h"
18 19


20 21 22 23 24 25
/**********************************************************************
 *
 * D E F I N I T I O N   O F   T H E   P U B L I C   F U N C T I O N S
 *
 **********************************************************************/

Celine Mercier committed
26

27
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value)
28
{
29
	if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0)
30
		return -1;
31 32

	// Set the value
Celine Mercier committed
33
	*(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
34

35 36 37 38
	return 0;
}


Celine Mercier committed
39 40
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
{
41
	if (obi_column_prepare_to_get_value(column, line_nb) < 0)
42
		return OBIBool_NA;
43

Celine Mercier committed
44 45 46 47
	return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
}


48
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value)
49
{
50
	index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
51
	if (element_idx == OBIIdx_NA)
52
		return -1;
53

54
	return obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value);
Celine Mercier committed
55 56 57
}


58
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
59
{
60
	index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
61
	if (element_idx == OBIIdx_NA)
62
		return OBIBool_NA;
63

64
	return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
65
}
66