Skip to content

Commit 460670c

Browse files
committed
cool
1 parent 41a62c7 commit 460670c

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

src/sys/flags.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ macro_rules! bits {
3939
pub fn bits(&self) -> RawFlags {
4040
self.0
4141
}
42-
}
42+
};
43+
}
44+
45+
macro_rules! contains {
46+
() => {
47+
pub fn contains<I>(&self, bit: I) -> bool
48+
where
49+
I: Into<Self> + Copy,
50+
{
51+
bit.into().0 == 0 || (self.0 & bit.into().0) != 0
52+
}
53+
};
4354
}
4455

4556
/// Control the behavior of table simplification.
@@ -79,29 +90,29 @@ pub struct SimplificationOptions(RawFlags);
7990

8091
impl SimplificationOptions {
8192
/// Default behavior
82-
const NONE: RawFlags = 0;
83-
const FILTER_SITES: RawFlags = ll_bindings::TSK_SIMPLIFY_FILTER_SITES;
93+
pub const NONE: RawFlags = 0;
94+
pub const FILTER_SITES: RawFlags = ll_bindings::TSK_SIMPLIFY_FILTER_SITES;
8495
/// If True, remove any populations that are not referenced by
8596
/// nodes after simplification; new population IDs are allocated
8697
/// sequentially from zero.
8798
/// If False, the population table will not be altered in any way.
88-
const FILTER_POPULATIONS: RawFlags = ll_bindings::TSK_SIMPLIFY_FILTER_POPULATIONS;
99+
pub const FILTER_POPULATIONS: RawFlags = ll_bindings::TSK_SIMPLIFY_FILTER_POPULATIONS;
89100
/// If True, remove any individuals that are not referenced by nodes
90101
/// after simplification; new individual IDs are allocated sequentially
91102
/// from zero. If False, the individual table will not be altered in any way.
92-
const FILTER_INDIVIDUALS: RawFlags = ll_bindings::TSK_SIMPLIFY_FILTER_INDIVIDUALS;
103+
pub const FILTER_INDIVIDUALS: RawFlags = ll_bindings::TSK_SIMPLIFY_FILTER_INDIVIDUALS;
93104
/// Whether to reduce the topology down to the trees that are present at sites.
94-
const REDUCE_TO_SITE_TOPOLOGY: RawFlags = ll_bindings::TSK_SIMPLIFY_REDUCE_TO_SITE_TOPOLOGY;
105+
pub const REDUCE_TO_SITE_TOPOLOGY: RawFlags = ll_bindings::TSK_SIMPLIFY_REDUCE_TO_SITE_TOPOLOGY;
95106
/// If True, preserve unary nodes (i.e. nodes with exactly one child)
96107
/// that exist on the path from samples to root.
97-
const KEEP_UNARY: RawFlags = ll_bindings::TSK_SIMPLIFY_KEEP_UNARY;
108+
pub const KEEP_UNARY: RawFlags = ll_bindings::TSK_SIMPLIFY_KEEP_UNARY;
98109
/// Whether to retain history ancestral to the MRCA of the samples.
99-
const KEEP_INPUT_ROOTS: RawFlags = ll_bindings::TSK_SIMPLIFY_KEEP_INPUT_ROOTS;
110+
pub const KEEP_INPUT_ROOTS: RawFlags = ll_bindings::TSK_SIMPLIFY_KEEP_INPUT_ROOTS;
100111
/// If True, preserve unary nodes that exist on the path from samples
101112
/// to root, but only if they are associated with an individual
102113
/// in the individuals table.
103114
/// Cannot be specified at the same time as `KEEP_UNARY`.
104-
const KEEP_UNARY_IN_INDIVIDUALS: RawFlags = ll_bindings::TSK_SIMPLIFY_KEEP_UNARY_IN_INDIVIDUALS;
115+
pub const KEEP_UNARY_IN_INDIVIDUALS: RawFlags = ll_bindings::TSK_SIMPLIFY_KEEP_UNARY_IN_INDIVIDUALS;
105116

106117
flag_builder_api!(
107118
/// Update to set [`KEEP_INPUT_ROOTS`](crate::SimplificationOptions::KEEP_INPUT_ROOTS).
@@ -188,6 +199,7 @@ impl SimplificationOptions {
188199
=> filter_individuals, FILTER_INDIVIDUALS);
189200

190201
bits!();
202+
contains!();
191203
}
192204

193205
/// Modify behavior of [`crate::TableCollection::clear`].
@@ -251,6 +263,7 @@ impl TableClearOptions {
251263
/// Set [`CLEAR_PROVENANCE`](crate::TableClearOptions::CLEAR_PROVENANCE)
252264
=> clear_provenance, CLEAR_PROVENANCE);
253265
bits!();
266+
contains!();
254267
}
255268

256269
/// Modify behavior of [`crate::TableCollection::equals`].
@@ -326,6 +339,7 @@ impl TableEqualityOptions {
326339
/// Set [`IGNORE_TIMESTAMPS`](crate::TableEqualityOptions::IGNORE_TIMESTAMPS)
327340
=> ignore_timestamps, IGNORE_TIMESTAMPS);
328341
bits!();
342+
contains!();
329343
}
330344

331345
/// Modify behavior of [`crate::TableCollection::sort`].
@@ -362,6 +376,7 @@ impl TableSortOptions {
362376
/// Set [`NO_CHECK_INTEGRITY`](crate::TableSortOptions::NO_CHECK_INTEGRITY)
363377
=> no_check_integrity, NO_CHECK_INTEGRITY);
364378
bits!();
379+
contains!();
365380
}
366381

367382
/// Modify behavior of [`crate::TableCollection::sort_individuals`].
@@ -383,6 +398,7 @@ impl IndividualTableSortOptions {
383398
/// Default behavior.
384399
pub const NONE: RawFlags = 0;
385400
bits!();
401+
contains!();
386402
}
387403

388404
/// Specify the behavior of iterating over [`Tree`] objects.
@@ -433,6 +449,7 @@ impl TreeFlags {
433449
/// Set [`NO_SAMPLE_COUNTS`](crate::TreeFlags::NO_SAMPLE_COUNTS)
434450
=> no_sample_counts, NO_SAMPLE_COUNTS);
435451
bits!();
452+
contains!();
436453
}
437454

438455
/// Modify behavior of [`crate::TableCollection::dump`].
@@ -461,6 +478,7 @@ pub struct TableOutputOptions(RawFlags);
461478

462479
impl TableOutputOptions {
463480
bits!();
481+
contains!();
464482
}
465483

466484
/// Modify behavior of [`crate::TableCollection::tree_sequence`]
@@ -499,6 +517,7 @@ impl TreeSequenceFlags {
499517
/// Set [`BUILD_INDEXES`](crate::TreeSequenceFlags::BUILD_INDEXES)
500518
=> build_indexes, BUILD_INDEXES);
501519
bits!();
520+
contains!();
502521
}
503522

504523
/// Flags to affect the behavior of
@@ -613,6 +632,7 @@ impl TableIntegrityCheckFlags {
613632
/// Set [`CHECK_TREES`](crate::TableIntegrityCheckFlags::CHECK_TREES)
614633
=> check_trees, CHECK_TREES);
615634
bits!();
635+
contains!();
616636
}
617637

618638
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -653,13 +673,7 @@ impl NodeFlags {
653673
}
654674

655675
bits!();
656-
657-
pub fn contains<I>(&self, bit: I) -> bool
658-
where
659-
I: Into<Self> + Copy,
660-
{
661-
bit.into().0 == 0 || (self.0 & bit.into().0) != 0
662-
}
676+
contains!();
663677

664678
pub fn toggle(&mut self, bit: tsk_flags_t) {
665679
self.0 ^= bit
@@ -693,6 +707,8 @@ impl IndividualFlags {
693707
pub fn is_valid(&self) -> bool {
694708
true
695709
}
710+
bits!();
711+
contains!();
696712
}
697713

698714
impl_flags!(SimplificationOptions);

0 commit comments

Comments
 (0)