Skip to content

Commit 7ed36b8

Browse files
committed
feat: add flag set/unset method
1 parent 430b3ba commit 7ed36b8

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

minimap2-sys/src/lib.rs

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ impl Drop for mm_idx_t {
1818
}
1919
}
2020

21-
2221
use std::mem::MaybeUninit;
2322

2423
impl Default for mm_mapopt_t {
@@ -31,6 +30,77 @@ impl Default for mm_mapopt_t {
3130
}
3231
}
3332

33+
macro_rules! add_flag_methods {
34+
($ty:ty, $struct_name:ident, $(($set_name:ident, $unset_name:ident, $flag:expr)),+) => {
35+
impl $struct_name {
36+
$(
37+
#[inline(always)]
38+
pub fn $set_name(mut self) -> Self {
39+
self.flag |= $flag as $ty;
40+
self
41+
}
42+
43+
#[inline(always)]
44+
pub fn $unset_name(mut self) -> Self {
45+
self.flag &= !$flag as $ty;
46+
self
47+
}
48+
)*
49+
}
50+
};
51+
}
52+
53+
add_flag_methods!(
54+
i64,
55+
mm_mapopt_t,
56+
(set_no_dual, unset_no_dual, MM_F_NO_DUAL),
57+
(set_no_diag, unset_no_diag, MM_F_NO_DIAG),
58+
(set_cigar, unset_cigar, MM_F_CIGAR),
59+
(set_out_sam, unset_out_sam, MM_F_OUT_SAM),
60+
(set_no_qual, unset_no_qual, MM_F_NO_QUAL),
61+
(set_out_cg, unset_out_cg, MM_F_OUT_CG),
62+
(set_out_cs, unset_out_cs, MM_F_OUT_CS),
63+
(set_splice, unset_splice, MM_F_SPLICE),
64+
(set_splice_for, unset_splice_for, MM_F_SPLICE_FOR),
65+
(set_splice_rev, unset_splice_rev, MM_F_SPLICE_REV),
66+
(set_no_ljoin, unset_no_ljoin, MM_F_NO_LJOIN),
67+
(set_out_cs_long, unset_out_cs_long, MM_F_OUT_CS_LONG),
68+
(set_sr, unset_sr, MM_F_SR),
69+
(set_frag_mode, unset_frag_mode, MM_F_FRAG_MODE),
70+
(set_no_print_2nd, unset_no_print_2nd, MM_F_NO_PRINT_2ND),
71+
(set_two_io_threads, unset_two_io_threads, MM_F_2_IO_THREADS),
72+
(set_long_cigar, unset_long_cigar, MM_F_LONG_CIGAR),
73+
(set_indep_seg, unset_indep_seg, MM_F_INDEPEND_SEG),
74+
(set_splice_flank, unset_splice_flank, MM_F_SPLICE_FLANK),
75+
(set_softclip, unset_softclip, MM_F_SOFTCLIP),
76+
(set_for_only, unset_for_only, MM_F_FOR_ONLY),
77+
(set_rev_only, unset_rev_only, MM_F_REV_ONLY),
78+
(set_heap_sort, unset_heap_sort, MM_F_HEAP_SORT),
79+
(set_all_chains, unset_all_chains, MM_F_ALL_CHAINS),
80+
(set_out_md, unset_out_md, MM_F_OUT_MD),
81+
(set_copy_comment, unset_copy_comment, MM_F_COPY_COMMENT),
82+
(set_eqx, unset_eqx, MM_F_EQX),
83+
(set_paf_no_hit, unset_paf_no_hit, MM_F_PAF_NO_HIT),
84+
(set_no_end_flt, unset_no_end_flt, MM_F_NO_END_FLT),
85+
(set_hard_mlevel, unset_hard_mlevel, MM_F_HARD_MLEVEL),
86+
(set_sam_hit_only, unset_sam_hit_only, MM_F_SAM_HIT_ONLY),
87+
(set_rmq, unset_rmq, MM_F_RMQ),
88+
(set_qstrand, unset_qstrand, MM_F_QSTRAND),
89+
(set_no_inv, unset_no_inv, MM_F_NO_INV),
90+
(set_no_hash_name, unset_no_hash_name, MM_F_NO_HASH_NAME),
91+
(set_splice_old, unset_splice_old, MM_F_SPLICE_OLD),
92+
(set_secondary_seq, unset_secondary_seq, MM_F_SECONDARY_SEQ),
93+
(set_out_ds, unset_out_ds, MM_F_OUT_DS)
94+
);
95+
96+
add_flag_methods!(
97+
std::os::raw::c_short,
98+
mm_idxopt_t,
99+
(set_hpc, unset_hpc, MM_I_HPC),
100+
(set_no_seq, unset_no_seq, MM_I_NO_SEQ),
101+
(set_no_name, unset_no_name, MM_I_NO_NAME)
102+
);
103+
34104
impl Default for mm_idxopt_t {
35105
fn default() -> Self {
36106
unsafe {
@@ -72,4 +142,24 @@ mod tests {
72142
fn idxopt() {
73143
let x: mm_idxopt_t = Default::default();
74144
}
145+
146+
#[test]
147+
fn test_mapopt_flags() {
148+
let mut opt = mm_mapopt_t::default();
149+
opt = opt.set_no_qual();
150+
assert_eq!(opt.flag & MM_F_NO_QUAL as i64, MM_F_NO_QUAL as i64);
151+
152+
opt = opt.unset_no_qual();
153+
assert_eq!(opt.flag & MM_F_NO_QUAL as i64, 0_i64);
154+
}
155+
156+
#[test]
157+
fn test_idxopt_flags() {
158+
let mut opt = mm_idxopt_t::default();
159+
opt = opt.set_hpc();
160+
assert_eq!(opt.flag & MM_I_HPC as i16, MM_I_HPC as i16);
161+
162+
opt = opt.unset_hpc();
163+
assert_eq!(opt.flag & MM_I_HPC as i16, 0_i16);
164+
}
75165
}

0 commit comments

Comments
 (0)