obidmscolumn_blob.c 1.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/****************************************************************************
 * OBIDMS_column_blob functions                                             *
 ****************************************************************************/

/**
 * @file obidsmcolumn_blob.c
 * @author Celine Mercier
 * @date November 9th 2015
 * @brief Functions handling OBIColumns containing data in the form of indices referring to Obiblobs, to get blobs directly without decoding.
 */


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

#include "obidmscolumn.h"
#include "obitypes.h"
#include "obiblob.h"


/**********************************************************************
 *
 * 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
 *
 **********************************************************************/


28
Obi_blob_p obi_column_get_blob_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
{
	index_t idx;

	if (obi_column_prepare_to_get_value(column, line_nb) < 0)
		return OBIBlob_NA;

	idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);

	// Check NA
	if (idx == OBIIdx_NA)
		return OBIBlob_NA;

	return obi_indexer_get(column->indexer, idx);
}


45
Obi_blob_p obi_column_get_blob_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
46 47 48 49 50
{
	index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
	if (element_idx == OBIIdx_NA)
		return OBIBlob_NA;

51
	return obi_column_get_blob_with_elt_idx(column, line_nb, element_idx);
52 53
}