Commit a6abc745 authored by celinemercier's avatar celinemercier

Cython sources modified to add the handling of OBIDMS columns with the

type OBI_INT
parent 5c674715
../../../src/obidms.h
../../../src/obidms.c
../../../src/obidmscolumn.h
../../../src/obidmscolumn.c
../../../src/obidmscolumndir.h
../../../src/obidmscolumndir.c
../../../src/obierrno.h
../../../src/obierrno.c
../../../src/obilittlebigman.h
......
cdef extern from *:
ctypedef char* const_char_p "const char*"
## Put somewhere else probably
cdef extern from "obitypes.h" nogil:
enum OBIType:
pass
ctypedef OBIType OBIType_t
cdef extern from "obidms.h" nogil:
struct OBIDMS_t:
pass
......@@ -17,13 +8,10 @@ cdef extern from "obidms.h" nogil:
ctypedef OBIDMS_t* OBIDMS_p
OBIDMS_p obi_create_dms(const_char_p dms_name)
OBIDMS_p obi_open_dms(const_char_p dms_name)
OBIDMS_p obi_dms(const_char_p dms_name)
int obi_close_dms(OBIDMS_p dms)
int obi_list_columns(OBIDMS_p dms)
cdef class OBIDMS:
cdef OBIDMS_p pointer
......@@ -2,10 +2,14 @@
from .capidms cimport *
cdef class OBIDMS:
cdef class OBIDMS :
def __init__(self, dms_name):
self.pointer = obi_dms(dms_name)
def __init__(self, dms_name) :
dms_name_b = dms_name.encode(encoding='UTF-8')
self.pointer = obi_dms(dms_name_b)
def __del__(self):
def __del__(self) :
obi_close_dms(self.pointer)
def list(self):
obi_list_columns(self.pointer)
\ No newline at end of file
../../../../src/obidmscolumn_int.c
../../../../src/obidmscolumn_int.h
../../../../src/obidmscolumn.h
../../../../src/obidmscolumn.c
../../../../src/obidmscolumndir.h
......
from obitools3.obidms.capidms cimport *
from libc.stdint cimport *
cdef extern from "obitypes.h" nogil:
enum OBIType:
pass
ctypedef OBIType OBIType_t
ctypedef int32_t obiint_t
ctypedef double obifloat_t
ctypedef char obichar_t
ctypedef size_t obiidx_t
cdef extern from "obidmscolumn.h" nogil:
struct OBIDMS_column_t:
pass
ctypedef OBIDMS_column_t* OBIDMS_column_p
ctypedef OBIDMS_column_t* OBIDMS_column_p
ctypedef int32_t obiversion_t
OBIDMS_column_p obi_create_column(OBIDMS_p dms, const char* column_name, OBIType_t type, size_t nb_elements, size_t nb_elements_per_line, const char* elements_names)
size_t obi_column_get_line_count(OBIDMS_column_p column)
const char* obi_column_get_elements_names(OBIDMS_column_p column)
void obi_column_make_unwritable(OBIDMS_column_p column)
size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name)
OBIDMS_column_p obi_open_column(OBIDMS_p dms, const char* column_name, obiversion_t version_number)
size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column)
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* column_name)
cdef class OBIDMS_column:
cdef OBIDMS_column_p pointer
cdef OBIDMS_p dms
cdef OBIType_t data_type
cdef str dms_name
cdef str column_name
#cython: language_level=3
from .capidmscolumn cimport *
from obitools3.obidms.obidmscolumn.obidmscolumn_int.capidmscolumn_int import OBIDMS_column_int
cdef class OBIDMS_column:
def __init__(self, dms_name, column_name, type, nb_elements, nb_elements_per_line=1, elements_names=None):
def __init__(self, dms_name, column_name,
create, version_number,
type, nb_elements,
nb_elements_per_line, elements_names):
column_name_b = column_name.encode(encoding='UTF-8')
dms_name_b = dms_name.encode(encoding='UTF-8')
self.dms_name = dms_name
self.column_name = column_name
self.data_type = type
if create :
dms = obi_dms(dms_name_b)
self.dms = dms
if elements_names == None :
elements_names_b = column_name_b
else :
elements_names_b = elements_names.encode(encoding='UTF-8')
self.pointer = obi_create_column(self.dms, column_name_b, type, nb_elements, nb_elements_per_line, elements_names_b)
else :
dms = obi_open_dms(dms_name_b)
self.dms = dms
self.pointer = obi_open_column(self.dms, column_name_b, version_number)
def create(self, dms_name, column_name, type, nb_elements, nb_elements_per_line=1, elements_names=None):
if elements_names == None :
elements_names = "[\""+column_name.decode('utf-8')+"\"]"
elements_names = bytes(elements_names, 'utf-8')
elements_names = column_name
self.dms = obi_dms(dms_name)
self.pointer = obi_create_column(self.dms, column_name, type, nb_elements, nb_elements_per_line, elements_names)
self.pointer = obi_create_column(self.dms, column_name, type, nb_elements, nb_elements_per_line, elements_names)
def __iter__(self):
elements_names = self.get_elements_names()
if len(elements_names) > 1 :
multiple_elements = True
else :
element_name = elements_names[0]
line_count = obi_column_get_line_count(self.pointer)
for line_nb in xrange(line_count):
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
def __setitem__(self, line_nb, value):
self.set_item(line_nb, "", value)
def __getitem__(self, line_nb):
return self.get_item(line_nb, "")
def get_elements_names(self):
elements_names = obi_column_get_elements_names(self.pointer)
return (elements_names.decode('UTF-8')).split(';')
def get_element_index_from_name(self, element_name):
element_name = element_name.encode(encoding='UTF-8')
return obi_column_get_element_index_from_name(self.pointer, element_name)
def get_data_type(self):
return self.data_type
def __del__(self):
if obi_close_column(self.pointer) != 0 :
raise Exception("Problem closing a column")
@staticmethod
def open(dms_name, column_name,
create=False, version_number=-1,
type=None, nb_elements=None,
nb_elements_per_line=1, elements_names=None):
column_name_b = column_name.encode(encoding='UTF-8')
dms_name_b = dms_name.encode(encoding='UTF-8')
dms = obi_dms(dms_name_b)
if type is None :
type = obi_column_get_data_type_from_name(dms, column_name_b)
if type == 1 :
column = OBIDMS_column_int(dms_name, column_name,
create, version_number,
type, nb_elements,
nb_elements_per_line, elements_names)
else :
"Problem with the data type"
return column
\ No newline at end of file
../../../../../src/obidmscolumn_int.c
../../../../../src/obidmscolumn_int.h
../../../../../src/obidmscolumn.h
../../../../../src/obidmscolumn.c
../../../../../src/obidmscolumndir.h
../../../../../src/obidmscolumndir.c
../../../../../src/obidms.h
../../../../../src/obidms.c
../../../../../src/obierrno.h
../../../../../src/obierrno.c
../../../../../src/obilittlebigman.h
../../../../../src/obilittlebigman.c
../../../../../src/obitypes.h
../../../../../src/obitypes.c
../../../../../src/private_at_functions.h
../../../../../src/private_at_functions.c
from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
cdef extern from "obidmscolumn_int.h" nogil:
int obi_column_set_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx, obiint_t value)
obiint_t obi_column_get_int(OBIDMS_column_p column, size_t line_nb, size_t element_idx)
#cython: language_level=3
from .capidmscolumn_int cimport *
cdef class OBIDMS_column_int(OBIDMS_column) :
def set_item(self, line_nb, element_name, value):
if element_name != "" :
element_idx = self.get_element_index_from_name(element_name)
else :
if obi_column_get_nb_elements_per_line(self.pointer) == 1 :
element_idx = 0
else :
print("An element name must be specified")
return -1
return obi_column_set_int(self.pointer, line_nb, element_idx, value)
def get_item(self, line_nb, element_name):
if element_name != "" :
element_idx = self.get_element_index_from_name(element_name)
else :
if obi_column_get_nb_elements_per_line(self.pointer) == 1 :
element_idx = 0
else :
print("An element name must be specified")
return -1
return obi_column_get_int(self.pointer, line_nb, element_idx)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment