Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
f31d8983
Commit
f31d8983
authored
Sep 01, 2015
by
Celine Mercier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Columns are now enlarged if needed when setting a value
parent
3b7536c0
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
406 additions
and
111 deletions
+406
-111
python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd
...dms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx
...dms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pxd
...dms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pxd
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pyx
...dms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pyx
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pxd
...s/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pxd
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pyx
...s/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pyx
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pxd
...bidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pxd
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pyx
...bidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pyx
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pxd
...bidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pxd
+2
-2
python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pyx
...bidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pyx
+2
-2
src/obidmscolumn.c
src/obidmscolumn.c
+179
-37
src/obidmscolumn.h
src/obidmscolumn.h
+29
-0
src/obidmscolumn_bool.c
src/obidmscolumn_bool.c
+31
-6
src/obidmscolumn_bool.h
src/obidmscolumn_bool.h
+4
-4
src/obidmscolumn_char.c
src/obidmscolumn_char.c
+35
-10
src/obidmscolumn_char.h
src/obidmscolumn_char.h
+4
-4
src/obidmscolumn_float.c
src/obidmscolumn_float.c
+31
-6
src/obidmscolumn_float.h
src/obidmscolumn_float.h
+4
-4
src/obidmscolumn_idx.c
src/obidmscolumn_idx.c
+31
-6
src/obidmscolumn_idx.h
src/obidmscolumn_idx.h
+4
-4
src/obidmscolumn_int.c
src/obidmscolumn_int.c
+30
-6
src/obidmscolumn_int.h
src/obidmscolumn_int.h
+4
-4
No files found.
python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pxd
View file @
f31d8983
...
...
@@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
cdef
extern
from
"obidmscolumn_bool.h"
nogil
:
int
obi_column_set_bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obibool_t
value
);
obibool_t
obi_column_get_bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
int
obi_column_set_
obi
bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obibool_t
value
);
obibool_t
obi_column_get_
obi
bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
python/obitools3/obidms/obidmscolumn/obidmscolumn_bool/capidmscolumn_bool.pyx
View file @
f31d8983
...
...
@@ -6,7 +6,7 @@ from .capidmscolumn_bool cimport *
cdef
class
OBIDMS_column_bool
(
OBIDMS_column
)
:
def
get_item
(
self
,
line_nb
,
element_name
):
return
obi_column_get_bool_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
return
obi_column_get_
obi
bool_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
cdef
class
OBIDMS_column_bool_read
(
OBIDMS_column_bool
)
:
...
...
@@ -22,7 +22,7 @@ cdef class OBIDMS_column_bool_read(OBIDMS_column_bool) :
cdef
class
OBIDMS_column_bool_writable
(
OBIDMS_column_bool
)
:
def
set_item
(
self
,
line_nb
,
element_name
,
value
):
return
obi_column_set_bool_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
return
obi_column_set_
obi
bool_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
def
close
(
self
):
if
obi_truncate_and_close_column
(
self
.
pointer
)
<
0
:
...
...
python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pxd
View file @
f31d8983
...
...
@@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
cdef
extern
from
"obidmscolumn_char.h"
nogil
:
int
obi_column_set_char_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obichar_t
*
value
)
obichar_t
*
obi_column_get_char_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
)
int
obi_column_set_
obi
char_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obichar_t
*
value
)
obichar_t
*
obi_column_get_
obi
char_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
)
python/obitools3/obidms/obidmscolumn/obidmscolumn_char/capidmscolumn_char.pyx
View file @
f31d8983
...
...
@@ -6,7 +6,7 @@ from .capidmscolumn_char cimport *
cdef
class
OBIDMS_column_char
(
OBIDMS_column
)
:
def
get_item
(
self
,
line_nb
,
element_name
):
return
(
obi_column_get_char_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))).
decode
(
encoding
=
'utf-8'
)[:
1
]
return
(
obi_column_get_
obi
char_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))).
decode
(
encoding
=
'utf-8'
)[:
1
]
cdef
class
OBIDMS_column_char_read
(
OBIDMS_column_char
)
:
...
...
@@ -22,7 +22,7 @@ cdef class OBIDMS_column_char_read(OBIDMS_column_char) :
cdef
class
OBIDMS_column_char_writable
(
OBIDMS_column_char
)
:
def
set_item
(
self
,
line_nb
,
element_name
,
value
):
return
obi_column_set_char_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
.
encode
(
'utf-8'
))
return
obi_column_set_
obi
char_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
.
encode
(
'utf-8'
))
def
close
(
self
):
if
obi_truncate_and_close_column
(
self
.
pointer
)
<
0
:
...
...
python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pxd
View file @
f31d8983
...
...
@@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
cdef
extern
from
"obidmscolumn_float.h"
nogil
:
int
obi_column_set_float_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obifloat_t
value
);
obifloat_t
obi_column_get_float_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
int
obi_column_set_
obi
float_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obifloat_t
value
);
obifloat_t
obi_column_get_
obi
float_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
python/obitools3/obidms/obidmscolumn/obidmscolumn_float/capidmscolumn_float.pyx
View file @
f31d8983
...
...
@@ -6,7 +6,7 @@ from .capidmscolumn_float cimport *
cdef
class
OBIDMS_column_float
(
OBIDMS_column
)
:
def
get_item
(
self
,
line_nb
,
element_name
):
return
obi_column_get_float_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
return
obi_column_get_
obi
float_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
cdef
class
OBIDMS_column_float_read
(
OBIDMS_column_float
)
:
...
...
@@ -22,7 +22,7 @@ cdef class OBIDMS_column_float_read(OBIDMS_column_float) :
cdef
class
OBIDMS_column_float_writable
(
OBIDMS_column_float
)
:
def
set_item
(
self
,
line_nb
,
element_name
,
value
):
return
obi_column_set_float_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
return
obi_column_set_
obi
float_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
def
close
(
self
):
if
obi_truncate_and_close_column
(
self
.
pointer
)
<
0
:
...
...
python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pxd
View file @
f31d8983
...
...
@@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
cdef
extern
from
"obidmscolumn_idx.h"
nogil
:
int
obi_column_set_idx_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obiidx_t
value
);
obiidx_t
obi_column_get_idx_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
int
obi_column_set_
obi
idx_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obiidx_t
value
);
obiidx_t
obi_column_get_
obi
idx_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
python/obitools3/obidms/obidmscolumn/obidmscolumn_idx/capidmscolumn_idx.pyx
View file @
f31d8983
...
...
@@ -6,7 +6,7 @@ from .capidmscolumn_idx cimport *
cdef
class
OBIDMS_column_idx
(
OBIDMS_column
)
:
def
get_item
(
self
,
line_nb
,
element_name
):
return
obi_column_get_idx_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
return
obi_column_get_
obi
idx_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
cdef
class
OBIDMS_column_idx_read
(
OBIDMS_column_idx
)
:
...
...
@@ -22,7 +22,7 @@ cdef class OBIDMS_column_idx_read(OBIDMS_column_idx) :
cdef
class
OBIDMS_column_idx_writable
(
OBIDMS_column_idx
)
:
def
set_item
(
self
,
line_nb
,
element_name
,
value
):
return
obi_column_set_idx_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
return
obi_column_set_
obi
idx_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
def
close
(
self
):
if
obi_truncate_and_close_column
(
self
.
pointer
)
<
0
:
...
...
python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pxd
View file @
f31d8983
...
...
@@ -3,5 +3,5 @@ from obitools3.obidms.obidmscolumn.capidmscolumn cimport *
cdef
extern
from
"obidmscolumn_int.h"
nogil
:
int
obi_column_set_int_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obiint_t
value
);
obiint_t
obi_column_get_int_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
int
obi_column_set_
obi
int_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obiint_t
value
);
obiint_t
obi_column_get_
obi
int_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
python/obitools3/obidms/obidmscolumn/obidmscolumn_int/capidmscolumn_int.pyx
View file @
f31d8983
...
...
@@ -6,7 +6,7 @@ from .capidmscolumn_int cimport *
cdef
class
OBIDMS_column_int
(
OBIDMS_column
)
:
def
get_item
(
self
,
line_nb
,
element_name
):
return
obi_column_get_int_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
return
obi_column_get_
obi
int_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
))
cdef
class
OBIDMS_column_int_read
(
OBIDMS_column_int
)
:
...
...
@@ -22,7 +22,7 @@ cdef class OBIDMS_column_int_read(OBIDMS_column_int) :
cdef
class
OBIDMS_column_int_writable
(
OBIDMS_column_int
)
:
def
set_item
(
self
,
line_nb
,
element_name
,
value
):
return
obi_column_set_int_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
return
obi_column_set_
obi
int_with_elt_name
(
self
.
pointer
,
line_nb
,
element_name
.
encode
(
'utf-8'
),
value
)
def
close
(
self
):
if
obi_truncate_and_close_column
(
self
.
pointer
)
<
0
:
...
...
src/obidmscolumn.c
View file @
f31d8983
...
...
@@ -600,7 +600,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
int
column_dir_file_descriptor
;
size_t
header_size
;
size_t
data_size
;
size_t
i
,
nb_elements
;
new_column
=
NULL
;
...
...
@@ -732,41 +731,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
strncpy
(
header
->
name
,
column_name
,
OBIDMS_MAX_COLNAME
);
// Fill the data with NA values
nb_elements
=
nb_lines
*
nb_elements_per_line
;
switch
(
type
)
{
case
OBI_VOID
:
// TODO;
break
;
case
OBI_INT
:
for
(
i
=
0
;
i
<
nb_elements
;
i
++
)
{
*
(((
obiint_t
*
)
(
new_column
->
data
))
+
i
)
=
OBIInt_NA
;
}
break
;
case
OBI_FLOAT
:
for
(
i
=
0
;
i
<
nb_elements
;
i
++
)
{
*
(((
obifloat_t
*
)
(
new_column
->
data
))
+
i
)
=
OBIFloat_NA
;
}
break
;
case
OBI_BOOL
:
for
(
i
=
0
;
i
<
nb_elements
;
i
++
)
{
*
(((
obibool_t
*
)
(
new_column
->
data
))
+
i
)
=
OBIBool_NA
;
}
break
;
case
OBI_CHAR
:
for
(
i
=
0
;
i
<
nb_elements
;
i
++
)
{
*
(((
obichar_t
*
)
(
new_column
->
data
))
+
i
)
=
OBIChar_NA
;
}
break
;
case
OBI_IDX
:
for
(
i
=
0
;
i
<
nb_elements
;
i
++
)
{
*
(((
obiidx_t
*
)
(
new_column
->
data
))
+
i
)
=
OBIIdx_NA
;
}
break
;
}
obi_ini_to_NA_values
(
new_column
,
0
,
nb_lines
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
...
...
@@ -1006,7 +971,7 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column)
}
// Open the column file
column_file_descriptor
=
openat
(
column_dir_file_descriptor
,
column_file_name
,
O_RDWR
|
O_CREAT
);
column_file_descriptor
=
openat
(
column_dir_file_descriptor
,
column_file_name
,
O_RDWR
);
if
(
column_file_descriptor
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
...
...
@@ -1066,6 +1031,139 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column)
}
int
obi_enlarge_column
(
OBIDMS_column_p
column
)
{
size_t
file_size
;
size_t
old_data_size
;
size_t
new_data_size
;
size_t
header_size
;
size_t
old_line_count
;
size_t
new_line_count
;
int
column_dir_file_descriptor
;
int
column_file_descriptor
;
char
*
column_file_name
;
// Get the file descriptor associated to the column directory
column_dir_file_descriptor
=
dirfd
((
column
->
column_directory
)
->
directory
);
if
(
column_dir_file_descriptor
<
0
)
{
obi_set_errno
(
OBICOLDIR_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error getting the file descriptor for a column directory"
);
return
-
1
;
}
// Get the column file name
column_file_name
=
build_column_file_name
((
column
->
header
)
->
name
,
(
column
->
header
)
->
version
);
if
(
column_file_name
==
NULL
)
{
return
-
1
;
}
// Open the column file
column_file_descriptor
=
openat
(
column_dir_file_descriptor
,
column_file_name
,
O_RDWR
|
O_CREAT
);
if
(
column_file_descriptor
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error getting the file descriptor of a column file"
);
free
(
column_file_name
);
return
-
1
;
}
// Calculate the new file size
old_line_count
=
(
column
->
header
)
->
line_count
;
new_line_count
=
old_line_count
*
GROWTH_FACTOR
;
if
(
new_line_count
>
MAXIMUM_LINE_COUNT
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error enlarging a column file: new line count greater than the maximum allowed"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
old_data_size
=
(
column
->
header
)
->
line_count
*
(
column
->
header
)
->
nb_elements_per_line
*
sizeof
((
column
->
header
)
->
data_type
);
new_data_size
=
old_data_size
*
GROWTH_FACTOR
;
header_size
=
(
column
->
header
)
->
header_size
;
file_size
=
header_size
+
new_data_size
;
// Unmap the data
if
(
munmap
(
column
->
data
,
old_data_size
)
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error munmapping the data of a column before enlarging"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
// Unmap the header
if
(
munmap
(
column
->
header
,
header_size
)
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error munmapping the header of a column before enlarging"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
// Enlarge the file
if
(
ftruncate
(
column_file_descriptor
,
file_size
)
<
0
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error enlarging a column file"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
// Remap the header (TODO not sure if necessary??)
column
->
header
=
mmap
(
NULL
,
header_size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
column_file_descriptor
,
0
);
if
(
column
->
header
==
MAP_FAILED
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error mmapping the header of a column after enlarging file"
);
close
(
column_file_descriptor
);
free
(
column_file_name
);
return
-
1
;
}
// Remap the data
column
->
data
=
mmap
(
NULL
,
new_data_size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
column_file_descriptor
,
(
column
->
header
)
->
header_size
);
if
(
column
->
data
==
MAP_FAILED
)
{
obi_set_errno
(
OBICOL_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error re-mmapping the data of a column after enlarging the file"
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
-
1
;
}
// Set new line count
(
column
->
header
)
->
line_count
=
new_line_count
;
// Initialize new data lines to NA
obi_ini_to_NA_values
(
column
,
old_line_count
,
new_line_count
-
old_line_count
);
free
(
column_file_name
);
close
(
column_file_descriptor
);
return
0
;
}
int
obi_truncate_and_close_column
(
OBIDMS_column_p
column
)
{
if
(
obi_truncate_column_to_lines_used
(
column
)
<
0
)
...
...
@@ -1077,6 +1175,50 @@ 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
)
{
size_t
i
,
end
,
nb_elements
;
nb_elements
=
nb_lines
*
((
column
->
header
)
->
nb_elements_per_line
);
end
=
start
+
nb_elements
;
switch
((
column
->
header
)
->
data_type
)
{
case
OBI_VOID
:
// TODO;
break
;
case
OBI_INT
:
for
(
i
=
start
;
i
<
end
;
i
++
)
{
*
(((
obiint_t
*
)
(
column
->
data
))
+
i
)
=
OBIInt_NA
;
}
break
;
case
OBI_FLOAT
:
for
(
i
=
start
;
i
<
end
;
i
++
)
{
*
(((
obifloat_t
*
)
(
column
->
data
))
+
i
)
=
OBIFloat_NA
;
}
break
;
case
OBI_BOOL
:
for
(
i
=
start
;
i
<
end
;
i
++
)
{
*
(((
obibool_t
*
)
(
column
->
data
))
+
i
)
=
OBIBool_NA
;
}
break
;
case
OBI_CHAR
:
for
(
i
=
start
;
i
<
end
;
i
++
)
{
*
(((
obichar_t
*
)
(
column
->
data
))
+
i
)
=
OBIChar_NA
;
}
break
;
case
OBI_IDX
:
for
(
i
=
start
;
i
<
end
;
i
++
)
{
*
(((
obiidx_t
*
)
(
column
->
data
))
+
i
)
=
OBIIdx_NA
;
}
break
;
}
}
void
obi_column_make_unwritable
(
OBIDMS_column_p
column
)
{
column
->
writable
=
false
;
...
...
src/obidmscolumn.h
View file @
f31d8983
...
...
@@ -27,6 +27,8 @@
#define ELEMENTS_NAMES_MAX (2048)
#define INITIAL_LINE_COUNT (1000)
#define GROWTH_FACTOR (2)
#define MAXIMUM_LINE_COUNT (1000000)
typedef
int32_t
obiversion_t
;
/**< Used to store the column version number
...
...
@@ -205,6 +207,20 @@ int obi_close_column(OBIDMS_column_p column);
int
obi_truncate_column_to_lines_used
(
OBIDMS_column_p
column
);
/**
* @brief Enlarges a column file.
*
* @param column a pointer on an OBIDMS column
*
* @return 0 if the operation was successfully completed
* @return -1 if an error occurred
*
* @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int
obi_enlarge_column
(
OBIDMS_column_p
column
);
/**
* @brief Truncates a column file to the number of lines used and closes it.
*
...
...
@@ -219,6 +235,19 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
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.
*
* @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
);
/**
* @brief Sets the 'writable' header attribute of an OBIDMS column to False.
*
...
...
src/obidmscolumn_bool.c
View file @
f31d8983
...
...
@@ -28,23 +28,47 @@
*
**********************************************************************/
int
obi_column_set_bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
,
obibool_t
value
)
int
obi_column_set_
obi
bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
,
obibool_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
,
"
\n
Error 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
*
(((
obibool_t
*
)
(
column
->
data
))
+
(
line_nb
*
((
column
->
header
)
->
nb_elements_per_line
))
+
element_idx
)
=
value
;
return
0
;
}
obibool_t
obi_column_get_bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
)
obibool_t
obi_column_get_
obi
bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
)
{
if
((
line_nb
+
1
)
>
(
column
->
header
)
->
line_count
)
{
obidebug
(
1
,
"
\n
Error trying to get a value that is beyond the current line count"
);
return
-
1
;
// TODO return NA value?
}
return
*
(((
obibool_t
*
)
(
column
->
data
))
+
(
line_nb
*
((
column
->
header
)
->
nb_elements_per_line
))
+
element_idx
);
}
int
obi_column_set_bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obibool_t
value
)
int
obi_column_set_
obi
bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obibool_t
value
)
{
size_t
element_idx
;
...
...
@@ -66,13 +90,13 @@ int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, ch
return
-
1
;
}
obi_column_set_bool_with_elt_idx
(
column
,
line_nb
,
element_idx
,
value
);
obi_column_set_
obi
bool_with_elt_idx
(
column
,
line_nb
,
element_idx
,
value
);
return
0
;
}
obibool_t
obi_column_get_bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
)
obibool_t
obi_column_get_
obi
bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
)
{
size_t
element_idx
;
...
...
@@ -94,5 +118,6 @@ obibool_t obi_column_get_bool_with_elt_name(OBIDMS_column_p column, size_t line_
return
-
1
;
}
return
obi_column_get_bool_with_elt_idx
(
column
,
line_nb
,
element_idx
);
return
obi_column_get_
obi
bool_with_elt_idx
(
column
,
line_nb
,
element_idx
);
}
src/obidmscolumn_bool.h
View file @
f31d8983
...
...
@@ -37,7 +37,7 @@
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int
obi_column_set_bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
,
obibool_t
value
);
int
obi_column_set_
obi
bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
,
obibool_t
value
);
/**
...
...
@@ -54,7 +54,7 @@ int obi_column_set_bool_with_elt_idx(OBIDMS_column_p column, size_t line_nb, siz
* @since July 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
obibool_t
obi_column_get_bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
);
obibool_t
obi_column_get_
obi
bool_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
);
/**
...
...
@@ -78,7 +78,7 @@ obibool_t obi_column_get_bool_with_elt_idx(OBIDMS_column_p column, size_t line_n
* @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int
obi_column_set_bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obibool_t
value
);
int
obi_column_set_
obi
bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
,
obibool_t
value
);
/**
...
...
@@ -97,5 +97,5 @@ int obi_column_set_bool_with_elt_name(OBIDMS_column_p column, size_t line_nb, ch
* @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
obibool_t
obi_column_get_bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
obibool_t
obi_column_get_
obi
bool_with_elt_name
(
OBIDMS_column_p
column
,
size_t
line_nb
,
char
*
element_name
);
src/obidmscolumn_char.c
View file @
f31d8983
...
...
@@ -28,23 +28,47 @@
*
**********************************************************************/
int
obi_column_set_
char_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
,
size_t
line_nb
,
size_t
element_idx
,
obichar_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
,
"
\n
Error 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
;
*
(((
obichar_t
*
)
(
column
->
data
))
+
(
line_nb
*
((
column
->
header
)
->
nb_elements_per_line
))
+
element_idx
)
=
value
[
0
];
// Set the value
*
(((
obichar_t
*
)
(
column
->
data
))
+
(
line_nb
*
((
column
->
header
)
->
nb_elements_per_line
))
+
element_idx
)
=
value
;
return
0
;
}
obichar_t
*
obi_column_get_
char_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
)
obichar_t
obi_column_get_obi
char_with_elt_idx
(
OBIDMS_column_p
column
,
size_t
line_nb
,
size_t
element_idx
)
{
return
((
obichar_t
*
)
(
column
->
data
))
+
(
line_nb
*
((
column
->
header
)
->
nb_elements_per_line
))
+
element_idx
;
if
((
line_nb
+
1
)
>
(
column
->
header
)
->
line_count
)
{
obidebug
(
1
,
"
\n
Error trying to get a value that is beyond the current line count"
);
return
'\0'
;
// TODO return NA value?
}
return
*
(((
obichar_t
*
)
(
column
->
data
))
+
(
line_nb
*
((
column
->
header
)
->
nb_elements_per_line
))
+
element_idx
);
}
int
obi_column_set_
char_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
,
size_t
line_nb
,
char
*
element_name
,
obichar_t
value
)
{
size_t
element_idx
;
...
...
@@ -66,13 +90,13 @@ int obi_column_set_char_with_elt_name(OBIDMS_column_p column, size_t line_nb, ch
return
-
1
;
}
obi_column_set_char_with_elt_idx
(
column
,
line_nb
,
element_idx
,
value
);