13 #include "canvas/Utilities/Exception.h"
42 throw art::Exception(art::errors::Configuration)
43 <<
"NameSelector: name '" << name <<
"' not configured.";
53 std::map<Response_t, Names_t> elements;
58 size_t nKnownElements = 0;
60 auto const& selected_elements = elements[
rsAccepted];
61 Names_t::const_iterator iName = selected_elements.cbegin(),
62 nend = selected_elements.cend();
63 out <<
" accept " << selected_elements.size()
64 <<
": '" << *(iName++) <<
"'";
65 while (iName != nend) out <<
", '" << *(iName++) <<
"'";
67 nKnownElements += selected_elements.size();
70 auto const& selected_elements = elements[
rsRejected];
71 Names_t::const_iterator iName = selected_elements.cbegin(),
72 nend = selected_elements.cend();
73 out <<
" reject " << selected_elements.size()
74 <<
": '" << *(iName++) <<
"'";
75 while (iName != nend) out <<
", '" << *(iName++) <<
"'";
77 nKnownElements += selected_elements.size();
80 auto const& selected_elements = elements[
rsThrow];
81 Names_t::const_iterator iName = selected_elements.cbegin(),
82 nend = selected_elements.cend();
83 out <<
" throw on " << selected_elements.size()
84 <<
": '" << *(iName++) <<
"'";
85 while (iName != nend) out <<
", '" << *(iName++) <<
"'";
87 nKnownElements += selected_elements.size();
89 if (nKnownElements > 0) out <<
" otherwise,";
91 case rsAccepted: out <<
" accept everything";
break;
92 case rsRejected: out <<
" reject everything";
break;
93 case rsThrow: out <<
" throw on anything";
break;
94 default: out <<
" I don't know";
101 KnownNames_t::const_iterator iResponse =
known_names.find(name);
110 ProcessItem(name_set,
name);
118 name_set[item] = { response };
132 final_response = item.second.response;
135 switch (item.second.response) {
136 case rsAccepted: final_response = rsRejected;
break;
137 case rsRejected: final_response = rsAccepted;
break;
139 throw art::Exception(art::errors::LogicError)
140 << __func__ <<
": unexpected code flow: invalid added response";
144 throw art::Exception(art::errors::LogicError)
145 << __func__ <<
": unexpected code flow: invalid response";
147 InsertItem(name_set, item.first, final_response);
162 for (KnownNames_t::value_type
const&
element: iDefinition->second)
172 bool bForceDef =
false;
174 if (item[0] ==
'@') {
179 Definitions_t::const_iterator iDefinition = definitions.find(item);
180 if ((iDefinition == definitions.end()) && bForceDef) {
181 throw art::Exception(art::errors::LogicError)
182 <<
"no set named '" << item <<
"'\n";
190 KnownNames_t::iterator iName = name_set.begin(), nend = name_set.end();
191 while (iName != nend) {
193 else iName = name_set.erase(iName);
203 for (
auto const& query_info: query_registry) {
204 if (query_info.first == DefaultName)
continue;
205 if (LookupResponse(query_info.first) != answer)
continue;
206 names.insert(query_info.first);
214 (std::ostream* out )
const
217 for (
auto const& elem: known_names) {
218 if (query_registry[elem.first] > 0U)
continue;
219 if (elem.first == DefaultName)
continue;
220 missing.insert(elem.first);
222 if (out && !missing.empty()) {
223 (*out) << missing.size() <<
" items not queried:";
227 return missing.empty();
235 if (item[0] ==
'+') {
239 if (item[0] ==
'-') {
static Name_t const ClearAllName
name instructing to delete all names
std::set< Name_t > Names_t
list of names
bool DoCheckQueryRegistry(std::ostream *out=nullptr) const
static Response_t ParseMode(Name_t &item, Response_t default_answer=rsAccepted)
Strips the mode specifier from item and returns the insertion mode.
Definitions_t::const_iterator FindDefinition(Name_t &item) const
Strips set specifier and returns iterator to the definition, or end()
std::map< Name_t, NameResponse_t > KnownNames_t
Information about known names.
Response_t DefaultResponse() const
Returns the default answer for names that are not registered.
bool Accepted(Name_t name) const
Returns whether the name is accepted as good.
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
Response_t LookupResponse(Name_t name) const
Returns the response for the specified name (does not register query)
void ParseName(Name_t name)
Parses a name and adds it to the selector.
A class providing a selection list.
Definitions_t definitions
a set of definitions
void ProcessItem(KnownNames_t &name_set, Name_t item) const
Fills name_set with an item.
Response_t
Possible responses.
KnownNames_t known_names
list of known names, with category
static const std::vector< std::string > names
static Name_t const DefaultName
name representing the default
Names_t QueriedWithStatus(Response_t answer) const
Returns the list of queried names whose response is answer.
void ClearNameSet(KnownNames_t &name_set) const
Erases all the names in the selector (default answer is unchanged)
QueryRegistry_t query_registry
record of all the queries
throw art::Exception (art::errors::Configuration)
bool empty(FixedBins< T, C > const &) noexcept
void InsertItem(KnownNames_t &name_set, Name_t item, Response_t response) const
Adds an item to the name set, working in specified mode.
std::string Name_t
type representing a name
Response_t Query(Name_t name) const
Returns the response for the specified name (does not throw)