
elements per line in a more efficient way + now elements_names are passed as a list + new function to recover only the header of a column
93 lines
2.8 KiB
C
93 lines
2.8 KiB
C
/****************************************************************************
|
|
* OBIDMS_column_bool functions *
|
|
****************************************************************************/
|
|
|
|
/**
|
|
* @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"
|
|
#include "obierrno.h"
|
|
#include "obidebug.h"
|
|
|
|
|
|
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
|
|
|
|
|
/**********************************************************************
|
|
*
|
|
* 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
|
|
*
|
|
**********************************************************************/
|
|
|
|
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value)
|
|
{
|
|
// Check that the line number is not greater than the maximum allowed
|
|
if (line_nb >= MAXIMUM_LINE_COUNT)
|
|
{
|
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
|
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
|
return -1;
|
|
}
|
|
|
|
// Check if the file needs to be enlarged
|
|
while ((line_nb+1) > (column->header)->line_count)
|
|
{
|
|
// Enlarge the file
|
|
if (obi_enlarge_column(column) < 0)
|
|
return -1;
|
|
}
|
|
|
|
// Update lines used
|
|
if ((line_nb+1) > (column->header)->lines_used)
|
|
(column->header)->lines_used = line_nb+1;
|
|
|
|
// Set the value
|
|
*(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
|
{
|
|
if ((line_nb+1) > (column->header)->lines_used)
|
|
{
|
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
|
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
|
return OBIBool_NA;
|
|
}
|
|
return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
|
}
|
|
|
|
|
|
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name, obibool_t value)
|
|
{
|
|
size_t element_idx;
|
|
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
|
if (element_idx == SIZE_MAX) //TODO
|
|
return -1;
|
|
obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value);
|
|
return 0;
|
|
}
|
|
|
|
|
|
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, const char* element_name)
|
|
{
|
|
size_t element_idx;
|
|
|
|
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
|
if (element_idx == SIZE_MAX) //TODO
|
|
return OBIBool_NA;
|
|
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
|
|
}
|
|
|