Major update : views
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
@ -29,19 +30,12 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
|
||||
{
|
||||
byte_t* value_b;
|
||||
index_t idx;
|
||||
|
||||
// Check that the column is not referring another
|
||||
if ((column->header)->referring)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError: Setting a value from a referring column is not allowed. The referred column must be cloned to be modified");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
@ -73,7 +67,7 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
return -1;
|
||||
|
||||
// Add the value's index in the column
|
||||
*(((index_t*) (column->data)) + (line_nb * ((column->header)->stored_nb_elements_per_line)) + element_idx) = idx;
|
||||
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
||||
|
||||
free(value_b);
|
||||
|
||||
@ -81,44 +75,100 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((view->line_selection != NULL) || (!(column->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (column->writable)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
column = obi_view_clone_column(view, (column->header)->name);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_nb+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
index_t idx;
|
||||
byte_t* value_b;
|
||||
index_t referring_idx;
|
||||
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return "\0"; // TODO
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
return OBISeq_NA;
|
||||
}
|
||||
|
||||
if ((column->header)->referring)
|
||||
{
|
||||
referring_idx = *(((index_t*) (column->data)) + line_nb);
|
||||
idx = *(((index_t*) ((column->referred_column)->data)) + (referring_idx * ((column->header)->returned_nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
else
|
||||
idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->stored_nb_elements_per_line)) + element_idx);
|
||||
idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
|
||||
// Check NA
|
||||
if (idx == OBIIdx_NA)
|
||||
return "\0"; // TODO
|
||||
return OBISeq_NA;
|
||||
|
||||
value_b = obi_avl_get(column->avl, idx);
|
||||
return obi_obibytes_to_seq(value_b);
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return OBISeq_NA;
|
||||
}
|
||||
|
||||
if (view->line_selection)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
return obi_column_get_obiseq_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
if (obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -129,7 +179,18 @@ const char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return "\0";
|
||||
return OBISeq_NA;
|
||||
return obi_column_get_obiseq_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return OBISeq_NA;
|
||||
return obi_column_get_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user