Reorganized the code to have less functions, and the functions to get
and format the creation date of a column are now working.
This commit is contained in:
@ -1317,31 +1317,7 @@ void obi_ini_to_NA_values(OBIDMS_column_p column,
|
||||
}
|
||||
|
||||
|
||||
void obi_column_make_unwritable(OBIDMS_column_p column) // TODO this might be irrelevant
|
||||
{
|
||||
column->writable = false;
|
||||
}
|
||||
|
||||
|
||||
size_t obi_column_get_line_count(OBIDMS_column_p column)
|
||||
{
|
||||
return (column->header)->line_count;
|
||||
}
|
||||
|
||||
|
||||
size_t obi_column_get_nb_lines_used(OBIDMS_column_p column)
|
||||
{
|
||||
return (column->header)->lines_used;
|
||||
}
|
||||
|
||||
|
||||
OBIType_t obi_column_get_data_type(OBIDMS_column_p column)
|
||||
{
|
||||
return (column->header)->data_type;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char* column_name)
|
||||
OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char* column_name) // ADD VERSION ARGUMENT
|
||||
{
|
||||
OBIDMS_column_header_p header;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
@ -1436,12 +1412,6 @@ int obi_unmap_header(OBIDMS_column_header_p header)
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_elements_names(OBIDMS_column_p column)
|
||||
{
|
||||
return (column->header)->elements_names;
|
||||
}
|
||||
|
||||
|
||||
// TODO to be rewritten in an optimized and safe way
|
||||
size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name)
|
||||
{
|
||||
@ -1483,146 +1453,28 @@ size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char
|
||||
}
|
||||
|
||||
|
||||
size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column)
|
||||
{
|
||||
// TODO check that column is not NULL?
|
||||
return (column->header)->nb_elements_per_line;
|
||||
}
|
||||
|
||||
|
||||
char* obi_column_get_formatted_creation_date(OBIDMS_column_p column) // TODO
|
||||
char* obi_column_format_date(time_t date)
|
||||
{
|
||||
char* formatted_time;
|
||||
struct tm* tmp;
|
||||
|
||||
formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char));
|
||||
|
||||
tmp = localtime(&((column->header)->creation_date));
|
||||
tmp = localtime(&date);
|
||||
if (tmp == NULL)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError formatting the creation date of a column");
|
||||
obidebug(1, "\nError formatting a date");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strftime(formatted_time, FORMATTED_TIME_LENGTH, "%c", tmp) == 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError formatting the creation date of a column");
|
||||
obidebug(1, "\nError formatting a date");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return formatted_time;
|
||||
}
|
||||
|
||||
|
||||
char* obi_column_get_formatted_creation_date_from_name(OBIDMS_p dms, const char* column_name) // TODO
|
||||
{
|
||||
OBIDMS_column_header_p header;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
int column_dir_file_descriptor;
|
||||
size_t header_size;
|
||||
obiversion_t version_number;
|
||||
char* formatted_time;
|
||||
struct tm* tmp;
|
||||
|
||||
// Get the column directory structure associated to the column
|
||||
column_directory = obi_open_column_directory(dms, column_name);
|
||||
if (column_directory == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening a column directory structure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the file descriptor associated to the column directory
|
||||
column_dir_file_descriptor = dirfd(column_directory->directory);
|
||||
if (column_dir_file_descriptor < 0)
|
||||
{
|
||||
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError getting the file descriptor of a column directory");
|
||||
obi_close_column_directory(column_directory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Calculate the header size
|
||||
header_size = obi_get_platform_header_size();
|
||||
|
||||
// Get the latest version number
|
||||
version_number = obi_get_latest_version_number(column_directory);
|
||||
if (version_number < 0)
|
||||
{
|
||||
obidebug(1, "\nError getting the latest version number in a column directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the column file name
|
||||
column_file_name = build_column_file_name(column_name, version_number);
|
||||
if (column_file_name == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open the column file (READ-ONLY)
|
||||
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDONLY);
|
||||
if (column_file_descriptor < 0)
|
||||
{
|
||||
obidebug(1, "\nError opening a column file");
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
free(column_file_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Fill the header structure
|
||||
header = mmap(NULL,
|
||||
header_size,
|
||||
PROT_READ,
|
||||
MAP_SHARED,
|
||||
column_file_descriptor,
|
||||
0
|
||||
);
|
||||
|
||||
if (header == MAP_FAILED)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError mmapping the header of a column");
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO Check endianness?
|
||||
|
||||
// Format time
|
||||
formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char));
|
||||
tmp = localtime(&(header->creation_date));
|
||||
if (tmp == NULL)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError formatting the creation date of a column");
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
return NULL;
|
||||
}
|
||||
if (strftime(formatted_time, FORMATTED_TIME_LENGTH, "%c", tmp) == 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError formatting the creation date of a column");
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Munmap header
|
||||
if (munmap(header, header->header_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping header after getting the creation date of a column");
|
||||
}
|
||||
|
||||
free(column_file_name);
|
||||
close(column_file_descriptor);
|
||||
|
||||
return formatted_time;
|
||||
}
|
||||
|
@ -283,56 +283,6 @@ int obi_truncate_and_close_column(OBIDMS_column_p column);
|
||||
void obi_ini_to_NA_values(OBIDMS_column_p column, size_t first_line_nb, size_t nb_lines); // TO make private?
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the 'writable' header attribute of an OBIDMS column to False. // TODO delete?
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
void obi_column_make_unwritable(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the line count of an OBIDMS column.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @returns The line count of the column.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
size_t obi_column_get_line_count(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the number of lines used in an OBIDMS column.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @returns The number of lines used in the column.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
size_t obi_column_get_nb_lines_used(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the data type of an OBIDMS column.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @returns The data type of the column.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIType_t obi_column_get_data_type(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the header of an OBIDMS column from the column name.
|
||||
*
|
||||
@ -364,19 +314,6 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
|
||||
int obi_unmap_header(OBIDMS_column_header_p header);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the elements names of an OBIDMS column.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @returns The elements names.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_column_get_elements_names(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the index of an element in an OBIDMS column from the element's name.
|
||||
*
|
||||
@ -393,43 +330,16 @@ size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the number of elements per line in an OBIDMS column.
|
||||
* @brief Formats a date in a way that is easy to read.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
* @param date A date.
|
||||
*
|
||||
* @returns The number of elements per line.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the creation date of an OBIDMS column.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @returns The creation date of the column.
|
||||
* @returns The date formatted in a way that is easy to read.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
char* obi_column_get_formatted_creation_date(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the creation date of an OBIDMS column from the column name.
|
||||
*
|
||||
* @param dms A pointer on an OBIDMS.
|
||||
* @param column_name The name of an OBIDMS column.
|
||||
*
|
||||
* @returns The creation date of the column.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
char* obi_column_get_get_formatted_creation_date_from_name(OBIDMS_p dms, const char* column_name);
|
||||
char* obi_column_format_date(time_t date);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_H_ */
|
||||
|
Reference in New Issue
Block a user