1
1
use crate :: bindings as ll_bindings;
2
- use crate :: tsk_flags_t ;
2
+ use crate :: Flags ;
3
3
use bitflags:: bitflags;
4
4
5
5
bitflags ! {
@@ -39,7 +39,8 @@ bitflags! {
39
39
/// assert!(!flags.contains(SO::FILTER_POPULATIONS));
40
40
/// ```
41
41
#[ derive( Default ) ]
42
- pub struct SimplificationOptions : tsk_flags_t {
42
+ #[ repr( transparent) ]
43
+ pub struct SimplificationOptions : Flags {
43
44
/// Default behavior
44
45
const NONE = 0 ;
45
46
const FILTER_SITES = ll_bindings:: TSK_FILTER_SITES ;
@@ -70,7 +71,8 @@ bitflags! {
70
71
bitflags ! {
71
72
/// Modify behavior of [`crate::TableCollection::clear`].
72
73
#[ derive( Default ) ]
73
- pub struct TableClearOptions : tsk_flags_t {
74
+ #[ repr( transparent) ]
75
+ pub struct TableClearOptions : Flags {
74
76
/// Default behavior.
75
77
const NONE = 0 ;
76
78
const CLEAR_METADATA_SCHEMAS = ll_bindings:: TSK_CLEAR_METADATA_SCHEMAS ;
@@ -82,7 +84,8 @@ bitflags! {
82
84
bitflags ! {
83
85
/// Modify behavior of [`crate::TableCollection::equals`].
84
86
#[ derive( Default ) ]
85
- pub struct TableEqualityOptions : tsk_flags_t {
87
+ #[ repr( transparent) ]
88
+ pub struct TableEqualityOptions : Flags {
86
89
/// Default behavior.
87
90
const NONE = 0 ;
88
91
const IGNORE_METADATA = ll_bindings:: TSK_CMP_IGNORE_METADATA ;
@@ -95,7 +98,8 @@ bitflags! {
95
98
bitflags ! {
96
99
/// Modify behavior of [`crate::TableCollection::sort`].
97
100
#[ derive( Default ) ]
98
- pub struct TableSortOptions : tsk_flags_t {
101
+ #[ repr( transparent) ]
102
+ pub struct TableSortOptions : Flags {
99
103
/// Default behavior.
100
104
const NONE = 0 ;
101
105
/// Do not validate contents of edge table.
@@ -106,7 +110,8 @@ bitflags! {
106
110
bitflags ! {
107
111
/// Modify behavior of [`crate::TableCollection::sort_individuals`].
108
112
#[ derive( Default ) ]
109
- pub struct IndividualTableSortOptions : tsk_flags_t {
113
+ #[ repr( transparent) ]
114
+ pub struct IndividualTableSortOptions : Flags {
110
115
/// Default behavior.
111
116
const NONE = 0 ;
112
117
}
@@ -116,7 +121,8 @@ bitflags! {
116
121
/// Specify the behavior of iterating over [`Tree`] objects.
117
122
/// See [`TreeSequence::tree_iterator`].
118
123
#[ derive( Default ) ]
119
- pub struct TreeFlags : tsk_flags_t {
124
+ #[ repr( transparent) ]
125
+ pub struct TreeFlags : Flags {
120
126
/// Default behavior.
121
127
const NONE = 0 ;
122
128
/// Update sample lists, enabling [`Tree::samples`].
@@ -140,7 +146,8 @@ bitflags! {
140
146
/// call [`crate::TableCollection::build_index`] prior to calling
141
147
/// [`crate::TableCollection::dump`].
142
148
#[ derive( Default ) ]
143
- pub struct TableOutputOptions : tsk_flags_t {
149
+ #[ repr( transparent) ]
150
+ pub struct TableOutputOptions : Flags {
144
151
const NONE = 0 ;
145
152
}
146
153
}
@@ -149,7 +156,8 @@ bitflags! {
149
156
/// Modify behavior of [`crate::TableCollection::tree_sequence`]
150
157
/// and [`crate::TreeSequence::new`].
151
158
#[ derive( Default ) ]
152
- pub struct TreeSequenceFlags : tsk_flags_t {
159
+ #[ repr( transparent) ]
160
+ pub struct TreeSequenceFlags : Flags {
153
161
/// Default behavior
154
162
const NONE = 0 ;
155
163
/// If used, then build table indexes if they are not present.
@@ -159,9 +167,10 @@ bitflags! {
159
167
160
168
bitflags ! {
161
169
#[ derive( Default ) ]
162
- pub struct TableIntegrityCheckFlags : tsk_flags_t {
170
+ #[ repr( transparent) ]
171
+ pub struct TableIntegrityCheckFlags : Flags {
163
172
/// Default behavior is a set of basic checks
164
- const DEFAULT = 0 ;
173
+ const NONE = 0 ;
165
174
/// Check that edges are ordered
166
175
const CHECK_EDGE_ORDERING =ll_bindings:: TSK_CHECK_EDGE_ORDERING ;
167
176
/// Check that sites are ordered
@@ -180,3 +189,81 @@ bitflags! {
180
189
const CHECK_TREES =ll_bindings:: TSK_CHECK_TREES ;
181
190
}
182
191
}
192
+
193
+ bitflags ! {
194
+ #[ derive( Default ) ]
195
+ #[ repr( transparent) ]
196
+ /// Node flags
197
+ pub struct NodeFlags : Flags {
198
+ /// Default (empty)
199
+ const NONE = 0 ;
200
+ /// Node is a sample
201
+ const IS_SAMPLE = ll_bindings:: TSK_NODE_IS_SAMPLE ;
202
+ }
203
+ }
204
+
205
+ bitflags ! {
206
+ #[ derive( Default ) ]
207
+ #[ repr( transparent) ]
208
+ /// Individual flags
209
+ pub struct IndividualFlags : Flags {
210
+ /// Default (empty)
211
+ const NONE = 0 ;
212
+ }
213
+ }
214
+
215
+ impl_flags ! ( SimplificationOptions ) ;
216
+ impl_flags ! ( TableClearOptions ) ;
217
+ impl_flags ! ( TableEqualityOptions ) ;
218
+ impl_flags ! ( TreeSequenceFlags ) ;
219
+ impl_flags ! ( TableSortOptions ) ;
220
+ impl_flags ! ( TreeFlags ) ;
221
+ impl_flags ! ( IndividualTableSortOptions ) ;
222
+ impl_flags ! ( TableIntegrityCheckFlags ) ;
223
+ impl_flags ! ( TableOutputOptions ) ;
224
+
225
+ impl_from_for_flag_types ! ( SimplificationOptions ) ;
226
+ impl_from_for_flag_types ! ( TableClearOptions ) ;
227
+ impl_from_for_flag_types ! ( TableEqualityOptions ) ;
228
+ impl_from_for_flag_types ! ( TreeSequenceFlags ) ;
229
+ impl_from_for_flag_types ! ( TableSortOptions ) ;
230
+ impl_from_for_flag_types ! ( TreeFlags ) ;
231
+ impl_from_for_flag_types ! ( IndividualTableSortOptions ) ;
232
+ impl_from_for_flag_types ! ( TableIntegrityCheckFlags ) ;
233
+ impl_from_for_flag_types ! ( TableOutputOptions ) ;
234
+
235
+ impl From < Flags > for NodeFlags {
236
+ fn from ( flags : Flags ) -> Self {
237
+ // Safety: node flags can contain user-defined values.
238
+ // It is an error on the user's part to define flags
239
+ // in the first 16 bits, as per the C API docs.
240
+ unsafe { Self :: from_bits_unchecked ( flags) }
241
+ }
242
+ }
243
+
244
+ impl From < Flags > for IndividualFlags {
245
+ fn from ( flags : Flags ) -> Self {
246
+ // Safety: node flags can contain user-defined values.
247
+ // It is an error on the user's part to define flags
248
+ // in the first 16 bits, as per the C API docs.
249
+ unsafe { Self :: from_bits_unchecked ( flags) }
250
+ }
251
+ }
252
+
253
+ impl NodeFlags {
254
+ /// We do not enforce valid flags in the library.
255
+ /// This function will return `true` if any bits
256
+ /// are set that do not correspond to allowed flags.
257
+ pub fn is_valid ( & self ) -> bool {
258
+ true
259
+ }
260
+ }
261
+
262
+ impl IndividualFlags {
263
+ /// We do not enforce valid flags in the library.
264
+ /// This function will return `true` if any bits
265
+ /// are set that do not correspond to allowed flags.
266
+ pub fn is_valid ( & self ) -> bool {
267
+ true
268
+ }
269
+ }
0 commit comments