Skip to content

Commit c648956

Browse files
committed
more
1 parent 54d21b0 commit c648956

File tree

7 files changed

+104
-82
lines changed

7 files changed

+104
-82
lines changed

src/individual_table.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,7 @@ impl IndividualTable {
217217
/// * `Some(location)` if `row` is valid.
218218
/// * `None` otherwise.
219219
pub fn location<I: Into<IndividualId> + Copy>(&self, row: I) -> Option<&[Location]> {
220-
assert!(
221-
(self.num_rows() == 0 && self.as_ref().location_length == 0)
222-
|| (!self.as_ref().location.is_null() && !self.as_ref().location_offset.is_null())
223-
);
224-
unsafe {
225-
sys::tsk_ragged_column_access(
226-
row.into(),
227-
self.as_ref().location,
228-
self.num_rows(),
229-
self.as_ref().location_offset,
230-
self.as_ref().location_length,
231-
)
232-
}
220+
self.table_.location(row.into())
233221
}
234222

235223
/// Return the parents for a given row.
@@ -239,19 +227,7 @@ impl IndividualTable {
239227
/// * `Some(parents)` if `row` is valid.
240228
/// * `None` otherwise.
241229
pub fn parents<I: Into<IndividualId> + Copy>(&self, row: I) -> Option<&[IndividualId]> {
242-
assert!(
243-
(self.num_rows() == 0 && self.as_ref().parents_length == 0)
244-
|| (!self.as_ref().parents.is_null() && !self.as_ref().location_offset.is_null())
245-
);
246-
unsafe {
247-
sys::tsk_ragged_column_access(
248-
row.into(),
249-
self.as_ref().parents,
250-
self.num_rows(),
251-
self.as_ref().parents_offset,
252-
self.as_ref().parents_length,
253-
)
254-
}
230+
self.table_.parents(row.into())
255231
}
256232

257233
/// Return the metadata for a given row.

src/provenance.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -192,27 +192,7 @@ impl ProvenanceTable {
192192
/// # }
193193
/// ```
194194
pub fn timestamp<P: Into<ProvenanceId> + Copy>(&self, row: P) -> Option<&str> {
195-
assert!(
196-
(self.num_rows() != 0 && self.as_ref().timestamp_length != 0)
197-
|| (!self.as_ref().timestamp.is_null()
198-
&& !self.as_ref().timestamp_offset.is_null())
199-
);
200-
201-
// SAFETY: the previous assert checks the safety
202-
// requirements
203-
let timestamp_slice = unsafe {
204-
sys::tsk_ragged_column_access(
205-
row.into(),
206-
self.as_ref().timestamp,
207-
self.num_rows(),
208-
self.as_ref().timestamp_offset,
209-
self.as_ref().timestamp_length,
210-
)
211-
};
212-
match timestamp_slice {
213-
Some(tstamp) => std::str::from_utf8(tstamp).ok(),
214-
None => None,
215-
}
195+
self.table_.timestamp(row.into())
216196
}
217197

218198
/// Get the provenance record for row `row`.
@@ -236,26 +216,7 @@ impl ProvenanceTable {
236216
/// # panic!("Expected Some(timestamp)");
237217
/// # }
238218
pub fn record<P: Into<ProvenanceId> + Copy>(&self, row: P) -> Option<&str> {
239-
assert!(
240-
(self.num_rows() != 0 && self.as_ref().record_length != 0)
241-
|| (!self.as_ref().record.is_null() && !self.as_ref().record_offset.is_null())
242-
);
243-
244-
// SAFETY: the previous assert checks the safety
245-
// requirements
246-
let record_slice = unsafe {
247-
sys::tsk_ragged_column_access(
248-
row.into(),
249-
self.as_ref().record,
250-
self.num_rows(),
251-
self.as_ref().record_offset,
252-
self.as_ref().record_length,
253-
)
254-
};
255-
match record_slice {
256-
Some(rec) => std::str::from_utf8(rec).ok(),
257-
None => None,
258-
}
219+
self.table_.record(row.into())
259220
}
260221

261222
/// Obtain a [`ProvenanceTableRow`] for row `row`.

src/site_table.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,7 @@ impl SiteTable {
210210
/// * `Some(ancestral state)` if `row` is valid.
211211
/// * `None` otherwise.
212212
pub fn ancestral_state<S: Into<SiteId>>(&self, row: S) -> Option<&[u8]> {
213-
assert!(
214-
(self.num_rows() == 0 && self.as_ref().ancestral_state_length == 0)
215-
|| (!self.as_ref().ancestral_state.is_null()
216-
&& !self.as_ref().ancestral_state_offset.is_null())
217-
);
218-
unsafe {
219-
sys::tsk_ragged_column_access(
220-
row.into(),
221-
self.as_ref().ancestral_state,
222-
self.num_rows(),
223-
self.as_ref().ancestral_state_offset,
224-
self.as_ref().ancestral_state_length,
225-
)
226-
}
213+
self.table_.ancestral_state(row.into())
227214
}
228215

229216
/// Retrieve decoded metadata for a `row`.

src/sys/individual_table.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,38 @@ impl IndividualTable {
7575
}
7676

7777
raw_metadata_getter_for_tables!(IndividualId);
78+
79+
pub fn location(&self, row: IndividualId) -> Option<&[super::newtypes::Location]> {
80+
assert!(
81+
(self.as_ref().num_rows == 0 && self.as_ref().location_length == 0)
82+
|| (!self.as_ref().location.is_null() && !self.as_ref().location_offset.is_null())
83+
);
84+
unsafe {
85+
super::tsk_ragged_column_access(
86+
row,
87+
self.as_ref().location,
88+
self.as_ref().num_rows,
89+
self.as_ref().location_offset,
90+
self.as_ref().location_length,
91+
)
92+
}
93+
}
94+
95+
pub fn parents(&self, row: IndividualId) -> Option<&[IndividualId]> {
96+
assert!(
97+
(self.as_ref().num_rows == 0 && self.as_ref().parents_length == 0)
98+
|| (!self.as_ref().parents.is_null() && !self.as_ref().location_offset.is_null())
99+
);
100+
unsafe {
101+
super::tsk_ragged_column_access(
102+
row,
103+
self.as_ref().parents,
104+
self.as_ref().num_rows,
105+
self.as_ref().parents_offset,
106+
self.as_ref().parents_length,
107+
)
108+
}
109+
}
78110
}
79111

80112
impl Default for IndividualTable {

src/sys/mutation_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl MutationTable {
109109
// SAFETY: either both columns are empty or both pointers at not NULL,
110110
// in which case the correct lengths are from the low-level objects
111111
unsafe {
112-
super::tsk_ragged_column_access(
112+
super::tsk_ragged_column_access(
113113
row,
114114
self.as_ref().derived_state,
115115
self.as_ref().num_rows,

src/sys/provenance_table.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::ptr::NonNull;
22

3+
use super::newtypes::ProvenanceId;
4+
35
use super::bindings::tsk_id_t;
46
use super::bindings::tsk_provenance_table_add_row;
57
use super::bindings::tsk_provenance_table_clear;
@@ -55,6 +57,53 @@ impl ProvenanceTable {
5557
};
5658
Ok(rv)
5759
}
60+
61+
pub fn timestamp(&self, row: ProvenanceId) -> Option<&str> {
62+
assert!(
63+
(self.as_ref().num_rows != 0 && self.as_ref().timestamp_length != 0)
64+
|| (!self.as_ref().timestamp.is_null()
65+
&& !self.as_ref().timestamp_offset.is_null())
66+
);
67+
68+
// SAFETY: the previous assert checks the safety
69+
// requirements
70+
let timestamp_slice = unsafe {
71+
super::tsk_ragged_column_access(
72+
row,
73+
self.as_ref().timestamp,
74+
self.as_ref().num_rows,
75+
self.as_ref().timestamp_offset,
76+
self.as_ref().timestamp_length,
77+
)
78+
};
79+
match timestamp_slice {
80+
Some(tstamp) => std::str::from_utf8(tstamp).ok(),
81+
None => None,
82+
}
83+
}
84+
85+
pub fn record(&self, row: ProvenanceId) -> Option<&str> {
86+
assert!(
87+
(self.as_ref().num_rows != 0 && self.as_ref().record_length != 0)
88+
|| (!self.as_ref().record.is_null() && !self.as_ref().record_offset.is_null())
89+
);
90+
91+
// SAFETY: the previous assert checks the safety
92+
// requirements
93+
let record_slice = unsafe {
94+
super::tsk_ragged_column_access(
95+
row,
96+
self.as_ref().record,
97+
self.as_ref().num_rows,
98+
self.as_ref().record_offset,
99+
self.as_ref().record_length,
100+
)
101+
};
102+
match record_slice {
103+
Some(rec) => std::str::from_utf8(rec).ok(),
104+
None => None,
105+
}
106+
}
58107
}
59108

60109
impl Default for ProvenanceTable {

src/sys/site_table.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ impl SiteTable {
7575
}
7676

7777
raw_metadata_getter_for_tables!(SiteId);
78+
79+
pub fn ancestral_state(&self, row: SiteId) -> Option<&[u8]> {
80+
assert!(
81+
(self.as_ref().num_rows == 0 && self.as_ref().ancestral_state_length == 0)
82+
|| (!self.as_ref().ancestral_state.is_null()
83+
&& !self.as_ref().ancestral_state_offset.is_null())
84+
);
85+
unsafe {
86+
super::tsk_ragged_column_access(
87+
row,
88+
self.as_ref().ancestral_state,
89+
self.as_ref().num_rows,
90+
self.as_ref().ancestral_state_offset,
91+
self.as_ref().ancestral_state_length,
92+
)
93+
}
94+
}
7895
}
7996

8097
impl Default for SiteTable {

0 commit comments

Comments
 (0)