This class represents a (possibly wildcard-like) selection of Source IDs. It can be modified by appending SourceIDs. More...
#include <BankSelection.h>
Classes | |
struct | iter_pair |
Public Types | |
typedef IDs::source | SourceID |
typedef std::vector< SourceID > | SourceList_t |
Public Member Functions | |
BankSelection (bool match_all=true) | |
The default-constructed selection matches all banks of the correct pulse type. | |
BankSelection (const SourceID &sid) | |
Construct matching a single Source ID (can be wild card). | |
BankSelection (const SourceList_t &list) | |
Construct matching the the list given. | |
virtual | ~BankSelection () |
Destructior. We may inherit from this class. | |
bool | Includes (const SourceID &sid) const |
Check if the provided SourceID is in the selection, either due to wildcards or exact matches. | |
bool | HasWildCardMatch (const SourceID &sid) const |
Check if the provided SourceID would be selected by the (channel) wildcards. | |
bool | HasExactMatch (const SourceID &sid) const |
Check if the provided SourceID is on the list of exact (channel) matches. | |
BankSelection & | MatchAll () |
Reset match criteria - accept everything. | |
BankSelection & | MatchNone () |
Reset match criteria - reject everything. | |
BankSelection & | MatchOnly (const SourceList_t &list) |
Set the match criteria to the provided list, overwriting the previous criteria. | |
BankSelection & | MatchOnly (const SourceID &sid) |
Set the match criteria to the provided ID, overwriting the previous criteria. | |
BankSelection & | Add (const SourceList_t &list) |
Add Sources from the provided list of Source IDs. | |
BankSelection & | Add (const SourceID &sid) |
Add the provided Source ID Logically this looks like SELF = SELF | LIST Note however, that this will add a Source ID even if an exact equal exists. Thus (for example) myBankSelection.Add(A) .Add(A); will append A twice To eliminate the duplicates, use BankSelection::Compact(). | |
BankSelection & | Compact () |
Remove any exact duplicates from the selection. This should not change the logic, but may speed up searches if many duplicates have been added. | |
BankSelection & | Remove (const SourceList_t &list) |
Remove Sources if they are on the provided list of Source IDs. | |
BankSelection & | Remove (const SourceList_t &list, SourceList_t &removed) |
Remove Sources if they are on the provided list of Source IDs. | |
BankSelection & | Remove (const SourceID &sid) |
Remove the given Source IDs. This overload of This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. BankSelection& Remove(const SourceList_t& list) has all the same caveats. | |
Protected Types | |
typedef SourceList_t::iterator | iter |
typedef SourceList_t::const_iterator | citer |
Protected Member Functions | |
bool | ListMatch (const SourceID &sid, const SourceList_t &list) const |
void | SortUnique (SourceList_t &list) |
Implementation function that removes duplicate SourceIDs from a list. | |
iter_pair | ImpRemove (const SourceList_t &list) |
Private Attributes | |
SourceList_t | fWildCards |
The list of Source IDs that match several Channels. | |
SourceList_t | fMatches |
The list of SourceIDs tha match a single Channel. |
This class represents a (possibly wildcard-like) selection of Source IDs. It can be modified by appending SourceIDs.
Assume that the most common reason for using wild cards (or not) is to match multiple detector channels. In contrast people asking for specific generators will likely have specific intentions in mind, and the output of particular generators will often be used for specific channels. It will be faster to check against wildcards than long lists of sources, so we store source wildcards separately.
As this class has no pointers, the default copy semantics are reasonable.
Definition at line 25 of file BankSelection.h.
typedef SourceList_t::const_iterator BankSelection::citer [protected] |
Definition at line 136 of file BankSelection.h.
typedef SourceList_t::iterator BankSelection::iter [protected] |
Definition at line 135 of file BankSelection.h.
typedef IDs::source BankSelection::SourceID |
Definition at line 28 of file BankSelection.h.
typedef std::vector<SourceID> BankSelection::SourceList_t |
Definition at line 29 of file BankSelection.h.
BankSelection::BankSelection | ( | bool | match_all = true |
) |
The default-constructed selection matches all banks of the correct pulse type.
match_all | [in] if optionally passed false or 0 it will match none. |
Definition at line 29 of file BankSelection.cpp.
00030 : fWildCards(match_all ? 1 : 0) 00031 {}
BankSelection::BankSelection | ( | const SourceID & | sid | ) |
Construct matching a single Source ID (can be wild card).
Definition at line 41 of file BankSelection.cpp.
References MatchOnly().
00042 { 00043 this->MatchOnly(sid); 00044 }
BankSelection::BankSelection | ( | const SourceList_t & | list | ) |
Construct matching the the list given.
Definition at line 35 of file BankSelection.cpp.
References MatchOnly().
BankSelection::~BankSelection | ( | ) | [virtual] |
Destructior. We may inherit from this class.
Definition at line 48 of file BankSelection.cpp.
BankSelection & BankSelection::Add | ( | const SourceID & | sid | ) |
Add the provided Source ID Logically this looks like SELF = SELF | LIST Note however, that this will add a Source ID even if an exact equal exists. Thus (for example) myBankSelection.Add(A)
.Add(A); will append A
twice To eliminate the duplicates, use BankSelection::Compact().
Definition at line 110 of file BankSelection.cpp.
References fMatches, and fWildCards.
00111 { 00112 if (unary_iwcc(sid)){ 00113 fWildCards.push_back(sid); 00114 } else { 00115 fMatches.push_back(sid); 00116 } 00117 00118 return *this; 00119 }
BankSelection & BankSelection::Add | ( | const SourceList_t & | list | ) |
Add Sources from the provided list of Source IDs.
Logically this looks like SELF = SELF | LIST Note however, that this will add a Source ID even if an exact equal exists. Thus (for example) myBankSelection.Add(listA)
.Add(listA); will append listA
twice To eliminate the duplicates, use BankSelection::Compact()
Definition at line 100 of file BankSelection.cpp.
Referenced by MatchOnly().
BankSelection & BankSelection::Compact | ( | ) |
Remove any exact duplicates from the selection. This should not change the logic, but may speed up searches if many duplicates have been added.
Definition at line 132 of file BankSelection.cpp.
References fMatches, fWildCards, and SortUnique().
Referenced by ImpRemove().
00133 { 00134 SortUnique(fWildCards); 00135 SortUnique(fMatches); 00136 return *this; 00137 }
bool BankSelection::HasExactMatch | ( | const SourceID & | sid | ) | const [inline] |
Check if the provided SourceID is on the list of exact (channel) matches.
Definition at line 57 of file BankSelection.h.
References fMatches, and ListMatch().
Referenced by Includes().
bool BankSelection::HasWildCardMatch | ( | const SourceID & | sid | ) | const [inline] |
Check if the provided SourceID would be selected by the (channel) wildcards.
Definition at line 52 of file BankSelection.h.
References fWildCards, and ListMatch().
Referenced by Includes().
00053 {return ListMatch(sid, fWildCards);}
BankSelection::iter_pair BankSelection::ImpRemove | ( | const SourceList_t & | list | ) | [protected] |
Implementation function to remove a list and return the new end()s first is wildcards second is exact matchess
Definition at line 141 of file BankSelection.cpp.
References Compact(), fMatches, fWildCards, BankSelection::iter_pair::match, and BankSelection::iter_pair::wildcard.
Referenced by Remove().
00142 { 00143 // REM. This only removes the elements, it does not erase them! 00144 00145 this->Compact(); 00146 iter_pair back; 00147 back.wildcard = fWildCards.end(); 00148 back.match = fMatches.end(); 00149 for (citer it = list.begin(); it != list.end() ; ++it) { 00150 if ( unary_iwcc(*it) ){ 00151 back.wildcard = std::remove(fWildCards.begin(), back.wildcard, (*it)); 00152 } else { 00153 back.match = std::remove(fMatches.begin(), back.match, (*it)); 00154 } 00155 } 00156 return back; 00157 }
bool BankSelection::Includes | ( | const SourceID & | sid | ) | const [inline] |
Check if the provided SourceID is in the selection, either due to wildcards or exact matches.
Definition at line 47 of file BankSelection.h.
References HasExactMatch(), and HasWildCardMatch().
00048 {return HasWildCardMatch(sid) || HasExactMatch(sid);}
bool BankSelection::ListMatch | ( | const SourceID & | sid, | |
const SourceList_t & | list | |||
) | const [protected] |
Implementation function that checks if a given Source ID matches any from a list
Definition at line 53 of file BankSelection.cpp.
Referenced by HasExactMatch(), and HasWildCardMatch().
BankSelection & BankSelection::MatchAll | ( | ) |
Reset match criteria - accept everything.
Definition at line 63 of file BankSelection.cpp.
References fMatches, and fWildCards.
00064 { 00065 fMatches.clear(); 00066 SourceList_t tmp(1); 00067 fWildCards.swap(tmp); 00068 return *this; 00069 }
BankSelection & BankSelection::MatchNone | ( | ) |
Reset match criteria - reject everything.
Definition at line 73 of file BankSelection.cpp.
References fMatches, and fWildCards.
Referenced by MatchOnly().
00074 { 00075 fMatches.clear(); 00076 fWildCards.clear(); 00077 return *this; 00078 }
BankSelection & BankSelection::MatchOnly | ( | const SourceID & | sid | ) |
Set the match criteria to the provided ID, overwriting the previous criteria.
Definition at line 94 of file BankSelection.cpp.
References Add(), and MatchNone().
BankSelection & BankSelection::MatchOnly | ( | const SourceList_t & | list | ) |
Set the match criteria to the provided list, overwriting the previous criteria.
Definition at line 82 of file BankSelection.cpp.
References Add(), fMatches, fWildCards, and MatchNone().
Referenced by BankSelection().
BankSelection & BankSelection::Remove | ( | const SourceID & | sid | ) |
Remove the given Source IDs. This overload of This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. BankSelection& Remove(const SourceList_t& list) has all the same caveats.
Definition at line 189 of file BankSelection.cpp.
References Remove().
00190 { 00191 return this->Remove(SourceList_t(1, sid)); 00192 }
BankSelection & BankSelection::Remove | ( | const SourceList_t & | list, | |
SourceList_t & | removed | |||
) |
Remove Sources if they are on the provided list of Source IDs.
removed | [out] is an optional parameter that lists all the IDs Removed() from the selection, If all parameters in list are unique, and all were removed then removed.size() = list.size() |
Definition at line 161 of file BankSelection.cpp.
References fMatches, fWildCards, ImpRemove(), BankSelection::iter_pair::match, and BankSelection::iter_pair::wildcard.
00163 { 00164 const iter_pair back = ImpRemove(list); 00165 00166 //use swap/temporary in case some loon passes the same object as 00167 //both arguments 00168 SourceList_t tmp; 00169 std::copy(back.wildcard, fWildCards.end(), tmp.end()); 00170 std::copy(back.match, fMatches.end(), tmp.end()); 00171 removed.swap(tmp); 00172 00173 fWildCards.erase(back.wildcard, fWildCards.end()); 00174 fMatches.erase(back.match, fMatches.end()); 00175 return *this; 00176 }
BankSelection & BankSelection::Remove | ( | const SourceList_t & | list | ) |
Remove Sources if they are on the provided list of Source IDs.
Definition at line 180 of file BankSelection.cpp.
References fMatches, fWildCards, ImpRemove(), BankSelection::iter_pair::match, and BankSelection::iter_pair::wildcard.
Referenced by Remove().
00181 { 00182 iter_pair back = ImpRemove(list); 00183 fWildCards.erase(back.wildcard, fWildCards.end()); 00184 fMatches.erase(back.match, fMatches.end()); 00185 return *this; 00186 }
void BankSelection::SortUnique | ( | SourceList_t & | list | ) | [protected] |
SourceList_t BankSelection::fMatches [private] |
The list of SourceIDs tha match a single Channel.
Definition at line 158 of file BankSelection.h.
Referenced by Add(), Compact(), HasExactMatch(), ImpRemove(), MatchAll(), MatchNone(), MatchOnly(), and Remove().
SourceList_t BankSelection::fWildCards [private] |
The list of Source IDs that match several Channels.
Definition at line 155 of file BankSelection.h.
Referenced by Add(), Compact(), HasWildCardMatch(), ImpRemove(), MatchAll(), MatchNone(), MatchOnly(), and Remove().