From 621b4972db22ddbdba86071d682026ad20486f66 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Fri, 18 Nov 2016 15:59:50 +0100 Subject: [PATCH] Functions to get obiblobs through views --- src/obidmscolumn_blob.c | 6 +++--- src/obidmscolumn_blob.h | 4 ++-- src/obiview.c | 40 ++++++++++++++++++++++++++++++++++++++ src/obiview.h | 43 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/src/obidmscolumn_blob.c b/src/obidmscolumn_blob.c index 117a310..34447b5 100644 --- a/src/obidmscolumn_blob.c +++ b/src/obidmscolumn_blob.c @@ -25,7 +25,7 @@ **********************************************************************/ -Obi_blob_p obi_column_get_obiblob_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx) +Obi_blob_p obi_column_get_blob_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx) { index_t idx; @@ -42,12 +42,12 @@ Obi_blob_p obi_column_get_obiblob_with_elt_idx(OBIDMS_column_p column, index_t l } -Obi_blob_p obi_column_get_obiblob_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) +Obi_blob_p obi_column_get_blob_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIBlob_NA; - return obi_column_get_obiblob_with_elt_idx(column, line_nb, element_idx); + return obi_column_get_blob_with_elt_idx(column, line_nb, element_idx); } diff --git a/src/obidmscolumn_blob.h b/src/obidmscolumn_blob.h index c17df59..a8d0c6d 100644 --- a/src/obidmscolumn_blob.h +++ b/src/obidmscolumn_blob.h @@ -36,7 +36,7 @@ * @since November 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -Obi_blob_p obi_column_get_obiblob_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx); +Obi_blob_p obi_column_get_blob_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx); /** @@ -53,7 +53,7 @@ Obi_blob_p obi_column_get_obiblob_with_elt_idx(OBIDMS_column_p column, index_t l * @since November 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -Obi_blob_p obi_column_get_obiblob_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); +Obi_blob_p obi_column_get_blob_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name); #endif /* OBIDMSCOLUMN_BLOB_H_ */ diff --git a/src/obiview.c b/src/obiview.c index 3e3b12c..e3dfda3 100644 --- a/src/obiview.c +++ b/src/obiview.c @@ -20,6 +20,7 @@ #include "obidms.h" #include "obidmscolumn.h" #include "obidmscolumn_idx.h" +#include "obidmscolumn_blob.h" #include "obidmscolumn_bool.h" #include "obidmscolumn_char.h" #include "obidmscolumn_float.h" @@ -32,6 +33,7 @@ #include "obilittlebigman.h" #include "hashtable.h" #include "utils.h" +#include "obiblob.h" #define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?) @@ -2000,6 +2002,44 @@ int obi_save_and_close_view(Obiview_p view) } +/*********** FOR BLOB COLUMNS ***********/ + +Obi_blob_p obi_get_blob_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) +{ + if (prepare_to_get_value_from_column(view, &line_nb) < 0) + return OBIBlob_NA; + return obi_column_get_blob_with_elt_idx(column_p, line_nb, element_idx); +} + + +Obi_blob_p obi_get_blob_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name) +{ + index_t element_idx = obi_column_get_element_index_from_name(column_p, element_name); + if (element_idx == OBIIdx_NA) + return OBIBlob_NA; + return obi_get_blob_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +Obi_blob_p obi_get_blob_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIBlob_NA; + return obi_get_blob_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +Obi_blob_p obi_get_blob_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIBlob_NA; + return obi_get_blob_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); +} + /*********** FOR BOOL COLUMNS ***********/ int obi_set_bool_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obibool_t value) diff --git a/src/obiview.h b/src/obiview.h index 053e288..a7c3da8 100644 --- a/src/obiview.h +++ b/src/obiview.h @@ -26,6 +26,7 @@ #include "obidmscolumn.h" #include "obierrno.h" #include "hashtable.h" +#include "obiblob.h" #define OBIVIEW_NAME_MAX_LENGTH (249) /**< The maximum length of an OBIDMS view name, without the extension. @@ -490,6 +491,48 @@ int obi_close_view(Obiview_p view); int obi_save_and_close_view(Obiview_p view); +/** + * @brief Recovers an obiblob from an OBIDMS column containing indices referring to obiblobs, in the context of a view. + * + * @param view A pointer on the opened view. + * @param column_p A pointer on the column. + * @param line_nb The number of the line where the value should be recovered. + * @param element_idx The index of the element that should be recovered in the line. + * + * @returns The recovered obiblob. + * @retval OBIBlob_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since November 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +Obi_blob_p obi_get_blob_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + +// TODO +Obi_blob_p obi_get_blob_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); + + +/** + * @brief Recovers an obiblob from an OBIDMS column containing indices referring to obiblobs, + * using the name of the element in the line, in the context of a view. + * + * @param view A pointer on the opened view. + * @param column_p A pointer on the column. + * @param line_nb The number of the line where the value should be recovered. + * @param element_name The name of the element that should be recovered in the line. + * + * @returns The recovered obiblob. + * @retval OBIBlob_NA the NA value of the type if an error occurred and obi_errno is set. + * + * @since November 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +Obi_blob_p obi_get_blob_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +Obi_blob_p obi_get_blob_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); + + /** * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line, * in the context of a view.