Skip to content

Commit 4df2fa4

Browse files
committed
more
1 parent cd421fe commit 4df2fa4

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

src/node_table.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,7 @@ impl NodeTable {
480480
/// # }
481481
/// ```
482482
pub fn time<N: Into<NodeId> + Copy>(&self, row: N) -> Option<Time> {
483-
assert!(self.num_rows() == 0 || !self.as_ref().time.is_null());
484-
// SAFETY: either the column is empty or the pointer is not null,
485-
// in which case the correct lengths are from the low-level objects
486-
unsafe {
487-
sys::tsk_column_access::<Time, _, _, _>(row.into(), self.as_ref().time, self.num_rows())
488-
}
483+
self.table_.time(row.into())
489484
}
490485

491486
/// Return the ``flags`` value from row ``row`` of the table.
@@ -510,16 +505,7 @@ impl NodeTable {
510505
/// # }
511506
/// ```
512507
pub fn flags<N: Into<NodeId> + Copy>(&self, row: N) -> Option<NodeFlags> {
513-
assert!(self.num_rows() == 0 || !self.as_ref().flags.is_null());
514-
// SAFETY: either the column is empty or the pointer is not null,
515-
// in which case the correct lengths are from the low-level objects
516-
unsafe {
517-
sys::tsk_column_access::<NodeFlags, _, _, _>(
518-
row.into(),
519-
self.as_ref().flags,
520-
self.num_rows(),
521-
)
522-
}
508+
self.table_.flags(row.into())
523509
}
524510

525511
/// Return the ``population`` value from row ``row`` of the table.
@@ -544,16 +530,7 @@ impl NodeTable {
544530
/// * `Some(population)` if `row` is valid.
545531
/// * `None` otherwise.
546532
pub fn population<N: Into<NodeId> + Copy>(&self, row: N) -> Option<PopulationId> {
547-
assert!(self.num_rows() == 0 || !self.as_ref().population.is_null());
548-
// SAFETY: either the column is empty or the pointer is not null,
549-
// in which case the correct lengths are from the low-level objects
550-
unsafe {
551-
sys::tsk_column_access::<PopulationId, _, _, _>(
552-
row.into(),
553-
self.as_ref().population,
554-
self.num_rows(),
555-
)
556-
}
533+
self.table_.population(row.into())
557534
}
558535

559536
/// Return the ``population`` value from row ``row`` of the table.
@@ -592,16 +569,7 @@ impl NodeTable {
592569
/// * `Some(individual)` if `row` is valid.
593570
/// * `None` otherwise.
594571
pub fn individual<N: Into<NodeId> + Copy>(&self, row: N) -> Option<IndividualId> {
595-
assert!(self.num_rows() == 0 || !self.as_ref().individual.is_null());
596-
// SAFETY: either the column is empty or the pointer is not null,
597-
// in which case the correct lengths are from the low-level objects
598-
unsafe {
599-
sys::tsk_column_access::<IndividualId, _, _, _>(
600-
row.into(),
601-
self.as_ref().individual,
602-
self.num_rows(),
603-
)
604-
}
572+
self.table_.individual(row.into())
605573
}
606574

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

src/sys/node_table.rs

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

3+
use crate::IndividualId;
4+
use crate::NodeFlags;
5+
use crate::PopulationId;
6+
use crate::Time;
7+
38
use super::bindings::tsk_node_table_add_row;
49
use super::bindings::tsk_node_table_clear;
510
use super::bindings::tsk_node_table_init;
@@ -108,6 +113,22 @@ impl NodeTable {
108113
})
109114
}
110115
}
116+
117+
pub fn individual(&self, row: NodeId) -> Option<IndividualId> {
118+
safe_tsk_column_access!(self, row, IndividualId, individual )
119+
}
120+
121+
pub fn population(&self, row: NodeId) -> Option<PopulationId> {
122+
safe_tsk_column_access!(self, row, PopulationId, population )
123+
}
124+
125+
pub fn time(&self, row: NodeId) -> Option<Time> {
126+
safe_tsk_column_access!(self, row, Time, time )
127+
}
128+
129+
pub fn flags(&self, row: NodeId) -> Option<NodeFlags> {
130+
safe_tsk_column_access!(self, row, NodeFlags, flags )
131+
}
111132
}
112133

113134
impl Default for NodeTable {

0 commit comments

Comments
 (0)