Column type is now passed as a character string when creating the column

(either 'OBI_INT', 'OBI_FLOAT', 'OBI_BOOL', 'OBI_CHAR', 'OBI_STR' or
'OBI_SEQ')
This commit is contained in:
Celine Mercier
2015-11-23 15:48:27 +01:00
parent 5a5516303d
commit 2cf10cb6f0
3 changed files with 44 additions and 14 deletions

View File

@ -20,7 +20,7 @@ cdef class OBIDMS:
bint create=*, bint create=*,
bint clone=*, bint clone_data=*, bint clone=*, bint clone_data=*,
obiversion_t version_number=*, obiversion_t version_number=*,
OBIType_t data_type=*, str type=*,
index_t nb_lines=*, index_t nb_lines=*,
index_t nb_elements_per_line=*, index_t nb_elements_per_line=*,
list elements_names=*, list elements_names=*,

View File

@ -16,6 +16,13 @@ from .capi.obidmscolumn cimport obi_column_get_header_from_name, \
obi_column_format_date, \ obi_column_format_date, \
OBIDMS_column_header_p OBIDMS_column_header_p
from .capi.obitypes cimport const_char_p, \ from .capi.obitypes cimport const_char_p, \
OBIType_t, \
OBI_INT, \
OBI_FLOAT, \
OBI_BOOL, \
OBI_CHAR, \
OBI_STR, \
OBI_SEQ, \
name_data_type name_data_type
@ -121,7 +128,7 @@ cdef class OBIDMS :
bint create=False, bint create=False,
bint clone=False, bint clone_data=True, bint clone=False, bint clone_data=True,
obiversion_t version_number=-1, obiversion_t version_number=-1,
OBIType_t data_type= <OBIType_t> 0, str type='',
index_t nb_lines=0, index_t nb_lines=0,
index_t nb_elements_per_line=0, index_t nb_elements_per_line=0,
list elements_names=None, list elements_names=None,
@ -133,7 +140,8 @@ cdef class OBIDMS :
cdef object subclass # TODO object? cdef object subclass # TODO object?
cdef bytes column_name_b cdef bytes column_name_b
cdef OBIDMS_column_header_p header cdef OBIDMS_column_header_p header
cdef OBIType_t data_type
header = NULL header = NULL
# Format the character string to send to C function # Format the character string to send to C function
@ -141,15 +149,30 @@ cdef class OBIDMS :
# Get the header of the latest version of the column if # Get the header of the latest version of the column if
# some needed informations are not provided # some needed informations are not provided
if ((not data_type or not nb_elements_per_line) and not create) : if ((not type or not nb_elements_per_line) and not create) :
header = obi_column_get_header_from_name(self.pointer, column_name_b, version_number) header = obi_column_get_header_from_name(self.pointer, column_name_b, version_number)
# Get the data type if not provided # Get the data type if not provided
if not data_type : if not type :
if create : if create :
raise Exception("A data type must be specified") raise Exception("A data type must be specified")
else : else :
data_type = header.data_type data_type = header.data_type
else :
if type == 'OBI_INT' :
data_type = OBI_INT
elif type == 'OBI_FLOAT' :
data_type = OBI_FLOAT
elif type == 'OBI_BOOL' :
data_type = OBI_BOOL
elif type == 'OBI_CHAR' :
data_type = OBI_CHAR
elif type == 'OBI_STR' :
data_type = OBI_STR
elif type == 'OBI_SEQ' :
data_type = OBI_SEQ
else :
raise Exception("Invalid provided data type")
# Get the number of elements per line if not provided and needed # Get the number of elements per line if not provided and needed
if not nb_elements_per_line : if not nb_elements_per_line :
@ -165,7 +188,7 @@ cdef class OBIDMS :
# Open the column with the right subclass depending on the data type, the mode # 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 # (read-only or writable) and whether there are multiple elements per line or not
if data_type == 1 : if data_type == OBI_INT :
if (create or clone) : if (create or clone) :
if nb_elements_per_line == 1 : if nb_elements_per_line == 1 :
subclass = OBIDMS_column_int_writable subclass = OBIDMS_column_int_writable
@ -176,7 +199,7 @@ cdef class OBIDMS :
subclass = OBIDMS_column_int subclass = OBIDMS_column_int
else : else :
subclass = OBIDMS_column_int_multi_elts subclass = OBIDMS_column_int_multi_elts
elif data_type == 2 : elif data_type == OBI_FLOAT :
if (create or clone) : if (create or clone) :
if nb_elements_per_line == 1 : if nb_elements_per_line == 1 :
subclass = OBIDMS_column_float_writable subclass = OBIDMS_column_float_writable
@ -187,7 +210,7 @@ cdef class OBIDMS :
subclass = OBIDMS_column_float subclass = OBIDMS_column_float
else : else :
subclass = OBIDMS_column_float_multi_elts subclass = OBIDMS_column_float_multi_elts
elif data_type == 3 : elif data_type == OBI_BOOL :
if (create or clone) : if (create or clone) :
if nb_elements_per_line == 1 : if nb_elements_per_line == 1 :
subclass = OBIDMS_column_bool_writable subclass = OBIDMS_column_bool_writable
@ -198,7 +221,7 @@ cdef class OBIDMS :
subclass = OBIDMS_column_bool subclass = OBIDMS_column_bool
else : else :
subclass = OBIDMS_column_bool_multi_elts subclass = OBIDMS_column_bool_multi_elts
elif data_type == 4 : elif data_type == OBI_CHAR :
if (create or clone) : if (create or clone) :
if nb_elements_per_line == 1 : if nb_elements_per_line == 1 :
subclass = OBIDMS_column_char_writable subclass = OBIDMS_column_char_writable
@ -209,7 +232,7 @@ cdef class OBIDMS :
subclass = OBIDMS_column_char subclass = OBIDMS_column_char
else : else :
subclass = OBIDMS_column_char_multi_elts subclass = OBIDMS_column_char_multi_elts
elif data_type == 5 : elif data_type == OBI_STR :
if (create or clone) : if (create or clone) :
if nb_elements_per_line == 1 : if nb_elements_per_line == 1 :
subclass = OBIDMS_column_str_writable subclass = OBIDMS_column_str_writable
@ -220,7 +243,7 @@ cdef class OBIDMS :
subclass = OBIDMS_column_str subclass = OBIDMS_column_str
else : else :
subclass = OBIDMS_column_str_multi_elts subclass = OBIDMS_column_str_multi_elts
elif data_type == 6 : elif data_type == OBI_SEQ :
if (create or clone) : if (create or clone) :
if nb_elements_per_line == 1 : if nb_elements_per_line == 1 :
subclass = OBIDMS_column_seq_writable subclass = OBIDMS_column_seq_writable
@ -254,7 +277,7 @@ cdef class OBIDMS_column :
bint create, bint create,
bint clone, bint clone_data, bint clone, bint clone_data,
obiversion_t version_number, obiversion_t version_number,
OBIType_t type, # There's a problem with this with the OBI_IDX columns as there are 2 subtypes OBIType_t type,
index_t nb_lines, index_t nb_lines,
index_t nb_elements_per_line, index_t nb_elements_per_line,
list elements_names, list elements_names,
@ -267,7 +290,7 @@ cdef class OBIDMS_column :
cdef bytes array_name_b cdef bytes array_name_b
cdef bytes elements_names_b cdef bytes elements_names_b
cdef bytes comments_b cdef bytes comments_b
# Fill structure # Fill structure
self.dms = dms self.dms = dms
self.data_type = bytes2str(name_data_type(type)) self.data_type = bytes2str(name_data_type(type))

View File

@ -17,7 +17,14 @@ cdef extern from "obidmscolumn.h" nogil:
cdef extern from "obitypes.h" nogil: cdef extern from "obitypes.h" nogil:
enum OBIType: enum OBIType:
pass OBI_VOID,
OBI_INT,
OBI_FLOAT,
OBI_BOOL,
OBI_CHAR,
OBI_STR,
OBI_SEQ
ctypedef OBIType OBIType_t ctypedef OBIType OBIType_t