2016-02-18 10:38:51 +01:00
/********************************************************************
* Obiview functions *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @ file obiview . c
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
* @ date 16 December 2015
* @ brief Obiview functions .
*/
# include <stdlib.h>
# include <stdio.h>
# include <stdbool.h>
# include <fcntl.h>
# include <sys/mman.h>
2018-08-08 19:51:05 +02:00
# include <inttypes.h>
2016-02-18 10:38:51 +01:00
# include "obiview.h"
2016-04-25 11:37:53 +02:00
# include "obidms.h"
2016-02-18 10:38:51 +01:00
# include "obidmscolumn.h"
# include "obidmscolumn_idx.h"
2016-11-18 15:59:50 +01:00
# include "obidmscolumn_blob.h"
2016-04-13 15:10:24 +02:00
# include "obidmscolumn_bool.h"
# include "obidmscolumn_char.h"
# include "obidmscolumn_float.h"
# include "obidmscolumn_int.h"
2016-05-20 16:45:22 +02:00
# include "obidmscolumn_qual.h"
2016-04-13 15:10:24 +02:00
# include "obidmscolumn_seq.h"
# include "obidmscolumn_str.h"
2017-11-15 13:48:59 +01:00
# include "obidmscolumn_array.h"
2016-04-25 11:37:53 +02:00
# include "obierrno.h"
# include "obidebug.h"
# include "obilittlebigman.h"
2016-08-01 18:25:30 +02:00
# include "hashtable.h"
2017-03-06 16:06:17 +01:00
# include "linked_list.h"
2016-04-25 11:37:53 +02:00
# include "utils.h"
2016-11-18 15:59:50 +01:00
# include "obiblob.h"
2018-10-07 18:56:46 +02:00
# include "libjson/json_utils.h"
2016-02-18 10:38:51 +01:00
# define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
/**************************************************************************
*
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2016-09-06 16:22:24 +02:00
/**
2017-02-07 17:16:09 +01:00
* Internal function building the file name where the informations about a finished , read - only obiview are stored .
2016-09-06 16:22:24 +02:00
*
* @ warning The returned pointer has to be freed by the caller .
*
* @ param view_name The name of the view .
*
* @ returns A pointer to the file name .
* @ retval NULL if an error occurred .
*
* @ since June 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
static char * build_obiview_file_name ( const char * view_name ) ;
/**
2017-02-07 17:16:09 +01:00
* Internal function building the file name where the informations about an unfinished , writable obiview are stored .
*
* @ warning The returned pointer has to be freed by the caller .
*
* @ param view_name The name of the view .
*
* @ returns A pointer to the file name .
* @ retval NULL if an error occurred .
*
* @ since February 2017
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
static char * build_unfinished_obiview_file_name ( const char * view_name ) ;
/**
* Internal function checking if a view ( either finished or unfinished ) with a given name already exists in a DMS .
2016-09-06 16:22:24 +02:00
*
* @ param dms The DMS .
* @ param view_name The name of the view .
*
* @ returns A boolean value indicating whether the view already exists or not .
*
* @ since September 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static bool view_exists ( OBIDMS_p dms , const char * view_name ) ;
2016-09-06 16:22:24 +02:00
2018-10-31 14:38:05 +01:00
/**
* Internal function checking if a view is finished .
*
* @ param dms The DMS .
* @ param view_name The name of the view .
*
2018-10-31 18:01:04 +01:00
* @ retval 1 if the view is finished .
* @ retval 0 if the view is not finished .
2018-10-31 14:38:05 +01:00
* @ retval - 1 if the view does not exist or if an error occurred .
*
* @ since October 2018
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2018-10-31 18:01:04 +01:00
static int view_is_finished ( OBIDMS_p dms , const char * view_name ) ;
2018-10-31 14:38:05 +01:00
2016-08-01 18:25:30 +02:00
/**
2016-08-18 17:57:03 +02:00
* Internal function calculating the initial size of the file where the informations about an obiview are stored .
2016-08-01 18:25:30 +02:00
*
2016-08-18 17:57:03 +02:00
* @ returns The initial size of the file in bytes , rounded to a multiple of page size .
2016-08-01 18:25:30 +02:00
*
* @ since June 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2018-10-17 12:00:40 +02:00
static size_t get_platform_view_file_size ( void ) ;
2016-08-01 18:25:30 +02:00
2016-02-18 10:38:51 +01:00
2016-08-18 17:57:03 +02:00
/**
* @ brief Internal function enlarging a view file .
*
* @ param view A pointer on the view .
* @ param new_size The new size needed , in bytes ( not necessarily rounded to a page size multiple ) .
*
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since August 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int enlarge_view_file ( Obiview_p view , size_t new_size ) ;
2016-08-18 17:57:03 +02:00
2016-06-30 11:41:30 +02:00
/**
* @ brief Internal function creating a file containing all the informations on a view .
2016-02-18 10:38:51 +01:00
*
2016-06-30 11:41:30 +02:00
* The file is named with the name of the view .
2016-02-18 10:38:51 +01:00
*
2016-06-30 11:41:30 +02:00
* @ param dms The DMS to which the view belongs .
* @ param view_name The name of the view .
2016-02-18 10:38:51 +01:00
*
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
2016-06-30 11:41:30 +02:00
* @ since June 2016
2016-02-18 10:38:51 +01:00
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int create_obiview_file ( OBIDMS_p dms , const char * view_name ) ;
2016-06-30 11:41:30 +02:00
/**
* @ brief Internal function to update the column references of a view .
*
* The column references stored in the mapped view infos structures are updated
* to match the columns opened in the opened view structure .
*
2016-08-01 18:25:30 +02:00
* @ warning The column pointer array should be up to date before using this function .
* @ warning Aliases are not updated by this function and have to be edited separately .
* This function simply reads the column pointer array associated with the view
* and fills the column names and versions in the column reference array accordingly ,
* without touching the alias .
* That means that for example if there is a shift in the column pointer array , this
* function should not be used .
*
2016-06-30 11:41:30 +02:00
* @ param view A pointer on the view .
*
2017-03-06 16:06:17 +01:00
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
2016-06-30 11:41:30 +02:00
* @ since June 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-03-06 16:06:17 +01:00
static int update_column_refs ( Obiview_p view ) ;
2016-02-18 10:38:51 +01:00
2016-08-01 18:25:30 +02:00
/**
* @ brief Internal function creating the column dictionary associated with a view .
*
* The column dictionary is built from the column references array , and associates each column alias
* with the pointer on the column .
*
* @ warning The column reference array and the column pointer array should be up to date before using this function .
*
* @ param view A pointer on the view .
*
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int create_column_dict ( Obiview_p view ) ;
2016-08-01 18:25:30 +02:00
/**
* @ brief Internal function updating the column dictionary associated with a view .
*
* The column dictionary is built from the column references array , and associates each column alias
* with the pointer on the column .
*
* @ warning The column reference array and the column pointer array should be up to date before using this function .
*
* @ param view A pointer on the view .
*
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int update_column_dict ( Obiview_p view ) ;
2016-08-01 18:25:30 +02:00
/**
* @ brief Internal function updating the column reference array and the column dictionary associated with a view .
*
* The column reference array is updated from the column pointer array , then the column dictionary that
* and associates each column alias with the pointer on the column is updated from the column reference array .
*
* @ warning The column pointer array should be up to date before using this function .
* @ warning Aliases are not updated by this function and have to be edited separately .
* This function simply reads the column pointer array associated with the view
* and fills the column names and versions in the column reference array accordingly ,
* without touching the alias .
* That means that for example if there is a shift in the column pointer array , this
* function should not be used .
*
* @ param view A pointer on the view .
*
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int update_column_refs_and_dict ( Obiview_p view ) ;
2016-08-01 18:25:30 +02:00
2016-04-25 18:11:37 +02:00
/**
* @ brief Internal function to update the line count in the context of a view .
*
* All columns of the view are enlarged to contain at least the new line count .
*
* @ warning The view must be writable .
*
* @ param view A pointer on the view .
* @ param line_count The new line count .
*
* @ returns A value indicating the success of the operation .
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since February 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int update_lines ( Obiview_p view , index_t line_count ) ;
2016-04-25 18:11:37 +02:00
2016-04-25 18:15:25 +02:00
/**
* @ brief Internal function to clone a column in the context of a view .
*
* Clones with the right line selection and replaces the cloned columns with the new ones in the view .
* If there is a line selection , all columns have to be cloned , otherwise only the column of interest is cloned .
*
* @ param view A pointer on the view .
* @ param column_name The name of the column in the view that should be cloned .
*
* @ returns A pointer on the new column .
* @ retval NULL if an error occurred .
*
* @ since February 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static OBIDMS_column_p clone_column_in_view ( Obiview_p view , const char * column_name ) ;
/**
* @ brief Saves a view , updating its informations in the view file .
*
* @ warning The view must be writable .
*
* @ param view A pointer on the view .
*
* @ returns A value indicating the success of the operation .
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since February 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
static int save_view ( Obiview_p view ) ;
/**
* @ brief Rename a view file once the view is finished , replacing the ' * . obiview_unfinished ' extension with ' * . obiview ' .
*
* @ param view A pointer on the view .
*
* @ returns A value indicating the success of the operation .
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since February 2017
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
static int rename_finished_view ( Obiview_p view ) ;
/**
* @ brief Finishes a view : check the predicates , save all the informations , rename the view file .
*
* @ param view A pointer on the view .
*
* @ returns A value indicating the success of the operation .
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since February 2017
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
static int finish_view ( Obiview_p view ) ;
/**
* @ brief Closes an opened view .
*
* @ warning Doesn ' t save the view .
*
* @ param view A pointer on the view .
*
* @ returns A value indicating the success of the operation .
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ see obi_save_and_close_view ( )
* @ since February 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
static int close_view ( Obiview_p view ) ;
2016-04-25 18:15:25 +02:00
2016-04-25 17:58:12 +02:00
/**
2016-07-12 14:54:11 +02:00
* @ brief Internal function preparing to set a value in a column , in the context of a view .
2016-04-25 17:58:12 +02:00
*
* The function checks that the view is not read - only , clones the column or all columns if needed ,
* and updates the line count if needed .
*
* @ param view The view .
* @ param column_pp A pointer on the pointer on the column , to allow replacing the column if it is cloned .
* @ param line_nb_p A pointer on the index of the line that will be modified , to allow replacing it if needed .
*
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since April 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int prepare_to_set_value_in_column ( Obiview_p view , OBIDMS_column_p * column_pp , index_t * line_nb_p ) ;
2016-04-13 15:10:24 +02:00
2016-04-25 17:58:12 +02:00
/**
2016-07-12 14:54:11 +02:00
* @ brief Internal function preparing to get a value from a column , in the context of a view .
2016-04-25 17:58:12 +02:00
*
* The function checks that the line index is not beyond the current line count of the view ,
* and modifies it if there is a line selection associated with the view .
*
* @ param view The view .
* @ param line_nb_p A pointer on the index of the line , to allow replacing it if needed .
*
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if an error occurred .
*
* @ since April 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static int prepare_to_get_value_from_column ( Obiview_p view , index_t * line_nb_p ) ;
2016-04-13 15:10:24 +02:00
2016-07-12 14:54:11 +02:00
/****** PREDICATE FUNCTIONS *******/
/**
* @ brief Internal function checking if a view has a NUC_SEQUENCE_COLUMN column .
*
* The function checks that the view has a column with the name attributed to obligatory
* nucleotide sequence columns .
*
* @ param view The view .
*
2016-07-19 15:31:21 +02:00
* @ returns A character string describing the predicate .
* @ retval NULL if the predicate is false or if there was an error .
2016-07-12 14:54:11 +02:00
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static char * view_has_nuc_sequence_column ( Obiview_p view ) ;
2016-07-12 14:54:11 +02:00
/**
* @ brief Internal function checking if a view has a QUALITY_COLUMN column .
*
* The function checks that the view has a column with the name attributed to obligatory
* quality columns .
*
* @ param view The view .
*
2016-07-19 15:31:21 +02:00
* @ returns A character string describing the predicate .
* @ retval NULL if the predicate is false or if there was an error .
2016-07-12 14:54:11 +02:00
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static char * view_has_quality_column ( Obiview_p view ) ;
2016-07-12 14:54:11 +02:00
/**
* @ brief Internal function checking if a view has a ID_COLUMN column .
*
* The function checks that the view has a column with the name attributed to obligatory
* id columns .
*
* @ param view The view .
*
2016-07-19 15:31:21 +02:00
* @ returns A character string describing the predicate .
* @ retval NULL if the predicate is false or if there was an error .
2016-07-12 14:54:11 +02:00
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static char * view_has_id_column ( Obiview_p view ) ;
2016-07-12 14:54:11 +02:00
/**
* @ brief Internal function checking if a view has a DEFINITION_COLUMN column .
*
* The function checks that the view has a column with the name attributed to obligatory
* definition columns .
*
* @ param view The view .
*
2016-07-19 15:31:21 +02:00
* @ returns A character string describing the predicate .
* @ retval NULL if the predicate is false or if there was an error .
2016-07-12 14:54:11 +02:00
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static char * view_has_definition_column ( Obiview_p view ) ;
2016-07-12 14:54:11 +02:00
/**
2016-11-25 12:04:57 +01:00
* @ brief Internal function checking that all the quality columns of a view and their associated sequence columns
2016-07-12 14:54:11 +02:00
* correspond properly :
* - when a line is defined for either column , it must also be defined for the other column
* - when a line is defined , the lengths of the sequence and of the quality must be equal
*
* @ param view The view .
*
2016-07-19 15:31:21 +02:00
* @ returns A character string describing the predicate .
* @ retval NULL if the predicate is false or if there was an error .
2016-07-12 14:54:11 +02:00
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static char * view_check_qual_match_seqs ( Obiview_p view ) ;
2016-07-12 14:54:11 +02:00
/**
* @ brief Internal function checking one predicate function on a view .
*
* @ param view The view .
* @ param predicate_function The predicate function to use .
*
2016-07-19 15:31:21 +02:00
* @ returns A character string describing the predicate .
* @ retval NULL if the predicate is false or if there was an error .
2016-07-12 14:54:11 +02:00
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2017-02-07 17:16:09 +01:00
static char * view_check_one_predicate ( Obiview_p view , char * ( * predicate_function ) ( Obiview_p view ) ) ;
2016-07-12 14:54:11 +02:00
/**
* @ brief Internal function checking all the predicates associated with a view .
*
* @ param view The view .
2018-10-07 18:56:46 +02:00
* @ param write Whether the verified predicates should be written in the view comments .
2016-07-12 14:54:11 +02:00
*
2018-10-07 18:56:46 +02:00
* @ retval 0 if the operation was successfully completed .
* @ retval - 1 if at least one of the predicates is false or if there was an error .
2016-07-12 14:54:11 +02:00
*
* @ since July 2016
* @ author Celine Mercier ( celine . mercier @ metabarcoding . org )
*/
2018-10-07 18:56:46 +02:00
static int view_check_all_predicates ( Obiview_p view , bool write ) ;
2016-07-12 14:54:11 +02:00
2016-02-18 10:38:51 +01:00
/************************************************************************
*
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2016-09-06 14:19:13 +02:00
static char * build_obiview_file_name ( const char * view_name )
{
char * file_name ;
// Build file name
file_name = ( char * ) malloc ( ( strlen ( view_name ) + 8 + 1 ) * sizeof ( char ) ) ;
if ( file_name = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for a view file name " ) ;
return NULL ;
}
if ( sprintf ( file_name , " %s.obiview " , view_name ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Problem building an obiview file name " ) ;
return NULL ;
}
return file_name ;
}
2016-06-30 11:41:30 +02:00
2017-02-07 17:16:09 +01:00
static char * build_unfinished_obiview_file_name ( const char * view_name )
{
char * file_name ;
// Build file name
file_name = ( char * ) malloc ( ( strlen ( view_name ) + 19 + 1 ) * sizeof ( char ) ) ;
if ( file_name = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for a view file name " ) ;
return NULL ;
}
if ( sprintf ( file_name , " %s.obiview_unfinished " , view_name ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Problem building an unfinished obiview file name " ) ;
return NULL ;
}
return file_name ;
}
static bool view_exists ( OBIDMS_p dms , const char * view_name )
2016-09-06 16:22:24 +02:00
{
2017-01-31 16:48:06 +01:00
struct dirent * dp ;
char * file_name ;
2016-09-06 16:22:24 +02:00
2017-02-07 17:16:09 +01:00
// Check finished views
2016-09-06 16:22:24 +02:00
// Create file name
file_name = build_obiview_file_name ( view_name ) ;
if ( file_name = = NULL )
return - 1 ;
2017-11-24 18:04:58 +01:00
rewinddir ( dms - > view_directory ) ;
2016-09-06 16:22:24 +02:00
while ( ( dp = readdir ( dms - > view_directory ) ) ! = NULL )
{
if ( ( dp - > d_name ) [ 0 ] = = ' . ' )
continue ;
if ( strcmp ( dp - > d_name , file_name ) = = 0 )
2017-02-07 17:16:09 +01:00
{
free ( file_name ) ;
return true ;
}
}
free ( file_name ) ;
// Check unfinished views
// Create file name
file_name = build_unfinished_obiview_file_name ( view_name ) ;
if ( file_name = = NULL )
return - 1 ;
2017-11-24 18:04:58 +01:00
rewinddir ( dms - > view_directory ) ;
2017-02-07 17:16:09 +01:00
while ( ( dp = readdir ( dms - > view_directory ) ) ! = NULL )
{
if ( ( dp - > d_name ) [ 0 ] = = ' . ' )
continue ;
if ( strcmp ( dp - > d_name , file_name ) = = 0 )
{
free ( file_name ) ;
2016-09-06 16:22:24 +02:00
return true ;
2017-02-07 17:16:09 +01:00
}
2016-09-06 16:22:24 +02:00
}
2017-02-07 17:16:09 +01:00
free ( file_name ) ;
2016-09-06 16:22:24 +02:00
return false ;
}
2018-10-31 17:51:10 +01:00
static int view_is_finished ( OBIDMS_p dms , const char * view_name )
2018-10-31 14:38:05 +01:00
{
struct dirent * dp ;
char * file_name ;
// Check finished views
// Create file name
file_name = build_obiview_file_name ( view_name ) ;
if ( file_name = = NULL )
return - 1 ;
rewinddir ( dms - > view_directory ) ;
while ( ( dp = readdir ( dms - > view_directory ) ) ! = NULL )
{
if ( ( dp - > d_name ) [ 0 ] = = ' . ' )
continue ;
if ( strcmp ( dp - > d_name , file_name ) = = 0 )
{
free ( file_name ) ;
return true ;
}
}
free ( file_name ) ;
// Check unfinished views
// Create file name
file_name = build_unfinished_obiview_file_name ( view_name ) ;
if ( file_name = = NULL )
return - 1 ;
rewinddir ( dms - > view_directory ) ;
while ( ( dp = readdir ( dms - > view_directory ) ) ! = NULL )
{
if ( ( dp - > d_name ) [ 0 ] = = ' . ' )
continue ;
if ( strcmp ( dp - > d_name , file_name ) = = 0 )
{
free ( file_name ) ;
return false ;
}
}
free ( file_name ) ;
return - 1 ;
}
2017-02-07 17:16:09 +01:00
static size_t get_platform_view_file_size ( )
2016-02-18 10:38:51 +01:00
{
size_t obiview_size ;
size_t rounded_obiview_size ;
double multiple ;
obiview_size = sizeof ( Obiview_infos_t ) ;
2016-06-30 11:41:30 +02:00
multiple = ceil ( ( double ) ( obiview_size ) / ( double ) getpagesize ( ) ) ;
2016-02-18 10:38:51 +01:00
rounded_obiview_size = multiple * getpagesize ( ) ;
return rounded_obiview_size ;
}
2017-02-07 17:16:09 +01:00
static int enlarge_view_file ( Obiview_p view , size_t new_size )
2016-08-18 17:57:03 +02:00
{
2016-09-05 12:37:36 +02:00
int obiview_file_descriptor ;
2016-08-18 17:57:03 +02:00
double multiple ;
size_t rounded_new_size ;
2016-09-06 14:19:13 +02:00
char * file_name ;
2016-08-18 17:57:03 +02:00
2016-09-06 14:19:13 +02:00
// Create file name
2017-02-07 17:16:09 +01:00
file_name = build_unfinished_obiview_file_name ( ( view - > infos ) - > name ) ;
2016-09-06 14:19:13 +02:00
if ( file_name = = NULL )
return - 1 ;
2016-08-18 17:57:03 +02:00
// Open view file
2016-09-06 14:19:13 +02:00
obiview_file_descriptor = openat ( ( view - > dms ) - > view_dir_fd , file_name , O_RDWR , 0777 ) ;
2016-08-18 17:57:03 +02:00
if ( obiview_file_descriptor < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error opening a view file " ) ;
2016-09-06 14:19:13 +02:00
free ( file_name ) ;
2016-08-18 17:57:03 +02:00
return - 1 ;
}
2016-09-06 14:19:13 +02:00
free ( file_name ) ;
2016-08-18 17:57:03 +02:00
// Round new size to a multiple of page size // TODO make function in utils
multiple = ceil ( ( double ) new_size / ( double ) getpagesize ( ) ) ;
rounded_new_size = multiple * getpagesize ( ) ;
// Enlarge the file
if ( ftruncate ( obiview_file_descriptor , rounded_new_size ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error enlarging a view file " ) ;
close ( obiview_file_descriptor ) ;
return - 1 ;
}
// Unmap and remap the file
if ( munmap ( view - > infos , ( view - > infos ) - > file_size ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error munmapping a view file when enlarging " ) ;
close ( obiview_file_descriptor ) ;
return - 1 ;
}
view - > infos = mmap ( NULL ,
rounded_new_size ,
PROT_READ | PROT_WRITE ,
MAP_SHARED ,
obiview_file_descriptor ,
0
) ;
if ( view - > infos = = MAP_FAILED )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error re-mmapping a view file after enlarging the file " ) ;
close ( obiview_file_descriptor ) ;
return - 1 ;
}
// Set new size
( view - > infos ) - > file_size = rounded_new_size ;
2016-09-15 11:58:56 +02:00
if ( close ( obiview_file_descriptor ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error closing a view file " ) ;
return - 1 ;
}
2016-08-18 17:57:03 +02:00
return 0 ;
}
2017-02-07 17:16:09 +01:00
static int create_obiview_file ( OBIDMS_p dms , const char * view_name )
2016-02-18 10:38:51 +01:00
{
2016-09-06 14:19:13 +02:00
char * file_name ;
2016-02-18 10:38:51 +01:00
int obiview_file_descriptor ;
size_t file_size ;
2016-09-06 14:19:13 +02:00
// Create file name
2017-02-07 17:16:09 +01:00
file_name = build_unfinished_obiview_file_name ( view_name ) ;
2016-09-06 14:19:13 +02:00
if ( file_name = = NULL )
return - 1 ;
2016-02-18 10:38:51 +01:00
// Create file
2016-09-06 14:19:13 +02:00
obiview_file_descriptor = openat ( dms - > view_dir_fd , file_name , O_RDWR | O_CREAT | O_EXCL , 0777 ) ;
2016-02-18 10:38:51 +01:00
if ( obiview_file_descriptor < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error creating an obiview file " ) ;
2016-09-06 14:19:13 +02:00
free ( file_name ) ;
2016-02-18 10:38:51 +01:00
return - 1 ;
}
2016-09-06 14:19:13 +02:00
free ( file_name ) ;
2016-02-18 10:38:51 +01:00
2016-08-18 17:57:03 +02:00
// Truncate file to the initial size
2016-06-30 11:41:30 +02:00
file_size = get_platform_view_file_size ( ) ;
2016-02-18 10:38:51 +01:00
if ( ftruncate ( obiview_file_descriptor , file_size ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error truncating an obiview file to the right size " ) ;
close ( obiview_file_descriptor ) ;
return - 1 ;
}
2016-08-18 17:57:03 +02:00
// Write file size
if ( write ( obiview_file_descriptor , & file_size , sizeof ( size_t ) ) < ( ( ssize_t ) sizeof ( size_t ) ) )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error writing the file size in an obiview file " ) ;
close ( obiview_file_descriptor ) ;
return - 1 ;
}
2016-09-15 11:58:56 +02:00
if ( close ( obiview_file_descriptor ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error closing a view file " ) ;
return - 1 ;
}
2016-02-18 10:38:51 +01:00
2016-06-30 11:41:30 +02:00
return 0 ;
}
2016-02-18 10:38:51 +01:00
2017-03-06 16:06:17 +01:00
static int update_column_refs ( Obiview_p view )
2016-06-30 11:41:30 +02:00
{
int i ;
2017-03-06 16:06:17 +01:00
OBIDMS_column_p column ;
2016-06-30 11:41:30 +02:00
for ( i = 0 ; i < ( view - > infos ) - > column_count ; i + + )
{
2017-03-06 16:06:17 +01:00
column = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column from the linked list of column pointers of a view " ) ;
return - 1 ;
}
strcpy ( ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . column_name , ( column - > header ) - > name ) ;
( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . version = ( column - > header ) - > version ;
2016-08-01 18:25:30 +02:00
}
2017-03-06 16:06:17 +01:00
return 0 ;
2016-08-01 18:25:30 +02:00
}
2017-02-07 17:16:09 +01:00
static int create_column_dict ( Obiview_p view )
2016-08-01 18:25:30 +02:00
{
int i ;
2017-03-06 16:06:17 +01:00
OBIDMS_column_p * column_pp ;
2016-08-01 18:25:30 +02:00
view - > column_dict = ht_create ( MAX_NB_OPENED_COLUMNS ) ;
if ( view - > column_dict = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error creating a column dictionary " ) ;
return - 1 ;
}
// Rebuild the dictionary from the column references and the column pointer array associated with the view
for ( i = 0 ; i < ( view - > infos ) - > column_count ; i + + )
{
// Check that each alias is unique
if ( ht_get ( view - > column_dict , ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias ) ! = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error: the name/alias identifying a column in a view is not unique " ) ;
return - 1 ;
}
2017-03-06 16:06:17 +01:00
column_pp = ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ;
if ( column_pp = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column from the linked list of column pointers of a view when creating a column dictionary " ) ;
return - 1 ;
}
if ( ht_set ( view - > column_dict , ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , column_pp ) < 0 )
2016-08-01 18:25:30 +02:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error adding a column in a column dictionary " ) ;
return - 1 ;
}
2016-06-30 11:41:30 +02:00
}
2016-08-01 18:25:30 +02:00
return 0 ;
}
2017-02-07 17:16:09 +01:00
static int update_column_dict ( Obiview_p view )
2016-08-01 18:25:30 +02:00
{
// Re-initialize the dictionary to rebuild it from scratch
ht_free ( view - > column_dict ) ;
if ( create_column_dict ( view ) < 0 )
return - 1 ;
return 0 ;
}
2017-02-07 17:16:09 +01:00
static int update_column_refs_and_dict ( Obiview_p view )
2016-08-01 18:25:30 +02:00
{
2017-03-06 16:06:17 +01:00
if ( update_column_refs ( view ) < 0 )
return - 1 ;
2016-08-01 18:25:30 +02:00
return update_column_dict ( view ) ;
2016-02-18 10:38:51 +01:00
}
2017-02-07 17:16:09 +01:00
static int update_lines ( Obiview_p view , index_t line_count )
2016-04-25 18:11:37 +02:00
{
2017-03-06 16:06:17 +01:00
int i ;
OBIDMS_column_p column ;
2016-09-05 12:37:36 +02:00
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to update the line count of all columns in a read-only view " ) ;
return - 1 ;
}
2016-04-25 18:11:37 +02:00
2016-06-30 11:41:30 +02:00
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
2016-04-25 18:11:37 +02:00
{
2017-03-06 16:06:17 +01:00
column = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column from the linked list of column pointers of a view when updating view lines " ) ;
return - 1 ;
}
2016-09-21 17:42:17 +02:00
// Clone the column first if needed
2017-03-06 16:06:17 +01:00
if ( ! ( column - > writable ) )
2016-09-21 17:42:17 +02:00
{
2017-04-14 16:25:55 +02:00
column = clone_column_in_view ( view , ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias ) ;
if ( column = = NULL )
2016-09-05 12:37:36 +02:00
{
2016-09-21 17:42:17 +02:00
obidebug ( 1 , " \n Error cloning a column in a view when updating its line count " ) ;
return - 1 ;
2016-09-05 12:37:36 +02:00
}
2016-09-21 17:42:17 +02:00
}
2017-04-14 16:25:55 +02:00
2016-09-21 17:42:17 +02:00
// Enlarge the column if needed
2017-03-06 16:06:17 +01:00
while ( line_count > ( column - > header ) - > line_count )
2016-09-21 17:42:17 +02:00
{
2017-03-06 16:06:17 +01:00
if ( obi_enlarge_column ( column ) < 0 )
2016-04-25 18:11:37 +02:00
return - 1 ;
}
2017-04-14 16:25:55 +02:00
2016-09-21 17:42:17 +02:00
// Set the number of lines used to the new view line count
2017-03-06 16:06:17 +01:00
( column - > header ) - > lines_used = line_count ;
2016-04-25 18:11:37 +02:00
}
2016-06-30 11:41:30 +02:00
( view - > infos ) - > line_count = line_count ;
2016-04-25 18:11:37 +02:00
return 0 ;
}
2017-02-07 17:16:09 +01:00
static OBIDMS_column_p clone_column_in_view ( Obiview_p view , const char * column_name )
2016-04-25 18:15:25 +02:00
{
int i ;
2016-04-26 14:38:46 +02:00
OBIDMS_column_p column = NULL ;
2017-03-06 16:06:17 +01:00
OBIDMS_column_p new_column = NULL ;
2016-04-25 18:15:25 +02:00
OBIDMS_column_p column_buffer ;
2016-08-01 18:25:30 +02:00
bool found ;
2016-04-25 18:15:25 +02:00
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to delete a column in a read-only view " ) ;
return NULL ;
}
2016-08-01 18:25:30 +02:00
found = false ;
2016-06-30 11:41:30 +02:00
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
2016-04-25 18:15:25 +02:00
{
2016-09-22 11:19:29 +02:00
if ( ( view - > line_selection ! = NULL ) | | ( ! strcmp ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , column_name ) ) )
2016-04-25 18:15:25 +02:00
{ // Clone with the right line selection and replace (for all columns if there is a line selection)
// Save pointer to close column after cloning
2017-03-06 16:06:17 +01:00
column_buffer = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column_buffer = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column to clone from the linked list of column pointers of a view " ) ;
return NULL ;
}
2016-04-25 18:15:25 +02:00
// Clone and replace the column in the view
2017-03-06 16:06:17 +01:00
column = obi_clone_column ( view - > dms , view - > line_selection , ( column_buffer - > header ) - > name , ( column_buffer - > header ) - > version , true ) ;
if ( column = = NULL )
2016-04-25 18:15:25 +02:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error cloning a column to replace in a view " ) ;
return NULL ;
}
2017-03-06 16:06:17 +01:00
// Change the pointer in the linked list of column pointers
if ( ll_set ( view - > columns , i , column ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error changing the column pointer of a cloned column in the linked list of column pointers of a view " ) ;
return NULL ;
}
2016-04-25 18:15:25 +02:00
// Close old cloned column
obi_close_column ( column_buffer ) ;
2016-08-01 18:25:30 +02:00
if ( ! strcmp ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , column_name ) )
2017-03-06 16:06:17 +01:00
// Found the column to return
new_column = column ;
2016-04-25 18:15:25 +02:00
}
}
2016-09-22 11:19:29 +02:00
// Close old line selection
2016-04-25 18:15:25 +02:00
if ( view - > line_selection ! = NULL )
{
obi_close_column ( view - > line_selection ) ;
view - > line_selection = NULL ;
2016-06-30 11:41:30 +02:00
// Update line selection reference
( ( ( view - > infos ) - > line_selection ) . column_name ) [ 0 ] = ' \0 ' ;
( ( view - > infos ) - > line_selection ) . version = - 1 ;
2016-04-25 18:15:25 +02:00
}
2016-08-01 18:25:30 +02:00
// Update column refs and dict
2017-03-06 16:06:17 +01:00
if ( update_column_refs_and_dict ( view ) < 0 )
{
obidebug ( 1 , " \n Error updating columns references and dictionary after cloning a column in a view " ) ;
return NULL ;
}
2016-06-30 11:41:30 +02:00
2017-03-06 16:06:17 +01:00
return new_column ;
2016-04-25 18:15:25 +02:00
}
2017-02-07 17:16:09 +01:00
static int save_view ( Obiview_p view )
{
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to save a read-only view " ) ;
return - 1 ;
}
// Store reference for the line selection associated with that view if there is one
if ( view - > line_selection ! = NULL ) // Unnecessary in theory, the line selection references are already saved
{
strcpy ( ( ( view - > infos ) - > line_selection ) . column_name , ( ( view - > line_selection ) - > header ) - > name ) ;
( ( view - > infos ) - > line_selection ) . version = ( ( view - > line_selection ) - > header ) - > version ;
( view - > infos ) - > all_lines = false ;
}
else // Necessary because line selection could have been deleted if a column was cloned
{
( ( ( view - > infos ) - > line_selection ) . column_name ) [ 0 ] = ' \0 ' ;
( ( view - > infos ) - > line_selection ) . version = - 1 ;
( view - > infos ) - > all_lines = true ;
}
2017-03-06 16:06:17 +01:00
if ( update_column_refs ( view ) < 0 )
{
obidebug ( 1 , " \n Error updating column references when saving a view " ) ;
return - 1 ;
}
2017-02-07 17:16:09 +01:00
return 0 ;
}
static int rename_finished_view ( Obiview_p view )
{
char * old_name ;
char * new_name ;
char * path_old_name ;
char * path_new_name ;
char * full_path_old_name ;
char * full_path_new_name ;
old_name = build_unfinished_obiview_file_name ( ( view - > infos ) - > name ) ;
new_name = build_obiview_file_name ( ( view - > infos ) - > name ) ;
path_old_name = malloc ( MAX_PATH_LEN ) ;
path_new_name = malloc ( MAX_PATH_LEN ) ;
strcpy ( path_old_name , " VIEWS/ " ) ;
strcat ( path_old_name , old_name ) ;
strcpy ( path_new_name , " VIEWS/ " ) ;
strcat ( path_new_name , new_name ) ;
full_path_old_name = obi_dms_get_full_path ( view - > dms , path_old_name ) ;
full_path_new_name = obi_dms_get_full_path ( view - > dms , path_new_name ) ;
if ( rename ( full_path_old_name , full_path_new_name ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error renaming the file of a finished view: %s " , full_path_new_name ) ;
free ( old_name ) ;
free ( new_name ) ;
return - 1 ;
}
free ( old_name ) ;
free ( new_name ) ;
free ( path_new_name ) ;
free ( path_old_name ) ;
free ( full_path_old_name ) ;
free ( full_path_new_name ) ;
return 0 ;
}
static int finish_view ( Obiview_p view )
{
2017-10-26 18:58:48 +02:00
int i ;
OBIDMS_column_p column ;
2017-02-07 17:16:09 +01:00
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to save a read-only view " ) ;
return - 1 ;
}
2017-07-17 17:31:09 +02:00
// Add count column if it's a NUC_SEQ_VIEW with no count column // TODO discuss
if ( ( ! strcmp ( ( view - > infos ) - > view_type , VIEW_TYPE_NUC_SEQS ) ) & & ( ! obi_view_column_exists ( view , COUNT_COLUMN ) ) )
{
if ( obi_create_auto_count_column ( view ) < 0 )
{
obidebug ( 1 , " \n Error creating an automatic count column when finishing a view " ) ;
return - 1 ;
}
}
// Add id column if it's a NUC_SEQ_VIEW with no id column // TODO discuss
if ( ( ! strcmp ( ( view - > infos ) - > view_type , VIEW_TYPE_NUC_SEQS ) ) & & ( ! obi_view_column_exists ( view , ID_COLUMN ) ) )
{
if ( obi_create_auto_id_column ( view , NULL ) < 0 )
{
obidebug ( 1 , " \n Error creating an automatic id column when finishing a view " ) ;
return - 1 ;
}
}
2017-02-07 17:16:09 +01:00
// Check predicates
2018-10-07 18:56:46 +02:00
if ( view_check_all_predicates ( view , true ) < 0 )
2017-02-07 17:16:09 +01:00
{
2018-10-07 18:56:46 +02:00
obidebug ( 1 , " \n View predicates not respected, view rollbacked " ) ;
obi_rollback_view ( view ) ; // TODO discuss, maybe never call from C layer
return - 1 ;
2017-02-07 17:16:09 +01:00
}
if ( save_view ( view ) < 0 )
return - 1 ;
if ( rename_finished_view ( view ) < 0 )
return - 1 ;
2017-10-26 18:58:48 +02:00
// Flag the columns as finished
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
{
column = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column to flag it as finished when finishing a view " ) ;
return - 1 ;
}
2017-10-26 19:11:29 +02:00
if ( column - > writable )
( column - > header ) - > finished = true ;
2017-10-26 18:58:48 +02:00
}
2018-05-17 15:17:19 +02:00
// Flag the line selection column as finished
if ( view - > line_selection ! = NULL )
{
column = view - > line_selection ;
if ( column - > writable )
( column - > header ) - > finished = true ;
}
2017-02-07 17:16:09 +01:00
// Flag the view as finished
( view - > infos ) - > finished = true ;
return 0 ;
}
static int close_view ( Obiview_p view )
{
int i ;
int ret_value ;
2017-03-06 16:06:17 +01:00
OBIDMS_column_p column ;
2017-02-07 17:16:09 +01:00
ret_value = 0 ;
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
{
2017-03-06 16:06:17 +01:00
column = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column to close from the linked list of column pointers of a view " ) ;
return - 1 ;
}
if ( obi_close_column ( column ) < 0 )
2017-02-07 17:16:09 +01:00
{
obidebug ( 1 , " \n Error closing a column while closing a view " ) ;
ret_value = - 1 ;
}
}
// Close line selection if there is one
if ( view - > line_selection ! = NULL )
{
if ( obi_close_column ( view - > line_selection ) < 0 )
{
obidebug ( 1 , " \n Error closing a line selection while closing a view " ) ;
ret_value = - 1 ;
}
}
2017-03-06 16:06:17 +01:00
// Free the linked list of column pointers
ll_free ( view - > columns ) ;
2017-02-07 17:16:09 +01:00
// Free the column dictionary
ht_free ( view - > column_dict ) ;
// Unmap view file
if ( obi_view_unmap_file ( view - > dms , view - > infos ) < 0 )
{
obidebug ( 1 , " \n Error unmaping a view file while closing a view " ) ;
ret_value = - 1 ;
}
free ( view ) ;
return ret_value ;
}
static int prepare_to_set_value_in_column ( Obiview_p view , OBIDMS_column_p * column_pp , index_t * line_nb_p )
2016-04-13 15:10:24 +02:00
{
2016-08-01 18:25:30 +02:00
int i ;
char * column_name = NULL ;
2016-06-03 18:55:58 +02:00
2016-04-13 15:10:24 +02:00
// Check that the view is not read-only
if ( view - > read_only )
{
obidebug ( 1 , " \n Error trying to set a value in a column in a read-only view " ) ;
return - 1 ;
}
// If there is a line selection associated with the view or if the column
// is read-only, all columns or this column respectively must be cloned
if ( ( view - > line_selection ! = NULL ) | | ( ! ( ( * column_pp ) - > writable ) ) )
{
2016-08-01 18:25:30 +02:00
// Get the name/alias of the column from the pointer
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
{
if ( obi_view_get_column ( view , ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias ) = = * column_pp )
column_name = ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias ;
}
2016-06-03 18:55:58 +02:00
if ( column_name = = NULL )
{
2016-08-01 18:25:30 +02:00
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to clone a column in a view: column alias not found from pointer " ) ;
2016-06-03 18:55:58 +02:00
return - 1 ;
}
2016-08-01 18:25:30 +02:00
2016-06-03 18:55:58 +02:00
( * column_pp ) = clone_column_in_view ( view , column_name ) ;
2016-04-13 15:10:24 +02:00
if ( ( * column_pp ) = = NULL )
{
obidebug ( 1 , " \n Error trying to clone a column to modify it " ) ;
return - 1 ;
}
}
2016-06-30 11:41:30 +02:00
if ( ( ( * line_nb_p ) + 1 ) > ( view - > infos ) - > line_count )
2016-04-13 15:10:24 +02:00
{
2016-04-25 18:11:37 +02:00
if ( update_lines ( view , ( ( * line_nb_p ) + 1 ) ) < 0 )
2016-04-13 15:10:24 +02:00
return - 1 ;
}
return 0 ;
}
2017-02-07 17:16:09 +01:00
static int prepare_to_get_value_from_column ( Obiview_p view , index_t * line_nb_p )
2016-04-13 15:10:24 +02:00
{
2016-06-30 11:41:30 +02:00
if ( ( ( * line_nb_p ) + 1 ) > ( ( view - > infos ) - > line_count ) )
2016-04-13 15:10:24 +02:00
{
obi_set_errno ( OBICOL_UNKNOWN_ERROR ) ;
obidebug ( 1 , " \n Error trying to get a value that is beyond the current line count of the view " ) ;
return - 1 ;
}
2016-09-21 17:42:17 +02:00
if ( view - > line_selection ! = NULL )
2016-04-13 15:10:24 +02:00
( * line_nb_p ) = * ( ( ( index_t * ) ( ( view - > line_selection ) - > data ) ) + ( * line_nb_p ) ) ;
return 0 ;
}
2016-07-12 14:54:11 +02:00
/****** PREDICATE FUNCTIONS *******/
2017-02-07 17:16:09 +01:00
static char * view_has_nuc_sequence_column ( Obiview_p view )
2016-07-12 14:54:11 +02:00
{
2016-07-19 15:31:21 +02:00
char * predicate ;
predicate = ( char * ) malloc ( ( strlen ( " The view has an associated nucleotide sequence column. " ) + 1 ) * sizeof ( char ) ) ;
if ( predicate = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for predicate character string. " ) ;
return NULL ;
}
strcpy ( predicate , " The view has an associated nucleotide sequence column. " ) ;
2016-07-12 14:54:11 +02:00
if ( obi_view_get_column ( view , NUC_SEQUENCE_COLUMN ) ! = NULL )
2016-07-19 15:31:21 +02:00
return predicate ;
2016-07-12 14:54:11 +02:00
else
2016-09-05 12:37:36 +02:00
{
obidebug ( 1 , " \n Error checking the predicate: %s " , predicate ) ;
2016-07-19 15:31:21 +02:00
return NULL ;
2016-09-05 12:37:36 +02:00
}
2016-07-12 14:54:11 +02:00
}
2017-02-07 17:16:09 +01:00
static char * view_has_quality_column ( Obiview_p view )
2016-07-12 14:54:11 +02:00
{
2016-07-19 15:31:21 +02:00
char * predicate ;
predicate = ( char * ) malloc ( ( strlen ( " The view has an associated sequence quality column. " ) + 1 ) * sizeof ( char ) ) ;
if ( predicate = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for predicate character string. " ) ;
return NULL ;
}
strcpy ( predicate , " The view has an associated sequence quality column. " ) ;
2016-07-12 14:54:11 +02:00
if ( obi_view_get_column ( view , QUALITY_COLUMN ) ! = NULL )
2016-07-19 15:31:21 +02:00
return predicate ;
2016-07-12 14:54:11 +02:00
else
2016-09-05 12:37:36 +02:00
{
obidebug ( 1 , " \n Error checking the predicate: %s " , predicate ) ;
2016-07-19 15:31:21 +02:00
return NULL ;
2016-09-05 12:37:36 +02:00
}
2016-07-12 14:54:11 +02:00
}
2017-02-07 17:16:09 +01:00
static char * view_has_id_column ( Obiview_p view )
2016-07-12 14:54:11 +02:00
{
2016-07-19 15:31:21 +02:00
char * predicate ;
predicate = ( char * ) malloc ( ( strlen ( " The view has an associated identifier column. " ) + 1 ) * sizeof ( char ) ) ;
if ( predicate = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for predicate character string. " ) ;
return NULL ;
}
strcpy ( predicate , " The view has an associated identifier column. " ) ;
2016-07-12 14:54:11 +02:00
if ( obi_view_get_column ( view , ID_COLUMN ) ! = NULL )
2016-07-19 15:31:21 +02:00
return predicate ;
2016-07-12 14:54:11 +02:00
else
2016-09-05 12:37:36 +02:00
{
obidebug ( 1 , " \n Error checking the predicate: %s " , predicate ) ;
2016-07-19 15:31:21 +02:00
return NULL ;
2016-09-05 12:37:36 +02:00
}
2016-07-12 14:54:11 +02:00
}
2017-02-07 17:16:09 +01:00
static char * view_has_definition_column ( Obiview_p view )
2016-07-12 14:54:11 +02:00
{
2016-07-19 15:31:21 +02:00
char * predicate ;
predicate = ( char * ) malloc ( ( strlen ( " The view has an associated definition column. " ) + 1 ) * sizeof ( char ) ) ;
if ( predicate = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for predicate character string. " ) ;
return NULL ;
}
strcpy ( predicate , " The view has an associated definition column. " ) ;
2016-07-12 14:54:11 +02:00
if ( obi_view_get_column ( view , DEFINITION_COLUMN ) ! = NULL )
2016-07-19 15:31:21 +02:00
return predicate ;
2016-07-12 14:54:11 +02:00
else
2016-09-05 12:37:36 +02:00
{
obidebug ( 1 , " \n Error checking the predicate: %s " , predicate ) ;
2016-07-19 15:31:21 +02:00
return NULL ;
2016-09-05 12:37:36 +02:00
}
2016-07-12 14:54:11 +02:00
}
2017-02-07 17:16:09 +01:00
static char * view_check_qual_match_seqs ( Obiview_p view )
2016-07-12 14:54:11 +02:00
{
2016-11-25 12:04:57 +01:00
index_t i , j , k ;
2016-07-12 14:54:11 +02:00
index_t nb_elements_per_line ;
int qual_len ;
const uint8_t * qual ;
char * seq ;
2017-03-06 16:06:17 +01:00
OBIDMS_column_p column ;
2016-07-12 14:54:11 +02:00
OBIDMS_column_p qual_column ;
OBIDMS_column_p seq_column ;
2016-07-19 15:31:21 +02:00
char * predicate ;
2016-11-25 12:04:57 +01:00
bool at_least_one_qual_col ;
2016-07-19 15:31:21 +02:00
2016-11-25 12:04:57 +01:00
// Go through all columns in the view and check the predicate for all quality columns
at_least_one_qual_col = false ;
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
2016-07-19 15:31:21 +02:00
{
2017-03-06 16:06:17 +01:00
column = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
2018-08-08 19:51:05 +02:00
obidebug ( 1 , " \n Error getting a column to clone from the linked list of column pointers of view %s " , ( view - > infos ) - > name ) ;
2017-03-06 16:06:17 +01:00
return NULL ;
}
2016-11-25 12:04:57 +01:00
// Check if it's a quality column
2017-03-06 16:06:17 +01:00
if ( ( column - > header ) - > returned_data_type = = OBI_QUAL )
2016-11-25 12:04:57 +01:00
{
at_least_one_qual_col = true ;
// Check that the quality arrays match the sequences of the associated column
2017-03-06 16:06:17 +01:00
qual_column = column ;
2016-11-25 12:04:57 +01:00
seq_column = obi_open_column ( view - > dms , ( ( qual_column - > header ) - > associated_column ) . column_name , ( ( qual_column - > header ) - > associated_column ) . version ) ;
if ( seq_column = = NULL )
{
2018-08-08 19:51:05 +02:00
obidebug ( 1 , " \n Error checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
2016-11-25 12:04:57 +01:00
return NULL ;
}
2016-07-12 14:54:11 +02:00
2018-11-19 11:05:53 +01:00
// Close and reopen indexers to remap them properly, because in writable mode they are mostly unmapped
if ( obi_close_indexer ( qual_column - > indexer ) < 0 )
{
obidebug ( 1 , " \n Error closing the quality indexer when checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
return NULL ;
}
qual_column - > indexer = obi_open_avl_group ( view - > dms , ( qual_column - > header ) - > indexer_name ) ;
if ( qual_column - > indexer = = NULL )
{
obidebug ( 1 , " \n Error reopening the quality indexer when checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
return NULL ;
}
if ( obi_close_indexer ( seq_column - > indexer ) < 0 )
{
obidebug ( 1 , " \n Error closing the sequence indexer when checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
return NULL ;
}
seq_column - > indexer = obi_open_avl_group ( view - > dms , ( seq_column - > header ) - > indexer_name ) ;
if ( seq_column - > indexer = = NULL )
{
obidebug ( 1 , " \n Error reopening the sequence indexer when checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
return NULL ;
}
2016-11-25 12:04:57 +01:00
nb_elements_per_line = ( qual_column - > header ) - > nb_elements_per_line ;
// Check that the quality and the sequence columns have the same number of elements per line
if ( nb_elements_per_line ! = ( seq_column - > header ) - > nb_elements_per_line )
{
2018-08-08 19:51:05 +02:00
obidebug ( 1 , " \n Error checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
2016-11-25 12:04:57 +01:00
return NULL ;
}
2016-07-12 14:54:11 +02:00
2017-03-06 16:06:17 +01:00
// Check each sequence and its quality
2016-11-25 12:04:57 +01:00
for ( j = 0 ; j < ( view - > infos ) - > line_count ; j + + )
{
for ( k = 0 ; k < nb_elements_per_line ; k + + )
{
qual = obi_get_qual_int_with_elt_idx_and_col_p_in_view ( view , qual_column , j , k , & qual_len ) ;
seq = obi_get_seq_with_elt_idx_and_col_p_in_view ( view , seq_column , j , k ) ;
if ( ( qual ! = OBIQual_int_NA ) & & ( seq ! = OBISeq_NA ) )
{
// Test that the lengths of the quality and the sequence are equal
2018-10-07 18:56:46 +02:00
if ( ( size_t ) qual_len ! = strlen ( seq ) )
2016-11-25 12:04:57 +01:00
{
2018-10-07 18:56:46 +02:00
obidebug ( 1 , " \n Error checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
2016-11-25 12:04:57 +01:00
return NULL ;
}
}
// Test if one value is NA and not the other
else if ( ( ( qual = = OBIQual_int_NA ) & & ( seq ! = OBISeq_NA ) ) | | ( ( qual ! = OBIQual_int_NA ) & & ( seq = = OBISeq_NA ) ) )
{
2018-08-08 19:51:05 +02:00
obidebug ( 1 , " \n Error checking the predicate for view %s: The sequences and sequence quality arrays match. " , ( view - > infos ) - > name ) ;
2016-11-25 12:04:57 +01:00
return NULL ;
}
2018-11-19 11:05:53 +01:00
free ( seq ) ;
2016-11-25 12:04:57 +01:00
}
}
2016-07-15 15:38:49 +02:00
2016-11-25 12:04:57 +01:00
obi_close_column ( seq_column ) ;
}
2016-09-05 12:37:36 +02:00
}
2016-07-12 14:54:11 +02:00
2016-11-25 12:04:57 +01:00
if ( at_least_one_qual_col )
2016-09-05 12:37:36 +02:00
{
2016-11-25 12:04:57 +01:00
predicate = ( char * ) malloc ( ( strlen ( " The sequences and sequence quality arrays match. " ) + 1 ) * sizeof ( char ) ) ;
if ( predicate = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for predicate character string. " ) ;
return NULL ;
}
strcpy ( predicate , " The sequences and sequence quality arrays match. " ) ;
2016-09-05 12:37:36 +02:00
}
2016-11-25 12:04:57 +01:00
else
2016-07-12 14:54:11 +02:00
{
2016-11-25 12:04:57 +01:00
predicate = ( char * ) malloc ( 1 * sizeof ( char ) ) ;
if ( predicate = = NULL )
2016-07-12 14:54:11 +02:00
{
2016-11-25 12:04:57 +01:00
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for predicate character string. " ) ;
return NULL ;
2016-07-12 14:54:11 +02:00
}
2016-11-25 12:04:57 +01:00
strcpy ( predicate , " " ) ;
2016-07-12 14:54:11 +02:00
}
2016-07-15 15:38:49 +02:00
2016-07-19 15:31:21 +02:00
return predicate ;
2016-07-12 14:54:11 +02:00
}
2017-02-07 17:16:09 +01:00
static char * view_check_one_predicate ( Obiview_p view , char * ( * predicate_function ) ( Obiview_p view ) )
2016-07-12 14:54:11 +02:00
{
return predicate_function ( view ) ;
}
2018-10-07 18:56:46 +02:00
static int view_check_all_predicates ( Obiview_p view , bool write )
2016-07-12 14:54:11 +02:00
{
2018-10-07 18:56:46 +02:00
int i ;
2016-07-19 15:31:21 +02:00
char * predicate = NULL ;
2016-07-12 14:54:11 +02:00
for ( i = 0 ; i < view - > nb_predicates ; i + + )
{
2018-10-07 18:56:46 +02:00
// Check predicate
2016-07-19 15:31:21 +02:00
predicate = view_check_one_predicate ( view , ( view - > predicate_functions ) [ i ] ) ;
if ( predicate = = NULL )
{
2018-10-07 18:56:46 +02:00
// TODO discuss what to do
return - 1 ;
2016-07-19 15:31:21 +02:00
}
else
{
2018-10-07 18:56:46 +02:00
if ( ( write ) & & ( predicate [ 0 ] ! = ' \0 ' ) )
{
// Add predicate in comments
if ( obi_view_add_comment ( view , PREDICATE_KEY , predicate ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error adding a verified predicate (%s) in the comments of a view. " , predicate ) ;
free ( predicate ) ;
return - 1 ;
}
}
free ( predicate ) ;
2016-07-19 15:31:21 +02:00
}
2016-07-12 14:54:11 +02:00
}
2018-10-07 18:56:46 +02:00
return 0 ;
2016-07-12 14:54:11 +02:00
}
// TODO predicate function that goes through each line / each elements
2016-02-18 10:38:51 +01:00
/**********************************************************************
*
* 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
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2016-09-06 14:19:13 +02:00
2016-02-29 17:56:55 +01:00
Obiview_p obi_new_view ( OBIDMS_p dms , const char * view_name , Obiview_p view_to_clone , index_t * line_selection , const char * comments )
2016-02-18 10:38:51 +01:00
{
2016-08-18 17:57:03 +02:00
Obiview_p view ;
int i ;
index_t line_nb ;
2017-03-06 16:06:17 +01:00
OBIDMS_column_p column ;
2018-10-07 18:56:46 +02:00
int comments_ok ;
2016-03-01 13:36:54 +01:00
2016-09-30 17:48:53 +02:00
// Check that the DMS is a valid pointer
if ( dms = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error creating a view: DMS pointer is NULL " ) ;
return NULL ;
}
// Check that the view name pointer is valid
if ( view_name = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error creating a view: view name is NULL " ) ;
return NULL ;
}
2016-06-30 11:41:30 +02:00
// Check uniqueness of name
2016-09-06 14:19:13 +02:00
if ( view_exists ( dms , view_name ) )
2016-03-01 13:36:54 +01:00
{
2018-10-17 19:47:40 +02:00
obi_set_errno ( OBIVIEW_ALREADY_EXISTS_ERROR ) ;
obidebug ( 1 , " \n Name of new view ('%s') already exists " , view_name ) ;
2016-09-06 14:19:13 +02:00
return NULL ;
2016-03-01 13:36:54 +01:00
}
2016-02-18 10:38:51 +01:00
2017-09-15 14:54:55 +02:00
// Check that the view name is not 'taxonomy' (used for URIs)
if ( strcmp ( view_name , " taxonomy " ) = = 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n View name can not be 'taxonomy' " ) ;
return NULL ;
}
2016-06-30 11:41:30 +02:00
// Allocate memory for view structure
2016-02-18 10:38:51 +01:00
view = ( Obiview_p ) malloc ( sizeof ( Obiview_t ) ) ;
if ( view = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for a view " ) ;
return NULL ;
}
2016-06-30 11:41:30 +02:00
view - > dms = dms ;
2016-11-24 11:19:07 +01:00
view - > read_only = false ;
2016-06-30 11:41:30 +02:00
// Create view file
if ( create_obiview_file ( dms , view_name ) < 0 )
{
free ( view ) ;
return NULL ;
}
// Map view file
2017-02-07 17:16:09 +01:00
view - > infos = obi_view_map_file ( dms , view_name , false ) ;
2016-06-30 11:41:30 +02:00
if ( view - > infos = = NULL )
{
obidebug ( 1 , " \n Error mapping the informations of a new view " ) ;
free ( view ) ;
return NULL ;
}
2016-11-24 11:19:07 +01:00
// Flag the view as being a work in progress
( view - > infos ) - > finished = false ;
2016-08-18 17:57:03 +02:00
// Write used size in view file for initial structure
( view - > infos ) - > used_size = sizeof ( Obiview_infos_t ) ;
2016-02-18 10:38:51 +01:00
// Clone view to clone if there is one
if ( view_to_clone ! = NULL )
{
2016-11-24 11:19:07 +01:00
if ( ( view_to_clone - > infos ) - > finished = = false )
2016-02-18 10:38:51 +01:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
2016-11-24 11:19:07 +01:00
obidebug ( 1 , " \n A view can not be cloned if it is not finished " ) ;
2016-06-30 11:41:30 +02:00
obi_view_unmap_file ( view - > dms , view - > infos ) ;
2016-02-18 10:38:51 +01:00
free ( view ) ;
return NULL ;
}
2016-04-25 11:37:53 +02:00
// If the view to clone has an associated line selection and there is no new line selection, open the associated line selection
if ( ( view_to_clone - > line_selection ! = NULL ) & & ( line_selection = = NULL ) )
2016-02-18 10:38:51 +01:00
{
view - > line_selection = obi_open_column ( dms , ( ( view_to_clone - > line_selection ) - > header ) - > name , ( ( view_to_clone - > line_selection ) - > header ) - > version ) ;
if ( view - > line_selection = = NULL )
2016-06-30 11:41:30 +02:00
{
obi_view_unmap_file ( view - > dms , view - > infos ) ;
free ( view ) ;
2016-02-18 10:38:51 +01:00
return NULL ;
2016-06-30 11:41:30 +02:00
}
( view - > infos ) - > line_count = ( view_to_clone - > infos ) - > line_count ;
2016-02-18 10:38:51 +01:00
}
2016-04-25 17:58:12 +02:00
// If there is a new line selection, build it by combining it with the one from the view to clone if there is one
2016-02-18 10:38:51 +01:00
else if ( line_selection ! = NULL )
{
2017-12-13 22:46:50 +01:00
view - > line_selection = obi_create_column ( view - > dms , LINES_COLUMN_NAME , OBI_IDX , 0 , 1 , NULL , false , false , false , NULL , NULL , - 1 , NULL ) ;
2016-02-18 10:38:51 +01:00
if ( ( view - > line_selection ) = = NULL )
{
obidebug ( 1 , " \n Error creating a column corresponding to a line selection " ) ;
2016-06-30 11:41:30 +02:00
obi_view_unmap_file ( view - > dms , view - > infos ) ;
free ( view ) ;
2016-02-18 10:38:51 +01:00
return NULL ;
}
2016-09-21 17:42:17 +02:00
2016-06-30 11:41:30 +02:00
( view - > infos ) - > all_lines = false ;
( view - > infos ) - > line_count = 0 ;
2016-02-18 10:38:51 +01:00
i = 0 ;
for ( i = 0 ; line_selection [ i ] ! = - 1 ; i + + )
{
line_nb = line_selection [ i ] ;
2016-06-30 11:41:30 +02:00
if ( line_nb > ( view_to_clone - > infos ) - > line_count )
2016-02-18 10:38:51 +01:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to select a line for a new view that is beyond the line count of the view to clone " ) ;
obi_close_column ( view - > line_selection ) ;
2016-06-30 11:41:30 +02:00
obi_view_unmap_file ( view - > dms , view - > infos ) ;
2016-02-18 10:38:51 +01:00
free ( view ) ;
return NULL ;
}
if ( view_to_clone - > line_selection ! = NULL )
2016-11-30 11:08:11 +01:00
line_nb = obi_column_get_index_with_elt_idx ( view_to_clone - > line_selection , line_nb , 0 ) ;
2016-02-18 10:38:51 +01:00
2016-11-30 11:08:11 +01:00
if ( obi_column_set_index_with_elt_idx ( view - > line_selection , ( ( view - > line_selection ) - > header ) - > lines_used , 0 , line_nb ) < 0 )
2016-02-18 10:38:51 +01:00
{
obi_close_column ( view - > line_selection ) ;
2016-06-30 11:41:30 +02:00
obi_view_unmap_file ( view - > dms , view - > infos ) ;
2016-02-18 10:38:51 +01:00
free ( view ) ;
return NULL ;
}
// Update view line count
2016-06-30 11:41:30 +02:00
( ( view - > infos ) - > line_count ) + + ;
2016-02-18 10:38:51 +01:00
}
}
2016-04-25 11:37:53 +02:00
else // If there is no line selection associated with the view to clone or the new view
2016-02-18 10:38:51 +01:00
{
view - > line_selection = NULL ;
2016-06-30 11:41:30 +02:00
( view - > infos ) - > all_lines = true ;
( view - > infos ) - > line_count = ( view_to_clone - > infos ) - > line_count ;
2016-02-18 10:38:51 +01:00
}
2016-08-01 18:25:30 +02:00
// Fill informations
2016-06-30 11:41:30 +02:00
strcpy ( ( view - > infos ) - > view_type , ( view_to_clone - > infos ) - > view_type ) ;
strcpy ( ( view - > infos ) - > created_from , ( view_to_clone - > infos ) - > name ) ;
2016-02-18 10:38:51 +01:00
}
2016-08-01 18:25:30 +02:00
2016-02-18 10:38:51 +01:00
// Else, fill empty view structure
else
{
2016-06-30 11:41:30 +02:00
( view - > infos ) - > column_count = 0 ;
( view - > infos ) - > line_count = 0 ;
( view - > infos ) - > all_lines = true ;
( ( view - > infos ) - > created_from ) [ 0 ] = ' \0 ' ;
( ( view - > infos ) - > view_type ) [ 0 ] = ' \0 ' ;
2017-03-06 16:06:17 +01:00
view - > line_selection = NULL ;
view - > columns = NULL ;
2016-02-18 10:38:51 +01:00
}
2016-08-01 18:25:30 +02:00
// Fill last informations
2016-06-30 11:41:30 +02:00
strcpy ( ( view - > infos ) - > name , view_name ) ;
( view - > infos ) - > creation_date = time ( NULL ) ;
2016-02-18 10:38:51 +01:00
2016-11-25 12:04:57 +01:00
// Fill automatic predicate functions
view - > nb_predicates = 1 ;
view - > predicate_functions = malloc ( ( view - > nb_predicates ) * sizeof ( char * ( * ) ( Obiview_p ) ) ) ;
if ( view - > predicate_functions = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for view predicates " ) ;
return NULL ;
}
( view - > predicate_functions ) [ 0 ] = view_check_qual_match_seqs ;
// Write comments
2018-10-07 18:56:46 +02:00
// Comments must be a json string, even empty
if ( ( strcmp ( comments , " " ) = = 0 ) | | ( comments = = NULL ) )
comments_ok = obi_view_write_comments ( view , " {} " ) ;
else
comments_ok = obi_view_write_comments ( view , comments ) ;
if ( comments_ok < 0 )
2016-08-18 17:57:03 +02:00
{
obidebug ( 1 , " \n Error writing comments when creating a view " ) ;
2017-02-07 17:16:09 +01:00
close_view ( view ) ;
2016-08-18 17:57:03 +02:00
return NULL ;
}
2018-10-07 18:56:46 +02:00
// Add the comment specifying the name of the cloned view if there is one
if ( view_to_clone ! = NULL )
{
if ( obi_view_add_comment ( view , " Cloned from " , ( view_to_clone - > infos ) - > name ) < 0 )
{
obidebug ( 1 , " \n Error adding comment about cloned view when creating a view " ) ;
close_view ( view ) ;
return NULL ;
}
}
2016-06-30 11:41:30 +02:00
// Store reference for line selection
if ( view - > line_selection = = NULL )
{
( ( ( view - > infos ) - > line_selection ) . column_name ) [ 0 ] = ' \0 ' ;
( ( view - > infos ) - > line_selection ) . version = - 1 ;
}
else
{
strcpy ( ( ( view - > infos ) - > line_selection ) . column_name , ( ( view - > line_selection ) - > header ) - > name ) ;
( ( view - > infos ) - > line_selection ) . version = ( ( view - > line_selection ) - > header ) - > version ;
}
2017-03-06 16:06:17 +01:00
// Initialize linked list of column pointers
view - > columns = NULL ;
2016-08-01 18:25:30 +02:00
// Create the column dictionary (hash table) associating column names (or aliases) to column pointers
if ( create_column_dict ( view ) < 0 )
{
2017-02-07 17:16:09 +01:00
close_view ( view ) ;
2016-08-01 18:25:30 +02:00
return NULL ;
}
// Once the view has been created with all its elements and informations, add the columns if the view is cloned from another view
if ( view_to_clone ! = NULL )
{
( view - > infos ) - > column_count = 0 ;
for ( i = 0 ; i < ( ( view_to_clone - > infos ) - > column_count ) ; i + + )
{
2017-03-06 16:06:17 +01:00
column = * ( ( OBIDMS_column_p * ) ll_get ( view_to_clone - > columns , i ) ) ;
if ( column = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column from the linked list of column pointers of a view " ) ;
return NULL ;
}
2016-08-01 18:25:30 +02:00
if ( obi_view_add_column ( view ,
2017-03-06 16:06:17 +01:00
( column - > header ) - > name ,
( column - > header ) - > version ,
2016-08-01 18:25:30 +02:00
( ( ( view_to_clone - > infos ) - > column_references ) [ i ] ) . alias ,
0 ,
2016-09-21 17:42:17 +02:00
0 ,
2016-08-01 18:25:30 +02:00
0 ,
NULL ,
2017-11-15 13:48:59 +01:00
false ,
2017-12-13 22:46:50 +01:00
false ,
false ,
2016-08-01 18:25:30 +02:00
NULL ,
NULL ,
- 1 ,
NULL ,
false )
< 0 )
{
obidebug ( 1 , " \n Error adding a column in a new view from a view to clone " ) ;
if ( view - > line_selection ! = NULL )
obi_close_column ( view - > line_selection ) ;
obi_view_unmap_file ( view - > dms , view - > infos ) ;
free ( view ) ;
return NULL ;
}
}
}
2016-06-30 11:41:30 +02:00
2016-02-18 10:38:51 +01:00
return view ;
}
2016-02-29 17:56:55 +01:00
Obiview_p obi_new_view_cloned_from_name ( OBIDMS_p dms , const char * view_name , const char * view_to_clone_name , index_t * line_selection , const char * comments )
2016-02-18 10:38:51 +01:00
{
Obiview_p view ;
Obiview_p view_to_clone ;
view_to_clone = obi_open_view ( dms , view_to_clone_name ) ;
if ( view_to_clone = = NULL )
return NULL ;
2016-02-29 17:56:55 +01:00
view = obi_new_view ( dms , view_name , view_to_clone , line_selection , comments ) ;
2016-02-25 09:43:27 +01:00
2017-02-07 17:16:09 +01:00
close_view ( view_to_clone ) ;
2016-02-25 09:43:27 +01:00
return view ;
}
2018-10-31 14:38:05 +01:00
Obiview_p obi_new_view_nuc_seqs ( OBIDMS_p dms , const char * view_name , Obiview_p view_to_clone , index_t * line_selection , const char * comments , bool quality_column , bool create_default_columns )
2016-04-25 18:07:58 +02:00
{
2016-07-15 15:38:49 +02:00
Obiview_p view ;
OBIDMS_column_p associated_nuc_column ;
2016-11-25 12:04:57 +01:00
int nb_predicates ;
2016-04-25 18:07:58 +02:00
if ( view_to_clone ! = NULL )
2016-11-25 12:04:57 +01:00
{ // Check that the view to clone is already a NUC_SEQS view
2016-06-30 11:41:30 +02:00
if ( strcmp ( ( view_to_clone - > infos ) - > view_type , VIEW_TYPE_NUC_SEQS ) )
2016-04-25 18:07:58 +02:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " Trying to clone a non-NUC SEQS view to create a NUC SEQS view " ) ;
return NULL ;
}
2017-04-21 11:58:15 +02:00
// Check if there is a quality column
if ( obi_view_get_column ( view_to_clone , QUALITY_COLUMN ) ! = NULL )
quality_column = true ;
else
quality_column = false ;
2016-04-25 18:07:58 +02:00
}
view = obi_new_view ( dms , view_name , view_to_clone , line_selection , comments ) ;
2016-06-30 11:41:30 +02:00
if ( view = = NULL )
2016-04-25 18:07:58 +02:00
return NULL ;
2016-06-30 11:41:30 +02:00
strcpy ( ( view - > infos ) - > view_type , VIEW_TYPE_NUC_SEQS ) ;
2016-04-25 18:07:58 +02:00
2018-10-31 14:38:05 +01:00
if ( ( view_to_clone = = NULL ) & & create_default_columns )
2016-04-25 18:07:58 +02:00
{
// Adding sequence column
2017-12-13 22:46:50 +01:00
if ( obi_view_add_column ( view , NUC_SEQUENCE_COLUMN , - 1 , NULL , OBI_SEQ , 0 , 1 , NULL , false , false , false , NULL , NULL , - 1 , " Nucleotide sequences " , true ) < 0 ) // discuss using same indexer "NUC_SEQ_INDEXER"
2016-04-25 18:07:58 +02:00
{
obidebug ( 1 , " Error adding an obligatory column in a nucleotide sequences view " ) ;
return NULL ;
}
// Adding id column
2017-12-13 22:46:50 +01:00
if ( obi_view_add_column ( view , ID_COLUMN , - 1 , NULL , OBI_STR , 0 , 1 , NULL , false , false , false , NULL , NULL , - 1 , " Sequence identifiers " , true ) < 0 )
2016-04-25 18:07:58 +02:00
{
obidebug ( 1 , " Error adding an obligatory column in a nucleotide sequences view " ) ;
return NULL ;
}
// Adding definition column
2017-12-13 22:46:50 +01:00
if ( obi_view_add_column ( view , DEFINITION_COLUMN , - 1 , NULL , OBI_STR , 0 , 1 , NULL , false , false , false , NULL , NULL , - 1 , " Definitions " , true ) < 0 )
2016-04-25 18:07:58 +02:00
{
obidebug ( 1 , " Error adding an obligatory column in a nucleotide sequences view " ) ;
return NULL ;
}
2016-05-20 16:45:22 +02:00
// Adding quality column
2016-08-16 15:17:26 +02:00
if ( quality_column )
2016-05-20 16:45:22 +02:00
{
2016-08-16 15:17:26 +02:00
associated_nuc_column = obi_view_get_column ( view , NUC_SEQUENCE_COLUMN ) ;
2017-12-13 22:46:50 +01:00
if ( obi_view_add_column ( view , QUALITY_COLUMN , - 1 , NULL , OBI_QUAL , 0 , 1 , NULL , false , false , false , NULL , ( associated_nuc_column - > header ) - > name , ( associated_nuc_column - > header ) - > version , " Sequence qualities " , true ) < 0 ) // TODO discuss automatic association
2016-08-16 15:17:26 +02:00
{
obidebug ( 1 , " Error adding an obligatory column in a nucleotide sequences view " ) ;
return NULL ;
}
2016-05-20 16:45:22 +02:00
}
2016-04-25 18:07:58 +02:00
}
2016-11-25 12:04:57 +01:00
// Add predicate functions specific to the view type
2016-08-16 15:17:26 +02:00
// TODO macros?
2018-03-21 16:37:19 +01:00
// if (quality_column) TODO
// nb_predicates = view->nb_predicates + 4;
// else
nb_predicates = view - > nb_predicates + 3 ;
2016-07-12 14:54:11 +02:00
2016-11-25 12:04:57 +01:00
if ( view - > nb_predicates = = 0 )
view - > predicate_functions = malloc ( nb_predicates * sizeof ( char * ( * ) ( Obiview_p ) ) ) ;
else
view - > predicate_functions = realloc ( view - > predicate_functions , nb_predicates * sizeof ( char * ( * ) ( Obiview_p ) ) ) ;
2016-07-12 14:54:11 +02:00
2016-11-25 12:04:57 +01:00
if ( view - > predicate_functions = = NULL )
2016-08-16 15:17:26 +02:00
{
2016-11-25 12:04:57 +01:00
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for view predicates " ) ;
return NULL ;
2016-08-16 15:17:26 +02:00
}
2016-07-12 14:54:11 +02:00
2016-11-25 12:04:57 +01:00
( view - > predicate_functions ) [ ( view - > nb_predicates ) ] = view_has_nuc_sequence_column ;
( view - > predicate_functions ) [ ( view - > nb_predicates ) + 1 ] = view_has_id_column ;
( view - > predicate_functions ) [ ( view - > nb_predicates ) + 2 ] = view_has_definition_column ;
2018-03-21 16:37:19 +01:00
// if (quality_column) # TODO discuss. Commented bc for example with obi annotate, clone view so clone predicate, then modify seq, so quality is deleted, and predicate boom
// (view->predicate_functions)[(view->nb_predicates) + 3] = view_has_quality_column;
2016-11-25 12:04:57 +01:00
view - > nb_predicates = nb_predicates ;
2016-04-25 18:07:58 +02:00
return view ;
}
2017-04-21 11:58:15 +02:00
Obiview_p obi_new_view_nuc_seqs_cloned_from_name ( OBIDMS_p dms , const char * view_name , const char * view_to_clone_name , index_t * line_selection , const char * comments )
2016-02-25 09:43:27 +01:00
{
Obiview_p view ;
Obiview_p view_to_clone ;
view_to_clone = obi_open_view ( dms , view_to_clone_name ) ;
if ( view_to_clone = = NULL )
return NULL ;
2018-10-31 14:38:05 +01:00
view = obi_new_view_nuc_seqs ( dms , view_name , view_to_clone , line_selection , comments , false , false ) ;
2017-04-21 11:58:15 +02:00
close_view ( view_to_clone ) ;
return view ;
}
Obiview_p obi_clone_view ( OBIDMS_p dms , Obiview_p view_to_clone , const char * view_name , index_t * line_selection , const char * comments )
{
if ( view_to_clone = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error: pointer on view to clone is NULL " ) ;
return NULL ;
}
if ( strcmp ( ( view_to_clone - > infos ) - > view_type , VIEW_TYPE_NUC_SEQS ) = = 0 )
2018-10-31 14:38:05 +01:00
return obi_new_view_nuc_seqs ( dms , view_name , view_to_clone , line_selection , comments , false , false ) ;
2017-04-21 11:58:15 +02:00
else // Non-typed view
return obi_new_view ( dms , view_name , view_to_clone , line_selection , comments ) ;
}
Obiview_p obi_clone_view_from_name ( OBIDMS_p dms , const char * view_to_clone_name , const char * view_name , index_t * line_selection , const char * comments )
{
Obiview_p view ;
Obiview_p view_to_clone ;
view_to_clone = obi_open_view ( dms , view_to_clone_name ) ;
if ( view_to_clone = = NULL )
{
obidebug ( 1 , " \n Error: could not open view to clone " ) ;
return NULL ;
}
view = obi_clone_view ( dms , view_to_clone , view_name , line_selection , comments ) ;
2016-02-25 09:43:27 +01:00
2017-02-07 17:16:09 +01:00
close_view ( view_to_clone ) ;
2016-02-25 09:43:27 +01:00
2016-02-18 10:38:51 +01:00
return view ;
}
2017-02-07 17:16:09 +01:00
Obiview_infos_p obi_view_map_file ( OBIDMS_p dms , const char * view_name , bool finished )
2016-02-18 10:38:51 +01:00
{
2016-09-06 14:19:13 +02:00
char * file_name ;
2016-06-30 11:41:30 +02:00
Obiview_infos_p view_infos ;
2016-02-18 10:38:51 +01:00
int obiview_file_descriptor ;
2016-06-30 11:41:30 +02:00
size_t file_size ;
2017-02-07 17:16:09 +01:00
int open_flag ;
int mmap_flag ;
2016-02-18 10:38:51 +01:00
2016-09-06 14:19:13 +02:00
// Create file name
2017-02-07 17:16:09 +01:00
if ( finished )
file_name = build_obiview_file_name ( view_name ) ;
else
file_name = build_unfinished_obiview_file_name ( view_name ) ;
2016-09-06 14:19:13 +02:00
if ( file_name = = NULL )
2016-09-06 16:22:24 +02:00
return NULL ;
2016-02-18 10:38:51 +01:00
2017-02-07 17:16:09 +01:00
// Set flags (read-only or not)
if ( finished )
{
open_flag = O_RDONLY ;
mmap_flag = PROT_READ ;
}
else
{
open_flag = O_RDWR ;
mmap_flag = PROT_READ | PROT_WRITE ;
}
2016-06-30 11:41:30 +02:00
// Open view file
2017-02-07 17:16:09 +01:00
obiview_file_descriptor = openat ( dms - > view_dir_fd , file_name , open_flag , 0777 ) ;
2016-02-18 10:38:51 +01:00
if ( obiview_file_descriptor < 0 )
{
2016-09-21 17:42:17 +02:00
if ( errno = = ENOENT )
{
obidebug ( 1 , " \n Error opening an obiview file: View %s does not exist " , view_name ) ;
}
else
{
obidebug ( 1 , " \n Error opening an obiview file " ) ;
}
2016-02-18 10:38:51 +01:00
obi_set_errno ( OBIVIEW_ERROR ) ;
2016-09-06 14:19:13 +02:00
free ( file_name ) ;
2016-02-18 10:38:51 +01:00
return NULL ;
}
2016-09-06 14:19:13 +02:00
free ( file_name ) ;
2016-02-18 10:38:51 +01:00
2016-08-18 17:57:03 +02:00
// Get file size
if ( read ( obiview_file_descriptor , & file_size , sizeof ( size_t ) ) < ( ( ssize_t ) sizeof ( size_t ) ) )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error reading the file size in an obiview file " ) ;
close ( obiview_file_descriptor ) ;
return NULL ;
}
2016-06-30 11:41:30 +02:00
// Map the view infos structure
view_infos = mmap ( NULL ,
file_size ,
2017-02-07 17:16:09 +01:00
mmap_flag ,
2016-06-30 11:41:30 +02:00
MAP_SHARED ,
obiview_file_descriptor ,
0
) ;
if ( view_infos = = NULL )
2016-02-18 10:38:51 +01:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
2016-06-30 11:41:30 +02:00
obidebug ( 1 , " \n Error mapping an obiview file " ) ;
2016-02-18 10:38:51 +01:00
return NULL ;
}
2016-09-15 11:58:56 +02:00
if ( close ( obiview_file_descriptor ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error closing a view file " ) ;
return NULL ;
}
2016-02-18 10:38:51 +01:00
2016-06-30 11:41:30 +02:00
return view_infos ;
}
2016-02-18 10:38:51 +01:00
2016-06-30 11:41:30 +02:00
int obi_view_unmap_file ( OBIDMS_p dms , Obiview_infos_p view_infos )
{
2017-02-07 17:16:09 +01:00
char * file_name ;
int obiview_file_descriptor ;
size_t file_size ;
2016-06-30 11:41:30 +02:00
2016-09-15 11:58:56 +02:00
// Get file name
2017-02-07 17:16:09 +01:00
if ( view_infos - > finished )
file_name = build_obiview_file_name ( view_infos - > name ) ;
else
file_name = build_unfinished_obiview_file_name ( view_infos - > name ) ;
2016-09-15 11:58:56 +02:00
if ( file_name = = NULL )
return - 1 ;
2016-06-30 11:41:30 +02:00
2016-09-15 11:58:56 +02:00
// Open view file
2017-02-07 17:16:09 +01:00
obiview_file_descriptor = openat ( dms - > view_dir_fd , file_name , O_RDONLY , 0777 ) ;
2016-09-15 11:58:56 +02:00
if ( obiview_file_descriptor < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
2018-10-31 14:38:05 +01:00
obidebug ( 1 , " \n Error opening an obiview file (%s) >%s< " , file_name , dms - > dms_name ) ;
2016-09-06 14:19:13 +02:00
free ( file_name ) ;
2016-09-15 11:58:56 +02:00
return - 1 ;
}
2016-06-30 11:41:30 +02:00
2016-09-15 11:58:56 +02:00
free ( file_name ) ;
2016-02-18 10:38:51 +01:00
2016-09-15 11:58:56 +02:00
// Unmap the view infos structure
file_size = view_infos - > file_size ;
if ( munmap ( view_infos , file_size ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error unmapping an obiview file " ) ;
2016-02-18 10:38:51 +01:00
close ( obiview_file_descriptor ) ;
2016-09-15 11:58:56 +02:00
return - 1 ;
}
2016-02-18 10:38:51 +01:00
2016-09-15 11:58:56 +02:00
if ( close ( obiview_file_descriptor ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error closing a view file " ) ;
return - 1 ;
}
return 0 ;
2016-06-30 11:41:30 +02:00
}
Obiview_p obi_open_view ( OBIDMS_p dms , const char * view_name )
{
2016-09-28 14:28:34 +02:00
Obiview_p view ;
const char * column_name ;
obiversion_t column_version ;
OBIDMS_column_p column_pointer ;
int i ;
2016-02-18 10:38:51 +01:00
2016-09-28 14:28:34 +02:00
// Check that the DMS is a valid pointer
if ( dms = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error opening a view: DMS pointer is NULL " ) ;
return NULL ;
}
// Check that the view name pointer is valid
if ( view_name = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error opening a view: view name is NULL " ) ;
return NULL ;
}
// Allocate the memory for the view structure
2016-02-18 10:38:51 +01:00
view = ( Obiview_p ) malloc ( sizeof ( Obiview_t ) ) ;
if ( view = = NULL )
{
2016-06-30 11:41:30 +02:00
obi_set_errno ( OBI_MALLOC_ERROR ) ;
2016-02-18 10:38:51 +01:00
obidebug ( 1 , " \n Error allocating memory for a view " ) ;
return NULL ;
}
2017-03-06 16:06:17 +01:00
// Initialize view informations
view - > dms = dms ;
view - > read_only = true ;
view - > nb_predicates = 0 ;
view - > predicate_functions = NULL ;
view - > columns = NULL ;
2016-06-30 11:41:30 +02:00
// Map view file
2017-02-07 17:16:09 +01:00
view - > infos = obi_view_map_file ( dms , view_name , true ) ;
if ( ( view - > infos ) = = NULL )
2016-11-24 11:19:07 +01:00
{
free ( view ) ;
return NULL ;
}
2016-06-30 11:41:30 +02:00
// Open the line selection associated with the view
if ( ( view - > infos ) - > all_lines )
2016-02-18 10:38:51 +01:00
view - > line_selection = NULL ;
else
{
2016-06-30 11:41:30 +02:00
view - > line_selection = obi_open_column ( dms , ( ( view - > infos ) - > line_selection ) . column_name , ( ( view - > infos ) - > line_selection ) . version ) ;
2016-02-18 10:38:51 +01:00
if ( view - > line_selection = = NULL )
{
2016-06-30 11:41:30 +02:00
obidebug ( 1 , " \n Error opening a line selection for a view " ) ;
obi_view_unmap_file ( view - > dms , view - > infos ) ;
free ( view ) ;
2016-02-18 10:38:51 +01:00
return NULL ;
}
}
// Open the columns to read
2016-06-30 11:41:30 +02:00
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
2016-02-18 10:38:51 +01:00
{
2016-08-01 18:25:30 +02:00
column_name = ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . column_name ;
column_version = ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . version ;
column_pointer = obi_open_column ( dms , column_name , column_version ) ;
if ( column_pointer = = NULL )
2016-02-18 10:38:51 +01:00
{
2016-08-01 18:25:30 +02:00
obidebug ( 1 , " \n Error opening a column for a view: column %d: %s, version %d " , i , column_name , column_version ) ;
2017-02-07 17:16:09 +01:00
close_view ( view ) ;
2016-02-18 10:38:51 +01:00
return NULL ;
}
2017-03-06 16:06:17 +01:00
view - > columns = ll_add ( view - > columns , column_pointer ) ;
if ( view - > columns = = NULL )
{
obidebug ( 1 , " \n Error adding a column in the column linked list of a view: column %d: %s, version %d " , i , column_name , column_version ) ;
close_view ( view ) ;
return NULL ;
}
2016-02-18 10:38:51 +01:00
}
2016-08-01 18:25:30 +02:00
// Create the column dictionary associating each column alias with its pointer
if ( create_column_dict ( view ) < 0 )
{
obidebug ( 1 , " \n Error creating the column dictionary when opening a view " ) ;
2017-02-07 17:16:09 +01:00
close_view ( view ) ;
2016-08-01 18:25:30 +02:00
return NULL ;
}
2016-02-18 10:38:51 +01:00
return view ;
}
2017-07-11 16:44:23 +02:00
// TODO return a pointer on the column?
2016-12-05 11:18:29 +01:00
int obi_view_add_column ( Obiview_p view ,
const char * column_name ,
2016-02-18 10:38:51 +01:00
obiversion_t version_number ,
2016-12-05 11:18:29 +01:00
const char * alias ,
OBIType_t data_type ,
index_t nb_lines ,
index_t nb_elements_per_line ,
char * elements_names ,
2017-12-13 22:46:50 +01:00
bool elt_names_formatted ,
2017-11-15 13:48:59 +01:00
bool tuples ,
2017-12-13 22:46:50 +01:00
bool to_eval ,
2016-12-05 11:18:29 +01:00
const char * indexer_name ,
const char * associated_column_name ,
2016-07-15 15:38:49 +02:00
obiversion_t associated_column_version ,
2017-02-22 13:49:50 +01:00
const char * comments ,
bool create ) // all infos for creation or open
2016-02-18 10:38:51 +01:00
{
2016-08-01 18:25:30 +02:00
int i ;
OBIDMS_column_p column ;
OBIDMS_column_p column_buffer ;
2016-02-18 10:38:51 +01:00
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to add a column in a read-only view " ) ;
return - 1 ;
}
2016-11-23 11:04:53 +01:00
// If there is a line selection , clone the columns to delete the line selection
2016-09-22 11:19:29 +02:00
if ( create & & ( view - > line_selection ! = NULL ) )
2016-05-11 16:34:20 +02:00
{
2016-06-30 11:41:30 +02:00
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
2016-05-11 16:34:20 +02:00
{
{ // Clone with the right line selection and replace for all columns
// Save pointer to close column after cloning
2017-03-06 16:06:17 +01:00
column_buffer = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column_buffer = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column to clone from the linked list of column pointers of a view " ) ;
return - 1 ;
}
2016-05-11 16:34:20 +02:00
// Clone and replace the column in the view
2017-03-06 16:06:17 +01:00
column = obi_clone_column ( view - > dms , view - > line_selection , ( column_buffer - > header ) - > name , ( column_buffer - > header ) - > version , 1 ) ;
if ( column = = NULL )
2016-05-11 16:34:20 +02:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error cloning a column to replace in a view " ) ;
return - 1 ;
}
2017-03-06 16:06:17 +01:00
// Change the pointer in the linked list of column pointers
if ( ll_set ( view - > columns , i , column ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error changing the column pointer of a cloned column in the linked list of column pointers of a view " ) ;
return - 1 ;
}
2016-05-11 16:34:20 +02:00
// Close old cloned column
obi_close_column ( column_buffer ) ;
}
}
2016-09-22 11:19:29 +02:00
// Close old line selection
2016-09-21 17:42:17 +02:00
if ( view - > line_selection ! = NULL )
{
obi_close_column ( view - > line_selection ) ;
view - > line_selection = NULL ;
// Update line selection reference
( ( ( view - > infos ) - > line_selection ) . column_name ) [ 0 ] = ' \0 ' ;
( ( view - > infos ) - > line_selection ) . version = - 1 ;
}
2016-05-11 16:34:20 +02:00
}
2016-09-21 17:42:17 +02:00
// Update the line count if needed
if ( create )
2016-05-11 16:34:20 +02:00
{
2016-09-21 17:42:17 +02:00
if ( ( view - > infos ) - > line_count > nb_lines )
nb_lines = ( view - > infos ) - > line_count ;
else if ( nb_lines > ( view - > infos ) - > line_count )
update_lines ( view , nb_lines ) ;
2016-05-11 16:34:20 +02:00
}
2016-02-18 10:38:51 +01:00
// Open or create the column
if ( create )
{ // Create column
2017-12-13 22:46:50 +01:00
column = obi_create_column ( view - > dms , column_name , data_type , nb_lines , nb_elements_per_line , elements_names , elt_names_formatted , tuples , to_eval , indexer_name , associated_column_name , associated_column_version , comments ) ;
2016-09-22 18:05:07 +02:00
if ( column = = NULL )
{
obidebug ( 1 , " \n Error creating a column to add to a view " ) ;
return - 1 ;
}
2016-09-21 17:42:17 +02:00
( column - > header ) - > lines_used = nb_lines ;
2016-02-18 10:38:51 +01:00
}
else
{ // Open column
column = obi_open_column ( view - > dms , column_name , version_number ) ;
2016-09-22 18:05:07 +02:00
if ( column = = NULL )
{
2018-10-31 14:38:05 +01:00
obidebug ( 1 , " \n Error opening a column to add to a view: %s, version %d " , column_name , version_number ) ;
2016-09-22 18:05:07 +02:00
return - 1 ;
}
2017-08-03 16:32:22 +02:00
// - If there is a line selection:
// - The column's lines_used attribute must be at least the view's line count
// - If there is no line selection:
// - If it's the first column in the view:
// - The view's line count is set to the column's lines_used attribute
// - If it's not the first column in the view:
// - The column's lines_used attribute must be equal to the view's line count
if ( ( view - > line_selection ! = NULL ) & & ( ( column - > header ) - > lines_used < ( view - > infos ) - > line_count ) )
{ // - If there is a line selection, the column's lines_used attribute must be at least the view's line count
2016-11-23 11:04:53 +01:00
obi_set_errno ( OBIVIEW_ERROR ) ;
2017-08-03 16:32:22 +02:00
obidebug ( 1 , " \n Error adding an existing column to a view: the column's lines_used attribute (%lld) must be equal to or greater than the view's line count (%lld) " , ( column - > header ) - > lines_used , ( view - > infos ) - > line_count ) ;
2016-11-23 11:04:53 +01:00
return - 1 ;
}
2017-08-03 16:32:22 +02:00
else if ( view - > line_selection = = NULL )
{ // If there is no line selection:
if ( ( view - > infos ) - > column_count = = 0 ) // If it's the first column in the view:
( view - > infos ) - > line_count = ( column - > header ) - > lines_used ; // The view's line count is set to the column's lines_used attribute
else if ( ( column - > header ) - > lines_used ! = ( view - > infos ) - > line_count )
{ // If it's not the first column in the view, the column's lines_used attribute must be equal to the view's line count
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error adding an existing column to a view: the column's lines_used attribute (%lld) must be equal to the view's line count (%lld) " , ( column - > header ) - > lines_used , ( view - > infos ) - > line_count ) ;
return - 1 ;
}
}
2016-02-18 10:38:51 +01:00
}
2016-08-01 18:25:30 +02:00
// Store column pointer in the view structure
2017-03-06 16:06:17 +01:00
view - > columns = ll_add ( view - > columns , column ) ;
if ( view - > columns = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error adding a column in the linked list of column pointers of a view: column %s, version %d " , column_name , version_number ) ;
return - 1 ;
}
2017-07-18 17:34:32 +02:00
// If an alias is not defined, it's the original name of the column.
if ( ( alias = = NULL ) | | ( * alias = = ' \0 ' ) )
2016-08-01 18:25:30 +02:00
alias = column_name ;
// Save column alias
strcpy ( ( ( ( view - > infos ) - > column_references ) [ ( view - > infos ) - > column_count ] ) . alias , alias ) ;
2016-09-21 17:42:17 +02:00
// Update column count in view
2016-06-30 11:41:30 +02:00
( view - > infos ) - > column_count + + ;
2016-08-01 18:25:30 +02:00
// Update column references and dictionary
2017-03-06 16:06:17 +01:00
if ( update_column_refs_and_dict ( view ) < 0 )
{
obidebug ( 1 , " \n Error updating column references and dictionary after adding a column to a view " ) ;
return - 1 ;
}
2016-08-01 18:25:30 +02:00
2018-10-31 14:38:05 +01:00
// Print dict
2016-08-01 18:25:30 +02:00
// for (i=0; i<((view->infos)->column_count); i++)
// {
2018-10-31 14:38:05 +01:00
// fprintf(stderr, "\n\n2305 alias: %s", (((view->infos)->column_references)[i]).alias);
2016-08-01 18:25:30 +02:00
// fprintf(stderr, "\npointer: %x\n", obi_view_get_column(view, (((view->infos)->column_references)[i]).alias));
// }
2016-02-18 10:38:51 +01:00
return 0 ;
}
int obi_view_delete_column ( Obiview_p view , const char * column_name )
{
int i ;
bool found ;
2017-03-06 16:06:17 +01:00
OBIDMS_column_p column ;
2016-02-18 10:38:51 +01:00
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to delete a column in a read-only view " ) ;
return - 1 ;
}
2016-08-01 18:25:30 +02:00
found = false ;
2016-06-30 11:41:30 +02:00
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
2016-02-18 10:38:51 +01:00
{
2016-08-01 18:25:30 +02:00
if ( ( ! found ) & & ( ! strcmp ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , column_name ) ) )
2016-02-18 10:38:51 +01:00
{
2017-04-06 14:44:07 +02:00
column = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column = = NULL )
2017-03-06 16:06:17 +01:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
2017-04-06 14:44:07 +02:00
obidebug ( 1 , " \n Error getting a column from the linked list of column pointers of a view when deleting a column from a view " ) ;
2017-03-06 16:06:17 +01:00
return - 1 ;
}
2017-04-06 14:44:07 +02:00
obi_close_column ( column ) ;
view - > columns = ll_delete ( view - > columns , i ) ;
// TODO how do we check for error? NULL can be empty list
2016-08-01 18:25:30 +02:00
found = true ;
2016-02-18 10:38:51 +01:00
}
if ( found )
{
2016-06-30 11:41:30 +02:00
if ( i ! = ( ( ( view - > infos ) - > column_count ) - 1 ) ) // not the last one
2017-03-06 16:06:17 +01:00
{ // Shift the references
2016-08-01 18:25:30 +02:00
strcpy ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , ( ( ( view - > infos ) - > column_references ) [ i + 1 ] ) . alias ) ;
strcpy ( ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . column_name , ( ( ( ( view - > infos ) - > column_references ) [ i + 1 ] ) . column_refs ) . column_name ) ;
( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . version = ( ( ( ( view - > infos ) - > column_references ) [ i + 1 ] ) . column_refs ) . version ;
}
2016-02-18 10:38:51 +01:00
else // Last column
2017-03-06 16:06:17 +01:00
{
strcpy ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , " " ) ;
strcpy ( ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . column_name , " " ) ;
( ( ( ( view - > infos ) - > column_references ) [ i ] ) . column_refs ) . version = - 1 ;
}
2016-02-18 10:38:51 +01:00
}
}
if ( ! found )
2016-08-01 18:25:30 +02:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to delete a column: column not found " ) ;
2016-02-18 10:38:51 +01:00
return - 1 ;
2016-08-01 18:25:30 +02:00
}
2016-02-18 10:38:51 +01:00
2016-06-30 11:41:30 +02:00
( ( view - > infos ) - > column_count ) - - ;
2016-08-01 18:25:30 +02:00
// Update column dictionary
update_column_dict ( view ) ;
2016-02-18 10:38:51 +01:00
return 0 ;
}
2016-04-25 18:07:58 +02:00
OBIDMS_column_p obi_view_get_column ( Obiview_p view , const char * column_name )
2016-08-01 18:25:30 +02:00
{
2017-04-21 11:58:15 +02:00
OBIDMS_column_p * column_pp ;
column_pp = ( OBIDMS_column_p * ) ( ht_get ( view - > column_dict , column_name ) ) ;
if ( column_pp = = NULL )
return NULL ;
return ( * column_pp ) ;
2016-08-01 18:25:30 +02:00
}
2017-07-18 17:34:32 +02:00
OBIDMS_column_p * obi_view_get_pointer_on_column_in_view ( Obiview_p view , const char * column_name )
{
return ( OBIDMS_column_p * ) ( ht_get ( view - > column_dict , column_name ) ) ;
}
2017-07-17 17:31:09 +02:00
bool obi_view_column_exists ( Obiview_p view , const char * column_name )
{
if ( obi_view_get_column ( view , column_name ) = = NULL )
return false ;
else
return true ;
}
2016-08-01 18:25:30 +02:00
int obi_view_create_column_alias ( Obiview_p view , const char * current_name , const char * alias )
2016-04-25 18:07:58 +02:00
{
int i ;
2016-08-01 18:25:30 +02:00
bool found ;
2016-04-25 18:07:58 +02:00
2016-08-01 18:25:30 +02:00
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to change a column alias in a read-only view " ) ;
return - 1 ;
}
// Check that the new alias is unique
if ( ht_get ( view - > column_dict , alias ) ! = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error: the new name/alias identifying a column in a view is not unique " ) ;
return - 1 ;
}
// Set the new alias in the column references
found = false ;
2016-06-30 11:41:30 +02:00
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
2016-04-25 18:07:58 +02:00
{
2016-08-01 18:25:30 +02:00
if ( ! strcmp ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , current_name ) )
{
strcpy ( ( ( ( view - > infos ) - > column_references ) [ i ] ) . alias , alias ) ;
found = true ;
}
2016-04-25 18:07:58 +02:00
}
2016-08-01 18:25:30 +02:00
if ( found = = false )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error: can't find the column '%s' to change its alias " , current_name ) ;
return - 1 ;
}
// Update the column dictionary
update_column_dict ( view ) ;
return 0 ;
2016-04-25 18:07:58 +02:00
}
2018-10-07 18:56:46 +02:00
int obi_view_write_comments ( Obiview_p view , const char * comments )
{
size_t new_size ;
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to write comments in a read-only view " ) ;
return - 1 ;
}
if ( comments = = NULL )
return 0 ; // TODO or error? discuss
new_size = sizeof ( Obiview_infos_t ) + strlen ( comments ) + 1 ;
// Check if the file has to be enlarged
if ( new_size > = ( view - > infos ) - > file_size )
{
if ( enlarge_view_file ( view , new_size ) < 0 )
return - 1 ;
}
strcpy ( ( view - > infos ) - > comments , comments ) ;
( view - > infos ) - > used_size = new_size ;
return 0 ;
}
int obi_view_add_comment ( Obiview_p view , const char * key , const char * value )
{
char * new_comments = NULL ;
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to add a comment to a read-only view " ) ;
return - 1 ;
}
new_comments = obi_add_comment ( ( view - > infos ) - > comments , key , value ) ;
if ( new_comments = = NULL )
{
obidebug ( 1 , " \n Error adding a comment to a view, key: %s, value: %s " , key , value ) ;
return - 1 ;
}
if ( obi_view_write_comments ( view , new_comments ) < 0 )
{
obidebug ( 1 , " \n Error adding a comment to a view, key: %s, value: %s " , key , value ) ;
return - 1 ;
}
free ( new_comments ) ;
return 0 ;
}
2016-06-30 11:41:30 +02:00
int obi_save_and_close_view ( Obiview_p view )
2016-04-25 18:07:58 +02:00
{
2017-02-07 17:16:09 +01:00
// Finish and save the view if it is not read-only
if ( ! ( view - > read_only ) )
if ( finish_view ( view ) < 0 )
2016-06-30 11:41:30 +02:00
return - 1 ;
2017-02-07 17:16:09 +01:00
if ( close_view ( view ) < 0 )
2016-04-25 18:07:58 +02:00
return - 1 ;
2017-02-07 17:16:09 +01:00
2016-04-25 18:07:58 +02:00
return 0 ;
}
2017-10-26 18:58:48 +02:00
int obi_clean_unfinished_views ( OBIDMS_p dms )
{
struct dirent * dp ;
int i ;
char * full_path ;
char * relative_path ;
Obiview_infos_p view_infos ;
char * view_name ;
int ret_value ;
char * to_delete [ 1000 ] ;
int d ;
ret_value = 0 ;
d = 0 ;
// Look for unfinished views and delete them
2017-11-24 18:04:58 +01:00
rewinddir ( dms - > view_directory ) ;
2017-10-26 18:58:48 +02:00
while ( ( dp = readdir ( dms - > view_directory ) ) ! = NULL )
{
if ( ( dp - > d_name ) [ 0 ] = = ' . ' )
continue ;
i = 0 ;
while ( ( dp - > d_name ) [ i ] ! = ' . ' )
i + + ;
relative_path = ( char * ) malloc ( strlen ( VIEW_DIR_NAME ) + strlen ( dp - > d_name ) + 2 ) ;
strcpy ( relative_path , VIEW_DIR_NAME ) ;
strcat ( relative_path , " / " ) ;
strcat ( relative_path , dp - > d_name ) ;
full_path = obi_dms_get_full_path ( dms , relative_path ) ;
free ( relative_path ) ;
if ( full_path = = NULL )
{
obidebug ( 1 , " \n Error getting the full path to a view file when cleaning unfinished views " ) ;
ret_value = - 1 ;
continue ;
}
if ( strcmp ( ( dp - > d_name ) + i , " .obiview_unfinished " ) = = 0 )
{
// Add to the list of files to delete (deleting in loop not safe)
to_delete [ d ] = full_path ;
d + + ;
}
else if ( strcmp ( ( dp - > d_name ) + i , " .obiview " ) = = 0 )
{ // Check if the view was properly flagged as finished
view_name = ( char * ) malloc ( ( i + 1 ) * sizeof ( char ) ) ;
if ( view_name = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for a view name when deleting unfinished views: file %s " , dp - > d_name ) ;
ret_value = - 1 ;
continue ;
}
strncpy ( view_name , dp - > d_name , i ) ;
view_name [ i ] = ' \0 ' ;
view_infos = obi_view_map_file ( dms , view_name , true ) ;
if ( view_infos = = NULL )
{
obidebug ( 1 , " \n Error reading a view file when deleting unfinished views: file %s " , dp - > d_name ) ;
ret_value = - 1 ;
continue ;
}
if ( view_infos - > finished = = false )
{
// Add to the list of files to delete (deleting in loop not safe)
to_delete [ d ] = full_path ;
d + + ;
}
}
2018-02-12 14:44:56 +01:00
}
2017-10-26 18:58:48 +02:00
2018-02-12 14:44:56 +01:00
for ( i = 0 ; i < d ; i + + )
{
if ( remove ( to_delete [ i ] ) < 0 )
2017-10-26 18:58:48 +02:00
{
2018-02-12 14:44:56 +01:00
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error deleting a view file when deleting unfinished views: file %s " , to_delete [ i ] ) ;
ret_value = - 1 ;
2017-10-26 18:58:48 +02:00
}
2018-02-12 14:44:56 +01:00
free ( to_delete [ i ] ) ;
2017-10-26 18:58:48 +02:00
}
2018-02-12 14:44:56 +01:00
2017-10-26 18:58:48 +02:00
return 0 ;
}
int obi_rollback_view ( Obiview_p view )
{
int i ;
int ret_value ;
int n ;
struct dirent * dp ;
OBIDMS_column_p column ;
char * column_file_path ;
char * column_dir_name ;
char * column_dir_path ;
char * view_file_name ;
char * view_relative_path ;
char * view_full_path ;
ret_value = 0 ;
// Don't rollback if view finished
if ( view - > read_only )
return ret_value ;
for ( i = 0 ; i < ( ( view - > infos ) - > column_count ) ; i + + )
{
column = * ( ( OBIDMS_column_p * ) ll_get ( view - > columns , i ) ) ;
if ( column = = NULL )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error getting a column from the linked list of column pointers of a view when rollbacking the view " ) ;
ret_value = - 1 ;
continue ;
}
// Delete the column file if it was created by the view (it was if it is writable)
if ( column - > writable )
{
// Build file and dir paths
column_file_path = obi_column_full_path ( view - > dms , ( column - > header ) - > name , ( column - > header ) - > version ) ;
if ( column_file_path = = NULL )
{
obidebug ( 1 , " \n Error getting a column file path when rollbacking a view " ) ;
ret_value = - 1 ;
continue ;
}
column_dir_name = obi_build_column_directory_name ( ( column - > header ) - > name ) ;
if ( column_dir_name = = NULL )
{
obidebug ( 1 , " \n Error getting a column directory name when rollbacking a view " ) ;
ret_value = - 1 ;
}
column_dir_path = obi_dms_get_full_path ( view - > dms , column_dir_name ) ;
if ( column_dir_path = = NULL )
{
obidebug ( 1 , " \n Error getting a column directory path when rollbacking a view " ) ;
ret_value = - 1 ;
}
// Try to close the column (?)
if ( obi_close_column ( column ) < 0 )
ret_value = - 1 ;
// Delete the column file
if ( remove ( column_file_path ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error deleting a column file when rollbacking a view " ) ;
ret_value = - 1 ;
}
2017-11-15 17:27:26 +01:00
// Delete column dir if it's empty TODO doesn't happen because version file
2017-10-26 18:58:48 +02:00
n = count_dir ( column_dir_path ) ;
if ( n = = 0 )
{
if ( remove ( column_dir_path ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error deleting a column directory when rollbacking a view " ) ;
ret_value = - 1 ;
}
}
free ( column_file_path ) ;
free ( column_dir_name ) ;
free ( column_dir_path ) ;
}
}
// Delete line selection if there is one
if ( view - > line_selection ! = NULL )
{
column = view - > line_selection ;
if ( column - > writable )
{
// Build file and dir paths
column_file_path = obi_column_full_path ( view - > dms , ( column - > header ) - > name , ( column - > header ) - > version ) ;
if ( column_file_path = = NULL )
{
obidebug ( 1 , " \n Error getting a column file path when rollbacking a view " ) ;
ret_value = - 1 ;
}
column_dir_name = obi_build_column_directory_name ( ( column - > header ) - > name ) ;
if ( column_dir_name = = NULL )
{
obidebug ( 1 , " \n Error getting a column directory name when rollbacking a view " ) ;
ret_value = - 1 ;
}
column_dir_path = obi_dms_get_full_path ( view - > dms , column_dir_name ) ;
if ( column_dir_path = = NULL )
{
obidebug ( 1 , " \n Error getting a column directory path when rollbacking a view " ) ;
ret_value = - 1 ;
}
// Try to close the column (?)
if ( obi_close_column ( column ) < 0 )
ret_value = - 1 ;
// Delete the column file
if ( remove ( column_file_path ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error deleting a column file when rollbacking a view " ) ;
ret_value = - 1 ;
}
2017-11-15 17:27:26 +01:00
// Delete column dir if it's empty TODO doesn't happen because version file
2017-10-26 18:58:48 +02:00
n = count_dir ( column_dir_path ) ;
if ( n = = 0 )
{
if ( remove ( column_dir_path ) < 0 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error deleting a column directory when rollbacking a view " ) ;
ret_value = - 1 ;
}
}
free ( column_file_path ) ;
free ( column_dir_name ) ;
free ( column_dir_path ) ;
}
}
// Delete view file
view_file_name = ( char * ) malloc ( strlen ( ( view - > infos ) - > name ) + strlen ( " .obiview_unfinished " ) + 1 ) ;
if ( view_file_name = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for a view file name " ) ;
ret_value = - 1 ;
}
else
{
strcpy ( view_file_name , ( view - > infos ) - > name ) ;
strcat ( view_file_name , " .obiview_unfinished " ) ;
2017-11-24 18:04:58 +01:00
rewinddir ( ( view - > dms ) - > view_directory ) ;
2017-10-26 18:58:48 +02:00
while ( ( dp = readdir ( ( view - > dms ) - > view_directory ) ) ! = NULL )
{
if ( ( dp - > d_name ) [ 0 ] = = ' . ' )
continue ;
if ( strcmp ( dp - > d_name , view_file_name ) = = 0 )
{
view_relative_path = ( char * ) malloc ( strlen ( VIEW_DIR_NAME ) + strlen ( view_file_name ) + 2 ) ;
strcpy ( view_relative_path , VIEW_DIR_NAME ) ;
strcat ( view_relative_path , " / " ) ;
strcat ( view_relative_path , view_file_name ) ;
view_full_path = obi_dms_get_full_path ( view - > dms , view_relative_path ) ;
remove ( view_full_path ) ;
2017-11-15 17:27:26 +01:00
free ( view_relative_path ) ;
free ( view_full_path ) ;
2017-10-26 18:58:48 +02:00
}
}
free ( view_file_name ) ;
}
// Free the linked list of column pointers
ll_free ( view - > columns ) ;
// Free the column dictionary
ht_free ( view - > column_dict ) ;
free ( view ) ;
return ret_value ;
}
2018-10-31 14:38:05 +01:00
int obi_delete_view ( OBIDMS_p dms , const char * view_name )
{
char * view_file_name ;
char * view_relative_path ;
char * view_full_path ;
struct dirent * dp ;
2018-10-31 17:51:10 +01:00
int finished_view ;
2018-10-31 14:38:05 +01:00
// Check that the view exists
if ( view_exists ( dms , view_name ) = = false )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to delete a view: view '%s' does not exist " , view_name ) ;
return - 1 ;
}
// Check that the view is finished
2018-10-31 17:51:10 +01:00
finished_view = view_is_finished ( dms , view_name ) ;
if ( finished_view = = - 1 )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to check if view '%s' is finished " , view_name ) ;
return - 1 ;
}
if ( finished_view = = 0 )
2018-10-31 14:38:05 +01:00
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to delete a view: view '%s' is not finished " , view_name ) ;
return - 1 ;
}
// Delete view file
view_file_name = ( char * ) malloc ( strlen ( view_name ) + strlen ( " .obiview " ) + 1 ) ;
if ( view_file_name = = NULL )
{
obi_set_errno ( OBI_MALLOC_ERROR ) ;
obidebug ( 1 , " \n Error allocating memory for a view file name " ) ;
return - 1 ;
}
strcpy ( view_file_name , view_name ) ;
strcat ( view_file_name , " .obiview " ) ;
rewinddir ( dms - > view_directory ) ;
while ( ( dp = readdir ( dms - > view_directory ) ) ! = NULL )
{
if ( ( dp - > d_name ) [ 0 ] = = ' . ' )
continue ;
if ( strcmp ( dp - > d_name , view_file_name ) = = 0 )
{
view_relative_path = ( char * ) malloc ( strlen ( VIEW_DIR_NAME ) + strlen ( view_file_name ) + 2 ) ;
strcpy ( view_relative_path , VIEW_DIR_NAME ) ;
strcat ( view_relative_path , " / " ) ;
strcat ( view_relative_path , view_file_name ) ;
view_full_path = obi_dms_get_full_path ( dms , view_relative_path ) ;
remove ( view_full_path ) ;
free ( view_relative_path ) ;
free ( view_full_path ) ;
}
}
free ( view_file_name ) ;
return 0 ;
}
2017-07-11 16:44:23 +02:00
int obi_create_auto_count_column ( Obiview_p view )
{
2017-07-17 17:31:09 +02:00
index_t i ;
OBIDMS_column_p column ;
2017-07-11 16:44:23 +02:00
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to create an automatic count column in a read-only view " ) ;
return - 1 ;
}
2017-12-13 22:46:50 +01:00
if ( obi_view_add_column ( view , COUNT_COLUMN , - 1 , NULL , OBI_INT , 0 , 1 , NULL , false , false , false , NULL , NULL , - 1 , " Sequence counts " , true ) < 0 )
2017-07-11 16:44:23 +02:00
{
obidebug ( 1 , " Error adding an automatic count column in a view " ) ;
return - 1 ;
}
column = obi_view_get_column ( view , COUNT_COLUMN ) ;
if ( column = = NULL )
{
obidebug ( 1 , " Error adding an automatic count column in a view " ) ;
return - 1 ;
}
// Fill the column with 1s
for ( i = 0 ; i < ( view - > infos ) - > line_count ; i + + )
{
2017-07-17 17:31:09 +02:00
if ( obi_set_int_with_elt_idx_and_col_p_in_view ( view , column , i , 0 , 1 ) < 0 )
{
obidebug ( 1 , " Error adding an automatic count column in a view " ) ;
return - 1 ;
}
}
return 0 ;
}
int obi_create_auto_id_column ( Obiview_p view , const char * prefix )
{
index_t i ;
OBIDMS_column_p column ;
char * id ;
// Check that the view is not read-only
if ( view - > read_only )
{
obi_set_errno ( OBIVIEW_ERROR ) ;
obidebug ( 1 , " \n Error trying to create an automatic count column in a read-only view " ) ;
return - 1 ;
}
// Delete old ID column if it exists
if ( obi_view_get_column ( view , ID_COLUMN ) ! = NULL )
{
if ( obi_view_delete_column ( view , ID_COLUMN ) < 0 )
{
obidebug ( 1 , " Error deleting an ID column to replace it in a view " ) ;
return - 1 ;
}
}
// Create the new ID column
2017-12-13 22:46:50 +01:00
if ( obi_view_add_column ( view , ID_COLUMN , - 1 , NULL , OBI_STR , 0 , 1 , NULL , false , false , false , NULL , NULL , - 1 , " Sequence identifiers " , true ) < 0 )
2017-07-17 17:31:09 +02:00
{
obidebug ( 1 , " Error adding an automatic ID column in a view " ) ;
return - 1 ;
}
column = obi_view_get_column ( view , ID_COLUMN ) ;
if ( column = = NULL )
{
obidebug ( 1 , " Error adding an automatic ID column in a view " ) ;
return - 1 ;
}
// If prefix is NULL, use default prefix
if ( prefix = = NULL )
prefix = ID_PREFIX ;
// Fill the column with automatic ids
for ( i = 0 ; i < ( view - > infos ) - > line_count ; i + + )
{
id = build_word_with_idx ( prefix , i ) ;
if ( id = = NULL )
{
obidebug ( 1 , " Error building an id for an automatic ID column " ) ;
return - 1 ;
}
if ( obi_set_str_with_elt_idx_and_col_p_in_view ( view , column , i , 0 , id ) < 0 )
2017-07-11 16:44:23 +02:00
{
obidebug ( 1 , " Error adding an automatic count column in a view " ) ;
return - 1 ;
}
2017-07-17 17:31:09 +02:00
free ( id ) ;
2017-07-11 16:44:23 +02:00
}
return 0 ;
}
// TODO Move to another file?
2016-11-18 15:59:50 +01:00
/*********** 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 ) ;
}
2016-04-13 15:10:24 +02:00
/*********** FOR BOOL COLUMNS ***********/
2016-08-02 16:33:19 +02:00
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 )
2016-04-13 15:10:24 +02:00
{
2016-08-02 16:33:19 +02:00
if ( prepare_to_set_value_in_column ( view , & column_p , & line_nb ) < 0 )
2016-04-13 15:10:24 +02:00
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_column_set_obibool_with_elt_idx ( column_p , line_nb , element_idx , value ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
obibool_t obi_get_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 )
2016-04-13 15:10:24 +02:00
{
2016-04-25 17:58:12 +02:00
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
2016-04-13 15:10:24 +02:00
return OBIBool_NA ;
2016-08-02 16:33:19 +02:00
return obi_column_get_obibool_with_elt_idx ( column_p , line_nb , element_idx ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
int obi_set_bool_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column_p , index_t line_nb , const char * element_name , obibool_t value )
2016-04-13 15:10:24 +02:00
{
2016-08-02 16:33:19 +02:00
index_t element_idx = obi_column_get_element_index_from_name ( column_p , element_name ) ;
2016-04-13 15:10:24 +02:00
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_set_bool_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
obibool_t obi_get_bool_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column_p , index_t line_nb , const char * element_name )
2016-04-13 15:10:24 +02:00
{
2016-08-02 16:33:19 +02:00
index_t element_idx = obi_column_get_element_index_from_name ( column_p , element_name ) ;
2016-04-13 15:10:24 +02:00
if ( element_idx = = OBIIdx_NA )
return OBIBool_NA ;
2016-08-02 16:33:19 +02:00
return obi_get_bool_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
int obi_set_bool_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , obibool_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_bool_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value ) ;
}
int obi_set_bool_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , obibool_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_bool_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
}
obibool_t obi_get_bool_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 OBIBool_NA ;
return obi_get_bool_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
obibool_t obi_get_bool_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 OBIBool_NA ;
return obi_get_bool_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name ) ;
2016-04-13 15:10:24 +02:00
}
/****************************************/
/*********** FOR CHAR COLUMNS ***********/
2016-08-02 16:33:19 +02:00
int obi_set_char_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , obichar_t value )
2016-04-13 15:10:24 +02:00
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_obichar_with_elt_idx ( column , line_nb , element_idx , value ) ;
}
2016-08-02 16:33:19 +02:00
obichar_t obi_get_char_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx )
2016-04-13 15:10:24 +02:00
{
2016-04-25 17:58:12 +02:00
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
2016-04-13 15:10:24 +02:00
return OBIChar_NA ;
return obi_column_get_obichar_with_elt_idx ( column , line_nb , element_idx ) ;
}
2016-08-02 16:33:19 +02:00
int obi_set_char_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , obichar_t value )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_set_char_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
obichar_t obi_get_char_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return OBIChar_NA ;
2016-08-02 16:33:19 +02:00
return obi_get_char_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx ) ;
}
int obi_set_char_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , obichar_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_char_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value ) ;
}
int obi_set_char_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , obichar_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_char_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
}
obichar_t obi_get_char_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 OBIChar_NA ;
return obi_get_char_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
obichar_t obi_get_char_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 OBIChar_NA ;
return obi_get_char_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name ) ;
2016-04-13 15:10:24 +02:00
}
/****************************************/
/*********** FOR FLOAT COLUMNS ***********/
2016-08-02 16:33:19 +02:00
int obi_set_float_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , obifloat_t value )
2016-04-13 15:10:24 +02:00
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_obifloat_with_elt_idx ( column , line_nb , element_idx , value ) ;
}
2016-08-02 16:33:19 +02:00
obifloat_t obi_get_float_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx )
2016-04-13 15:10:24 +02:00
{
2016-04-25 17:58:12 +02:00
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
2016-04-13 15:10:24 +02:00
return OBIFloat_NA ;
return obi_column_get_obifloat_with_elt_idx ( column , line_nb , element_idx ) ;
}
2016-08-02 16:33:19 +02:00
int obi_set_float_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , obifloat_t value )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_set_float_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
obifloat_t obi_get_float_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return OBIFloat_NA ;
2016-08-02 16:33:19 +02:00
return obi_get_float_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx ) ;
}
int obi_set_float_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , obifloat_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_float_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value ) ;
}
int obi_set_float_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , obifloat_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_float_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
}
obifloat_t obi_get_float_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 OBIFloat_NA ;
return obi_get_float_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
obifloat_t obi_get_float_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 OBIFloat_NA ;
return obi_get_float_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name ) ;
2016-04-13 15:10:24 +02:00
}
/****************************************/
/*********** FOR INT COLUMNS ***********/
2016-08-02 16:33:19 +02:00
int obi_set_int_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , obiint_t value )
2016-04-13 15:10:24 +02:00
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_obiint_with_elt_idx ( column , line_nb , element_idx , value ) ;
}
2016-08-02 16:33:19 +02:00
obiint_t obi_get_int_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx )
2016-04-13 15:10:24 +02:00
{
2016-04-25 17:58:12 +02:00
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
2016-04-13 15:10:24 +02:00
return OBIInt_NA ;
return obi_column_get_obiint_with_elt_idx ( column , line_nb , element_idx ) ;
}
2016-08-02 16:33:19 +02:00
int obi_set_int_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , obiint_t value )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_set_int_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
obiint_t obi_get_int_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return OBIInt_NA ;
2016-08-02 16:33:19 +02:00
return obi_get_int_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx ) ;
}
int obi_set_int_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , obiint_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_int_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value ) ;
}
int obi_set_int_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , obiint_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_int_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
}
obiint_t obi_get_int_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 OBIInt_NA ;
return obi_get_int_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
obiint_t obi_get_int_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 OBIInt_NA ;
return obi_get_int_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name ) ;
2016-04-13 15:10:24 +02:00
}
/****************************************/
2016-05-20 16:45:22 +02:00
/*********** FOR QUAL COLUMNS ***********/
2017-07-27 19:24:41 +02:00
int obi_set_qual_char_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , const char * value , int offset )
2016-05-20 16:45:22 +02:00
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
2017-07-27 19:24:41 +02:00
return obi_column_set_obiqual_char_with_elt_idx ( column , line_nb , element_idx , value , offset ) ;
2016-05-20 16:45:22 +02:00
}
2016-08-02 16:33:19 +02:00
int obi_set_qual_int_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , const uint8_t * value , int value_length )
2016-05-20 16:45:22 +02:00
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_obiqual_int_with_elt_idx ( column , line_nb , element_idx , value , value_length ) ;
}
2017-07-27 19:24:41 +02:00
char * obi_get_qual_char_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , int offset )
2016-05-20 16:45:22 +02:00
{
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
return OBIQual_char_NA ;
2017-07-27 19:24:41 +02:00
return obi_column_get_obiqual_char_with_elt_idx ( column , line_nb , element_idx , offset ) ;
2016-05-20 16:45:22 +02:00
}
2016-08-02 16:33:19 +02:00
const uint8_t * obi_get_qual_int_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , int * value_length )
2016-05-20 16:45:22 +02:00
{
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
return OBIQual_int_NA ;
return obi_column_get_obiqual_int_with_elt_idx ( column , line_nb , element_idx , value_length ) ;
}
2017-07-27 19:24:41 +02:00
int obi_set_qual_char_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , const char * value , int offset )
2016-05-20 16:45:22 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2017-07-27 19:24:41 +02:00
return obi_set_qual_char_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value , offset ) ;
2016-05-20 16:45:22 +02:00
}
2016-08-02 16:33:19 +02:00
int obi_set_qual_int_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , const uint8_t * value , int value_length )
2016-05-20 16:45:22 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_set_qual_int_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value , value_length ) ;
2016-05-20 16:45:22 +02:00
}
2017-07-27 19:24:41 +02:00
char * obi_get_qual_char_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , int offset )
2016-05-20 16:45:22 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return OBIQual_char_NA ;
2017-07-27 19:24:41 +02:00
return obi_get_qual_char_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , offset ) ;
2016-05-20 16:45:22 +02:00
}
2016-08-02 16:33:19 +02:00
const uint8_t * obi_get_qual_int_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , int * value_length )
2016-05-20 16:45:22 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return OBIQual_int_NA ;
2016-08-02 16:33:19 +02:00
return obi_get_qual_int_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value_length ) ;
}
2017-07-27 19:24:41 +02:00
int obi_set_qual_char_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , const char * value , int offset )
2016-08-02 16:33:19 +02:00
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
2017-07-27 19:24:41 +02:00
return obi_set_qual_char_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value , offset ) ;
2016-08-02 16:33:19 +02:00
}
2017-07-27 19:24:41 +02:00
int obi_set_qual_char_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , const char * value , int offset )
2016-08-02 16:33:19 +02:00
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
2017-07-27 19:24:41 +02:00
return obi_set_qual_char_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value , offset ) ;
2016-08-02 16:33:19 +02:00
}
2017-07-27 19:24:41 +02:00
char * obi_get_qual_char_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , int offset )
2016-08-02 16:33:19 +02:00
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return OBIQual_char_NA ;
2017-07-27 19:24:41 +02:00
return obi_get_qual_char_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , offset ) ;
2016-08-02 16:33:19 +02:00
}
2017-07-27 19:24:41 +02:00
char * obi_get_qual_char_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , int offset )
2016-08-02 16:33:19 +02:00
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return OBIQual_char_NA ;
2017-07-27 19:24:41 +02:00
return obi_get_qual_char_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , offset ) ;
2016-08-02 16:33:19 +02:00
}
int obi_set_qual_int_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , const uint8_t * value , int value_length )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_qual_int_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value , value_length ) ;
}
int obi_set_qual_int_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , const uint8_t * value , int value_length )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_qual_int_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value , value_length ) ;
}
const uint8_t * obi_get_qual_int_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , int * value_length )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return OBIQual_int_NA ;
return obi_get_qual_int_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value_length ) ;
}
const uint8_t * obi_get_qual_int_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , int * value_length )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return OBIQual_int_NA ;
return obi_get_qual_int_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value_length ) ;
2016-05-20 16:45:22 +02:00
}
/****************************************/
2016-04-13 15:10:24 +02:00
/*********** FOR SEQ COLUMNS ***********/
2016-08-02 16:33:19 +02:00
int obi_set_seq_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , const char * value )
2016-04-13 15:10:24 +02:00
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_obiseq_with_elt_idx ( column , line_nb , element_idx , value ) ;
}
2016-08-02 16:33:19 +02:00
char * obi_get_seq_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx )
2016-04-13 15:10:24 +02:00
{
2016-04-25 17:58:12 +02:00
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
2016-04-13 15:10:24 +02:00
return OBISeq_NA ;
return obi_column_get_obiseq_with_elt_idx ( column , line_nb , element_idx ) ;
}
2016-08-02 16:33:19 +02:00
int obi_set_seq_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , const char * value )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_set_seq_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
char * obi_get_seq_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return OBISeq_NA ;
2016-08-02 16:33:19 +02:00
return obi_get_seq_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx ) ;
}
int obi_set_seq_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , const char * value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_seq_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value ) ;
}
int obi_set_seq_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , const char * value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_seq_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
}
char * obi_get_seq_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 OBISeq_NA ;
return obi_get_seq_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
char * obi_get_seq_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 OBISeq_NA ;
return obi_get_seq_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name ) ;
2016-04-13 15:10:24 +02:00
}
/****************************************/
/*********** FOR STR COLUMNS ***********/
2016-08-02 16:33:19 +02:00
int obi_set_str_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , const char * value )
2016-04-13 15:10:24 +02:00
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_obistr_with_elt_idx ( column , line_nb , element_idx , value ) ;
}
2016-08-02 16:33:19 +02:00
const char * obi_get_str_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx )
2016-04-13 15:10:24 +02:00
{
2016-04-25 17:58:12 +02:00
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
2016-04-13 15:10:24 +02:00
return OBIStr_NA ;
return obi_column_get_obistr_with_elt_idx ( column , line_nb , element_idx ) ;
}
2016-08-02 16:33:19 +02:00
int obi_set_str_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , const char * value )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
2016-08-02 16:33:19 +02:00
return obi_set_str_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value ) ;
2016-04-13 15:10:24 +02:00
}
2016-08-02 16:33:19 +02:00
const char * obi_get_str_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name )
2016-04-13 15:10:24 +02:00
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return OBIStr_NA ;
2016-08-02 16:33:19 +02:00
return obi_get_str_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx ) ;
}
int obi_set_str_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , const char * value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_str_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value ) ;
}
int obi_set_str_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , const char * value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_str_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
}
const char * obi_get_str_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 OBIStr_NA ;
return obi_get_str_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
const char * obi_get_str_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 OBIStr_NA ;
return obi_get_str_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name ) ;
2016-04-13 15:10:24 +02:00
}
/****************************************/
2016-11-28 11:35:19 +01:00
/*********** FOR COLUMNS WITH INDEXED VALUES ***********/
2016-11-30 11:08:11 +01:00
int obi_set_index_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx , index_t value )
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_index_with_elt_idx ( column , line_nb , element_idx , value ) ;
}
2016-11-28 11:35:19 +01:00
index_t obi_get_index_with_elt_idx_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , index_t element_idx )
{
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
return OBIIdx_NA ;
return obi_column_get_index_with_elt_idx ( column , line_nb , element_idx ) ;
}
2016-11-30 11:08:11 +01:00
int obi_set_index_with_elt_name_and_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const char * element_name , index_t value )
{
index_t element_idx = obi_column_get_element_index_from_name ( column , element_name ) ;
if ( element_idx = = OBIIdx_NA )
return - 1 ;
return obi_set_index_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx , value ) ;
}
2016-11-28 11:35:19 +01:00
index_t obi_get_index_with_elt_name_and_col_p_in_view ( Obiview_p view , 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 OBIIdx_NA ;
return obi_get_index_with_elt_idx_and_col_p_in_view ( view , column , line_nb , element_idx ) ;
}
2016-11-30 11:08:11 +01:00
int obi_set_index_with_elt_name_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const char * element_name , index_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_index_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name , value ) ;
}
int obi_set_index_with_elt_idx_and_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , index_t element_idx , index_t value )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_index_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx , value ) ;
}
2016-11-28 11:35:19 +01:00
index_t obi_get_index_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 OBIIdx_NA ;
return obi_get_index_with_elt_idx_and_col_p_in_view ( view , column_p , line_nb , element_idx ) ;
}
index_t obi_get_index_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 OBIIdx_NA ;
return obi_get_index_with_elt_name_and_col_p_in_view ( view , column_p , line_nb , element_name ) ;
}
/****************************************/
2017-11-15 13:48:59 +01:00
/*********** FOR ARRAY COLUMNS ***********/
int obi_set_array_with_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , const void * value , uint8_t elt_size , int32_t value_length )
{
if ( prepare_to_set_value_in_column ( view , & column , & line_nb ) < 0 )
return - 1 ;
return obi_column_set_array ( column , line_nb , value , elt_size , value_length ) ;
}
const void * obi_get_array_with_col_p_in_view ( Obiview_p view , OBIDMS_column_p column , index_t line_nb , int32_t * value_length_p )
{
if ( prepare_to_get_value_from_column ( view , & line_nb ) < 0 )
return OBITuple_NA ;
return obi_column_get_array ( column , line_nb , value_length_p ) ;
}
int obi_set_array_with_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , const void * value , uint8_t elt_size , int32_t value_length )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return - 1 ;
return obi_set_array_with_col_p_in_view ( view , column_p , line_nb , value , elt_size , value_length ) ;
}
const void * obi_get_array_with_col_name_in_view ( Obiview_p view , const char * column_name , index_t line_nb , int32_t * value_length_p )
{
OBIDMS_column_p column_p ;
column_p = obi_view_get_column ( view , column_name ) ;
if ( column_p = = NULL )
return OBITuple_NA ;
return obi_get_array_with_col_p_in_view ( view , column_p , line_nb , value_length_p ) ;
}
/****************************************/