Go to the documentation of this file.Go to the SVN repository for this file.
1 #ifndef OBJECTS_MISC___SEQUENCE_UTIL_MACROS__HPP
2 #define OBJECTS_MISC___SEQUENCE_UTIL_MACROS__HPP
51 #define NCBI_SERIAL_TEST_EXPLORE(Test, Type, Var, Cont) \
52 if (! (Test)) {} else for (CTypeConstIterator<Type> Var (Cont); Var; ++Var)
54 #define NCBI_SERIAL_NC_EXPLORE(Test, Type, Var, Cont) \
55 if (! (Test)) {} else for (CTypeIterator<Type> Var (Cont); Var; ++Var)
66 #define NCBI_CS_ITERATE(Test, Type, Var, Cont) \
67 if (! (Test)) {} else ITERATE (Type, Var, Cont)
72 #define NCBI_NC_ITERATE(Test, Type, Var, Cont) \
73 if (! (Test)) {} else ERASE_ITERATE (Type, Var, Cont)
78 #define NCBI_SWITCH(Test, Chs) \
79 if (! (Test)) {} else switch(Chs)
84 #define FOR_EACH(Base, Itr, Var) \
85 NCBI_CS_ITERATE (Base##_Test(Var), Base##_Type, Itr, Base##_Get(Var))
89 #define EDIT_EACH(Base, Itr, Var) \
90 NCBI_NC_ITERATE (Base##_Test(Var), Base##_Type, Itr, Base##_Set(Var))
94 #define ADD_ITEM(Base, Var, Ref) \
95 (Base##_Set(Var).push_back(Ref))
99 #define LIST_ERASE_ITEM(Base, Itr, Var) \
100 (Base##_Set(Var).erase(Itr))
104 #define VECTOR_ERASE_ITEM(Base, Itr, Var) \
105 (VECTOR_ERASE (Itr, Base##_Set(Var)))
109 #define ITEM_HAS(Base, Var) \
114 #define FIELD_IS_EMPTY(Base, Var) \
115 (Base##_Test(Var) && Base##_Get(Var).empty() )
119 #define RAW_FIELD_IS_EMPTY(Var, Fld) \
120 ( (Var).IsSet##Fld() && (Var).Get##Fld().empty() )
124 #define FIELD_IS_EMPTY_OR_UNSET(Base, Var) \
125 ( ! Base##_Test(Var) || Base##_Get(Var).empty() )
129 #define RAW_FIELD_IS_EMPTY_OR_UNSET(Var, Fld) \
130 ( ! (Var).IsSet##Fld() || (Var).Get##Fld().empty() )
135 #define RAW_FIELD_GET_SIZE_IF_SET(Var, Fld) \
136 ( (Var).IsSet##Fld() ? (Var).Get##Fld().size() : 0 )
141 #define SET_FIELD_IF_UNSET(Var, Fld, Val) \
142 do { if( ! (Var).IsSet##Fld() ) { (Var).Set##Fld(Val); ChangeMade(CCleanupChange::eChangeQualifiers); } } while(false)
147 #define REMOVE_IF_EMPTY_FIELD(Base, Var) \
148 do { if( FIELD_IS_EMPTY(Base, Var) ) { Base##_Reset(Var); ChangeMade(CCleanupChange::eChangeQualifiers); } } while(false)
152 #define GET_STRING_OR_BLANK(Base, Var) \
153 (Base##_Test(Var) ? Base##_Get(Var) : kEmptyStr )
157 #define CHOICE_IS(Base, Var, Chs) \
158 (Base##_Test(Var) && Base##_Chs(Var) == Chs)
163 #define SWITCH_ON(Base, Var) \
164 NCBI_SWITCH (Base##_Test(Var), Base##_Chs(Var))
169 template <
class Iter,
class Comp>
187 template <
class Iterator,
class Predicate>
190 Iterator
prev = iter1;
191 if (iter1 == iter2) {
194 for (++iter1; iter1 != iter2; ++iter1, ++
prev) {
195 if (pred(*iter1, *
prev)) {
205 #define IS_SORTED(Base, Var, Func) \
206 ((! Base##_Test(Var)) || \
207 seq_mac_is_sorted (Base##_Set(Var).begin(), \
208 Base##_Set(Var).end(), \
213 #define DO_LIST_SORT(Base, Var, Func) \
214 (Base##_Set(Var).sort (Func))
218 #define DO_VECTOR_SORT(Base, Var, Func) \
219 (stable_sort (Base##_Set(Var).begin(), \
220 Base##_Set(Var).end(), \
230 #define DO_LIST_SORT_HACK(Base, Var, Func) \
232 vector< Base##_Type::value_type > vec; \
233 copy( Base##_Get(Var).begin(), Base##_Get(Var).end(), back_inserter(vec) ); \
234 stable_sort( vec.begin(), vec.end(), Func ); \
235 Base##_Set(Var).clear(); \
236 copy( vec.begin(), vec.end(), back_inserter(Base##_Set(Var)) ); \
242 #define IS_UNIQUE(Base, Var, Func) \
243 ((! Base##_Test(Var)) || \
244 seq_mac_is_unique (Base##_Set(Var).begin(), \
245 Base##_Set(Var).end(), \
250 #define DO_UNIQUE(Base, Var, Func) \
252 Base##_Type::iterator it = unique (Base##_Set(Var).begin(), \
253 Base##_Set(Var).end(), \
255 it = Base##_Set(Var).erase(it, Base##_Set(Var).end()); \
259 #define UNIQUE_WITHOUT_SORT(Base, Var, FuncType, CleanupChangeType) \
261 if( Base##_Test(Var) ) { \
262 set<Base##_Type::value_type, FuncType> valuesAlreadySeen; \
263 Base##_Type non_duplicate_items; \
264 FOR_EACH(Base, iter, Var ) { \
265 if( valuesAlreadySeen.find(*iter) == valuesAlreadySeen.end() ) { \
266 non_duplicate_items.push_back( *iter ); \
267 valuesAlreadySeen.insert( *iter ); \
270 if( Base##_Get(Var).size() != non_duplicate_items.size() ) { \
271 ChangeMade(CleanupChangeType); \
273 Base##_Set(Var).swap( non_duplicate_items ); \
278 #define BEGIN_COMMA_END(container) \
279 (container).begin(), (container).end()
300 #define STRING_IN_LIST_Type list <string>
301 #define STRING_IN_LIST_Test(Var) (! (Var).empty())
302 #define STRING_IN_LIST_Get(Var) (Var)
303 #define STRING_IN_LIST_Set(Var) (Var)
307 #define LIST_HAS_STRING(Var) \
308 ITEM_HAS (STRING_IN_LIST, Var)
314 #define FOR_EACH_STRING_IN_LIST(Itr, Var) \
315 FOR_EACH (STRING_IN_LIST, Itr, Var)
317 #define EDIT_EACH_STRING_IN_LIST(Itr, Var) \
318 EDIT_EACH (STRING_IN_LIST, Itr, Var)
322 #define ADD_STRING_TO_LIST(Var, Ref) \
323 ADD_ITEM (STRING_IN_LIST, Var, Ref)
327 #define ERASE_STRING_IN_LIST(Itr, Var) \
328 LIST_ERASE_ITEM (STRING_IN_LIST, Itr, Var)
332 #define STRING_IN_LIST_IS_SORTED(Var, Func) \
333 IS_SORTED (STRING_IN_LIST, Var, Func)
337 #define SORT_STRING_IN_LIST(Var, Func) \
338 DO_LIST_SORT (STRING_IN_LIST, Var, Func)
342 #define STRING_IN_LIST_IS_UNIQUE(Var, Func) \
343 IS_UNIQUE (STRING_IN_LIST, Var, Func)
347 #define UNIQUE_STRING_IN_LIST(Var, Func) \
348 DO_UNIQUE (STRING_IN_LIST, Var, Func)
356 #define STRING_IN_VECTOR_Type vector <string>
357 #define STRING_IN_VECTOR_Test(Var) (! (Var).empty())
358 #define STRING_IN_VECTOR_Get(Var) (Var)
359 #define STRING_IN_VECTOR_Set(Var) (Var)
363 #define VECTOR_HAS_STRING(Var) \
364 ITEM_HAS (STRING_IN_VECTOR, Var)
370 #define FOR_EACH_STRING_IN_VECTOR(Itr, Var) \
371 FOR_EACH (STRING_IN_VECTOR, Itr, Var)
373 #define EDIT_EACH_STRING_IN_VECTOR(Itr, Var) \
374 EDIT_EACH (STRING_IN_VECTOR, Itr, Var)
378 #define ADD_STRING_TO_VECTOR(Var, Ref) \
379 ADD_ITEM (STRING_IN_VECTOR, Var, Ref)
383 #define ERASE_STRING_IN_VECTOR(Itr, Var) \
384 VECTOR_ERASE_ITEM (STRING_IN_VECTOR, Itr, Var)
388 #define STRING_IN_VECTOR_IS_SORTED(Var, Func) \
389 IS_SORTED (STRING_IN_VECTOR, Var, Func)
393 #define SORT_STRING_IN_VECTOR(Var, Func) \
394 DO_VECTOR_SORT (STRING_IN_VECTOR, Var, Func)
398 #define STRING_IN_VECTOR_IS_UNIQUE(Var, Func) \
399 IS_UNIQUE (STRING_IN_VECTOR, Var, Func)
403 #define UNIQUE_STRING_IN_VECTOR(Var, Func) \
404 DO_UNIQUE (STRING_IN_VECTOR, Var, Func)
412 #define CHAR_IN_STRING_Type string
413 #define CHAR_IN_STRING_Test(Var) (! (Var).empty())
414 #define CHAR_IN_STRING_Get(Var) (Var)
415 #define CHAR_IN_STRING_Set(Var) (Var)
419 #define STRING_HAS_CHAR(Var) \
420 ITEM_HAS (CHAR_IN_STRING, Var)
426 #define FOR_EACH_CHAR_IN_STRING(Itr, Var) \
427 FOR_EACH (CHAR_IN_STRING, Itr, Var)
429 #define EDIT_EACH_CHAR_IN_STRING(Itr, Var) \
430 EDIT_EACH (CHAR_IN_STRING, Itr, Var)
434 #define ADD_CHAR_TO_STRING(Var, Ref) \
435 ADD_ITEM (CHAR_IN_STRING, Var, Ref)
439 #define ERASE_CHAR_IN_STRING(Itr, Var) \
440 LIST_ERASE_ITEM (CHAR_IN_STRING, Itr, Var)
444 #define CHAR_IN_STRING_IS_SORTED(Var, Func) \
445 IS_SORTED (CHAR_IN_STRING, Var, Func)
449 #define SORT_CHAR_IN_STRING(Var, Func) \
450 DO_LIST_SORT (CHAR_IN_STRING, Var, Func)
454 #define CHAR_IN_STRING_IS_UNIQUE(Var, Func) \
455 IS_UNIQUE (CHAR_IN_STRING, Var, Func)
459 #define UNIQUE_CHAR_IN_STRING(Var, Func) \
460 DO_UNIQUE (CHAR_IN_STRING, Var, Func)
464 #define CHAR_IN_STRING_IS_EMPTY(Var) \
465 FIELD_IS_EMPTY(CHAR_IN_STRING, Var, Func)
473 #define FIELD_IS(Var, Fld) \
478 #define FIELD_CHAIN_OF_2_IS(Var, Fld1, Fld2) \
479 ( (Var).Is##Fld1() && \
480 (Var).Get##Fld1().Is##Fld2() )
484 #define FIELD_IS_SET_AND_IS(Var, Fld, Chs) \
485 ( (Var).IsSet##Fld() && (Var).Get##Fld().Is##Chs() )
489 #define FIELD_IS_AND_IS_SET(Var, Chs, Fld) \
490 ( (Var).Is##Chs() && (Var).Get##Chs().IsSet##Fld() )
494 #define FIELD_IS_SET(Var, Fld) \
499 #define FIELD_CHAIN_OF_2_IS_SET(Var, Fld1, Fld2) \
500 ( (Var).IsSet##Fld1() && \
501 (Var).Get##Fld1().IsSet##Fld2() )
505 #define FIELD_CHAIN_OF_3_IS_SET(Var, Fld1, Fld2, Fld3) \
506 ( (Var).IsSet##Fld1() && \
507 (Var).Get##Fld1().IsSet##Fld2() && \
508 (Var).Get##Fld1().Get##Fld2().IsSet##Fld3() )
512 #define FIELD_CHAIN_OF_4_IS_SET(Var, Fld1, Fld2, Fld3, Fld4) \
513 ( (Var).IsSet##Fld1() && \
514 (Var).Get##Fld1().IsSet##Fld2() && \
515 (Var).Get##Fld1().Get##Fld2().IsSet##Fld3() && \
516 (Var).Get##Fld1().Get##Fld2().Get##Fld3().IsSet##Fld4() )
521 #define FIELD_CHAIN_OF_5_IS_SET(Var, Fld1, Fld2, Fld3, Fld4, Fld5) \
522 ( (Var).IsSet##Fld1() && \
523 (Var).Get##Fld1().IsSet##Fld2() && \
524 (Var).Get##Fld1().Get##Fld2().IsSet##Fld3() && \
525 (Var).Get##Fld1().Get##Fld2().Get##Fld3().IsSet##Fld4() && \
526 (Var).Get##Fld1().Get##Fld2().Get##Fld3().Get##Fld4().IsSet##Fld5() )
530 #define GET_FIELD(Var, Fld) \
535 #define GET_FIELD_OR_DEFAULT(Var, Fld, Dflt) \
536 ((Var).IsSet##Fld() ? (Var).Get##Fld() : Dflt )
540 #define GET_FIELD_CHOICE_OR_DEFAULT(Var, Fld, Dflt) \
541 ((Var).Is##Fld() ? (Var).Get##Fld() : Dflt )
546 #define GET_MUTABLE(Var, Fld) \
551 #define SET_FIELD(Var, Fld, Val) \
552 ((Var).Set##Fld(Val))
556 #define RESET_FIELD(Var, Fld) \
562 #define STRING_FIELD_MATCH(Var, Fld, Str) \
563 ((Var).IsSet##Fld() && NStr::EqualNocase((Var).Get##Fld(), Str))
567 #define STRING_FIELD_MATCH_BUT_ONLY_CASE_INSENSITIVE(Var, Fld, Str) \
568 ((Var).IsSet##Fld() && NStr::EqualNocase((Var).Get##Fld(), (Str)) && \
569 (Var).Get##Fld() != (Str) )
573 #define STRING_FIELD_CHOICE_MATCH( Var, Fld, Chs, Value) \
574 ( (Var).IsSet##Fld() && (Var).Get##Fld().Is##Chs() && \
575 NStr::EqualNocase((Var).Get##Fld().Get##Chs(), (Value)) )
580 #define GET_STRING_FLD_OR_BLANK(Var, Fld) \
581 ( (Var).IsSet##Fld() ? (Var).Get##Fld() : kEmptyStr )
585 #define STRING_FIELD_NOT_EMPTY(Var, Fld) \
586 ( (Var).IsSet##Fld() && ! (Var).Get##Fld().empty() )
591 #define STRING_FIELD_APPEND(Var, Fld, Delim, Str) \
593 const string sStr = (Str); \
594 if( ! sStr.empty() ) { \
595 if( ! (Var).IsSet##Fld() ) { \
596 (Var).Set##Fld(""); \
598 string & field = (Var).Set##Fld(); \
599 if( ! field.empty() ) { \
609 #define STRING_SET_MATCH(Var, Fld, Str) \
610 ((Var).IsSet##Fld() && NStr::FindNoCase((Var).Get##Fld(), Str) != NULL)
614 #define FIELD_OUT_OF_RANGE(Var, Fld, Lower, Upper) \
615 ( (Var).IsSet##Fld() && ( (Var).Get##Fld() < (Lower) || (Var).Get##Fld() > (Upper) ) )
619 #define FIELD_EQUALS( Var, Fld, Value ) \
620 ( (Var).IsSet##Fld() && (Var).Get##Fld() == (Value) )
624 #define FIELD_CHOICE_EQUALS( Var, Fld, Chs, Value) \
625 ( (Var).IsSet##Fld() && (Var).Get##Fld().Is##Chs() && \
626 (Var).Get##Fld().Get##Chs() == (Value) )
628 #define FIELD_CHOICE_EMPTY( Var, Fld, Chs) \
629 ( ! (Var).IsSet##Fld() || ! (Var).Get##Fld().Is##Chs() || \
630 (Var).Get##Fld().Get##Chs().empty() )
634 #define CALL_IF_SET( Func, Var, Fld ) \
636 if( (Var).IsSet##Fld() ) { \
637 Func( GET_MUTABLE( (Var), Fld) ); \
643 #define CALL_IF_SET_CHAIN_2( Func, Var, Fld1, Fld2 ) \
645 if( (Var).IsSet##Fld1() ) { \
646 CALL_IF_SET( Func, (Var).Set##Fld1(), Fld2 ); \
655 #define CLONE_IF_SET_ELSE_RESET(DestVar, DestFld, SrcVar, SrcFld) \
657 if( FIELD_IS_SET(SrcVar, SrcFld) ) { \
658 (DestVar).Set##DestFld( *SerialClone( GET_FIELD(SrcVar, SrcFld) ) ); \
660 (DestVar).Reset##DestFld(); \
666 #define ASSIGN_IF_SET_ELSE_RESET(DestVar, DestFld, SrcVar, SrcFld) \
668 if( FIELD_IS_SET(SrcVar, SrcFld) ) { \
669 (DestVar).Set##DestFld( GET_FIELD(SrcVar, SrcFld) ); \
671 (DestVar).Reset##DestFld(); \
677 #define TEST_FIELD_CHOICE( Var, Fld, Chs ) \
678 ( (Var).IsSet##Fld() && (Var).Get##Fld().Which() == (Chs) )
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
bool seq_mac_is_sorted(Iter first, Iter last, Comp comp)
bool seq_mac_is_unique(Iterator iter1, Iterator iter2, Predicate pred)