@@ -14,6 +14,8 @@ unsafe impl Send for mm_idx_t {}
1414unsafe impl Send for mm_idx_reader_t { }
1515unsafe impl Send for mm_mapopt_t { }
1616
17+ use paste:: paste;
18+
1719impl Drop for mm_idx_t {
1820 fn drop ( & mut self ) {
1921 unsafe { mm_idx_destroy ( self ) } ;
@@ -60,6 +62,80 @@ impl Default for mm_mapopt_t {
6062 }
6163}
6264
65+
66+ macro_rules! add_flag_methods {
67+ ( $ty: ty, $struct_name: ident, $( ( $set_name: ident, $unset_name: ident, $flag: expr) ) ,+) => {
68+ impl $struct_name {
69+ $(
70+ paste! {
71+ #[ inline( always) ]
72+ #[ doc = "Set the " $flag " flag" ]
73+ pub fn $set_name( & mut self ) {
74+ self . flag |= $flag as $ty;
75+ }
76+
77+ #[ inline( always) ]
78+ #[ doc = "Unset the " $flag " flag" ]
79+ pub fn $unset_name( & mut self ) {
80+ self . flag &= !$flag as $ty;
81+ }
82+ }
83+ ) *
84+ }
85+ } ;
86+ }
87+
88+ add_flag_methods ! (
89+ i64 ,
90+ mm_mapopt_t,
91+ ( set_no_dual, unset_no_dual, MM_F_NO_DUAL ) ,
92+ ( set_no_diag, unset_no_diag, MM_F_NO_DIAG ) ,
93+ ( set_cigar, unset_cigar, MM_F_CIGAR ) ,
94+ ( set_out_sam, unset_out_sam, MM_F_OUT_SAM ) ,
95+ ( set_no_qual, unset_no_qual, MM_F_NO_QUAL ) ,
96+ ( set_out_cg, unset_out_cg, MM_F_OUT_CG ) ,
97+ ( set_out_cs, unset_out_cs, MM_F_OUT_CS ) ,
98+ ( set_splice, unset_splice, MM_F_SPLICE ) ,
99+ ( set_splice_for, unset_splice_for, MM_F_SPLICE_FOR ) ,
100+ ( set_splice_rev, unset_splice_rev, MM_F_SPLICE_REV ) ,
101+ ( set_no_ljoin, unset_no_ljoin, MM_F_NO_LJOIN ) ,
102+ ( set_out_cs_long, unset_out_cs_long, MM_F_OUT_CS_LONG ) ,
103+ ( set_sr, unset_sr, MM_F_SR ) ,
104+ ( set_frag_mode, unset_frag_mode, MM_F_FRAG_MODE ) ,
105+ ( set_no_print_2nd, unset_no_print_2nd, MM_F_NO_PRINT_2ND ) ,
106+ ( set_two_io_threads, unset_two_io_threads, MM_F_2_IO_THREADS ) ,
107+ ( set_long_cigar, unset_long_cigar, MM_F_LONG_CIGAR ) ,
108+ ( set_indep_seg, unset_indep_seg, MM_F_INDEPEND_SEG ) ,
109+ ( set_splice_flank, unset_splice_flank, MM_F_SPLICE_FLANK ) ,
110+ ( set_softclip, unset_softclip, MM_F_SOFTCLIP ) ,
111+ ( set_for_only, unset_for_only, MM_F_FOR_ONLY ) ,
112+ ( set_rev_only, unset_rev_only, MM_F_REV_ONLY ) ,
113+ ( set_heap_sort, unset_heap_sort, MM_F_HEAP_SORT ) ,
114+ ( set_all_chains, unset_all_chains, MM_F_ALL_CHAINS ) ,
115+ ( set_out_md, unset_out_md, MM_F_OUT_MD ) ,
116+ ( set_copy_comment, unset_copy_comment, MM_F_COPY_COMMENT ) ,
117+ ( set_eqx, unset_eqx, MM_F_EQX ) ,
118+ ( set_paf_no_hit, unset_paf_no_hit, MM_F_PAF_NO_HIT ) ,
119+ ( set_no_end_flt, unset_no_end_flt, MM_F_NO_END_FLT ) ,
120+ ( set_hard_mlevel, unset_hard_mlevel, MM_F_HARD_MLEVEL ) ,
121+ ( set_sam_hit_only, unset_sam_hit_only, MM_F_SAM_HIT_ONLY ) ,
122+ ( set_rmq, unset_rmq, MM_F_RMQ ) ,
123+ ( set_qstrand, unset_qstrand, MM_F_QSTRAND ) ,
124+ ( set_no_inv, unset_no_inv, MM_F_NO_INV ) ,
125+ ( set_no_hash_name, unset_no_hash_name, MM_F_NO_HASH_NAME ) ,
126+ ( set_splice_old, unset_splice_old, MM_F_SPLICE_OLD ) ,
127+ ( set_secondary_seq, unset_secondary_seq, MM_F_SECONDARY_SEQ ) ,
128+ ( set_out_ds, unset_out_ds, MM_F_OUT_DS )
129+ ) ;
130+
131+ add_flag_methods ! (
132+ std:: os:: raw:: c_short,
133+ mm_idxopt_t,
134+ ( set_hpc, unset_hpc, MM_I_HPC ) ,
135+ ( set_no_seq, unset_no_seq, MM_I_NO_SEQ ) ,
136+ ( set_no_name, unset_no_name, MM_I_NO_NAME )
137+ ) ;
138+
63139impl Default for mm_idxopt_t {
64140 fn default ( ) -> Self {
65141 unsafe {
@@ -101,4 +177,24 @@ mod tests {
101177 fn idxopt ( ) {
102178 let x: mm_idxopt_t = Default :: default ( ) ;
103179 }
180+
181+ #[ test]
182+ fn test_mapopt_flags ( ) {
183+ let mut opt = mm_mapopt_t:: default ( ) ;
184+ opt. set_no_qual ( ) ;
185+ assert_eq ! ( opt. flag & MM_F_NO_QUAL as i64 , MM_F_NO_QUAL as i64 ) ;
186+
187+ opt. unset_no_qual ( ) ;
188+ assert_eq ! ( opt. flag & MM_F_NO_QUAL as i64 , 0_i64 ) ;
189+ }
190+
191+ #[ test]
192+ fn test_idxopt_flags ( ) {
193+ let mut opt = mm_idxopt_t:: default ( ) ;
194+ opt. set_hpc ( ) ;
195+ assert_eq ! ( opt. flag & MM_I_HPC as i16 , MM_I_HPC as i16 ) ;
196+
197+ opt. unset_hpc ( ) ;
198+ assert_eq ! ( opt. flag & MM_I_HPC as i16 , 0_i16 ) ;
199+ }
104200}
0 commit comments