Compare commits
21 Commits
cython_thi
...
cython_bug
Author | SHA1 | Date | |
---|---|---|---|
9b066f4327 | |||
456551ffeb | |||
ecb9d97adb | |||
0eaa5aa784 | |||
21923e213d | |||
6877fc4892 | |||
dbed3d9d1d | |||
fc8bf16769 | |||
e114a3c9cb | |||
ebc9f6f512 | |||
2b3f03ec28 | |||
8fd9c06be2 | |||
b553eef781 | |||
ee4c513fd4 | |||
c013e6ad33 | |||
c98d567e2f | |||
392f110c8d | |||
6ced3c4896 | |||
4b8bf41a71 | |||
c59a244e9d | |||
4b7f2d268b |
2
doc/.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
/build/
|
||||
/doxygen/
|
||||
/build_dir.txt
|
||||
/.DS_Store
|
||||
/.gitignore
|
||||
|
@ -57,7 +57,7 @@ html:
|
||||
@echo "Generating Doxygen documentation..."
|
||||
doxygen Doxyfile
|
||||
@echo "Doxygen documentation generated. \n"
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
$(SPHINXBUILD) -b html -c ./ $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
|
@ -36,7 +36,7 @@ extensions = [
|
||||
'sphinx.ext.pngmath',
|
||||
'sphinx.ext.ifconfig',
|
||||
'sphinx.ext.viewcode',
|
||||
'breathe',
|
||||
# 'breathe',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
@ -51,7 +51,7 @@ source_suffix = '.rst'
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
master_doc = 'source/index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'OBITools3'
|
||||
@ -292,7 +292,7 @@ texinfo_documents = [
|
||||
#texinfo_no_detailmenu = False
|
||||
|
||||
#Breathe configuration
|
||||
sys.path.append( "../breathe/" )
|
||||
breathe_projects = { "OBITools3": "../doxygen/xml/" }
|
||||
sys.path.append( "breathe/" )
|
||||
breathe_projects = { "OBITools3": "doxygen/xml/" }
|
||||
breathe_default_project = "OBITools3"
|
||||
|
4
doc/doxygen/xml/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
@ -13,7 +13,7 @@ Up to now, each of these categories of data were stored in separate
|
||||
files, and nothing made it mandatory to keep them together.
|
||||
|
||||
|
||||
The `Data Management System` (DMS) of OBITools3 can be regarded as a basic
|
||||
The `Data Management System` (DMS) of OBITools3 can be viewed like a basic
|
||||
database system.
|
||||
|
||||
|
||||
@ -27,9 +27,7 @@ OBIDMS UML
|
||||
|
||||
An OBIDMS directory contains :
|
||||
* one `OBIDMS history file <#obidms-history-files>`_
|
||||
* Two different kinds of directories :
|
||||
* OBIDMS column directories
|
||||
* OBIDMS column group directories containing OBIDMS column directories
|
||||
* OBIDMS column directories
|
||||
|
||||
|
||||
OBIDMS column directories
|
||||
@ -39,16 +37,9 @@ OBIDMS column directories contain :
|
||||
* all the different versions of one OBIDMS column, under the form of different files (`OBIDMS column files <#obidms-column-files>`_)
|
||||
* one `OBIDMS version file <#obidms-version-files>`_
|
||||
|
||||
The directory name is the column attribute, or sub-attribute if the column directory is in a column group directory.
|
||||
The directory name is the column attribute with the extension ``.obicol``.
|
||||
|
||||
|
||||
OBIDMS column group directories
|
||||
===============================
|
||||
|
||||
OBIDMS column group directories contain OBIDMS column directories. They are used to store dictionary-like data, where
|
||||
each key corresponds to an OBIDMS column.
|
||||
|
||||
The directory name is the dictionary attribute. Each key is considered a sub-attribute and is associated to its column.
|
||||
Example: ``count.obicol``
|
||||
|
||||
|
||||
OBIDMS column files
|
||||
@ -57,7 +48,7 @@ OBIDMS column files
|
||||
Each OBIDMS column file contains :
|
||||
* a header of a size equal to a multiple of PAGESIZE (PAGESIZE being equal to 4096 bytes
|
||||
on most systems) containing metadata
|
||||
* one column of data with the same `OBIType <types.html#obitypes>`_
|
||||
* Lines of data with the same `OBIType <types.html#obitypes>`_
|
||||
|
||||
|
||||
Header
|
||||
@ -79,7 +70,14 @@ The header of an OBIDMS column contains :
|
||||
Data
|
||||
----
|
||||
|
||||
A column of data with the same `OBIType <types.html#obitypes>`_.
|
||||
A line of data corresponds to a vector of elements. Each element is associated with an element name.
|
||||
Elements names are stored in the header. The correspondance between an element and its name is done
|
||||
using their order in the lists of elements and elements names. This structure allows the storage of
|
||||
dictionary-like data.
|
||||
|
||||
Example: In the header, the attribute ``elements_names`` will be associated with the value ``"sample_1;
|
||||
sample_2;sample_3"``, and a line of data with the type ``OBInt_t`` will be stored as an ``OBInt_t`` vector
|
||||
of size three e.g. ``5|8|4``.
|
||||
|
||||
|
||||
Mandatory columns
|
||||
@ -158,3 +156,5 @@ operations ever done in the OBIDMS directory and the views in between them :
|
||||
.. image:: ./images/history.png
|
||||
:width: 150 px
|
||||
:align: center
|
||||
|
||||
|
BIN
doc/source/UML/OBIDMS_UML.png
Normal file
After Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
1874
doc/source/UML/ObiDMS_UML.class.violet.html
Normal file
@ -2,8 +2,8 @@
|
||||
Data in OBITools3
|
||||
#################
|
||||
|
||||
The OBITools3 inaugure a new way to manage DNA metabarcoding data.
|
||||
They rely on a `Data management System` (DMS) that can be considered as
|
||||
The OBITools3 introduce a new way to manage DNA metabarcoding data.
|
||||
They rely on a `Data management System` (DMS) that can be viewed like
|
||||
a simplified database system.
|
||||
|
||||
|
@ -70,7 +70,7 @@ Tickets should always be labeled with the branches for which they are relevant.
|
||||
Documentation
|
||||
*************
|
||||
|
||||
C functions are documented in the header files.
|
||||
C functions are documented in the header files for public functions, and in the source file for private functions.
|
||||
|
||||
|
||||
**************
|
||||
@ -92,7 +92,7 @@ C99 :
|
||||
* Object layer
|
||||
* OBITools3 library
|
||||
|
||||
`Python 3 <https://www.python.org/>`_ :
|
||||
`Python 3.5 <https://www.python.org/>`_ :
|
||||
* Top layer code (scripts)
|
||||
|
||||
For the documentation, `Sphinx <http://sphinx-doc.org/>`_ should be used for both the original
|
||||
@ -111,6 +111,8 @@ Enum members, macros, constants: ``ALL_CAPS``
|
||||
|
||||
Functions, local variables: ``lower_case``
|
||||
|
||||
Public functions: ``obi_lower_case``
|
||||
|
||||
Functions that shouldn't be called directly: ``_lower_case`` (``_`` prefix)
|
||||
|
||||
Global variables: ``g_lower_case`` (``g_`` prefix)
|
||||
@ -120,9 +122,6 @@ Pointers: ``pointer_ptr`` (``_ptr`` suffi
|
||||
.. note::
|
||||
Underscores are used to delimit 'words'.
|
||||
|
||||
.. todo::
|
||||
``obi_function`` for public functions names?
|
||||
|
||||
|
||||
*****************
|
||||
Programming rules
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
@ -11,7 +11,6 @@ OBITools3 documentation
|
||||
|
||||
Programming guidelines <guidelines>
|
||||
Data structures <data>
|
||||
Pistes de reflexion <pistes>
|
||||
|
||||
|
||||
Indices and tables
|
@ -7,13 +7,16 @@ NA values
|
||||
=========
|
||||
|
||||
All OBITypes have an associated NA (Not Available) value.
|
||||
NA values are implemented by specifying an explicit NA value for each type, corresponding to the R standards:
|
||||
NA values are implemented by specifying an explicit NA value for each type,
|
||||
corresponding to the R standards as much as possible:
|
||||
|
||||
* For the types ``OBIInt_t``, ``OBIBool_t``, ``OBIIdx_t`` and ``OBITaxid_t``, the NA value is ``INT_MIN``.
|
||||
* For the type ``OBIInt_t``, the NA value is ``INT_MIN``.
|
||||
|
||||
* For the type ``OBIChar_t``: the NA value is ``\0`` (?).
|
||||
* For the type ``OBIBool_t``, the NA value is ``2``.
|
||||
|
||||
* For the type ``OBIStr_t`` : the NA value is ``\0`` (?).
|
||||
* For the type ``OBIIdx_t`` and ``OBITaxid_t``, the NA value is ``SIZE_MAX``.
|
||||
|
||||
* For the type ``OBIChar_t``: the NA value is ``\0``.
|
||||
|
||||
* For the type ``OBIFloat_t``::
|
||||
|
||||
@ -29,7 +32,7 @@ NA values are implemented by specifying an explicit NA value for each type, corr
|
||||
x.word[hw] = 0x7ff00000;
|
||||
x.word[lw] = 1954;
|
||||
return x.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Minimum and maximum values for ``OBIInt_t``
|
@ -7,11 +7,14 @@ OBITypes
|
||||
:download:`html version of the OBITypes UML file <UML/OBITypes_UML.class.violet.html>`
|
||||
|
||||
|
||||
.. image:: ./UML/Obicolumn_classes_UML.png
|
||||
|
||||
:download:`html version of the OBIDMS classes UML file <UML/Obicolumn_classes_UML.class.violet.html>`
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
The elementary types <elementary>
|
||||
The containers <containers>
|
||||
Special values <specialvalues>
|
||||
|
||||
|
1
doc/sphinx/build_dir.txt
Normal file
@ -0,0 +1 @@
|
||||
build/lib.macosx-10.6-intel-3.5
|
Before Width: | Height: | Size: 66 KiB |
@ -1,23 +0,0 @@
|
||||
###################
|
||||
Pistes de reflexion
|
||||
###################
|
||||
|
||||
|
||||
******************************
|
||||
Ce que l'on veut pouvoir faire
|
||||
******************************
|
||||
|
||||
* Gerer les valeurs manquantes
|
||||
* Modifier une colonne en cours d'ecriture (mmap)
|
||||
* Ajouter des valeurs a la fin du fichier d'une colonne en cours d'ecriture (mmap)
|
||||
|
||||
|
||||
******
|
||||
Divers
|
||||
******
|
||||
|
||||
* Si l'ordre d'une colonne est change, elle est reecrite (pas d'index).
|
||||
* Utilisation de semaphores pour la lecture
|
||||
* Utilisation de tas pour l'indexation des chaines de caracteres. Chaque colonne dont
|
||||
le type est OBIStr_t est stockee dans 3 fichiers : un fichier contenant les chaines, un
|
||||
fichier contenant les index, et un fichier contenant le tas.
|
@ -1,31 +0,0 @@
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
from obitools3.obidms.obidmscolumn.capidmscolumn import OBIDMS_column
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
parser = argparse.ArgumentParser(description='Computes the sum of a column.')
|
||||
|
||||
parser.add_argument('-d', '--dms', dest='dms_name', type=str,
|
||||
help='Name of the OBIDMS containing the column')
|
||||
parser.add_argument('-c', '--column', dest='column_name', type=str, default='count',
|
||||
help="Name of the OBIDMS column (default: 'count')")
|
||||
parser.add_argument('-v', '--version', dest='version_number', type=int, default=-1,
|
||||
help='Version number of the column (default: latest version)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
c = OBIDMS_column.open(args.dms_name, args.column_name, version_number=args.version_number)
|
||||
|
||||
# check that 1 element / line and summable type?
|
||||
|
||||
total = 0
|
||||
|
||||
for count in c :
|
||||
total+=count
|
||||
|
||||
print("Total count = ", total)
|
||||
|
@ -12,3 +12,5 @@
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiarray.h
|
||||
../../../src/obiarray.c
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
from .capi.obidms cimport OBIDMS_p
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
from .capi.obitypes cimport obiversion_t, OBIType_t
|
||||
from .capi.obitypes cimport obiversion_t, OBIType_t, index_t
|
||||
|
||||
|
||||
cdef class OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS:
|
||||
|
||||
@ -12,27 +14,34 @@ cdef class OBIDMS:
|
||||
cdef str dms_name
|
||||
|
||||
cpdef dict list(self)
|
||||
|
||||
cpdef close(self)
|
||||
cpdef OBIDMS_column open_column(self,
|
||||
str column_name,
|
||||
bint create=*,
|
||||
bint clone=*, bint clone_data=*,
|
||||
obiversion_t version_number=*,
|
||||
OBIType_t data_type=*,
|
||||
size_t nb_lines=*,
|
||||
size_t nb_elements_per_line=*,
|
||||
str elements_names=*)
|
||||
index_t nb_lines=*,
|
||||
index_t nb_elements_per_line=*,
|
||||
list elements_names=*,
|
||||
str array_name=*)
|
||||
|
||||
|
||||
cdef class OBIDMS_column:
|
||||
|
||||
cdef OBIDMS_column_p pointer
|
||||
cdef OBIDMS dms
|
||||
cdef str data_type # TODO keep as OBIType_t? both?
|
||||
cdef str dms_name
|
||||
cdef str column_name
|
||||
cdef OBIDMS_column_p pointer
|
||||
cdef OBIDMS dms
|
||||
cdef str data_type # TODO keep as OBIType_t? both?
|
||||
cdef str dms_name
|
||||
cdef str column_name
|
||||
cdef index_t nb_elements_per_line
|
||||
cdef list elements_names
|
||||
|
||||
# cpdef object get_item(self, index_t line_nb, str element_name) TODO can't declare because not the same in all subclasses
|
||||
# cpdef set_item(self, index_t line_nb, str element_name, object value) TODO can't declare because object value
|
||||
cpdef list get_elements_names(self)
|
||||
cpdef str get_data_type(self)
|
||||
cpdef index_t get_nb_lines_used(self)
|
||||
cpdef str get_creation_date(self)
|
||||
cpdef close(self)
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name)
|
||||
cpdef list get_elements_names(self)
|
||||
cpdef str get_data_type(self)
|
||||
cpdef size_t get_nb_lines_used(self)
|
||||
|
@ -4,36 +4,48 @@ from pathlib import Path
|
||||
|
||||
from obitools3.utils cimport bytes2str, str2bytes
|
||||
|
||||
from .capi.obidms cimport obi_dms
|
||||
from .capi.obidmscolumn cimport obi_column_get_data_type_from_name, \
|
||||
from .capi.obidms cimport obi_dms, \
|
||||
obi_close_dms
|
||||
from .capi.obidmscolumn cimport obi_column_get_header_from_name, \
|
||||
obi_unmap_header, \
|
||||
obi_column_get_latest_version_from_name, \
|
||||
obi_column_get_line_count_from_name, \
|
||||
obi_column_get_nb_lines_used, \
|
||||
obi_column_get_elements_names, \
|
||||
obi_create_column, \
|
||||
obi_clone_column, \
|
||||
obi_open_column, \
|
||||
obi_close_column
|
||||
from .capi.obitypes cimport const_char_p, name_data_type
|
||||
|
||||
obi_close_column, \
|
||||
obi_column_format_date, \
|
||||
OBIDMS_column_header_p
|
||||
from .capi.obitypes cimport const_char_p, \
|
||||
name_data_type
|
||||
|
||||
|
||||
from ._obidms cimport OBIDMS
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
from ._obidmscolumn_int cimport OBIDMS_column_int, \
|
||||
OBIDMS_column_int_writable
|
||||
|
||||
OBIDMS_column_int_writable, \
|
||||
OBIDMS_column_int_multi_elts, \
|
||||
OBIDMS_column_int_multi_elts_writable
|
||||
|
||||
from ._obidmscolumn_float cimport OBIDMS_column_float, \
|
||||
OBIDMS_column_float_writable
|
||||
OBIDMS_column_float_writable, \
|
||||
OBIDMS_column_float_multi_elts, \
|
||||
OBIDMS_column_float_multi_elts_writable
|
||||
|
||||
from ._obidmscolumn_bool cimport OBIDMS_column_bool, \
|
||||
OBIDMS_column_bool_writable
|
||||
OBIDMS_column_bool_writable, \
|
||||
OBIDMS_column_bool_multi_elts, \
|
||||
OBIDMS_column_bool_multi_elts_writable
|
||||
|
||||
from ._obidmscolumn_char cimport OBIDMS_column_char, \
|
||||
OBIDMS_column_char_writable
|
||||
OBIDMS_column_char_writable, \
|
||||
OBIDMS_column_char_multi_elts, \
|
||||
OBIDMS_column_char_multi_elts_writable
|
||||
|
||||
from ._obidmscolumn_idx cimport OBIDMS_column_idx, \
|
||||
OBIDMS_column_idx_writable
|
||||
from ._obidmscolumn_str cimport OBIDMS_column_str, \
|
||||
OBIDMS_column_str_writable, \
|
||||
OBIDMS_column_str_multi_elts, \
|
||||
OBIDMS_column_str_multi_elts_writable
|
||||
|
||||
|
||||
cdef class OBIDMS :
|
||||
@ -49,10 +61,13 @@ cdef class OBIDMS :
|
||||
# Fill structure and create or open the DMS
|
||||
self.dms_name = dms_name
|
||||
self.pointer = obi_dms(<const_char_p> dms_name_b)
|
||||
# TODO: test pointer and raise Exception("Failed opening or creating an OBIDMS")
|
||||
|
||||
|
||||
# def __del__(self) : # TODO problem with closing dir breaking everything
|
||||
# obi_close_dms(self.pointer)
|
||||
cpdef close(self) :
|
||||
#TODO close all columns
|
||||
if (obi_close_dms(self.pointer)) < 0 :
|
||||
raise Exception("Problem closing an OBIDMS")
|
||||
|
||||
|
||||
cpdef dict list(self):
|
||||
@ -63,125 +78,151 @@ cdef class OBIDMS :
|
||||
cdef str column_name
|
||||
cdef bytes column_name_b
|
||||
cdef str data_type
|
||||
cdef str creation_date
|
||||
cdef obiversion_t latest_version
|
||||
cdef size_t line_count
|
||||
cdef index_t line_count
|
||||
cdef OBIDMS_column_header_p header
|
||||
|
||||
p = Path(self.dms_name+'.obidms')
|
||||
|
||||
print("{:<25} {:<25} {:<25} {:<25}".format('-Column name-','-Data type-','-Latest version number-', '-Line count of latest version-'))
|
||||
print("{:<30} {:<12} {:<25} {:<30} {:<40}".format('-Column name-',
|
||||
'-Data type-',
|
||||
'-Latest version number-',
|
||||
'-Line count of latest version-',
|
||||
'-Creation date of latest version-'))
|
||||
for entry in p.iterdir():
|
||||
if entry.suffix == ".obicol":
|
||||
column_name = entry.stem
|
||||
column_name_b = str2bytes(column_name)
|
||||
dms[column_name] = {}
|
||||
data_type = bytes2str(name_data_type(obi_column_get_data_type_from_name(self.pointer, column_name_b)))
|
||||
header = obi_column_get_header_from_name(self.pointer, column_name_b)
|
||||
data_type = bytes2str(name_data_type(header.data_type))
|
||||
line_count = header.line_count
|
||||
creation_date = bytes2str(obi_column_format_date(header.creation_date))
|
||||
obi_unmap_header(header) # TODO check if error? but C will already warn and there's nothing to do
|
||||
latest_version = obi_column_get_latest_version_from_name(self.pointer, column_name_b)
|
||||
line_count = obi_column_get_line_count_from_name(self.pointer, column_name_b)
|
||||
dms[column_name]['data_type'] = data_type
|
||||
dms[column_name]['latest_version'] = latest_version
|
||||
dms[column_name]['line_count'] = line_count
|
||||
print("{:<25} {:<25} {:<25} {:<25}".format(column_name, data_type, latest_version, line_count))
|
||||
dms[column_name]['creation_date'] = creation_date
|
||||
# TODO : actually get all the informations in the header
|
||||
print("{:<30} {:<12} {:<25} {:<30} {:<40}".format(column_name, data_type, latest_version, line_count, creation_date))
|
||||
|
||||
return dms
|
||||
|
||||
|
||||
cpdef OBIDMS_column open_column(self,
|
||||
str column_name,
|
||||
bint create=False,
|
||||
bint clone=False, bint clone_data=True,
|
||||
obiversion_t version_number=-1,
|
||||
OBIType_t data_type= <OBIType_t> 0,
|
||||
size_t nb_lines=0,
|
||||
size_t nb_elements_per_line=1,
|
||||
str elements_names=None):
|
||||
index_t nb_lines=0,
|
||||
index_t nb_elements_per_line=0,
|
||||
list elements_names=None,
|
||||
str array_name="default_obiarray"):
|
||||
|
||||
# Declarations
|
||||
cdef OBIDMS_column column
|
||||
cdef object subclass # TODO object?
|
||||
cdef bytes column_name_b
|
||||
cdef OBIDMS_column_header_p header
|
||||
|
||||
header = NULL
|
||||
|
||||
# Format the character string to send to C function
|
||||
column_name_b = str2bytes(column_name)
|
||||
|
||||
# Get the header of the latest version of the column if
|
||||
# some needed informations are not provided
|
||||
if ((not data_type or not nb_elements_per_line) and not create) :
|
||||
header = obi_column_get_header_from_name(self.pointer, column_name_b)
|
||||
|
||||
# Get the data type if not provided
|
||||
if not data_type :
|
||||
if create :
|
||||
raise Exception("A data type must be specified")
|
||||
else :
|
||||
data_type = obi_column_get_data_type_from_name(self.pointer, column_name_b)
|
||||
data_type = header.data_type
|
||||
|
||||
# Open the column with the right subclass depending on the data type and the mode (read-only or writable)
|
||||
# Get the number of elements per line if not provided and needed
|
||||
if not nb_elements_per_line :
|
||||
if create : # Set to one if not provided (default value)
|
||||
nb_elements_per_line = 1
|
||||
else :
|
||||
nb_elements_per_line = header.nb_elements_per_line
|
||||
if nb_elements_per_line > 1 :
|
||||
elements_names = bytes2str(header.elements_names).split(';')
|
||||
|
||||
if header != NULL :
|
||||
obi_unmap_header(header) # TODO check if error? but C will already warn and there's nothing to do
|
||||
|
||||
# Open the column with the right subclass depending on the data type, the mode
|
||||
# (read-only or writable) and whether there are multiple elements per line or not
|
||||
if data_type == 1 :
|
||||
if (create or clone) :
|
||||
column = OBIDMS_column_int_writable(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_int_writable
|
||||
else :
|
||||
subclass = OBIDMS_column_int_multi_elts_writable
|
||||
else :
|
||||
column = OBIDMS_column_int(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_int
|
||||
else :
|
||||
subclass = OBIDMS_column_int_multi_elts
|
||||
elif data_type == 2 :
|
||||
if (create or clone) :
|
||||
column = OBIDMS_column_float_writable(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_float_writable
|
||||
else :
|
||||
subclass = OBIDMS_column_float_multi_elts_writable
|
||||
else :
|
||||
column = OBIDMS_column_float(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_float
|
||||
else :
|
||||
subclass = OBIDMS_column_float_multi_elts
|
||||
elif data_type == 3 :
|
||||
if (create or clone) :
|
||||
column = OBIDMS_column_bool_writable(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_bool_writable
|
||||
else :
|
||||
subclass = OBIDMS_column_bool_multi_elts_writable
|
||||
else :
|
||||
column = OBIDMS_column_bool(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_bool
|
||||
else :
|
||||
subclass = OBIDMS_column_bool_multi_elts
|
||||
elif data_type == 4 :
|
||||
if (create or clone) :
|
||||
column = OBIDMS_column_char_writable(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_char_writable
|
||||
else :
|
||||
subclass = OBIDMS_column_char_multi_elts_writable
|
||||
else :
|
||||
column = OBIDMS_column_char(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names)
|
||||
|
||||
# elif data_type == 5 :
|
||||
# if (create or clone) :
|
||||
# column = OBIDMS_column_idx_writable(self, column_name,
|
||||
# create, clone, clone_data,
|
||||
# version_number, data_type,
|
||||
# nb_lines, nb_elements_per_line,
|
||||
# elements_names)
|
||||
# else :
|
||||
# column = OBIDMS_column_idx(self, column_name,
|
||||
# create, clone, clone_data,
|
||||
# version_number, data_type,
|
||||
# nb_lines, nb_elements_per_line,
|
||||
# elements_names)
|
||||
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_char
|
||||
else :
|
||||
subclass = OBIDMS_column_char_multi_elts
|
||||
elif data_type == 5 :
|
||||
if (create or clone) :
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_str_writable
|
||||
else :
|
||||
subclass = OBIDMS_column_str_multi_elts_writable
|
||||
else :
|
||||
if nb_elements_per_line == 1 :
|
||||
subclass = OBIDMS_column_str
|
||||
else :
|
||||
subclass = OBIDMS_column_str_multi_elts
|
||||
else :
|
||||
raise Exception("Problem with the data type")
|
||||
|
||||
column = subclass(self, column_name,
|
||||
create, clone, clone_data,
|
||||
version_number, data_type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names, array_name)
|
||||
|
||||
return column
|
||||
|
||||
|
||||
@ -196,88 +237,90 @@ cdef class OBIDMS_column :
|
||||
bint clone, bint clone_data,
|
||||
obiversion_t version_number,
|
||||
OBIType_t type,
|
||||
size_t nb_lines,
|
||||
size_t nb_elements_per_line,
|
||||
str elements_names):
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
list elements_names,
|
||||
str array_name):
|
||||
|
||||
# Declarations
|
||||
cdef bytes column_name_b
|
||||
cdef bytes dms_name_b
|
||||
cdef bytes array_name_b
|
||||
cdef bytes elements_names_b
|
||||
|
||||
# Fill structure
|
||||
self.dms = dms
|
||||
self.data_type = bytes2str(name_data_type(type))
|
||||
self.column_name = column_name
|
||||
self.nb_elements_per_line = nb_elements_per_line
|
||||
self.elements_names = elements_names
|
||||
|
||||
# Format the character strings to send them to C functions
|
||||
column_name_b = str2bytes(column_name)
|
||||
dms_name_b = str2bytes(self.dms.dms_name)
|
||||
array_name_b = str2bytes(array_name)
|
||||
|
||||
# Create, clone or open column
|
||||
if create :
|
||||
if elements_names == None :
|
||||
elements_names_b = column_name_b
|
||||
else :
|
||||
elements_names_b = str2bytes(elements_names)
|
||||
self.pointer = obi_create_column(self.dms.pointer, column_name_b, type, nb_lines, nb_elements_per_line, elements_names_b)
|
||||
elements_names_b = str2bytes(";".join(elements_names))
|
||||
self.pointer = obi_create_column(self.dms.pointer, column_name_b, type,
|
||||
nb_lines, nb_elements_per_line,
|
||||
elements_names_b, array_name_b)
|
||||
else :
|
||||
if clone :
|
||||
self.pointer = obi_clone_column(self.dms.pointer, column_name_b, version_number, clone_data)
|
||||
else :
|
||||
self.pointer = obi_open_column(self.dms.pointer, column_name_b, version_number)
|
||||
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
|
||||
# Declarations
|
||||
cdef list elements_names
|
||||
cdef str element_name
|
||||
cdef bint multiple_elements
|
||||
cdef object line # TODO
|
||||
cdef size_t lines_used
|
||||
cdef size_t line_nb
|
||||
|
||||
# Check if there are multiple elements per line anf if yes, get their names
|
||||
elements_names = self.get_elements_names()
|
||||
if len(elements_names) > 1 :
|
||||
multiple_elements = True
|
||||
else :
|
||||
element_name = elements_names[0]
|
||||
cdef index_t lines_used
|
||||
cdef index_t line_nb
|
||||
|
||||
# Yield each line
|
||||
lines_used = obi_column_get_nb_lines_used(self.pointer)
|
||||
for line_nb in xrange(lines_used):
|
||||
if multiple_elements :
|
||||
line = []
|
||||
for element_name in elements_names :
|
||||
line.append(self.get_item(line_nb, element_name))
|
||||
else :
|
||||
line = self.get_item(line_nb, element_name)
|
||||
yield line
|
||||
lines_used = self.pointer.header.lines_used
|
||||
for line_nb in range(lines_used):
|
||||
yield self.get_line(line_nb)
|
||||
|
||||
|
||||
def __setitem__(self, size_t line_nb, object value):
|
||||
self.set_item(line_nb, "", value)
|
||||
def __setitem__(self, index_t line_nb, object value):
|
||||
self.set_line(line_nb, value)
|
||||
|
||||
|
||||
def __getitem__(self, size_t line_nb):
|
||||
return self.get_item(line_nb, "")
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name):
|
||||
raise NotImplementedError
|
||||
def __getitem__(self, index_t line_nb):
|
||||
return self.get_line(line_nb)
|
||||
|
||||
|
||||
# cpdef object get_item(self, index_t line_nb, str element_name): TODO
|
||||
# raise NotImplementedError
|
||||
|
||||
|
||||
# cpdef set_item(self, index_t line_nb, str element_name, object value): TODO
|
||||
# raise NotImplementedError
|
||||
|
||||
|
||||
cpdef list get_elements_names(self):
|
||||
cdef bytes elements_names
|
||||
elements_names = obi_column_get_elements_names(self.pointer)
|
||||
return (bytes2str(elements_names)).split(';')
|
||||
return self.elements_names
|
||||
|
||||
|
||||
cpdef str get_data_type(self):
|
||||
return self.data_type
|
||||
|
||||
|
||||
cpdef size_t get_nb_lines_used(self):
|
||||
return obi_column_get_nb_lines_used(self.pointer)
|
||||
|
||||
|
||||
cpdef index_t get_nb_lines_used(self):
|
||||
return self.pointer.header.lines_used
|
||||
|
||||
|
||||
cpdef str get_creation_date(self):
|
||||
return bytes2str(obi_column_format_date(self.pointer.header.creation_date))
|
||||
|
||||
|
||||
cpdef close(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
@ -14,3 +14,5 @@
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiarray.h
|
||||
../../../src/obiarray.c
|
||||
|
@ -1,17 +1,25 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport obibool_t
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
|
||||
from ._obidms cimport OBIDMS_column
|
||||
from .capi.obitypes cimport obibool_t, index_t
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool(OBIDMS_column):
|
||||
cpdef object get_item(self, size_t line_nb, str element_name)
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value)
|
||||
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obibool_t value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
|
||||
cdef class OBIDMS_column_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts):
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obibool_t value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
cpdef close(self)
|
||||
|
@ -3,7 +3,9 @@
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obibool_with_elt_name, \
|
||||
obi_column_set_obibool_with_elt_name
|
||||
obi_column_get_obibool_with_elt_idx, \
|
||||
obi_column_set_obibool_with_elt_name, \
|
||||
obi_column_set_obibool_with_elt_idx
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIBool_NA
|
||||
|
||||
@ -13,8 +15,41 @@ from cpython.bool cimport PyBool_FromLong
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool(OBIDMS_column):
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obibool_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obibool_with_elt_idx(self.pointer, line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIBool_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyBool_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if obi_column_set_obibool_with_elt_idx(self.pointer, line_nb, 0, <obibool_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool_multi_elts(OBIDMS_column_bool):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obibool_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
@ -25,22 +60,45 @@ cdef class OBIDMS_column_bool(OBIDMS_column):
|
||||
else :
|
||||
result = PyBool_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obibool_t value
|
||||
cdef object result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = obi_column_get_obibool_with_elt_idx(self.pointer, line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
result[self.elements_names[i]] = PyBool_FromLong(value)
|
||||
if all_NA and (value != OBIBool_NA) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obibool_t value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool_writable(OBIDMS_column_bool):
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obibool_t value):
|
||||
if obi_column_set_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0 :
|
||||
cdef class OBIDMS_column_bool_multi_elts_writable(OBIDMS_column_bool_multi_elts):
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obibool_t value):
|
||||
if obi_column_set_obibool_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
cdef obibool_t value
|
||||
for element_name in values :
|
||||
value = <obibool_t> values[element_name]
|
||||
self.set_item(line_nb, element_name, value)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
|
@ -14,3 +14,5 @@
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiarray.h
|
||||
../../../src/obiarray.c
|
||||
|
@ -1,17 +1,25 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport obichar_t
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
|
||||
from ._obidms cimport OBIDMS_column
|
||||
from .capi.obitypes cimport obichar_t, index_t
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char(OBIDMS_column):
|
||||
cpdef object get_item(self, size_t line_nb, str element_name)
|
||||
cpdef set_item(self, size_t line_nb, str element_name, bytes value)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
|
||||
cpdef set_item(self, size_t line_nb, str element_name, bytes value)
|
||||
cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, bytes value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
|
||||
cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
|
||||
cpdef set_item(self, index_t line_nb, str element_name, bytes value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
cpdef close(self)
|
||||
|
@ -3,17 +3,52 @@
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obichar_with_elt_name, \
|
||||
obi_column_set_obichar_with_elt_name
|
||||
obi_column_get_obichar_with_elt_idx, \
|
||||
obi_column_set_obichar_with_elt_name, \
|
||||
obi_column_set_obichar_with_elt_idx
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIChar_NA
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char(OBIDMS_column) :
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name):
|
||||
cdef char value
|
||||
cdef class OBIDMS_column_char(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obichar_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obichar_with_elt_idx(self.pointer, line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIChar_NA :
|
||||
result = None
|
||||
else :
|
||||
result = <bytes> value
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char_writable(OBIDMS_column_char):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if obi_column_set_obichar_with_elt_idx(self.pointer, line_nb, 0, <bytes> value[0]) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char_multi_elts(OBIDMS_column_char):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obichar_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
@ -23,22 +58,81 @@ cdef class OBIDMS_column_char(OBIDMS_column) :
|
||||
else :
|
||||
result = <bytes> value
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obichar_t value
|
||||
cdef object result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = obi_column_get_obichar_with_elt_idx(self.pointer, line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
result[self.elements_names[i]] = <bytes> value
|
||||
if all_NA and (value != OBIChar_NA) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, bytes value):
|
||||
cpdef set_item(self, index_t line_nb, str element_name, bytes value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char_writable(OBIDMS_column_char) :
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, bytes value):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char_multi_elts_writable(OBIDMS_column_char_multi_elts):
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, bytes value):
|
||||
if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
cdef bytes value
|
||||
for element_name in values :
|
||||
value = <bytes> values[element_name]
|
||||
self.set_item(line_nb, element_name, value)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# cdef class OBIDMS_column_char(OBIDMS_column) :
|
||||
#
|
||||
# cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
# cdef char value
|
||||
# cdef object result
|
||||
# value = obi_column_get_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
# if obi_errno > 0 :
|
||||
# raise IndexError(line_nb, element_name)
|
||||
# if value == OBIChar_NA :
|
||||
# result = None
|
||||
# else :
|
||||
# result = <bytes> value
|
||||
# return result
|
||||
#
|
||||
# cpdef set_item(self, index_t line_nb, str element_name, bytes value):
|
||||
# raise Exception("Column is read-only")
|
||||
#
|
||||
# cpdef close(self):
|
||||
# if obi_close_column(self.pointer) < 0 :
|
||||
# raise Exception("Problem closing a column")
|
||||
#
|
||||
#
|
||||
# cdef class OBIDMS_column_char_writable(OBIDMS_column_char) :
|
||||
#
|
||||
# cpdef set_item(self, index_t line_nb, str element_name, bytes value):
|
||||
# if obi_column_set_obichar_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value[0]) < 0:
|
||||
# raise Exception("Problem setting a value in a column")
|
||||
#
|
||||
# cpdef close(self):
|
||||
# if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
# raise Exception("Problem closing a column")
|
||||
#
|
||||
|
@ -14,3 +14,5 @@
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiarray.h
|
||||
../../../src/obiarray.c
|
||||
|
@ -1,16 +1,25 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport obifloat_t
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
|
||||
from ._obidms cimport OBIDMS_column
|
||||
from .capi.obitypes cimport obifloat_t, index_t
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_float(OBIDMS_column):
|
||||
cpdef object get_item(self, size_t line_nb, str element_name)
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value)
|
||||
|
||||
cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
|
||||
cdef class OBIDMS_column_float_multi_elts_writable(OBIDMS_column_float_multi_elts):
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
cpdef close(self)
|
||||
|
@ -3,7 +3,9 @@
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obifloat_with_elt_name, \
|
||||
obi_column_set_obifloat_with_elt_name
|
||||
obi_column_get_obifloat_with_elt_idx, \
|
||||
obi_column_set_obifloat_with_elt_name, \
|
||||
obi_column_set_obifloat_with_elt_idx
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIFloat_NA
|
||||
|
||||
@ -12,7 +14,40 @@ from obitools3.utils cimport str2bytes
|
||||
|
||||
cdef class OBIDMS_column_float(OBIDMS_column):
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name):
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obifloat_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obifloat_with_elt_idx(self.pointer, line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIFloat_NA :
|
||||
result = None
|
||||
else :
|
||||
result = <double> value
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if obi_column_set_obifloat_with_elt_idx(self.pointer, line_nb, 0, <obifloat_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_float_multi_elts(OBIDMS_column_float):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obifloat_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
@ -21,24 +56,48 @@ cdef class OBIDMS_column_float(OBIDMS_column):
|
||||
if value == OBIFloat_NA :
|
||||
result = None
|
||||
else :
|
||||
result = <float> value
|
||||
result = <double> value
|
||||
return result
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value):
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obifloat_t value
|
||||
cdef object result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = obi_column_get_obifloat_with_elt_idx(self.pointer, line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
result[self.elements_names[i]] = <double> value
|
||||
if all_NA and (value != OBIFloat_NA) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cdef class OBIDMS_column_float_writable(OBIDMS_column_float):
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obifloat_t value):
|
||||
cdef class OBIDMS_column_float_multi_elts_writable(OBIDMS_column_float_multi_elts):
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obifloat_t value):
|
||||
if obi_column_set_obifloat_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
cdef obifloat_t value
|
||||
for element_name in values :
|
||||
value = <obifloat_t> values[element_name]
|
||||
self.set_item(line_nb, element_name, value)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport obiidx_t
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_idx(OBIDMS_column):
|
||||
cpdef object get_item(self, size_t line_nb, str element_name)
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiidx_t value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_idx_writable(OBIDMS_column_idx):
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiidx_t value)
|
||||
cpdef close(self)
|
@ -1,46 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obiidx_with_elt_name, \
|
||||
obi_column_set_obiidx_with_elt_name
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIIdx_NA
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
from cpython.int cimport PyInt_FromSsize_t
|
||||
|
||||
|
||||
cdef class OBIDMS_column_idx(OBIDMS_column):
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name):
|
||||
cdef obiidx_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obiidx_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIIdx_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyInt_FromSsize_t(value)
|
||||
return result
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiidx_t value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_idx_writable(OBIDMS_column_idx):
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiidx_t value):
|
||||
if obi_column_set_obiidx_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
@ -14,3 +14,5 @@
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiarray.h
|
||||
../../../src/obiarray.c
|
||||
|
@ -1,16 +1,25 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport obiint_t
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
|
||||
from ._obidms cimport OBIDMS_column
|
||||
from .capi.obitypes cimport obiint_t, index_t
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
cpdef object get_item(self, size_t line_nb, str element_name)
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value)
|
||||
|
||||
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
|
||||
cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts):
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
cpdef close(self)
|
||||
|
@ -3,7 +3,9 @@
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obiint_with_elt_name, \
|
||||
obi_column_set_obiint_with_elt_name
|
||||
obi_column_get_obiint_with_elt_idx, \
|
||||
obi_column_set_obiint_with_elt_name, \
|
||||
obi_column_set_obiint_with_elt_idx
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIInt_NA
|
||||
|
||||
@ -11,12 +13,43 @@ from obitools3.utils cimport str2bytes
|
||||
|
||||
from cpython.int cimport PyInt_FromLong
|
||||
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
|
||||
cpdef object get_item(self, size_t line_nb, str element_name):
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obiint_with_elt_idx(self.pointer, line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIInt_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyInt_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if obi_column_set_obiint_with_elt_idx(self.pointer, line_nb, 0, <obiint_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int_multi_elts(OBIDMS_column_int):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
value = obi_column_get_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
@ -28,21 +61,44 @@ cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
result = PyInt_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value):
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = obi_column_get_obiint_with_elt_idx(self.pointer, line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
result[self.elements_names[i]] = PyInt_FromLong(value)
|
||||
if all_NA and (value != OBIInt_NA) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cdef class OBIDMS_column_int_writable(OBIDMS_column_int):
|
||||
|
||||
cpdef set_item(self, size_t line_nb, str element_name, obiint_t value):
|
||||
cdef class OBIDMS_column_int_multi_elts_writable(OBIDMS_column_int_multi_elts):
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, obiint_t value):
|
||||
if obi_column_set_obiint_with_elt_name(self.pointer, line_nb, str2bytes(element_name), value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
cdef obiint_t value
|
||||
for element_name in values :
|
||||
value = <obiint_t> values[element_name]
|
||||
self.set_item(line_nb, element_name, value)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
@ -14,3 +14,5 @@
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiarray.h
|
||||
../../../src/obiarray.c
|
25
python/obitools3/obidms/_obidmscolumn_str.pxd
Normal file
@ -0,0 +1,25 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIDMS_column
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_str_writable(OBIDMS_column_str):
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef close(self)
|
||||
|
||||
cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, str value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
|
||||
cdef class OBIDMS_column_str_multi_elts_writable(OBIDMS_column_str_multi_elts):
|
||||
cpdef set_item(self, index_t line_nb, str element_name, str value)
|
||||
cpdef set_line(self, index_t line_nb, object values)
|
||||
cpdef close(self)
|
103
python/obitools3/obidms/_obidmscolumn_str.pyx
Normal file
@ -0,0 +1,103 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_close_column,\
|
||||
obi_truncate_and_close_column, \
|
||||
obi_column_get_obistr_with_elt_name, \
|
||||
obi_column_get_obistr_with_elt_idx, \
|
||||
obi_column_set_obistr_with_elt_name, \
|
||||
obi_column_set_obistr_with_elt_idx
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIIdx_NA, const_char_p
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef bytes value
|
||||
cdef object result
|
||||
value = <bytes> obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIIdx_NA :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str_writable(OBIDMS_column_str):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if obi_column_set_obistr_with_elt_idx(self.pointer, line_nb, 0, str2bytes(value)) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str_multi_elts(OBIDMS_column_str):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef bytes value
|
||||
cdef object result
|
||||
value = <bytes> obi_column_get_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIIdx_NA :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef bytes value
|
||||
cdef object result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = <bytes> obi_column_get_obistr_with_elt_idx(self.pointer, line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
result[self.elements_names[i]] = bytes2str(value)
|
||||
if all_NA and (value != OBIIdx_NA) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, str value):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
raise Exception("Column is read-only")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str_multi_elts_writable(OBIDMS_column_str_multi_elts):
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, str value):
|
||||
if obi_column_set_obistr_with_elt_name(self.pointer, line_nb, str2bytes(element_name), str2bytes(value)) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object values):
|
||||
cdef str value
|
||||
for element_name in values :
|
||||
value = values[element_name]
|
||||
self.set_item(line_nb, element_name, value)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column(self.pointer) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
@ -8,38 +8,48 @@ from ..capi.obitypes cimport const_char_p, \
|
||||
obibool_t, \
|
||||
obichar_t, \
|
||||
obifloat_t, \
|
||||
obiidx_t
|
||||
index_t, \
|
||||
time_t
|
||||
|
||||
|
||||
cdef extern from "obidmscolumn.h" nogil:
|
||||
|
||||
struct OBIDMS_column_header_t:
|
||||
bint little_endian
|
||||
int header_size
|
||||
index_t line_count
|
||||
index_t lines_used
|
||||
index_t nb_elements_per_line
|
||||
const_char_p elements_names
|
||||
OBIType_t data_type
|
||||
time_t creation_date
|
||||
obiversion_t version
|
||||
obiversion_t cloned_from
|
||||
const_char_p name
|
||||
const_char_p array_name
|
||||
const_char_p comments
|
||||
|
||||
ctypedef OBIDMS_column_header_t* OBIDMS_column_header_p
|
||||
|
||||
struct OBIDMS_column_t:
|
||||
pass
|
||||
OBIDMS_column_header_p header
|
||||
|
||||
ctypedef OBIDMS_column_t* OBIDMS_column_p
|
||||
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
const_char_p column_name,
|
||||
OBIType_t type,
|
||||
size_t nb_lines,
|
||||
size_t nb_elements_per_line,
|
||||
const_char_p elements_names)
|
||||
|
||||
size_t obi_column_get_nb_lines_used(OBIDMS_column_p column)
|
||||
|
||||
const_char_p obi_column_get_elements_names(OBIDMS_column_p column)
|
||||
|
||||
void obi_column_make_unwritable(OBIDMS_column_p column)
|
||||
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const_char_p elements_names,
|
||||
const_char_p array_name)
|
||||
|
||||
OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number)
|
||||
|
||||
OBIType_t obi_column_get_type(OBIDMS_column_p column)
|
||||
|
||||
|
||||
int obi_close_column(OBIDMS_column_p column)
|
||||
|
||||
OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms,
|
||||
const_char_p column_name)
|
||||
|
||||
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number,
|
||||
@ -49,65 +59,112 @@ cdef extern from "obidmscolumn.h" nogil:
|
||||
|
||||
obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms,
|
||||
const_char_p column_name)
|
||||
|
||||
OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms,
|
||||
const_char_p column_name)
|
||||
|
||||
OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms,
|
||||
const_char_p column_name)
|
||||
|
||||
size_t obi_column_get_line_count_from_name(OBIDMS_p dms,
|
||||
const_char_p column_name)
|
||||
|
||||
int obi_unmap_header(OBIDMS_column_header_p header)
|
||||
|
||||
char* obi_column_format_date(time_t date)
|
||||
|
||||
|
||||
cdef extern from "obidmscolumn_int.h" nogil:
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obiint_t value)
|
||||
|
||||
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obiint_t value)
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
||||
cdef extern from "obidmscolumn_bool.h" nogil:
|
||||
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obibool_t value)
|
||||
|
||||
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obibool_t value)
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_char.h" nogil:
|
||||
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obichar_t value)
|
||||
|
||||
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obichar_t value)
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_float.h" nogil:
|
||||
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obifloat_t value)
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
cdef extern from "obidmscolumn_idx.h" nogil:
|
||||
|
||||
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
const_char_p element_name,
|
||||
obiidx_t value)
|
||||
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obifloat_t value)
|
||||
|
||||
obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column,
|
||||
size_t line_nb,
|
||||
const_char_p element_name)
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_str.h" nogil:
|
||||
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
char* value)
|
||||
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
char* value)
|
||||
|
||||
const_char_p obi_column_get_obistr_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
const_char_p obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
#cython: language_level=3
|
||||
|
||||
|
||||
from libc.stdint cimport int32_t
|
||||
from libc.stdint cimport int32_t, int64_t
|
||||
from posix.types cimport time_t
|
||||
|
||||
|
||||
cdef extern from *:
|
||||
@ -32,10 +33,10 @@ cdef extern from "obitypes.h" nogil:
|
||||
ctypedef int32_t obiint_t
|
||||
ctypedef double obifloat_t
|
||||
ctypedef char obichar_t
|
||||
ctypedef size_t obiidx_t
|
||||
ctypedef int64_t index_t
|
||||
|
||||
extern obiint_t OBIInt_NA
|
||||
extern obiidx_t OBIIdx_NA
|
||||
extern index_t OBIIdx_NA
|
||||
extern obifloat_t OBIFloat_NA
|
||||
extern obichar_t OBIChar_NA
|
||||
extern obibool_t OBIBool_NA
|
||||
|
271
python/obitools3/unit_tests.py
Normal file
@ -0,0 +1,271 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import unittest
|
||||
from random import randint, uniform, choice
|
||||
import string
|
||||
|
||||
from obitools3.obidms._obidms import OBIDMS
|
||||
|
||||
|
||||
LINE_COUNT_FOR_TEST_COLUMN = 10000 # TODO randomize?
|
||||
SMALLER_LINE_COUNT_FOR_TEST_COLUMN = 1000 # TODO randomize?
|
||||
NB_ELEMENTS_PER_LINE = 20 # TODO randomize?
|
||||
DMS_NAME = "unit_test_dms"
|
||||
DATA_TYPES = ['OBI_INT', 'OBI_FLOAT', 'OBI_BOOL', 'OBI_CHAR', 'OBI_IDX']
|
||||
|
||||
|
||||
def create_test_obidms():
|
||||
dms_name = DMS_NAME
|
||||
dms_dir_name = dms_name+'.obidms'
|
||||
dms = OBIDMS(dms_name)
|
||||
return (dms, dms_name, dms_dir_name)
|
||||
|
||||
|
||||
def create_test_column(dms, data_type_code, multiple_elements_per_line=False):
|
||||
data_types = DATA_TYPES
|
||||
data_type_code = data_type_code
|
||||
data_type_str = data_types[data_type_code-1]
|
||||
col_name = "unit_test_"+data_type_str
|
||||
|
||||
if multiple_elements_per_line :
|
||||
elts_names = elements_names()
|
||||
col = dms.open_column(col_name,
|
||||
create=True,
|
||||
data_type=data_type_code,
|
||||
nb_elements_per_line=NB_ELEMENTS_PER_LINE,
|
||||
elements_names=elts_names)
|
||||
return (col, col_name, elts_names, data_type_str)
|
||||
|
||||
else :
|
||||
col = dms.open_column(col_name,
|
||||
create=True,
|
||||
data_type=data_type_code)
|
||||
return (col, col_name, data_type_str)
|
||||
|
||||
|
||||
def elements_names():
|
||||
names = [str(i) for i in range(NB_ELEMENTS_PER_LINE)]
|
||||
return names
|
||||
|
||||
|
||||
def random_obivalue(data_type):
|
||||
r = 1000000
|
||||
if data_type == "OBI_INT" :
|
||||
return randint(-r,r)
|
||||
elif data_type == "OBI_FLOAT" :
|
||||
return uniform(-r,r)
|
||||
elif data_type == "OBI_BOOL" :
|
||||
return randint(0,1)
|
||||
elif data_type == "OBI_CHAR" :
|
||||
nucs = 'atgc'
|
||||
return bytes(nucs[randint(0,3)], 'utf-8')
|
||||
elif data_type == "OBI_IDX" :
|
||||
length = randint(1,500)
|
||||
randoms = ''.join(choice(string.ascii_lowercase) for i in range(length))
|
||||
return randoms
|
||||
|
||||
class OBIDMS_Column_TestCase(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
self.col.close()
|
||||
self.dms.close()
|
||||
shutil.rmtree(self.dms_dir_name, ignore_errors=True)
|
||||
def test_OBIDMS_column_type(self):
|
||||
assert self.col.get_data_type() == self.data_type_str, 'Wrong data type associated with column'
|
||||
def test_OBIDMS_column_cloning(self):
|
||||
for i in range(LINE_COUNT_FOR_TEST_COLUMN):
|
||||
self.col[i]= random_obivalue(self.data_type_str)
|
||||
self.col.close()
|
||||
clone = self.dms.open_column(self.col_name, clone=True)
|
||||
self.col = self.dms.open_column(self.col_name)
|
||||
assert clone.get_nb_lines_used() == self.col.get_nb_lines_used(), "Cloned column doesn't have the same number of lines used"
|
||||
i=0
|
||||
for i in range(clone.get_nb_lines_used()) :
|
||||
assert clone[i] == self.col[i], "Different value in original column and cloned column"
|
||||
assert clone[i] is not None, "None value"
|
||||
clone.close()
|
||||
def test_OBIDMS_column_set_and_get(self):
|
||||
for i in range(LINE_COUNT_FOR_TEST_COLUMN):
|
||||
v = random_obivalue(self.data_type_str)
|
||||
self.col[i] = v
|
||||
assert self.col[i] == v, "Different value than the set value"
|
||||
assert self.col[i] is not None, "None value"
|
||||
|
||||
|
||||
class OBIDMS_Column_multiple_elements_TestCase(OBIDMS_Column_TestCase):
|
||||
def test_OBIDMS_column_cloning(self):
|
||||
pass
|
||||
for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN):
|
||||
v = {}
|
||||
for e in self.elts_names :
|
||||
v[e] = random_obivalue(self.data_type_str)
|
||||
self.col[i] = v
|
||||
self.col.close()
|
||||
clone = self.dms.open_column(self.col_name, clone=True)
|
||||
self.col = self.dms.open_column(self.col_name)
|
||||
assert clone.get_nb_lines_used() == self.col.get_nb_lines_used(), "Cloned column doesn't have the same number of lines used"
|
||||
i=0
|
||||
for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN):
|
||||
assert self.col[i] == clone[i], "Different value in original column and cloned column"
|
||||
assert self.col[i] is not None, "None value"
|
||||
clone.close()
|
||||
def test_OBIDMS_column_set_and_get_with_elements_names(self):
|
||||
for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN):
|
||||
for e in range(NB_ELEMENTS_PER_LINE) :
|
||||
v = random_obivalue(self.data_type_str)
|
||||
self.col.set_item(i, self.elts_names[e], v)
|
||||
assert self.col.get_item(i, self.elts_names[e]) == v, "Different value than the set value"
|
||||
assert self.col.get_item(i, self.elts_names[e]) is not None, "None value"
|
||||
def test_OBIDMS_column_set_and_get(self):
|
||||
for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN):
|
||||
v = {}
|
||||
for e in self.elts_names :
|
||||
v[e] = random_obivalue(self.data_type_str)
|
||||
self.col[i] = v
|
||||
assert self.col[i] == v, "Different value than the set value"
|
||||
assert self.col[i] is not None, "None value"
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_INT_TestCase(OBIDMS_Column_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 1
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_INT_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 1
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.elts_names, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code,
|
||||
multiple_elements_per_line=True)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_FLOAT_TestCase(OBIDMS_Column_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 2
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_FLOAT_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 2
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.elts_names, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code,
|
||||
multiple_elements_per_line=True)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_BOOL_TestCase(OBIDMS_Column_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 3
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_BOOL_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 3
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.elts_names, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code,
|
||||
multiple_elements_per_line=True)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_CHAR_TestCase(OBIDMS_Column_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 4
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_CHAR_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 4
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.elts_names, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code,
|
||||
multiple_elements_per_line=True)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_STR_TestCase(OBIDMS_Column_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 5
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code)
|
||||
|
||||
|
||||
class OBIDMS_Column_OBI_STR_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase):
|
||||
def setUp(self):
|
||||
self.data_type_code = 5
|
||||
self.dms, \
|
||||
self.dms_name, \
|
||||
self.dms_dir_name = create_test_obidms()
|
||||
self.col, \
|
||||
self.col_name, \
|
||||
self.elts_names, \
|
||||
self.data_type_str = create_test_column(self.dms,
|
||||
self.data_type_code,
|
||||
multiple_elements_per_line=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2, defaultTest=["OBIDMS_Column_OBI_INT_TestCase",
|
||||
"OBIDMS_Column_OBI_INT_multiple_elements_TestCase",
|
||||
"OBIDMS_Column_OBI_FLOAT_TestCase",
|
||||
"OBIDMS_Column_OBI_FLOAT_multiple_elements_TestCase",
|
||||
"OBIDMS_Column_OBI_BOOL_TestCase",
|
||||
"OBIDMS_Column_OBI_BOOL_multiple_elements_TestCase",
|
||||
"OBIDMS_Column_OBI_CHAR_TestCase",
|
||||
"OBIDMS_Column_OBI_CHAR_multiple_elements_TestCase",
|
||||
"OBIDMS_Column_OBI_STR_TestCase",
|
||||
"OBIDMS_Column_OBI_STR_multiple_elements_TestCase"])
|
||||
|
||||
|
@ -2,4 +2,4 @@ major = 1
|
||||
minor = 1
|
||||
serial= '16'
|
||||
|
||||
version ="%2d.%02d.%s" % (major,minor,serial)
|
||||
version ="%d.%02d.%s" % (major,minor,serial)
|
||||
|
1176
src/obiarray.c
Normal file
285
src/obiarray.h
Normal file
@ -0,0 +1,285 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS array header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obiarray.h
|
||||
* @author Celine Mercier
|
||||
* @date October 19th 2015
|
||||
* @brief Header file for handling arrays for storing and retrieving byte arrays (i.e. coding for character strings).
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIARRAY_H_
|
||||
#define OBIARRAY_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "obidms.h"
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
#define ARRAY_MAX_NAME (2048) /**< The maximum length of an array name.
|
||||
*/
|
||||
#define ARRAY_GROWTH_FACTOR (2) /**< The growth factor when an array is enlarged.
|
||||
*/
|
||||
#define BYTE_ARRAY_HEADER_SIZE (5) /**< The size of the header of a byte array.
|
||||
*/
|
||||
|
||||
|
||||
typedef char byte_t; /**< Defining byte type since data is stored in bits
|
||||
* and char (stored on one byte) is the smallest addressable unit.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief OBIDMS array data header structure.
|
||||
*/
|
||||
typedef struct OBIDMS_array_data_header {
|
||||
int header_size; /**< Size of the header in bytes.
|
||||
*/
|
||||
index_t data_size_used; /**< Size of the data used in bytes.
|
||||
*/
|
||||
index_t data_size_max; /**< Max size of the data in bytes.
|
||||
*/
|
||||
index_t nb_items; /**< Number of items.
|
||||
*/
|
||||
char array_name[ARRAY_MAX_NAME+1]; /**< The array name as a NULL terminated string.
|
||||
*/
|
||||
time_t creation_date; /**< Date of creation of the file.
|
||||
*/
|
||||
} OBIDMS_array_data_header_t, *OBIDMS_array_data_header_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief OBIDMS array data structure.
|
||||
*/
|
||||
typedef struct OBIDMS_array_data {
|
||||
OBIDMS_array_data_header_p header; /**< A pointer to the header of the array data.
|
||||
*/
|
||||
byte_t* data; /**< A pointer to the beginning of the data.
|
||||
*/
|
||||
} OBIDMS_array_data_t, *OBIDMS_array_data_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief OBIDMS array header structure.
|
||||
*/
|
||||
typedef struct OBIDMS_array_header {
|
||||
int header_size; /**< Size of the header in bytes.
|
||||
*/
|
||||
size_t array_size; /**< Size of the array in bytes.
|
||||
*/
|
||||
index_t nb_items; /**< Number of items in the array.
|
||||
*/
|
||||
index_t nb_items_max; /**< Maximum number of items in the array before it has to be enlarged.
|
||||
*/
|
||||
char array_name[ARRAY_MAX_NAME+1]; /**< The array name as a NULL terminated string.
|
||||
*/
|
||||
time_t creation_date; /**< Date of creation of the file.
|
||||
*/
|
||||
} OBIDMS_array_header_t, *OBIDMS_array_header_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief OBIDMS array structure.
|
||||
*/
|
||||
typedef struct OBIDMS_array {
|
||||
OBIDMS_array_header_p header; /**< A pointer to the header of the array.
|
||||
*/
|
||||
index_t* first; /**< A pointer to the beginning of the array itself.
|
||||
*/
|
||||
OBIDMS_array_data_p data; /**< A pointer to the structure containing the data
|
||||
* that the array references.
|
||||
*/
|
||||
DIR* directory; /**< A directory entry usable to
|
||||
* refer and scan the array directory.
|
||||
*/
|
||||
} OBIDMS_array_t, *OBIDMS_array_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks if an obiarray already exists or not.
|
||||
*
|
||||
* @param dms The OBIDMS to which the obiarray belongs.
|
||||
* @param array_name The name of the obiarray.
|
||||
*
|
||||
* @returns A value indicating whether the obiarray exists or not.
|
||||
* @retval 1 if the obiarray exists.
|
||||
* @retval 0 if the obiarray does not exist.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_array_exists(OBIDMS_p dms, const char* array_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens an obiarray and creates it if it does not already exist.
|
||||
*
|
||||
* Note: An obiarray is made of two files (referred to by two structures).
|
||||
* One file contains the indices referring to the data, and the other
|
||||
* file contains the data itself. The obiarray as a whole is referred
|
||||
* to via the OBIDMS_array structure.
|
||||
*
|
||||
* @param dms The OBIDMS to which the obiarray belongs.
|
||||
* @param array_name The name of the obiarray.
|
||||
*
|
||||
* @returns A pointer to the obiarray structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_array_p obi_array(OBIDMS_p dms, const char* array_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates an obiarray. Fails if it already exists.
|
||||
*
|
||||
* Note: An obiarray is made of two files (referred to by two structures).
|
||||
* One file contains the indices referring to the data, and the other
|
||||
* file contains the data itself. The obiarray as a whole is referred
|
||||
* to via the OBIDMS_array structure.
|
||||
*
|
||||
* @param dms The OBIDMS to which the obiarray belongs.
|
||||
* @param array_name The name of the obiarray.
|
||||
*
|
||||
* @returns A pointer to the newly created obiarray structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_array_p obi_create_array(OBIDMS_p dms, const char* array_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens an obiarray. Fails if it does not already exist.
|
||||
*
|
||||
* Note: An obiarray is made of two files (referred to by two structures).
|
||||
* One file contains the indices referring to the data, and the other
|
||||
* file contains the data itself. The obiarray as a whole is referred
|
||||
* to via the OBIDMS_array structure.
|
||||
*
|
||||
* @param dms The OBIDMS to which the obiarray belongs.
|
||||
* @param array_name The name of the obiarray.
|
||||
*
|
||||
* @returns A pointer to the obiarray structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_array_p obi_open_array(OBIDMS_p dms, const char* array_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Closes an obiarray.
|
||||
*
|
||||
* Note: An obiarray is made of two files (referred to by two structures).
|
||||
* One file contains the indices referring to the data, and the other
|
||||
* file contains the data itself. The obiarray as a whole is referred
|
||||
* to via the OBIDMS_array structure.
|
||||
*
|
||||
* @param array A pointer to the obiarray structure to close and free.
|
||||
*
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_close_array(OBIDMS_array_p array);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adds a value (byte array) in an obiarray, checking first if it is already in it.
|
||||
*
|
||||
* @warning The byte array to add must already be encoded and contain its header.
|
||||
*
|
||||
* @param array A pointer to the obiarray.
|
||||
* @param value The byte array to add in the obiarray.
|
||||
*
|
||||
* @returns The index of the value, whether it was added or already in the obiarray.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
index_t obi_array_add(OBIDMS_array_p array, byte_t* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value (byte array) in an obiarray.
|
||||
*
|
||||
* @warning The byte array recovered is encoded and contains its header.
|
||||
*
|
||||
* @param array A pointer to the obiarray.
|
||||
* @param index The index of the value in the data array.
|
||||
*
|
||||
* @returns A pointer to the byte array recovered.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
byte_t* obi_array_get(OBIDMS_array_p array, index_t index);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Searches a value (byte array) in an obiarray performing a binary search.
|
||||
*
|
||||
* @warning The byte array to search must already be encoded and contain its header.
|
||||
*
|
||||
* @param array A pointer to the obiarray.
|
||||
* @param value The byte array to add in the obiarray.
|
||||
*
|
||||
* @returns If the value is found, its data index is returned.
|
||||
* If the value is not found, the array index indicating where the value's data index
|
||||
* should be in the array is returned in the form (- (index + 1)), as data indices in an
|
||||
* obiarray are sorted according to the ascending order of the values (byte arrays) themselves.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
index_t obi_array_search(OBIDMS_array_p array, byte_t* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a character string to a byte array with a header.
|
||||
*
|
||||
* @warning The byte array must be freed by the caller.
|
||||
*
|
||||
* @param value The character string to convert.
|
||||
*
|
||||
* @returns A pointer to the byte array created.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
byte_t* obi_str_to_obibytes(char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a byte array to a character string.
|
||||
*
|
||||
* @param value_b The byte array to convert.
|
||||
*
|
||||
* @returns A pointer to the character string contained in the byte array.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_obibytes_to_str(byte_t* value_b);
|
||||
|
||||
|
||||
#endif /* OBIARRAY_H_ */
|
||||
|
@ -1,8 +1,12 @@
|
||||
/*
|
||||
* obidebug.h
|
||||
*
|
||||
* Created on: June 25th 2015
|
||||
* Author: Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
/****************************************************************************
|
||||
* Header file for the debugging code *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidebug.h
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 25 June 2015
|
||||
* @brief Header file for the debugging code.
|
||||
*/
|
||||
|
||||
|
||||
@ -12,7 +16,7 @@
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
//#ifndef DEBUG_LEVEL
|
||||
//#ifndef DEBUG_LEVEL // TODO
|
||||
//#define DEBUG_LEVEL MAXINT
|
||||
//#endif
|
||||
|
||||
|
101
src/obidms.c
@ -1,14 +1,20 @@
|
||||
/*
|
||||
* obidms.c
|
||||
*
|
||||
* @date 23 May 2015
|
||||
* @Author: coissac
|
||||
/********************************************************************
|
||||
* OBIDMS functions *
|
||||
********************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidms.c
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
* @date 23 May 2015
|
||||
* @brief OBIDMS functions.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
@ -16,9 +22,10 @@
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obidmscolumn.h"
|
||||
#include "private_at_functions.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
@ -29,27 +36,22 @@
|
||||
|
||||
|
||||
/**
|
||||
* Internal function building the directory name from an OBIDMS name.
|
||||
* Internal function building the OBIDMS directory name from an OBIDMS name.
|
||||
*
|
||||
* The function builds the directory name corresponding to an OBIDMS.
|
||||
* It checks also that the name is not too long.
|
||||
* It also checks that the name is not too long.
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
* @param dms_name the name of the OBIDMS
|
||||
* @param dms_name The name of the OBIDMS.
|
||||
*
|
||||
* @return a pointer to the directory name
|
||||
* @retvalue <directory_name> if everything is ok
|
||||
* @retvalue NULL if an error occurs
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* @returns A pointer to the directory name.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
static char *build_directory_name(const char *dms_name);
|
||||
static char* build_directory_name(const char* dms_name);
|
||||
|
||||
|
||||
/************************************************************************
|
||||
@ -58,9 +60,9 @@ static char *build_directory_name(const char *dms_name);
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
static char *build_directory_name(const char *dms_name)
|
||||
static char* build_directory_name(const char* dms_name)
|
||||
{
|
||||
char *directory_name;
|
||||
char* directory_name;
|
||||
|
||||
// Build the database directory name
|
||||
if (asprintf(&directory_name, "%s.obidms", dms_name) < 0)
|
||||
@ -113,7 +115,9 @@ int obi_dms_exists(const char* dms_name)
|
||||
|
||||
OBIDMS_p obi_create_dms(const char* dms_name)
|
||||
{
|
||||
char *directory_name;
|
||||
char* directory_name;
|
||||
DIR* dms_dir;
|
||||
int dms_file_descriptor;
|
||||
|
||||
// Build and check the directory name
|
||||
directory_name = build_directory_name(dms_name);
|
||||
@ -132,6 +136,33 @@ OBIDMS_p obi_create_dms(const char* dms_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get file descriptor of DMS directory to create the arrays directory
|
||||
dms_dir = opendir(directory_name);
|
||||
if (dms_dir == NULL)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nProblem opening a newly created OBIDMS directory");
|
||||
free(directory_name);
|
||||
return NULL;
|
||||
}
|
||||
dms_file_descriptor = dirfd(dms_dir);
|
||||
if (dms_file_descriptor < 0)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nProblem getting the file descriptor of a newly created OBIDMS directory");
|
||||
free(directory_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create the arrays directory
|
||||
if (mkdirat(dms_file_descriptor, ARRAY_DIR_NAME, 00777) < 0)
|
||||
{
|
||||
obi_set_errno(OBI_ARRAY_ERROR);
|
||||
obidebug(1, "\nProblem creating an arrays directory");
|
||||
free(directory_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(directory_name);
|
||||
|
||||
return obi_open_dms(dms_name);
|
||||
@ -143,6 +174,7 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
||||
OBIDMS_p dms;
|
||||
char* directory_name;
|
||||
DIR* directory;
|
||||
int dms_file_descriptor;
|
||||
|
||||
dms = NULL;
|
||||
|
||||
@ -191,6 +223,26 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
||||
strcpy(dms->directory_name, directory_name);
|
||||
dms->directory = directory;
|
||||
|
||||
// Get file descriptor of DMS directory to open the arrays directory
|
||||
dms_file_descriptor = dirfd(directory);
|
||||
if (dms_file_descriptor < 0)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError getting the file descriptor for a newly created OBIDMS directory");
|
||||
free(directory_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open the arrays directory
|
||||
dms->array_directory = private_opendirat(dms_file_descriptor, ARRAY_DIR_NAME);
|
||||
if (dms->array_directory == NULL)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError opening the arrays directory");
|
||||
free(directory_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(directory_name);
|
||||
|
||||
return dms;
|
||||
@ -223,7 +275,14 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
if (closedir(dms->directory) < 0)
|
||||
{
|
||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
||||
obidebug(1, "\nError closing an OBIDSM directory");
|
||||
obidebug(1, "\nError closing an OBIDMS directory");
|
||||
free(dms);
|
||||
return -1;
|
||||
}
|
||||
if (closedir(dms->array_directory) < 0)
|
||||
{
|
||||
obi_set_errno(OBI_ARRAY_ERROR);
|
||||
obidebug(1, "\nError closing an array directory");
|
||||
free(dms);
|
||||
return -1;
|
||||
}
|
||||
|
109
src/obidms.h
@ -1,13 +1,19 @@
|
||||
/*
|
||||
* obidms.h
|
||||
*
|
||||
* Created on: 23 mai 2015
|
||||
* Author: coissac
|
||||
/********************************************************************
|
||||
* OBIDMS header file *
|
||||
********************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidmscolumn.h
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
* @date 23 May 2015
|
||||
* @brief Header file for the OBIDMS functions and structures.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMS_H_
|
||||
#define OBIDMS_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
@ -17,38 +23,42 @@
|
||||
|
||||
#include "obierrno.h"
|
||||
|
||||
#define OBIDMS_MAX_NAME (2048) /**< The maximum length of an OBIDMS name
|
||||
*/
|
||||
|
||||
/** @brief A structure describing an OBIDMS instance
|
||||
#define OBIDMS_MAX_NAME (2048) /**< The maximum length of an OBIDMS name.
|
||||
*/
|
||||
#define ARRAY_DIR_NAME "arrays" /**< The name of the arrays directory.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief A structure describing an OBIDMS instance
|
||||
*
|
||||
* A pointer to this structure is returned on creation
|
||||
* and opening of an OBITools Data Management System (DMS)
|
||||
*/
|
||||
|
||||
typedef struct OBIDMS {
|
||||
char directory_name[OBIDMS_MAX_NAME+1]; /**< The name of the directory
|
||||
* containing the DMS
|
||||
* containing the DMS.
|
||||
*/
|
||||
DIR* directory; /**< A directory entry usable to
|
||||
* refer and scan the database directory
|
||||
* refer and scan the database directory.
|
||||
*/
|
||||
DIR* array_directory; /**< A directory entry usable to
|
||||
* refer and scan the array directory.
|
||||
*/
|
||||
} OBIDMS_t, *OBIDMS_p;
|
||||
|
||||
|
||||
/*@
|
||||
* @brief Checks if an OBIDMS exists
|
||||
/**
|
||||
* @brief Checks if an OBIDMS exists.
|
||||
*
|
||||
* @param dms_name a pointer to a C string containing the name of the database.
|
||||
* The actual directory name used to store the DMS will be
|
||||
* `<dms_name>.obidms`.
|
||||
* @param dms_name A pointer to a C string containing the name of the database.
|
||||
*
|
||||
* @return an integer value indicating the status of the database
|
||||
* @retvalue 1 the database exist
|
||||
* @retvalue 0 the database does not exist
|
||||
* @retvalue -1 an error occurred
|
||||
* @returns An integer value indicating the status of the database
|
||||
* @retval 1 if the database exists.
|
||||
* @retval 0 if the database does not exist.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
@ -62,79 +72,64 @@ int obi_dms_exists(const char* dms_name);
|
||||
* if a directory with this name does not already exist
|
||||
* before creating the new database.
|
||||
*
|
||||
* @param dms_name a pointer to a C string containing the name of the database.
|
||||
* The actual directory name used to store the DMS will be
|
||||
* `<name>.obidms`
|
||||
* A directory to store obiarrays is also created.
|
||||
*
|
||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||
* @retval NULL on error and the `obi_errno` variable is set.
|
||||
* @param dms_name A pointer to a C string containing the name of the database.
|
||||
* The actual directory name used to store the DMS will be
|
||||
* `<dms_name>.obidms`.
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* @returns A pointer to an OBIDMS structure describing the newly created DMS.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_p obi_create_dms(const char *dms_name);
|
||||
OBIDMS_p obi_create_dms(const char* dms_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens an existing OBITools Data Management instance (OBIDMS).
|
||||
*
|
||||
* @param dms_name a pointer to a C string containing the name of the database.
|
||||
* The actual directory name used to store the DMS will be
|
||||
* `<name>.obidms`
|
||||
* @param dms_name A pointer to a C string containing the name of the database.
|
||||
*
|
||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||
* @retval NULL on error and the `obi_errno`variable is set.
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* @returns A pointer to an OBIDMS structure describing the opened DMS.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_p obi_open_dms(const char *dms_name);
|
||||
OBIDMS_p obi_open_dms(const char* dms_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a new OBIDMS instance.
|
||||
* @brief Creates or opens a new OBIDMS instance.
|
||||
*
|
||||
* If the database already exists, this function opens it, otherwise it
|
||||
* creates a new database.
|
||||
*
|
||||
* @param dms_name a pointer to a C string containing the name of the database.
|
||||
* The actual directory name used to store the DMS is
|
||||
* `<name>.obidms`
|
||||
* @param dms_name A pointer to a C string containing the name of the database.
|
||||
*
|
||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||
* @retval NULL on error and the `obi_errno`variable is set.
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* @returns A pointer to an OBIDMS structure describing the OBIDMS.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_p obi_dms(const char *dms_name);
|
||||
OBIDMS_p obi_dms(const char* dms_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Closes an opened OBITools Data Management instance (OBIDMS).
|
||||
*
|
||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
||||
* @param dms A pointer as returned by obi_create_dms() or obi_open_dms().
|
||||
*
|
||||
* @return an integer value indicating the success of the operation. Even on
|
||||
* error, the `OBIDMS` structure is freed
|
||||
* @retvalue 0 on success
|
||||
* @retvalue -1 on failure and the `obi_errno` variable is set.
|
||||
* @returns An integer value indicating the success of the operation. Even on
|
||||
* error, the `OBIDMS` structure is freed.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred?-.
|
||||
*
|
||||
* @see obi_create_dms()
|
||||
* @see obi_open_dms()
|
||||
|
@ -1,12 +1,12 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column functions *
|
||||
* OBIDMS columns functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidmscolumn.c
|
||||
* @author Celine Mercier
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 22 May 2015
|
||||
* @brief Functions for the shared elements of all the OBIColumn structures.
|
||||
* @brief Functions shared by all the OBIDMS columns.
|
||||
*/
|
||||
|
||||
|
||||
@ -16,10 +16,11 @@
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <sys/mman.h> /* mmap() is defined in this header */
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obidmscolumndir.h"
|
||||
@ -28,9 +29,10 @@
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "obiarray.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
@ -47,18 +49,16 @@
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
* @param column_name the name of the OBIDMS column.
|
||||
* @param column_name The name of the OBIDMS column file.
|
||||
* @param version_number The version number of the OBIDMS column file.
|
||||
*
|
||||
* @return a pointer to the column file name
|
||||
* @retvalue NULL if an error occurs
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* @returns A pointer to the column file name.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
static char *build_column_file_name(const char *column_name, obiversion_t version_number);
|
||||
static char* build_column_file_name(const char* column_name, obiversion_t version_number);
|
||||
|
||||
|
||||
/**
|
||||
@ -69,32 +69,28 @@ static char *build_column_file_name(const char *column_name, obiversion_t versio
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
* @param column_name the name of the OBIDMS column.
|
||||
* @param column_name The name of the OBIDMS column.
|
||||
*
|
||||
* @return a pointer to the version file name
|
||||
* @retvalue NULL if an error occurs
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
||||
* @returns A pointer to the version file name.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
static char *build_version_file_name(const char *column_name);
|
||||
static char* build_version_file_name(const char* column_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function returning a new column version number
|
||||
* in the `dms` database
|
||||
* in the OBIDMS database.
|
||||
*
|
||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
||||
* @param column_name the name of the column
|
||||
* @param block is the call is blocking or not
|
||||
* - `true` the call is blocking
|
||||
* - `false` the call is not blocking
|
||||
* @param column_directory A pointer as returned by obi_create_column_directory() or obi_open_column_directory().
|
||||
* @param block Whether the call is blocking or not:
|
||||
* - `true` the call is blocking
|
||||
* - `false` the call is not blocking.
|
||||
*
|
||||
* @return the bigger version number used for this column
|
||||
* @retvalue -1 if the column does not exist
|
||||
* @returns The next version number for this column.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
@ -104,50 +100,50 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
|
||||
|
||||
/**
|
||||
* @brief Internal function creating a new column version file
|
||||
* in the `dms` database
|
||||
* in the OBIDMS database.
|
||||
*
|
||||
* The new file is initialized with the minimum version number `0`.
|
||||
*
|
||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
||||
* @param column_name the name of the column
|
||||
* @param column_directory A pointer as returned by obi_create_column_directory() or obi_open_column_directory().
|
||||
*
|
||||
* @return the next usable version number for this column : `0`
|
||||
* @retvalue -1 if the column does not exist
|
||||
* @returns The next usable version number for this column : `0`.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
static int create_version_file(OBIDMS_column_directory_p column_directory);
|
||||
static obiversion_t create_version_file(OBIDMS_column_directory_p column_directory);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function setting the elements names of the lines of a
|
||||
* column in the header of the OBIDMS column structure.
|
||||
* column in the header of the OBIDMS column structure.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @param elements_names the names of the elements with ';' as separator
|
||||
* @param column A pointer as returned by obi_create_column().
|
||||
* @param elements_names The names of the elements with ';' as separator.
|
||||
*
|
||||
* @return 0 if the operation was successfully completed
|
||||
* @retvalue -1 if an error occurred
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_elements_names(OBIDMS_column_p column, const char* elements_names);
|
||||
static int obi_column_set_elements_names(OBIDMS_column_p column, const char* elements_names);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function computing how many lines of an OBIDMS column fill in a memory page.
|
||||
* @brief Internal function computing how many lines of an OBIDMS column
|
||||
* fit in a memory page.
|
||||
*
|
||||
* @param data_type the data OBIType
|
||||
* @param nb_elements_per_line the number of elements per line
|
||||
* @param data_type The data OBIType.
|
||||
* @param nb_elements_per_line The number of elements per line.
|
||||
*
|
||||
* @return the line count for one memory page
|
||||
* @returns The line count for one memory page.
|
||||
*
|
||||
* @since September 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
size_t get_line_count_per_page(OBIType_t data_type, size_t nb_elements_per_line);
|
||||
static index_t get_line_count_per_page(OBIType_t data_type, index_t nb_elements_per_line);
|
||||
|
||||
|
||||
/************************************************************************
|
||||
@ -157,35 +153,35 @@ size_t get_line_count_per_page(OBIType_t data_type, size_t nb_elements_per_line)
|
||||
************************************************************************/
|
||||
|
||||
|
||||
static char *build_column_file_name(const char *column_name, obiversion_t version_number)
|
||||
static char* build_column_file_name(const char* column_name, obiversion_t version_number)
|
||||
{
|
||||
char *filename;
|
||||
char* file_name;
|
||||
|
||||
// Build the database directory name
|
||||
if (asprintf(&filename,"%s@%d.odc", column_name, version_number) < 0)
|
||||
// Build the file name
|
||||
if (asprintf(&file_name,"%s@%d.odc", column_name, version_number) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_MEMORY_ERROR);
|
||||
obidebug(1, "\nError building a column file name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return filename;
|
||||
return file_name;
|
||||
}
|
||||
|
||||
|
||||
static char *build_version_file_name(const char *column_name)
|
||||
static char* build_version_file_name(const char* column_name)
|
||||
{
|
||||
char *filename;
|
||||
char* file_name;
|
||||
|
||||
// Build the database directory name
|
||||
if (asprintf(&filename,"%s.odv", column_name) < 0)
|
||||
// Build the file name
|
||||
if (asprintf(&file_name,"%s.odv", column_name) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_MEMORY_ERROR);
|
||||
obidebug(1, "\nError building a version file name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return filename;
|
||||
return file_name;
|
||||
}
|
||||
|
||||
|
||||
@ -232,10 +228,10 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
|
||||
else
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError opening a version file");
|
||||
free(version_file_name);
|
||||
return -1;
|
||||
}
|
||||
obidebug(1, "\nError opening a version file");
|
||||
free(version_file_name);
|
||||
}
|
||||
|
||||
// Test if the version file size is ok
|
||||
@ -346,7 +342,7 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
|
||||
}
|
||||
|
||||
|
||||
static int create_version_file(OBIDMS_column_directory_p column_directory)
|
||||
static obiversion_t create_version_file(OBIDMS_column_directory_p column_directory)
|
||||
{
|
||||
off_t loc_size;
|
||||
obiversion_t version_number;
|
||||
@ -467,7 +463,7 @@ int obi_column_set_elements_names(OBIDMS_column_p column, const char* elements_n
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t get_line_count_per_page(OBIType_t data_type, size_t nb_elements_per_line)
|
||||
index_t get_line_count_per_page(OBIType_t data_type, index_t nb_elements_per_line)
|
||||
{
|
||||
return getpagesize() / (obi_sizeof(data_type) * nb_elements_per_line);
|
||||
}
|
||||
@ -599,28 +595,30 @@ obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms, const char* c
|
||||
|
||||
size_t obi_get_platform_header_size()
|
||||
{
|
||||
return getpagesize() * 1;
|
||||
return getpagesize() * 2;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
OBIType_t data_type,
|
||||
size_t nb_lines,
|
||||
size_t nb_elements_per_line,
|
||||
const char* elements_names)
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* array_name)
|
||||
{
|
||||
OBIDMS_column_p new_column;
|
||||
OBIDMS_column_p new_column;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
OBIDMS_column_header_p header;
|
||||
size_t file_size;
|
||||
obiversion_t version_number;
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
int column_dir_file_descriptor;
|
||||
size_t header_size;
|
||||
size_t data_size;
|
||||
size_t minimum_line_count;
|
||||
OBIDMS_column_header_p header;
|
||||
OBIDMS_array_p array;
|
||||
size_t file_size;
|
||||
obiversion_t version_number;
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
int column_dir_file_descriptor;
|
||||
size_t header_size;
|
||||
size_t data_size;
|
||||
index_t minimum_line_count;
|
||||
|
||||
new_column = NULL;
|
||||
|
||||
@ -635,24 +633,29 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
obidebug(1, "\nCan't create column because of empty column name");
|
||||
return NULL;
|
||||
}
|
||||
if ((data_type < 1) || (data_type > 4))
|
||||
if ((data_type < 1) || (data_type > 5))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of invalid data type");
|
||||
return NULL;
|
||||
}
|
||||
if ((data_type == 5) && (array_name == NULL))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of empty array name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// The initial line count should be between the minimum (corresponding to the page size) and the maximum allowed
|
||||
minimum_line_count = get_line_count_per_page(data_type, nb_elements_per_line);
|
||||
if (nb_lines > MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of line count greater than the maximum allowed (%lld)", MAXIMUM_LINE_COUNT);
|
||||
obidebug(1, "\nCan't create column because of line count greater than the maximum allowed (%d)", MAXIMUM_LINE_COUNT);
|
||||
return NULL;
|
||||
}
|
||||
else if (nb_lines < minimum_line_count)
|
||||
nb_lines = minimum_line_count;
|
||||
|
||||
// The number of elements names should be equal to the number of elements per line
|
||||
|
||||
if ((elements_names == NULL) && (nb_elements_per_line > 1))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because no elements names were given for a number of elements per line greater than 1");
|
||||
@ -661,7 +664,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
else if ((elements_names != NULL) && (nb_elements_per_line > 1))
|
||||
{
|
||||
char* token;
|
||||
size_t n = 0;
|
||||
index_t n = 0;
|
||||
token = strdup(elements_names);
|
||||
token = strtok(token, ";");
|
||||
while (token != NULL)
|
||||
@ -723,6 +726,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
if (column_file_descriptor < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError opening a column file");
|
||||
free(column_file_name);
|
||||
return NULL;
|
||||
}
|
||||
@ -800,11 +804,28 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
header->creation_date = time(NULL);
|
||||
header->version = version_number;
|
||||
header->cloned_from = -1;
|
||||
header->comments[0] = 0x0;
|
||||
header->comments[0] = 0x0; // TODO
|
||||
|
||||
obi_column_set_elements_names(new_column, elements_names);
|
||||
|
||||
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
|
||||
strncpy(header->name, column_name, OBIDMS_COLUMN_MAX_NAME);
|
||||
|
||||
// If the data type is OBI_IDX, the associated obi_array is opened or created
|
||||
if (data_type == 5)
|
||||
{
|
||||
array = obi_array(dms, array_name);
|
||||
if (array == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening or creating the array associated with a column");
|
||||
munmap(new_column->header, header_size);
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
free(new_column);
|
||||
return NULL;
|
||||
}
|
||||
new_column->array = array;
|
||||
strncpy(header->array_name, array_name, ARRAY_MAX_NAME);
|
||||
}
|
||||
|
||||
// Fill the data with NA values
|
||||
obi_ini_to_NA_values(new_column, 0, nb_lines);
|
||||
@ -816,10 +837,13 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversion_t version_number)
|
||||
OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
obiversion_t version_number)
|
||||
{
|
||||
OBIDMS_column_p column;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
OBIDMS_array_p array;
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
int column_dir_file_descriptor;
|
||||
@ -911,8 +935,9 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversio
|
||||
// TODO Check endianness?
|
||||
|
||||
// Compute data size from the informations in the header
|
||||
data_size = ((column->header)->line_count) * sizeof((column->header)->data_type);
|
||||
data_size = obi_array_sizeof((column->header)->data_type, (column->header)->line_count, (column->header)->nb_elements_per_line);
|
||||
|
||||
// Map the data
|
||||
column->data = mmap(NULL,
|
||||
data_size,
|
||||
PROT_READ,
|
||||
@ -934,6 +959,22 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversio
|
||||
|
||||
column->writable = false;
|
||||
|
||||
// If the data type is OBI_IDX, the associated obi_array is opened or created
|
||||
if ((column->header)->data_type == 5)
|
||||
{
|
||||
array = obi_array(dms, (column->header)->array_name);
|
||||
if (array == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening the array associated with a column");
|
||||
munmap(column->header, header_size);
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
free(column);
|
||||
return NULL;
|
||||
}
|
||||
column->array = array;
|
||||
}
|
||||
|
||||
free(column_file_name);
|
||||
close(column_file_descriptor);
|
||||
|
||||
@ -941,12 +982,15 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversio
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms, const char* column_name, obiversion_t version_number, bool clone_data)
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
obiversion_t version_number,
|
||||
bool clone_data)
|
||||
{
|
||||
OBIDMS_column_p column_to_clone;
|
||||
OBIDMS_column_p new_column;
|
||||
size_t nb_lines;
|
||||
size_t nb_elements_per_line;
|
||||
index_t nb_lines;
|
||||
index_t nb_elements_per_line;
|
||||
size_t data_size;
|
||||
OBIType_t data_type;
|
||||
|
||||
@ -972,7 +1016,8 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, const char* column_name, obiversi
|
||||
data_type,
|
||||
nb_lines,
|
||||
nb_elements_per_line,
|
||||
(column_to_clone->header)->elements_names);
|
||||
(column_to_clone->header)->elements_names,
|
||||
(column_to_clone->header)->array_name);
|
||||
|
||||
if (new_column == NULL)
|
||||
{
|
||||
@ -1010,7 +1055,7 @@ int obi_close_column(OBIDMS_column_p column)
|
||||
size_t data_size;
|
||||
|
||||
// Munmap data
|
||||
data_size = (column->header)->line_count * (column->header)->nb_elements_per_line * sizeof((column->header)->data_type);
|
||||
data_size = obi_array_sizeof((column->header)->data_type, (column->header)->line_count, (column->header)->nb_elements_per_line);
|
||||
if (munmap(column->data, data_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
@ -1026,25 +1071,27 @@ int obi_close_column(OBIDMS_column_p column)
|
||||
return -1;
|
||||
}
|
||||
|
||||
obi_close_column_directory(column->column_directory);
|
||||
|
||||
free(column);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int obi_truncate_column_to_lines_used(OBIDMS_column_p column)
|
||||
int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it necessary to unmap/remap?
|
||||
{
|
||||
size_t file_size;
|
||||
size_t data_size;
|
||||
size_t new_line_count;
|
||||
index_t new_line_count;
|
||||
double multiple;
|
||||
int column_dir_file_descriptor;
|
||||
int column_file_descriptor;
|
||||
char* column_file_name;
|
||||
|
||||
// Compute the new line count = the number of lines used rounded to the nearest multiple of page size
|
||||
multiple = ceil((double) ((column->header)->lines_used * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)) / (double) getpagesize());
|
||||
new_line_count = (int) multiple * getpagesize();
|
||||
// Compute the new line count = the number of lines used rounded to the nearest greater multiple of page size greater than 0
|
||||
multiple = ceil((double) (ONE_IF_ZERO((column->header)->lines_used) * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)) / (double) getpagesize());
|
||||
new_line_count = floor((((int) multiple) * getpagesize()) / ((column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type))); // TODO is it safe to cast like this?
|
||||
|
||||
// Check that it is actually greater than the current number of lines allocated in the file, otherwise no need to truncate
|
||||
if ((column->header)->line_count == new_line_count)
|
||||
@ -1133,8 +1180,8 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
size_t old_data_size;
|
||||
size_t new_data_size;
|
||||
size_t header_size;
|
||||
size_t old_line_count;
|
||||
size_t new_line_count;
|
||||
index_t old_line_count;
|
||||
index_t new_line_count;
|
||||
int column_dir_file_descriptor;
|
||||
int column_file_descriptor;
|
||||
char* column_file_name;
|
||||
@ -1168,7 +1215,7 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
|
||||
// Calculate the new file size
|
||||
old_line_count = (column->header)->line_count;
|
||||
new_line_count = old_line_count * GROWTH_FACTOR;
|
||||
new_line_count = old_line_count * COLUMN_GROWTH_FACTOR;
|
||||
|
||||
if (new_line_count > MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
@ -1179,7 +1226,7 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
return -1;
|
||||
}
|
||||
old_data_size = obi_array_sizeof((column->header)->data_type, old_line_count, (column->header)->nb_elements_per_line);
|
||||
new_data_size = old_data_size * GROWTH_FACTOR;
|
||||
new_data_size = old_data_size * COLUMN_GROWTH_FACTOR;
|
||||
header_size = (column->header)->header_size;
|
||||
file_size = header_size + new_data_size;
|
||||
|
||||
@ -1193,7 +1240,8 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Remap the data: try enlarging mapped region (this actually never works on my mac without the MAP_FIXED flag which overwrites everything)
|
||||
// Remap the data: try enlarging mapped region (TODO this actually never works on my mac without the MAP_FIXED flag which overwrites everything)
|
||||
// TODO : makes separate function even if it's only used here?
|
||||
//obidebug(2, "\ntry enlarging mapped region: old size = %ld, new size = %ld, size = %ld", old_data_size, new_data_size, new_data_size - old_data_size);
|
||||
new_data = mmap(column->data,
|
||||
new_data_size - old_data_size,
|
||||
@ -1267,11 +1315,14 @@ int obi_truncate_and_close_column(OBIDMS_column_p column)
|
||||
}
|
||||
|
||||
|
||||
void obi_ini_to_NA_values(OBIDMS_column_p column, size_t start, size_t nb_lines)
|
||||
void obi_ini_to_NA_values(OBIDMS_column_p column,
|
||||
index_t first_line_nb,
|
||||
index_t nb_lines)
|
||||
{
|
||||
size_t i, end, nb_elements;
|
||||
index_t i, start, end, nb_elements;
|
||||
|
||||
nb_elements = nb_lines*((column->header)->nb_elements_per_line);
|
||||
start = first_line_nb*((column->header)->nb_elements_per_line);
|
||||
end = start + nb_elements;
|
||||
|
||||
switch ((column->header)->data_type) {
|
||||
@ -1304,38 +1355,14 @@ void obi_ini_to_NA_values(OBIDMS_column_p column, size_t start, size_t nb_lines)
|
||||
|
||||
case OBI_IDX: for (i=start;i<end;i++)
|
||||
{
|
||||
*(((obiidx_t*) (column->data)) + i) = OBIIdx_NA;
|
||||
*(((index_t*) (column->data)) + i) = OBIIdx_NA;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void obi_column_make_unwritable(OBIDMS_column_p column)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
OBIType_t obi_column_get_data_type_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) // TODO ADD VERSION ARGUMENT
|
||||
{
|
||||
OBIDMS_column_header_p header;
|
||||
OBIDMS_column_directory_p column_directory;
|
||||
@ -1343,7 +1370,6 @@ OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms, const char* column_na
|
||||
int column_file_descriptor;
|
||||
int column_dir_file_descriptor;
|
||||
size_t header_size;
|
||||
OBIType_t data_type;
|
||||
obiversion_t version_number;
|
||||
|
||||
// Get the column directory structure associated to the column
|
||||
@ -1351,7 +1377,7 @@ OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms, const char* column_na
|
||||
if (column_directory == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening a column directory structure");
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the file descriptor associated to the column directory
|
||||
@ -1361,25 +1387,25 @@ OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms, const char* column_na
|
||||
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError getting the file descriptor of a column directory");
|
||||
obi_close_column_directory(column_directory);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Calculate the header size
|
||||
header_size = obi_get_platform_header_size();
|
||||
header_size = obi_get_platform_header_size(); // TODO read in header itself
|
||||
|
||||
// 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 -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the column file name
|
||||
column_file_name = build_column_file_name(column_name, version_number);
|
||||
if (column_file_name == NULL)
|
||||
{
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open the column file (READ-ONLY)
|
||||
@ -1389,7 +1415,7 @@ OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms, const char* column_na
|
||||
obidebug(1, "\nError opening a column file");
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
free(column_file_name);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Fill the header structure
|
||||
@ -1407,124 +1433,42 @@ OBIType_t obi_column_get_data_type_from_name(OBIDMS_p dms, const char* column_na
|
||||
obidebug(1, "\nError mmapping the header of a column");
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check endianness?
|
||||
|
||||
data_type = header->data_type;
|
||||
// TODO Check endianness?
|
||||
|
||||
free(column_file_name);
|
||||
close(column_file_descriptor);
|
||||
munmap(header, header_size);
|
||||
return data_type;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
|
||||
size_t obi_column_get_line_count_from_name(OBIDMS_p dms, const char* column_name)
|
||||
int obi_unmap_header(OBIDMS_column_header_p header)
|
||||
{
|
||||
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;
|
||||
size_t line_count;
|
||||
obiversion_t version_number;
|
||||
|
||||
// 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 -1;
|
||||
}
|
||||
|
||||
// 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 -1;
|
||||
}
|
||||
|
||||
// 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 -1;
|
||||
}
|
||||
|
||||
// Get the column file name
|
||||
column_file_name = build_column_file_name(column_name, version_number);
|
||||
if (column_file_name == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 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 -1;
|
||||
}
|
||||
|
||||
// Fill the header structure
|
||||
header = mmap(NULL,
|
||||
header_size,
|
||||
PROT_READ,
|
||||
MAP_SHARED,
|
||||
column_file_descriptor,
|
||||
0
|
||||
);
|
||||
|
||||
if (header == MAP_FAILED)
|
||||
if (munmap(header, header->header_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError mmapping the header of a column");
|
||||
close(column_file_descriptor);
|
||||
free(column_file_name);
|
||||
obidebug(1, "\nError munmapping a column header");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check endianness?
|
||||
|
||||
line_count = header->line_count;
|
||||
|
||||
free(column_file_name);
|
||||
close(column_file_descriptor);
|
||||
munmap(header, header_size);
|
||||
return line_count;
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_elements_names(OBIDMS_column_p column)
|
||||
{
|
||||
return (column->header)->elements_names;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// 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)
|
||||
index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name)
|
||||
{
|
||||
char* elements_names;
|
||||
char* name;
|
||||
size_t element_index;
|
||||
index_t element_index;
|
||||
|
||||
elements_names = strdup((column->header)->elements_names);
|
||||
if (elements_names == NULL)
|
||||
{
|
||||
obidebug(1, "\nError strdup-ing the elements names");
|
||||
return -1;
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
|
||||
element_index = 0;
|
||||
@ -1550,14 +1494,32 @@ size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char
|
||||
|
||||
obidebug(1, "\nCan't find an element name");
|
||||
free(elements_names);
|
||||
return -1;
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
|
||||
|
||||
size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column)
|
||||
char* obi_column_format_date(time_t date)
|
||||
{
|
||||
return (column->header)->nb_elements_per_line;
|
||||
char* formatted_time;
|
||||
struct tm* tmp;
|
||||
|
||||
formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char));
|
||||
|
||||
tmp = localtime(&date);
|
||||
if (tmp == NULL)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
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 a date");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return formatted_time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column header file *
|
||||
* OBIDMS columns header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidmscolumn.h
|
||||
* @author Celine Mercier
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 12 May 2015
|
||||
* @brief Header file for the shared elements of all the OBIDMS column structures.
|
||||
* @brief Header file for the functions and structures shared by all the OBIDMS columns.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMN_H_
|
||||
#define OBIDMSCOLUMN_H_
|
||||
|
||||
@ -24,65 +25,86 @@
|
||||
#include "obierrno.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "obidmscolumndir.h"
|
||||
#include "obiarray.h"
|
||||
|
||||
#define ELEMENTS_NAMES_MAX (2048)
|
||||
#define GROWTH_FACTOR (2)
|
||||
#define MAXIMUM_LINE_COUNT (1000000)
|
||||
|
||||
#define ONE_IF_ZERO(x) (((x)==0)?1:(x)) /**< If x is equal to 0, x takes the value 1.
|
||||
*/
|
||||
#define ELEMENTS_NAMES_MAX (2048) /**< The maximum length of the list of elements names.
|
||||
*/
|
||||
#define COLUMN_GROWTH_FACTOR (2) /**< The growth factor when a column is enlarged.
|
||||
*/
|
||||
#define MAXIMUM_LINE_COUNT (1000000) /**< The maximum line count for the data of a column. //TODO
|
||||
*/
|
||||
#define FORMATTED_TIME_LENGTH (1024) /**< The length allocated for the character string containing a formatted date
|
||||
*/
|
||||
|
||||
|
||||
typedef int32_t obiversion_t; /**< Used to store the column version number
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief OBIColumnHeader structure.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief OBIDMS column header structure.
|
||||
*/
|
||||
typedef struct OBIDMS_column_header {
|
||||
bool little_endian; /**< endianness of the column:
|
||||
* - `true` on little endian platforms
|
||||
* - `false` on big endian platforms
|
||||
*
|
||||
* @see obi_is_little_endian()
|
||||
*/
|
||||
int header_size; /**< size of the header in bytes */
|
||||
size_t line_count; /**< number of lines of data */
|
||||
size_t lines_used; /**< number of lines of data used */
|
||||
size_t nb_elements_per_line; /**< number of elements per line (default : 1) */
|
||||
char elements_names[ELEMENTS_NAMES_MAX+1]; /**< names of the line elements (default : "["column_name"]") */
|
||||
OBIType_t data_type; /**< type of the data */
|
||||
time_t creation_date; /**< date of creation of the file */
|
||||
obiversion_t version; /**< version of the OBIColumn */
|
||||
obiversion_t cloned_from; /**< version of the OBIColumn from which the column was cloned from (-1 if it does not come from cloning).*/
|
||||
char name[OBIDMS_MAX_COLNAME+1]; /**< The column name as a NULL
|
||||
* terminated string.
|
||||
*/
|
||||
char comments[1]; /**< comments stored as a classical
|
||||
zero end C string.
|
||||
The size of the comment is only limited
|
||||
by the header size
|
||||
*/
|
||||
bool little_endian; /**< Endianness of the column:
|
||||
* - `true` on little endian platforms
|
||||
* - `false` on big endian platforms
|
||||
* @see obi_is_little_endian()
|
||||
*/
|
||||
size_t header_size; /**< Size of the header in bytes.
|
||||
*/
|
||||
index_t line_count; /**< Number of lines of data allocated.
|
||||
*/
|
||||
index_t lines_used; /**< Number of lines of data used.
|
||||
*/
|
||||
index_t nb_elements_per_line; /**< Number of elements per line (default: 1).
|
||||
*/
|
||||
char elements_names[ELEMENTS_NAMES_MAX+1]; /**< Names of the line elements with ';' as separator
|
||||
* (should be the column name if one element per line).
|
||||
*/
|
||||
OBIType_t data_type; /**< Type of the data.
|
||||
*/
|
||||
time_t creation_date; /**< Date of creation of the file.
|
||||
*/
|
||||
obiversion_t version; /**< Version of the column.
|
||||
*/
|
||||
obiversion_t cloned_from; /**< Version of the column from which this column
|
||||
* was cloned from (-1 if it was not created by cloning
|
||||
* another column).
|
||||
*/
|
||||
char name[OBIDMS_COLUMN_MAX_NAME+1]; /**< The column name as a NULL terminated string.
|
||||
*/
|
||||
char array_name[ARRAY_MAX_NAME+1]; /**< If there is one, the obi_array name as a NULL terminated string.
|
||||
*/
|
||||
char comments[1]; /**< Comments stored as a classical zero end C string.
|
||||
* The size of the comment is only limited by the header size.
|
||||
*/
|
||||
} OBIDMS_column_header_t, *OBIDMS_column_header_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Structure describing a Column of the OBITools DMS
|
||||
* @brief OBIDMS column structure.
|
||||
*
|
||||
* A data structure of this type is returned by the functions
|
||||
* creating, opening or cloning an OBIDMS_column.
|
||||
* creating, opening or cloning an OBIDMS column.
|
||||
*/
|
||||
typedef struct OBIDMS_column {
|
||||
OBIDMS_p dms; /**< A pointer to a DMS instance */
|
||||
OBIDMS_column_directory_p column_directory; /**< A pointer to an OBIDMS column directory instance */
|
||||
OBIDMS_column_header_p header; /**< A pointer to the header of the column */
|
||||
void* data; /**< A `void` pointer to the beginning of the
|
||||
* data.
|
||||
OBIDMS_p dms; /**< A pointer to the OBIDMS structure to which the column belongs.
|
||||
*/
|
||||
OBIDMS_column_directory_p column_directory; /**< A pointer to the OBIDMS column directory structure to which the column belongs.
|
||||
*/
|
||||
OBIDMS_column_header_p header; /**< A pointer to the header of the column.
|
||||
*/
|
||||
OBIDMS_array_p array; /**< A pointer to the array associated with the column if there is one.
|
||||
*/
|
||||
void* data; /**< A `void` pointer to the beginning of the data.
|
||||
*
|
||||
* @warning never use this member directly
|
||||
* outside of the code of the
|
||||
* low level functions
|
||||
* of the OBITools DMS
|
||||
* @warning Never use this member directly outside of the code of the
|
||||
* low level functions of the OBIDMS.
|
||||
*/
|
||||
bool writable; /**< Indicates if the column is writable or not.
|
||||
bool writable; /**< Indicates if the column is writable or not. TODO delete?
|
||||
* - `true` the column is writable
|
||||
* - `false` the column is read-only
|
||||
*
|
||||
@ -93,23 +115,30 @@ typedef struct OBIDMS_column {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the latest version of a column in a column directory
|
||||
* @brief Returns the latest version number of a column in a column directory using the column directory structure.
|
||||
*
|
||||
* @param column_directory
|
||||
* @param column_directory A pointer as returned by obi_create_column_directory() or obi_open_column_directory().
|
||||
*
|
||||
* @return the latest version number kept in the version file
|
||||
* @return -1 if an error occurred
|
||||
* @returns The latest version number kept in the version file.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
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
|
||||
* @brief Returns the latest version of a column in a column directory using the column name.
|
||||
*
|
||||
* @param column_name
|
||||
* @param dms A pointer on an OBIDMS.
|
||||
* @param column_name The column name.
|
||||
*
|
||||
* @return the latest version number kept in the version file
|
||||
* @return -1 if an error occurred
|
||||
* @returns The latest version number kept in the version file.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms, const char* column_name);
|
||||
|
||||
@ -118,9 +147,9 @@ obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms, const char* c
|
||||
* @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.
|
||||
* Up to now the header size is defined as one time the page size.
|
||||
* As of now the header size is defined as one time the page size.
|
||||
*
|
||||
* @return a `size_t` value corresponding to the header size in bytes
|
||||
* @returns The header size in bytes.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
@ -131,30 +160,43 @@ size_t obi_get_platform_header_size();
|
||||
/**
|
||||
* @brief Creates a 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_lines the number of lines to be stored
|
||||
* The minimum data size allocated is one memory page, and the data is initialized to the NA value of the OBIType.
|
||||
* If there is an array associated with the column, it is opened or created if it does not already exist.
|
||||
*
|
||||
* @warning If there is one element per line, elements_names should be equal to column_name. // TODO change this condition?
|
||||
*
|
||||
* @param dms A pointer on an OBIDMS.
|
||||
* @param column_name The name of the new column.
|
||||
* @param data_type The OBIType code of the data.
|
||||
* @param nb_lines The number of lines to be stored.
|
||||
* @param nb_elements_per_line The number of elements per line.
|
||||
* @param elements_names The names of the elements with ';' as separator.
|
||||
* @param array_name The name of the array if there is one associated with the column.
|
||||
*
|
||||
* @returns A pointer on the newly created column structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
const char* column_name,
|
||||
OBIType_t type,
|
||||
size_t nb_lines,
|
||||
size_t nb_elements_per_line,
|
||||
const char* elements_names);
|
||||
const char* column_name,
|
||||
OBIType_t data_type,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* array_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens a column in read-only mode.
|
||||
*
|
||||
* @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 (if -1, the latest version number is retrieved)
|
||||
* @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 (if -1, the latest version is retrieved).
|
||||
*
|
||||
* @return a pointer to the opened column
|
||||
* @returns A pointer on the opened column structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -165,12 +207,13 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversio
|
||||
/**
|
||||
* @brief Clones a column, and returns a pointer to the writable new column.
|
||||
*
|
||||
* @param dms a pointer on an OBIDMS
|
||||
* @param column_name the name of the column to clone
|
||||
* @param version_number the version of the column that should be cloned (if -1, the latest version number is retrieved)
|
||||
* @param clone_data whether the data should be copied or not
|
||||
* @param dms A pointer on an OBIDMS.
|
||||
* @param column_name The name of the column to clone.
|
||||
* @param version_number The version of the column that should be cloned (if -1, the latest version is retrieved).
|
||||
* @param clone_data Whether the data should be copied or not.
|
||||
*
|
||||
* @return a pointer to the created column
|
||||
* @returns A pointer to the created column.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -181,10 +224,10 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, const char* column_name, obiversi
|
||||
/**
|
||||
* @brief Closes a column.
|
||||
*
|
||||
* @param column a pointer on an OBIDMS column
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @return 0 if the operation was successfully completed
|
||||
* @return -1 if an error occurred
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -193,12 +236,13 @@ int obi_close_column(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Truncates a column file to the number of lines used.
|
||||
* @brief Truncates a column file to the number of lines used rounded to the nearest
|
||||
* greater multiple of the page size.
|
||||
*
|
||||
* @param column a pointer on an OBIDMS column
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @return 0 if the operation was successfully completed
|
||||
* @return -1 if an error occurred
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -209,10 +253,10 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
|
||||
/**
|
||||
* @brief Enlarges a column file.
|
||||
*
|
||||
* @param column a pointer on an OBIDMS column
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @return 0 if the operation was successfully completed
|
||||
* @return -1 if an error occurred
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -221,12 +265,13 @@ int obi_enlarge_column(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Truncates a column file to the number of lines used and closes it.
|
||||
* @brief Truncates a column file to the number of lines used rounded to the nearest
|
||||
* greater multiple of the page size and closes it.
|
||||
*
|
||||
* @param column a pointer on an OBIDMS column
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @return 0 if the operation was successfully completed
|
||||
* @return -1 if an error occurred
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -235,134 +280,75 @@ int obi_truncate_and_close_column(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/*
|
||||
* @brief Sets the data in a column to the NA value of the data type.
|
||||
* @brief Sets the data in a column to the NA value of the data OBIType.
|
||||
*
|
||||
* @param column a pointer on an OBIDMS column
|
||||
* @param start the first line number of the block that should be set
|
||||
* @param nb_lines the number of lines that should be set
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
* @param start The first line number of the block that should be set.
|
||||
* @param nb_lines The number of lines that should be set.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
void obi_ini_to_NA_values(OBIDMS_column_p column, size_t start, size_t nb_lines);
|
||||
void obi_ini_to_NA_values(OBIDMS_column_p column, index_t first_line_nb, index_t nb_lines); // TO make private?
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the 'writable' header attribute of an OBIDMS column to False.
|
||||
* @brief Recovers the header of an OBIDMS column from the column name.
|
||||
*
|
||||
* @param column a pointer on an OBIDMS column
|
||||
* @warning The header structure has to be munmapped by the caller.
|
||||
*
|
||||
* @param dms A pointer on an OBIDMS.
|
||||
* @param column_name The name of an OBIDMS column.
|
||||
*
|
||||
* @returns A pointer on the mmapped header of the column.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char* column_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Munmap a mmapped header as returned by obi_column_get_header_from_name().
|
||||
*
|
||||
* @param header A pointer on the mmapped header structure.
|
||||
*
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_unmap_header(OBIDMS_column_header_p header);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the index of an element in an OBIDMS column from the element's name.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
* @param element_name The name of the element.
|
||||
*
|
||||
* @returns The index of the element in a line of the column.
|
||||
* @retval SIZE_MAX if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
void obi_column_make_unwritable(OBIDMS_column_p column);
|
||||
index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers the line count of 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.
|
||||
*
|
||||
* @return the line count of the column
|
||||
* @returns The date formatted in a way that is easy to read.
|
||||
*
|
||||
* @since July 2015
|
||||
* @since October 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
|
||||
*
|
||||
* @return 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
|
||||
*
|
||||
* @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 line count 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 line count of the column
|
||||
*
|
||||
* @since September 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
size_t obi_column_get_line_count_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);
|
||||
char* obi_column_format_date(time_t date);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_H_ */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column_bool functions *
|
||||
* OBIDMS_column_bool functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
@ -19,7 +19,7 @@
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@ -28,7 +28,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value)
|
||||
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
@ -57,7 +57,7 @@ int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
@ -69,56 +69,24 @@ obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t lin
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value)
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return OBIBool_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return OBIBool_NA;
|
||||
}
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return OBIBool_NA;
|
||||
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,10 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMN_BOOL_H_
|
||||
#define OBIDMSCOLUMN_BOOL_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -20,82 +24,76 @@
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @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.
|
||||
*
|
||||
* @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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obibool_t value);
|
||||
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, size_t element_idx, obibool_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @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.
|
||||
*
|
||||
* @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
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, size_t element_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the name of the element in the line.
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param element_name The name of the element that should be set in the line.
|
||||
* @param value The value that should be set.
|
||||
*
|
||||
* @param element_name the name of the element that should be set in the line
|
||||
* If empty, it is checked that there is only one element per 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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obibool_t value);
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL, using the name of the element in the line.
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param element_name The name of the element that should be recovered in the line.
|
||||
*
|
||||
* @param line_nb the number of the line where the value should be recovered
|
||||
*
|
||||
* @param element_name the name of the element that should be recovered in the line
|
||||
* If empty, it is checked that there is only one element per line
|
||||
*
|
||||
* @return the recovered value
|
||||
* @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_BOOL_H_ */
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@ -28,7 +28,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t value)
|
||||
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
@ -57,7 +57,7 @@ int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
@ -65,61 +65,28 @@ obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t lin
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIChar_NA;
|
||||
}
|
||||
|
||||
return *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t value)
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return OBIChar_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return OBIChar_NA;
|
||||
}
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return OBIChar_NA;
|
||||
return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,10 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMN_CHAR_H_
|
||||
#define OBIDMSCOLUMN_CHAR_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -20,82 +24,76 @@
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the index of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @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.
|
||||
*
|
||||
* @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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obichar_t* value);
|
||||
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @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.
|
||||
*
|
||||
* @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
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obichar_t* obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the name of the element in the line.
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param element_name The name of the element that should be set in the line.
|
||||
* @param value The value that should be set.
|
||||
*
|
||||
* @param element_name the name of the element that should be set in the line
|
||||
* If empty, it is checked that there is only one element per 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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obichar_t value);
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR, using the name of the element in the line.
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param element_name The name of the element that should be recovered in the line.
|
||||
*
|
||||
* @param line_nb the number of the line where the value should be recovered
|
||||
*
|
||||
* @param element_name the name of the element that should be recovered in the line
|
||||
* If empty, it is checked that there is only one element per line
|
||||
*
|
||||
* @return the recovered value
|
||||
* @retvalue NULL on failure and the `obi_errno` variable is set. TODO an other value should be chosen maybe
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_CHAR_H_ */
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@ -28,7 +28,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value)
|
||||
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
@ -57,7 +57,7 @@ int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
@ -69,56 +69,24 @@ obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t l
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value)
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return OBIFloat_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return OBIFloat_NA;
|
||||
}
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return OBIFloat_NA;
|
||||
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,10 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMN_FLOAT_H_
|
||||
#define OBIDMSCOLUMN_FLOAT_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -20,82 +24,76 @@
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the index of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @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.
|
||||
*
|
||||
* @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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obifloat_t value);
|
||||
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @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.
|
||||
*
|
||||
* @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
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the name of the element in the line.
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param element_name The name of the element that should be set in the line.
|
||||
* @param value The value that should be set.
|
||||
*
|
||||
* @param element_name the name of the element that should be set in the line
|
||||
* If empty, it is checked that there is only one element per 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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obifloat_t value);
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT, using the name of the element in the line.
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param element_name The name of the element that should be recovered in the line.
|
||||
*
|
||||
* @param line_nb the number of the line where the value should be recovered
|
||||
*
|
||||
* @param element_name the name of the element that should be recovered in the line
|
||||
* If empty, it is checked that there is only one element per line
|
||||
*
|
||||
* @return the recovered value
|
||||
* @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_FLOAT_H_ */
|
||||
|
||||
|
@ -1,124 +0,0 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column_idx functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidsmcolumn_idx.c
|
||||
* @author Celine Mercier
|
||||
* @date August 10th 2015
|
||||
* @brief Functions handling OBIColumns containing data with the OBIType OBI_IDX.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* 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_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
|
||||
// Set the value
|
||||
*(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obiidx_t obi_column_get_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
return *(((obiidx_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
obi_column_set_obiidx_with_elt_idx(column, line_nb, element_idx, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
|
||||
return obi_column_get_obiidx_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
@ -1,101 +0,0 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column_idx header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidsmcolumn_idx.h
|
||||
* @author Celine Mercier
|
||||
* @date August 10th 2015
|
||||
* @brief Header file for the functions handling OBIColumns containing data with the OBIType OBI_IDX.
|
||||
*/
|
||||
|
||||
|
||||
#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_IDX, using the index of the element in the line.
|
||||
*
|
||||
* @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_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiidx_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX.
|
||||
*
|
||||
* @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)
|
||||
*/
|
||||
obiidx_t obi_column_get_obiidx_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_IDX, using the name of the element in the line.
|
||||
*
|
||||
* @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_name the name of the element that should be set in the line
|
||||
* If empty, it is checked that there is only one element per 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 August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiidx_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_IDX, using the name of the element in the line.
|
||||
*
|
||||
* @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_name the name of the element that should be recovered in the line
|
||||
* If empty, it is checked that there is only one element per line
|
||||
*
|
||||
* @return the recovered value
|
||||
* @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obiidx_t obi_column_get_obiidx_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@ -28,7 +28,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value)
|
||||
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
@ -57,7 +57,7 @@ int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, s
|
||||
}
|
||||
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
@ -69,56 +69,24 @@ obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value)
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name)
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
size_t element_idx;
|
||||
|
||||
if (!strcmp(element_name, "\0")) // element name is empty
|
||||
{
|
||||
if (obi_column_get_nb_elements_per_line(column) == 1) // check that there is only one element per line
|
||||
element_idx = 0;
|
||||
else // there is more than one element per line
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nAn element name must be specified");
|
||||
return OBIInt_NA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == -1)
|
||||
return OBIInt_NA;
|
||||
}
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return OBIInt_NA;
|
||||
return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,15 @@
|
||||
/**
|
||||
* @file obidsmcolumn_int.h
|
||||
* @author Celine Mercier
|
||||
* @date July 21st 2015
|
||||
* @date August 10th 2015
|
||||
* @brief Header file for the functions handling OBIColumns containing data with the OBIType OBI_INT.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMN_INT_H_
|
||||
#define OBIDMSCOLUMN_INT_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -20,82 +24,76 @@
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the index of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @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.
|
||||
*
|
||||
* @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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value);
|
||||
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_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 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.
|
||||
*
|
||||
* @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
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since July 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, size_t line_nb, size_t element_idx);
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the name of the element in the line.
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @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 column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param element_name The name of the element that should be set in the line.
|
||||
* @param value The value that should be set.
|
||||
*
|
||||
* @param element_name the name of the element that should be set in the line
|
||||
* If empty, it is checked that there is only one element per 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.
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name, obiint_t value);
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT, using the name of the element in the line.
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column a pointer as returned by obi_create_column()
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param element_name The name of the element that should be recovered in the line.
|
||||
*
|
||||
* @param line_nb the number of the line where the value should be recovered
|
||||
*
|
||||
* @param element_name the name of the element that should be recovered in the line
|
||||
* If empty, it is checked that there is only one element per line
|
||||
*
|
||||
* @return the recovered value
|
||||
* @retvalue -1 on failure and the `obi_errno` variable is set. TODO an other value must be chosen
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, size_t line_nb, char* element_name);
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_INT_H_ */
|
||||
|
||||
|
120
src/obidmscolumn_str.c
Normal file
@ -0,0 +1,120 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column_str functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidsmcolumn_str.c
|
||||
* @author Celine Mercier
|
||||
* @date October 28th 2015
|
||||
* @brief Functions handling OBIColumns containing data in the form of indices referring to character strings.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obiarray.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* 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_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
|
||||
{
|
||||
byte_t* value_b;
|
||||
index_t idx;
|
||||
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
|
||||
// Encode the value on a byte array with a header
|
||||
value_b = obi_str_to_obibytes(value);
|
||||
if (value_b == NULL)
|
||||
return -1;
|
||||
|
||||
// Add in the obiarray
|
||||
idx = obi_array_add(column->array, value_b);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
|
||||
// Add the value's index in the column
|
||||
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
||||
|
||||
free(value_b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
index_t idx;
|
||||
byte_t* value_b;
|
||||
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used");
|
||||
return "\0"; // TODO
|
||||
}
|
||||
|
||||
idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
|
||||
// Check NA
|
||||
if (idx == OBIIdx_NA)
|
||||
return "\0"; // TODO
|
||||
|
||||
value_b = obi_array_get(column->array, idx);
|
||||
return obi_obibytes_to_str(value_b);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
if (obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return "\0";
|
||||
return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
101
src/obidmscolumn_str.h
Normal file
@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
* OBIDMS_column_str header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidsmcolumn_str.h
|
||||
* @author Celine Mercier
|
||||
* @date October 28th 2015
|
||||
* @brief Header file for the functions handling OBIColumns containing data in the form of indices referring to character strings.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMN_STR_H_
|
||||
#define OBIDMSCOLUMN_STR_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an obiarray, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an obiarray, using the index of the element in the line.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an obiarray, using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be set.
|
||||
* @param element_name The name of the element that should be set in the line.
|
||||
* @param value The value that should be set.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an obiarray, using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
* @param element_name The name of the element that should be recovered in the line.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_IDX_H_ */
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
/**
|
||||
* @file obidmscolumndir.c
|
||||
* @author Celine Mercier
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 18 June 2015
|
||||
* @brief Functions for OBIDMS column directories.
|
||||
*/
|
||||
@ -25,7 +25,7 @@
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
@ -43,15 +43,10 @@
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
* @param column_name the name of the OBIDMS column
|
||||
* @param column_name The name of the OBIDMS column.
|
||||
*
|
||||
* @return a pointer to the OBIDMS column directory name
|
||||
* @retvalue <column_directory_name> if everything is ok
|
||||
* @retvalue NULL if an error occurs
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* @returns A pointer to the OBIDMS column directory name.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -78,10 +73,10 @@ static char* build_column_directory_name(const char* column_name)
|
||||
}
|
||||
|
||||
// Test if the database name is not too long
|
||||
if (strlen(column_directory_name) >= OBIDMS_COLUMN_DIR_MAX_NAME)
|
||||
if (strlen(column_directory_name) >= OBIDMS_COLUMN_MAX_NAME)
|
||||
{
|
||||
obi_set_errno(OBICOLDIR_LONG_NAME_ERROR);
|
||||
obidebug(1, "\nError building a column directory name");
|
||||
obidebug(1, "\nError due to column name too long");
|
||||
free(column_directory_name);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -6,57 +6,56 @@
|
||||
* @file obidmscolumndir.h
|
||||
* @author Celine Mercier
|
||||
* @date 18 June 2015
|
||||
* @brief Header file for OBIDMS column directories.
|
||||
* @brief Header file for the OBIDMS column directories structures and functions.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIDMSCOLUMNGROUP_H_
|
||||
#define OBIDMSCOLUMNGROUP_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "obidms.h"
|
||||
|
||||
#define OBIDMS_MAX_COLNAME (128) /**< The maximum length of an OBIDMS column name
|
||||
*/
|
||||
|
||||
#define OBIDMS_COLUMN_DIR_MAX_NAME (2048) /**< The maximum length of an OBIDMS column directory name
|
||||
*/
|
||||
#define OBIDMS_COLUMN_MAX_NAME (2048) /**< The maximum length of an OBIDMS column name.
|
||||
*/
|
||||
|
||||
/** @brief A structure describing an OBIDMS column directory instance
|
||||
|
||||
/**
|
||||
* @brief A structure describing an OBIDMS column directory instance.
|
||||
*
|
||||
* A pointer to this structure is returned on creation
|
||||
* and opening of an OBIDMS column directory.
|
||||
*/
|
||||
|
||||
typedef struct OBIDMS_column_directory {
|
||||
OBIDMS_p dms; /**< A pointer to a DMS instance.
|
||||
OBIDMS_p dms; /**< A pointer to a DMS instance.
|
||||
*/
|
||||
char column_name[OBIDMS_MAX_COLNAME+1]; /**< The name of the column
|
||||
* contained in the directory.
|
||||
char column_name[OBIDMS_COLUMN_MAX_NAME+1]; /**< The name of the column
|
||||
* contained in the directory.
|
||||
*/
|
||||
char directory_name[OBIDMS_COLUMN_DIR_MAX_NAME+1]; /**< The name of the directory
|
||||
* containing the column.
|
||||
char directory_name[OBIDMS_COLUMN_MAX_NAME+1]; /**< The name of the directory
|
||||
* containing the column.
|
||||
*/
|
||||
DIR* directory; /**< A directory entry usable to
|
||||
* refer and scan the database directory.
|
||||
DIR* directory; /**< A directory entry usable to
|
||||
* refer and scan the database directory.
|
||||
*/
|
||||
} OBIDMS_column_directory_t, *OBIDMS_column_directory_p;
|
||||
|
||||
|
||||
/*@
|
||||
* @brief Checks if an OBIDMS column directory exists
|
||||
/**
|
||||
* @brief Checks if an OBIDMS column directory exists.
|
||||
*
|
||||
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||
* @param column_name a pointer to a C string containing the name of the column.
|
||||
* The actual directory name used to store the column is
|
||||
* `<column_name>.obicol`.
|
||||
* @param dms A pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms().
|
||||
* @param column_name A pointer to a C string containing the name of the column.
|
||||
*
|
||||
* @return an integer value indicating the status of the column directory
|
||||
* @retvalue 1 the directory exist
|
||||
* @retvalue 0 the directory does not exist
|
||||
* @retvalue -1 an error occurred
|
||||
* @returns An integer value indicating the status of the column directory.
|
||||
* @retval 1 if the directory exists.
|
||||
* @retval 0 if the directory does not exist.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @see obi_close_column_directory()
|
||||
* @since June 2015
|
||||
@ -72,17 +71,14 @@ int obi_column_directory_exists(OBIDMS_p dms, const char* column_name);
|
||||
* if a directory with this name does not already exist
|
||||
* before creating the new column directory.
|
||||
*
|
||||
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||
* @param column_name a pointer to a C string containing the name of the column.
|
||||
* @param dms A pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms().
|
||||
* @param column_name A pointer to a C string containing the name of the column.
|
||||
* The actual directory name used to store the column will be
|
||||
* `<column_name>.obicol`.
|
||||
*
|
||||
* @return a pointer to an OBIDMS column directory structure describing the newly created
|
||||
* directory
|
||||
* @retval NULL on error and the `obi_errno` variable is set.
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_COL_DIR_EXIST_ERROR : xxxxx a database with the same name already exists.
|
||||
* @returns A pointer to an OBIDMS column directory structure describing the newly created
|
||||
* directory.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @see obi_close_column_directory()
|
||||
* @since June 2015
|
||||
@ -94,16 +90,13 @@ OBIDMS_column_directory_p obi_create_column_directory(OBIDMS_p dms, const char*
|
||||
/**
|
||||
* @brief Opens an existing OBIDMS column directory instance.
|
||||
*
|
||||
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||
* @param column_name a pointer to a C string containing the name of the column.
|
||||
* @param dms A pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms().
|
||||
* @param column_name A pointer to a C string containing the name of the column.
|
||||
* The actual directory name used to store the column is
|
||||
* `<column_name>.obicol`.
|
||||
*
|
||||
* @return a pointer to the OBIDMS column directory structure describing the directory
|
||||
* @retval NULL on error and the `obi_errno`variable is set.
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_COL_DIR_ERROR : xxxxx a database with the same name already exists.
|
||||
* @returns A pointer to the OBIDMS column directory structure describing the directory.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @see obi_close_column_directory()
|
||||
* @since June 2015
|
||||
@ -118,17 +111,13 @@ OBIDMS_column_directory_p obi_open_column_directory(OBIDMS_p dms, const char* co
|
||||
* If the directory already exists, this function opens it, otherwise it
|
||||
* creates a new column directory.
|
||||
*
|
||||
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||
* @param column_name a pointer to a C string containing the name of the column.
|
||||
* @param dms A pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms().
|
||||
* @param column_name A pointer to a C string containing the name of the column.
|
||||
* The actual directory name used to store the column is
|
||||
* `<column_name>.obicol`.
|
||||
*
|
||||
* @return a pointer to the OBIDMS column directory structure describing the directory
|
||||
* @retval NULL on error and the `obi_errno`variable is set.
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* @returns A pointer to the OBIDMS column directory structure describing the directory.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -139,13 +128,13 @@ OBIDMS_column_directory_p obi_column_directory(OBIDMS_p dms, const char* column_
|
||||
/**
|
||||
* @brief Closes an opened OBIDMS column directory instance.
|
||||
*
|
||||
* @param column_directory a pointer to an OBIDMS column directory as returned by
|
||||
* obi_create_column_directory() or obi_open_column_directory()
|
||||
* @param column_directory A pointer to an OBIDMS column directory as returned by
|
||||
* obi_create_column_directory() or obi_open_column_directory().
|
||||
*
|
||||
* @return an integer value indicating the success of the operation. Even on
|
||||
* error, the `OBIDMS_column_directory` structure is freed
|
||||
* @retvalue 0 on success
|
||||
* @retvalue -1 on failure and the `obi_errno` variable is set.
|
||||
* @returns An integer value indicating the success of the operation. Even on
|
||||
* error, the `OBIDMS_column_directory` structure is freed.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @see obi_create_column_directory()
|
||||
* @see obi_open_column_directory()
|
||||
|
@ -1,10 +1,14 @@
|
||||
/*
|
||||
* obierrno.c
|
||||
*
|
||||
* Created on: 23 mai 2015
|
||||
* Author: coissac
|
||||
/****************************************************************************
|
||||
* Code for obi errnos *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obierrno.c
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
* @date 23 May 2015
|
||||
* @brief Code for obi errnos.
|
||||
*/
|
||||
|
||||
|
||||
int obi_errno;
|
||||
int obi_errno = 0;
|
||||
|
||||
|
@ -1,20 +1,26 @@
|
||||
/*
|
||||
* obierrno.h
|
||||
*
|
||||
* Created on: 23 mai 2015
|
||||
* Author: coissac
|
||||
/****************************************************************************
|
||||
* Header file for obi errnos *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obierrno.h
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
* @date 23 May 2015
|
||||
* @brief Header file for obi errnos.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIERRNO_H_
|
||||
#define OBIERRNO_H_
|
||||
|
||||
|
||||
/**
|
||||
* @brief The declaration of the external variable `obi_errno`.
|
||||
*
|
||||
* `obi_errno` is an equivalent of `errno` for the system level error,
|
||||
* but for errors generated by the C layer of the OBITools framework.
|
||||
* but for errors generated by the C layer of the OBITools3 framework.
|
||||
*
|
||||
* @todo We have to look into defining this variable as thread specific.
|
||||
* @TODO We have to look into defining this variable as thread specific.
|
||||
*/
|
||||
extern int obi_errno;
|
||||
|
||||
@ -24,8 +30,8 @@ extern int obi_errno;
|
||||
* the specified `err` code
|
||||
*
|
||||
* This function is defined as a macro to reduce the risk
|
||||
* of increasing the problem generating the error by calling
|
||||
* a new function.
|
||||
* of increasing the problem by generating another error by calling
|
||||
* another function.
|
||||
*
|
||||
* @param err The error code as an integer value.
|
||||
*
|
||||
@ -41,6 +47,8 @@ extern int obi_errno;
|
||||
* Error codes set in errno following an error related
|
||||
* to the manipulation of an OBIDMS.
|
||||
*
|
||||
* @TODO
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define OBIDMS_EXIST_ERROR (1) /**< Trying to create an OBIDMS with a name
|
||||
@ -90,6 +98,8 @@ extern int obi_errno;
|
||||
*/
|
||||
#define OBICOL_ACCESS_ERROR (19) /**< Permission error trying to access an OBIDSM column directory
|
||||
*/
|
||||
#define OBI_ARRAY_ERROR (20) /** Error while handling an array
|
||||
*/
|
||||
/**@}*/
|
||||
|
||||
#endif /* OBIERRNO_H_ */
|
||||
|
@ -1,8 +1,12 @@
|
||||
/*
|
||||
* littlebigman.c
|
||||
*
|
||||
* Created on: 23 mai 2015
|
||||
* Author: coissac
|
||||
/****************************************************************************
|
||||
* Code for endianness checking *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obilittlebigman.c
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
* @date 23 May 2015
|
||||
* @brief Code endianness checking.
|
||||
*/
|
||||
|
||||
#include "obilittlebigman.h"
|
||||
|
@ -1,15 +1,22 @@
|
||||
/*
|
||||
* littlebigman.h
|
||||
*
|
||||
* Created on: 23 mai 2015
|
||||
* Author: coissac
|
||||
/****************************************************************************
|
||||
* Header file for endianness checking *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obilittlebigman.h
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
* @date 23 May 2015
|
||||
* @brief Header file for endianness checking.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBILITTLEBIGMAN_H_
|
||||
#define OBILITTLEBIGMAN_H_
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/**
|
||||
* Test if the architecture of the processor is little endian.
|
||||
*
|
||||
@ -41,7 +48,7 @@
|
||||
* In this architecture, the last address is
|
||||
* used to store the byte of lighter weight (LITTLE ENDian)
|
||||
*
|
||||
* @return a `bool` value:
|
||||
* @returns a `bool` value:
|
||||
* - `true` if the architecture is little endian
|
||||
* - `false` if the architecture is big endian
|
||||
*
|
||||
|
@ -1,8 +1,12 @@
|
||||
/*
|
||||
* obitypes.c
|
||||
*
|
||||
* Created on: 23 mai 2015
|
||||
* Author: coissac
|
||||
/****************************************************************************
|
||||
* OBITypes functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obitypes.h
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
* @date 23 May 2015
|
||||
* @brief Functions for the handling of OBITypes.
|
||||
*/
|
||||
|
||||
|
||||
@ -13,7 +17,7 @@
|
||||
#include "obierrno.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
size_t obi_sizeof(OBIType_t type)
|
||||
@ -36,7 +40,7 @@ size_t obi_sizeof(OBIType_t type)
|
||||
case OBI_CHAR: size = sizeof(obichar_t);
|
||||
break;
|
||||
|
||||
case OBI_IDX: size = sizeof(obiidx_t);
|
||||
case OBI_IDX: size = sizeof(index_t);
|
||||
break;
|
||||
|
||||
default: size = 0;
|
||||
@ -46,7 +50,7 @@ size_t obi_sizeof(OBIType_t type)
|
||||
}
|
||||
|
||||
|
||||
size_t obi_array_sizeof(OBIType_t type, size_t nb_lines, size_t nb_elements_per_line)
|
||||
size_t obi_array_sizeof(OBIType_t type, index_t nb_lines, index_t nb_elements_per_line)
|
||||
{
|
||||
size_t size;
|
||||
size_t rsize;
|
||||
|
@ -1,10 +1,15 @@
|
||||
/****************************************************************************
|
||||
* Header file for OBITypes *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obitypes.h
|
||||
* @author Celine Mercier
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 18 May 2015
|
||||
* @brief Header file for the OBITypes.
|
||||
* @brief Header file for the handling of OBITypes.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBITYPES_H_
|
||||
#define OBITYPES_H_
|
||||
|
||||
@ -13,10 +18,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define OBIInt_NA (INT32_MIN)
|
||||
#define OBIIdx_NA (SIZE_MAX)
|
||||
#define OBIFloat_NA (float_NA())
|
||||
#define OBIChar_NA (0) // TODO not sure about this one as it can be impossible to distinguish from uninitialized values
|
||||
#define OBIInt_NA (INT32_MIN) /**< NA value for the type OBI_INT */
|
||||
#define OBIIdx_NA (INT64_MIN) /**< NA value for indices */
|
||||
#define OBIFloat_NA (float_NA()) /**< NA value for the type OBI_FLOAT */
|
||||
#define OBIChar_NA (0) /**< NA value for the type OBI_CHAR */
|
||||
// TODO not sure about this one as it can be impossible to distinguish from uninitialized values
|
||||
|
||||
|
||||
/**
|
||||
@ -38,16 +44,19 @@ typedef enum OBIType {
|
||||
OBI_FLOAT, /**< a floating value (C type : double) */
|
||||
OBI_BOOL, /**< a boolean true/false value, see obibool_t enum */
|
||||
OBI_CHAR, /**< a character (C type : char) */
|
||||
OBI_IDX /**< an index in a data structure (C type : size_t) */
|
||||
OBI_IDX /**< an index in a data structure (C type : int64_t) */
|
||||
} OBIType_t, *OBIType_p;
|
||||
|
||||
|
||||
typedef int64_t index_t;
|
||||
typedef int32_t obiint_t;
|
||||
typedef double obifloat_t;
|
||||
typedef char obichar_t;
|
||||
typedef size_t obiidx_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Union used to compute the NA value of the OBI_FLOAT OBIType.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
double value;
|
||||
@ -55,7 +64,11 @@ typedef union
|
||||
} ieee_double;
|
||||
|
||||
|
||||
static double float_NA(void) // as defined in R
|
||||
/**
|
||||
* @brief Returns the NA value of the OBI_FLOAT OBIType.
|
||||
* This value corresponds to the float NA value as defined in R.
|
||||
*/
|
||||
static double float_NA(void)
|
||||
{
|
||||
volatile ieee_double x;
|
||||
x.word[0] = 0x7ff00000;
|
||||
@ -65,12 +78,12 @@ static double float_NA(void) // as defined in R
|
||||
|
||||
|
||||
/**
|
||||
* @brief returns the memory size in bytes of an OBIType
|
||||
* @brief Returns the memory size in bytes of an OBIType.
|
||||
*
|
||||
* @param type the OBIType code used as query
|
||||
* @param type The OBIType code used as query.
|
||||
*
|
||||
* @return the size in bytes of the type
|
||||
* @retval 0 on error (unknown type)
|
||||
* @returns The size in bytes of the type.
|
||||
* @retval 0 if an error occurred (unknown type).
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
@ -79,31 +92,32 @@ size_t obi_sizeof(OBIType_t type);
|
||||
|
||||
|
||||
/**
|
||||
* @brief returns the size requested to store an array of OBIType
|
||||
* @brief Returns the size required to store an array of elements with an OBIType.
|
||||
*
|
||||
* The returned size is large enough to store an array of size nbelement
|
||||
* but rounded at a multiple of the memory page size.
|
||||
* The returned size is large enough to store an array large enough
|
||||
* to store all the elements but rounded at a multiple of the memory page size. // TODO this might be redundant but still a good thing
|
||||
*
|
||||
* @param type the OBIType code used as query
|
||||
* @param nbelement the number of elements to be stored
|
||||
* @param data_type The OBIType of the elements.
|
||||
* @param nb_lines The number of lines to be stored.
|
||||
* @param nb_elements_per_line The number of elements per line.
|
||||
*
|
||||
* @return the size in bytes of the array
|
||||
* @retval 0 on error (unknown type)
|
||||
* @returns The size in bytes of the array.
|
||||
* @retval 0 if an error occurred (unknown type).
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
size_t obi_array_sizeof(OBIType_t type, size_t nbelements, size_t nb_elements_per_line);
|
||||
size_t obi_array_sizeof(OBIType_t data_type, index_t nb_lines, index_t nb_elements_per_line);
|
||||
|
||||
|
||||
/**
|
||||
* @brief returns the name in the form of a character string of an OBIType
|
||||
* @brief Returns the name in the form of a character string of an OBIType.
|
||||
*
|
||||
*
|
||||
* @param data_type the OBIType code used as query
|
||||
* @param data_type The OBIType code used as query.
|
||||
*
|
||||
* @return the name of the OBIType
|
||||
* @retval NULL on error (unknown type or error allocating the memory for the character string)
|
||||
* @returns The name of the OBIType.
|
||||
* @retval NULL if an error occurred (unknown type or error allocating the memory for the character string).
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
|
@ -3,8 +3,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file private_at_functions.h
|
||||
* @author Celine Mercier
|
||||
* @file private_at_functions.c
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 15 June 2015
|
||||
* @brief Private replacement functions for *at functions.
|
||||
*/
|
||||
@ -23,14 +23,7 @@
|
||||
#include "obierrno.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* 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
|
||||
*
|
||||
**********************************************************************/
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
char* get_full_path(int directory_file_descriptor, const char* path_name)
|
||||
@ -50,7 +43,7 @@ char* get_full_path(int directory_file_descriptor, const char* path_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO check errors
|
||||
// TODO check errors?
|
||||
strlcat(full_path, "/", MAX_PATH_LEN);
|
||||
strlcat(full_path, path_name, MAX_PATH_LEN);
|
||||
|
||||
@ -77,39 +70,3 @@ DIR* private_opendirat(int directory_file_descriptor, const char* path_name)
|
||||
}
|
||||
|
||||
|
||||
//int private_openat(int directory_file_descriptor, const char* path_name, int flags)
|
||||
//{
|
||||
// char* full_path;
|
||||
// int file_descriptor;
|
||||
//
|
||||
// full_path = get_full_path(directory_file_descriptor, path_name);
|
||||
// if (full_path == NULL)
|
||||
// return -1;
|
||||
//
|
||||
// file_descriptor = open(full_path, flags);
|
||||
//
|
||||
// free(full_path);
|
||||
//
|
||||
// return file_descriptor;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//int private_mkdirat(int directory_file_descriptor, const char* path_name, mode_t mode)
|
||||
//{
|
||||
// char* full_path;
|
||||
//
|
||||
// full_path = get_full_path(directory_file_descriptor, path_name);
|
||||
// if (full_path == NULL)
|
||||
// return -1;
|
||||
//
|
||||
// if (mkdir(full_path, mode) < 0)
|
||||
// {
|
||||
// free(full_path);
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// free(full_path);
|
||||
//
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
|
@ -1,10 +1,15 @@
|
||||
/****************************************************************************
|
||||
* Header file for private *at functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file private_openat.h
|
||||
* @author Celine Mercier
|
||||
* @file private_at_functions.h
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 15 June 2015
|
||||
* @brief Header file for the replacement *at function.
|
||||
* @brief Header file for the private replacement functions for *at functions.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PRIVATE_OPENAT_H_
|
||||
#define PRIVATE_OPENAT_H_
|
||||
|
||||
@ -12,27 +17,22 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
#define MAX_PATH_LEN 4096
|
||||
#define MAX_PATH_LEN 4096 /**< Maximum length for the character string defining a
|
||||
file or directory path */
|
||||
|
||||
|
||||
/**
|
||||
* Internal function getting the full path of a file or a directory from its
|
||||
* path relative to a directory file descriptor.
|
||||
*
|
||||
* @brief Internal function getting the full path of a file or a directory from its
|
||||
* path relative to a directory file descriptor.
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
* @param directory_file_descriptor the file descriptor for the directory to which
|
||||
* path_name is relative
|
||||
* @param path_name the path name for the file or directory, relative to directory_file_descriptor
|
||||
* @param directory_file_descriptor The file descriptor for the directory to which
|
||||
* path_name is relative.
|
||||
* @param path_name The path name for the file or directory, relative to directory_file_descriptor.
|
||||
*
|
||||
* @return a pointer to the full path
|
||||
* @retvalue <full_path> if everything is ok
|
||||
* @retvalue NULL if an error occurs
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* @returns A pointer to the full path.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -43,10 +43,11 @@ char* get_full_path(int directory_file_descriptor, const char* path_name);
|
||||
/**
|
||||
* @brief Replacement function for opendirat() : open a directory relative to a directory file descriptor.
|
||||
*
|
||||
* @param directory_file_descriptor the file descriptor for the directory in which the directory should be opened
|
||||
* @param path_name the path name for the directory to be opened, relative to directory_file_descriptor
|
||||
* @param directory_file_descriptor The file descriptor for the directory in which the directory should be opened.
|
||||
* @param path_name The path name for the directory to be opened, relative to directory_file_descriptor.
|
||||
*
|
||||
* @return the file descriptor of the opened directory
|
||||
* @returns The file descriptor of the opened directory.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
@ -54,34 +55,4 @@ char* get_full_path(int directory_file_descriptor, const char* path_name);
|
||||
DIR* private_opendirat(int directory_file_descriptor, const char* path_name);
|
||||
|
||||
|
||||
///**
|
||||
// * @brief Replacement function for openat() : open a file relative to a directory file descriptor.
|
||||
// *
|
||||
// * @param directory_file_descriptor the file descriptor for the directory in which the file should be opened
|
||||
// * @param path_name the path name for the file, relative to directory_file_descriptor
|
||||
// * @param flags the access modes
|
||||
// *
|
||||
// * @return the file descriptor of the opened file
|
||||
// *
|
||||
// * @since June 2015
|
||||
// * @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
// */
|
||||
//int private_openat(int directory_file_descriptor, const char* path_name, int flags);
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @brief Replacement function for mkdirat() : create a directory relative to a directory file descriptor.
|
||||
// *
|
||||
// * @param directory_file_descriptor the file descriptor for the directory in which the directory should be created
|
||||
// * @param path_name the path name for the new directory, relative to directory_file_descriptor
|
||||
// * @param mode the access mode
|
||||
// *
|
||||
// * @return the file descriptor of the created directory
|
||||
// *
|
||||
// * @since June 2015
|
||||
// * @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
// */
|
||||
//int private_mkdirat(int directory_file_descriptor, const char* path_name, mode_t mode);
|
||||
|
||||
|
||||
#endif /* PRIVATEOPENAT_H_ */
|
||||
|