@@ -16,6 +16,24 @@ pub struct Bookmark {
16
16
pub offsets : ll_bindings:: tsk_bookmark_t ,
17
17
}
18
18
19
+ macro_rules! bookmark_getter {
20
+ ( $name: ident) => {
21
+ /// Get the current value
22
+ pub fn $name( & self ) -> $crate:: SizeType {
23
+ self . offsets. $name. into( )
24
+ }
25
+ } ;
26
+ }
27
+
28
+ macro_rules! bookmark_setter {
29
+ ( $name: ident, $field: ident) => {
30
+ /// Set the current value
31
+ pub fn $name<I : Into <$crate:: bindings:: tsk_size_t>>( & mut self , value: I ) {
32
+ self . offsets. $field = value. into( ) ;
33
+ }
34
+ } ;
35
+ }
36
+
19
37
impl Bookmark {
20
38
pub const fn new ( ) -> Self {
21
39
Bookmark {
@@ -31,13 +49,37 @@ impl Bookmark {
31
49
} ,
32
50
}
33
51
}
52
+
53
+ bookmark_getter ! ( individuals) ;
54
+ bookmark_getter ! ( nodes) ;
55
+ bookmark_getter ! ( edges) ;
56
+ bookmark_getter ! ( migrations) ;
57
+ bookmark_getter ! ( sites) ;
58
+ bookmark_getter ! ( mutations) ;
59
+ bookmark_getter ! ( populations) ;
60
+ bookmark_getter ! ( provenances) ;
61
+ bookmark_setter ! ( set_individuals, individuals) ;
62
+ bookmark_setter ! ( set_nodes, nodes) ;
63
+ bookmark_setter ! ( set_edges, edges) ;
64
+ bookmark_setter ! ( set_migrations, migrations) ;
65
+ bookmark_setter ! ( set_sites, sites) ;
66
+ bookmark_setter ! ( set_mutations, mutations) ;
67
+ bookmark_setter ! ( set_populations, populations) ;
68
+ bookmark_setter ! ( set_provenances, provenances) ;
34
69
}
35
70
36
71
#[ cfg( test) ]
37
72
mod test {
38
73
39
74
use super :: * ;
40
75
76
+ macro_rules! test_set {
77
+ ( $bmark: ident, $setter: ident, $getter: ident) => {
78
+ $bmark. $setter( $crate:: SizeType :: from( 3 ) ) ;
79
+ assert_eq!( $bmark. $getter( ) , 3 ) ;
80
+ } ;
81
+ }
82
+
41
83
#[ test]
42
84
fn test_bookmark_mutability ( ) {
43
85
let mut b = Bookmark :: new ( ) ;
@@ -49,7 +91,22 @@ mod test {
49
91
assert_eq ! ( b. offsets. mutations, 0 ) ;
50
92
assert_eq ! ( b. offsets. populations, 0 ) ;
51
93
assert_eq ! ( b. offsets. provenances, 0 ) ;
52
- b. offsets . nodes = 3 ;
53
- assert_eq ! ( b. offsets. nodes, 3 ) ;
94
+ assert_eq ! ( b. nodes( ) , 0 ) ;
95
+ assert_eq ! ( b. edges( ) , 0 ) ;
96
+ assert_eq ! ( b. individuals( ) , 0 ) ;
97
+ assert_eq ! ( b. migrations( ) , 0 ) ;
98
+ assert_eq ! ( b. sites( ) , 0 ) ;
99
+ assert_eq ! ( b. mutations( ) , 0 ) ;
100
+ assert_eq ! ( b. populations( ) , 0 ) ;
101
+ assert_eq ! ( b. provenances( ) , 0 ) ;
102
+
103
+ test_set ! ( b, set_nodes, nodes) ;
104
+ test_set ! ( b, set_edges, edges) ;
105
+ test_set ! ( b, set_migrations, migrations) ;
106
+ test_set ! ( b, set_sites, sites) ;
107
+ test_set ! ( b, set_mutations, mutations) ;
108
+ test_set ! ( b, set_populations, populations) ;
109
+ test_set ! ( b, set_provenances, provenances) ;
110
+ test_set ! ( b, set_individuals, individuals) ;
54
111
}
55
112
}
0 commit comments