Commit 5f62cd85 by celinemercier

C sources modified to add the handling of OBIDM columns with the type

OBI_INT, and the handling of multiple types in general
parent a6abc745
......@@ -14,6 +14,10 @@
#include "obidms.h"
#include "obierrno.h"
#include "obidebug.h"
#include "obidmscolumn.h"
#define DEBUG_LEVEL 0
/**************************************************************************
......@@ -148,6 +152,7 @@ OBIDMS_p obi_open_dms(const char* dms_name)
directory = opendir(directory_name);
if (directory == NULL)
{
obidebug(1, "Can't open DMS");
switch (errno)
{
case ENOENT:
......@@ -206,6 +211,49 @@ OBIDMS_p obi_dms(const char* dms_name)
}
int obi_list_columns(OBIDMS_p dms)
{
DIR *d;
struct dirent *dir;
char* dir_name;
char* extension;
OBIType_t data_type;
obiversion_t latest_version;
d = dms->directory;
dir = readdir(d);
fprintf(stderr, "Column name\tData type\tLatest version");
while (dir != NULL)
{
dir_name = strdup(dir->d_name);
if (dir_name == NULL)
{
obidebug(1, "\nError strdup-ing a directory name");
return -1;
}
dir_name = strtok(dir_name, ".");
extension = strtok(NULL, ".");
if ((extension != NULL) && (strcmp("obicol", extension) == 0))
// Found a column directory
{
data_type = obi_column_get_data_type_from_name(dms, dir_name);
latest_version = obi_column_get_latest_version_from_name(dms, dir_name);
fprintf(stderr, "\n%s\t%d\t%d", dir_name, data_type, latest_version);
}
dir = readdir(d);
}
rewinddir(d);
return(0);
}
int obi_close_dms(OBIDMS_p dms)
{
if (dms != NULL)
......
......@@ -127,6 +127,23 @@ OBIDMS_p obi_dms(const char *dms_name);
/**
* @brief Lists all the column directories in the OBIDMS, their data type and
* their latest version.
*
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms().
*
* @return an integer value indicating the success of the operation.
*
* @retvalue 0 on success
* @retvalue -1 on failure and the `obi_errno` variable is set.
*
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_list_columns(OBIDMS_p dms);
/**
* @brief Closes an opened OBITools Data Management instance (OBIDMS).
*
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
......
......@@ -87,6 +87,28 @@ typedef struct OBIDMS_column {
/**
* @brief Returns the latest version of a column in a column directory
*
* @param column_directory
*
* @return the latest version number kept in the version file
* @return -1 if an error occurred
*/
obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_directory);
/**
* @brief Returns the latest version of a column in a column directory
*
* @param column_name
*
* @return the latest version number kept in the version file
* @return -1 if an error occurred
*/
obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms, const char* column_name);
/**
* @brief Returns the header size in bytes of a column on this platform.
*
* The header size is defined as a multiple of the memory page size.
......@@ -103,7 +125,7 @@ size_t obi_get_platform_header_size();
/**
* @brief Creates a column.
*
* @param dms a pointer on an OBIDMS column
* @param dms a pointer on an OBIDMS
* @param column_name the name of the new column
* @param type the OBIType code used to create the column
* @param nb_elements the number of elements to be stored
......@@ -120,15 +142,123 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
/**
* @brief Returns the latest column version in the `dms` database
* @brief Opens a column in read-only mode.
*
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
* @param dms a pointer on an OBIDMS
* @param column_name the name of the column
* @param version_number the version of the column that should be opened
*
* @return a pointer to the opened column
*
* @return the bigger version number used for this column
* @return -1 if the column does not exist
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_directory);
OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversion_t version_number);
/**
* @brief Closes a column.
*
* @param column a pointer on an OBIDMS column
*
* @return 0 if the operation was successfully completed
* @return -1 if an error occurred
*
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_close_column(OBIDMS_column_p column);
/**
* @brief Sets the 'writable' header attribute of an OBIDMS column to False.
*
* @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
*
* @return 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 data type of an OBIDMS column.
*
* @param column a pointer on an OBIDMS column
*
* @return 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 data type of an OBIDMS column from the column name.
*
* @param dms a pointer on an OBIDMS
* @param column_name the name of an OBIDMS column
*
* @return the data type of the column
*
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms, const char* column_name);
/**
* @brief Recovers the elements names of an OBIDMS column.
*
* @param column a pointer on an OBIDMS column
*
* @return 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 its name.
*
* @param column a pointer on an OBIDMS column
* @param element_name the name of the element
*
* @return the index of the element in a line of the column
*
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name);
/**
* @brief Recovers the number of elements per line in an OBIDMS column.
*
* @param column a pointer on an OBIDMS column
*
* @return 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);
#endif /* OBIDMSCOLUMN_H_ */
/****************************************************************************
* OBIDMS_column_int functions *
****************************************************************************/
/**
* @file obidsmcolumn_int.c
* @author Celine Mercier
* @date July 21st 2015
* @brief Functions handling OBIColumns containing data with the OBIType OBI_INT.
*/
#include <stdlib.h>
#include <stdio.h>
#include "obidmscolumn.h"
#include "obitypes.h"
#include "obierrno.h"
#include "obidebug.h"
/**********************************************************************
*
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
*
**********************************************************************/
int obi_column_set_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value)
{
// check if can write?
size_t nb_elements_per_line = -1;
nb_elements_per_line = (column->header)->nb_elements_per_line;
*(((obiint_t*) (column->data)) + (line_nb * nb_elements_per_line) + element_idx) = value;
return 0;
}
obiint_t obi_column_get_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
{
size_t nb_elements_per_line = -1;
nb_elements_per_line = (column->header)->nb_elements_per_line;
return *(((obiint_t*) (column->data)) + (line_nb * nb_elements_per_line) + element_idx);
}
//obiint_t* obi_column_get_line_address_int(OBIDMS_column_p column, size_t nb_elements_per_line, size_t line_nb)
//{
// return (((obiint_t*) (column->data)) + (line_nb * nb_elements_per_line));
//}
/****************************************************************************
* OBIDMS_column_int header file *
****************************************************************************/
/**
* @file obidsmcolumn_int.h
* @author Celine Mercier
* @date July 21st 2015
* @brief Header file for the functions handling OBIColumns containing data with the OBIType OBI_INT.
*/
#include <stdlib.h>
#include <stdio.h>
#include "obidmscolumn.h"
#include "obitypes.h"
/**
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT.
*
* @param column a pointer as returned by obi_create_column()
* @warning Pointers returned by obi_open_column() don't allow writing.
*
* @param line_nb the number of the line where the value should be set
*
* @param element_idx the index of the element that should be set in the line
*
* @param value the value that should be set
*
* @return an integer value indicating the success of the operation.
*
* @retvalue 0 on success
* @retvalue -1 on failure and the `obi_errno` variable is set.
*
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_column_set_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value);
/**
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT.
*
* @param column a pointer as returned by obi_create_column()
*
* @param line_nb the number of the line where the value should be recovered
*
* @param element_idx the index of the element that should be recovered in the line
*
* @return the recovered value
*
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
obiint_t obi_column_get_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment