LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
Manages a set of names. More...
#include "NameSelector.h"
Classes | |
struct | NameResponse_t |
A data structure containing how to react to a name. More... | |
Public Types | |
enum | Response_t { rsRejected, rsAccepted, rsThrow, rsDefault = rsAccepted } |
Possible responses. More... | |
using | Name_t = std::string |
type representing a name More... | |
using | Names_t = std::set< Name_t > |
list of names More... | |
using | NameList = std::initializer_list< Name_t > |
Public Member Functions | |
NameSelector (Response_t default_answer=rsDefault) | |
Constructor: an empty selector with a default answer for unknown names. More... | |
template<typename LIST > | |
NameSelector (LIST const &items, Response_t default_answer=rsDefault) | |
Constructor: Parse()s the specified items. More... | |
void | SetDefaultResponse (Response_t default_answer) |
Sets the default answer for names that are not registered. More... | |
template<typename LIST > | |
void | Parse (LIST const &items) |
Parses the names in the list and adds them to the selector. More... | |
void | ParseName (Name_t name) |
Parses a name and adds it to the selector. More... | |
template<typename... NAMES> | |
void | ParseNames (NAMES...names) |
Parses a list of names and adds them to the selector. More... | |
void | Clear () |
Erases all the names in the selector (default answer is unchanged) More... | |
template<typename LIST > | |
void | Define (std::string set_name, LIST const &items) |
Defines a set. More... | |
template<typename... NAMES> | |
void | AddToDefinition (std::string set_name, NAMES...names) |
Parses a list of names and add them to the specified definition. More... | |
Response_t | Query (Name_t name) const |
Returns the response for the specified name (does not throw) More... | |
bool | Accepted (Name_t name) const |
Returns whether the name is accepted as good. More... | |
bool | Rejected (Name_t name) const |
Returns whether the name is rejected as bad. More... | |
Response_t | DefaultResponse () const |
Returns the default answer for names that are not registered. More... | |
bool | operator() (Name_t name) const |
Returns whether the name is accepted as good (alias for accept()) More... | |
void | PrintConfiguration (std::ostream &) const |
Prints the configuration into a stream. More... | |
Names_t | AcceptedNames () const |
Returns a list of names that were accepted. More... | |
Names_t | RejectedNames () const |
Returns a list of names that were rejected. More... | |
void | ClearQueryRegistry () |
Reests the query registry. More... | |
template<> | |
void | AddFirstName (KnownNames_t &name_set, Name_t name) |
bool | CheckQueryRegistry () const |
Checks that no known element with valid response was left unqueried. More... | |
bool | CheckQueryRegistry (std::ostream &out) const |
Checks that no known element with valid response was left unqueried. More... | |
Static Public Attributes | |
static Name_t const | DefaultName = "*" |
name representing the default More... | |
static Name_t const | ClearAllName = "!" |
name instructing to delete all names More... | |
Protected Types | |
using | KnownNames_t = std::map< Name_t, NameResponse_t > |
Information about known names. More... | |
using | Definitions_t = std::map< Name_t, KnownNames_t > |
Type of list of definitions. More... | |
using | QueryRegistry_t = std::map< Name_t, size_t > |
Type of query counters. More... | |
Protected Member Functions | |
Response_t | LookupResponse (Name_t name) const |
Returns the response for the specified name (does not register query) More... | |
template<typename LIST > | |
void | BuildNameSet (KnownNames_t &name_set, LIST const &items) const |
Fills name_set with a list of items. More... | |
template<typename... NAMES> | |
void | AddFirstName (KnownNames_t &name_set, Name_t name, NAMES...other_names) |
Parses the first of the provided names, and recurs. More... | |
void | InsertItem (KnownNames_t &name_set, Name_t item, Response_t response) const |
Adds an item to the name set, working in specified mode. More... | |
void | InsertItem (KnownNames_t &name_set, KnownNames_t::value_type item, Response_t response) const |
Adds an item with response to the name set, working in specified mode. More... | |
void | ProcessItem (KnownNames_t &name_set, Name_t item) const |
Fills name_set with an item. More... | |
Definitions_t::const_iterator | FindDefinition (Name_t &item) const |
Strips set specifier and returns iterator to the definition, or end() More... | |
void | ClearNameSet (KnownNames_t &name_set) const |
Erases all the names in the selector (default answer is unchanged) More... | |
Names_t | QueriedWithStatus (Response_t answer) const |
Returns the list of queried names whose response is answer. More... | |
bool | DoCheckQueryRegistry (std::ostream *out=nullptr) const |
Static Protected Member Functions | |
static Response_t | ParseMode (Name_t &item, Response_t default_answer=rsAccepted) |
Strips the mode specifier from item and returns the insertion mode. More... | |
Protected Attributes | |
KnownNames_t | known_names |
list of known names, with category More... | |
Definitions_t | definitions |
a set of definitions More... | |
QueryRegistry_t | query_registry |
record of all the queries More... | |
Manages a set of names.
This class contains a set of names to be "accepted" and a set of names to be "rejected". Queries on unknown names will generate a default answer that can be acceptance, rejection or an exception.
The class is initialized by a list of strings following the convention detailed in ProcessItem(). The default answer is set on construction, but it can be overridden to a "reject by default" using a specific identifier.
Definition at line 37 of file NameSelector.h.
|
protected |
Type of list of definitions.
Definition at line 185 of file NameSelector.h.
|
protected |
Information about known names.
Definition at line 182 of file NameSelector.h.
using testing::NameSelector::Name_t = std::string |
type representing a name
Definition at line 40 of file NameSelector.h.
using testing::NameSelector::NameList = std::initializer_list<Name_t> |
Definition at line 51 of file NameSelector.h.
using testing::NameSelector::Names_t = std::set<Name_t> |
list of names
Definition at line 41 of file NameSelector.h.
|
protected |
Type of query counters.
Definition at line 188 of file NameSelector.h.
Possible responses.
Enumerator | |
---|---|
rsRejected |
rejected |
rsAccepted |
accepted |
rsThrow | |
rsDefault |
Definition at line 44 of file NameSelector.h.
|
inline |
Constructor: an empty selector with a default answer for unknown names.
Definition at line 54 of file NameSelector.h.
References SetDefaultResponse().
|
inline |
Constructor: Parse()s the specified items.
Definition at line 58 of file NameSelector.h.
References Parse().
bool testing::NameSelector::Accepted | ( | Name_t | name | ) | const |
Returns whether the name is accepted as good.
Definition at line 39 of file NameSelector.cxx.
References art::errors::Configuration, Query(), rsAccepted, and rsThrow.
Referenced by AddToDefinition(), operator()(), and Rejected().
|
inline |
Returns a list of names that were accepted.
Definition at line 158 of file NameSelector.h.
References QueriedWithStatus(), and rsAccepted.
void testing::NameSelector::AddFirstName | ( | KnownNames_t & | name_set, |
Name_t | name | ||
) |
Definition at line 104 of file NameSelector.cxx.
References ProcessItem().
|
protected |
Parses the first of the provided names, and recurs.
Definition at line 304 of file NameSelector.h.
Referenced by AddToDefinition(), and ParseNames().
|
inline |
Parses a list of names and add them to the specified definition.
NAMES | Name_t-compatible types |
set_name | name of the set to be defined |
names | the definitions to be used |
Specified items are processed with ProcessItem(); the result is added to the set with the specified name. If a set with that name does not exist, it's created empty.
Definition at line 134 of file NameSelector.h.
References Accepted(), AddFirstName(), definitions, and Query().
|
protected |
Fills name_set with a list of items.
LIST | type of container of name directives |
name_set | set to be modified |
items | name directives |
A name set is modified according to the instructions in each of the items. The items are parsed sequentially, and their order matters for the final result. Each item is processed through ProcessItem().
Definition at line 290 of file NameSelector.h.
References ProcessItem().
Referenced by Define(), and Parse().
|
inline |
Checks that no known element with valid response was left unqueried.
Definition at line 168 of file NameSelector.h.
Referenced by ClearQueryRegistry().
|
inline |
Checks that no known element with valid response was left unqueried.
Definition at line 169 of file NameSelector.h.
References DoCheckQueryRegistry().
|
inline |
Erases all the names in the selector (default answer is unchanged)
Definition at line 107 of file NameSelector.h.
References ClearNameSet(), Define(), and known_names.
|
protected |
Erases all the names in the selector (default answer is unchanged)
Definition at line 179 of file NameSelector.cxx.
References DefaultName.
Referenced by Clear(), and ProcessItem().
|
inline |
Reests the query registry.
Definition at line 164 of file NameSelector.h.
References CheckQueryRegistry(), DoCheckQueryRegistry(), and query_registry.
|
inline |
Returns the default answer for names that are not registered.
Definition at line 149 of file NameSelector.h.
References DefaultName, and known_names.
Referenced by LookupResponse(), and PrintConfiguration().
void testing::NameSelector::Define | ( | std::string | set_name, |
LIST const & | items | ||
) |
Defines a set.
LIST | type of list of strings |
set_name | name of the set to be defined |
items | the definitions to be used |
Specified items are processed with BuildSet(); the result is stored as a set with the specified name. If a set with that name already exists, it's replaced and the old one is lost.
Definition at line 281 of file NameSelector.h.
References BuildNameSet(), and definitions.
Referenced by Clear().
|
protected |
Definition at line 203 of file NameSelector.cxx.
References DefaultName, known_names, and query_registry.
Referenced by CheckQueryRegistry(), and ClearQueryRegistry().
|
protected |
Strips set specifier and returns iterator to the definition, or end()
Definition at line 162 of file NameSelector.cxx.
References definitions, and art::errors::LogicError.
Referenced by ProcessItem().
|
protected |
Adds an item to the name set, working in specified mode.
Definition at line 110 of file NameSelector.cxx.
Referenced by InsertItem(), and ProcessItem().
|
protected |
Adds an item with response to the name set, working in specified mode.
Definition at line 116 of file NameSelector.cxx.
References InsertItem(), art::errors::LogicError, rsAccepted, and rsRejected.
|
protected |
Returns the response for the specified name (does not register query)
Definition at line 96 of file NameSelector.cxx.
References DefaultResponse(), and known_names.
Referenced by QueriedWithStatus(), and Query().
|
inline |
Returns whether the name is accepted as good (alias for accept())
Definition at line 152 of file NameSelector.h.
References Accepted(), and PrintConfiguration().
|
inline |
Parses the names in the list and adds them to the selector.
LIST | type of list of strings |
items | the definitions to be used |
Specified items are processed with ProcessItem() and the current set is modified.
Definition at line 79 of file NameSelector.h.
References BuildNameSet(), known_names, and ParseName().
Referenced by NameSelector().
|
staticprotected |
Strips the mode specifier from item and returns the insertion mode.
Definition at line 221 of file NameSelector.cxx.
References rsAccepted, and rsRejected.
Referenced by ProcessItem().
void testing::NameSelector::ParseName | ( | Name_t | name | ) |
Parses a name and adds it to the selector.
name | name specification to be parsed |
The name is processed with ProcessItem() and the current set is modified.
Definition at line 26 of file NameSelector.cxx.
References known_names, and ProcessItem().
Referenced by Parse().
|
inline |
Parses a list of names and adds them to the selector.
NAMES | Name_t-compatible types |
names | the definitions to be used |
Specified items are processed with ProcessItem() and modify the current set.
Definition at line 101 of file NameSelector.h.
References AddFirstName(), and known_names.
void testing::NameSelector::PrintConfiguration | ( | std::ostream & | out | ) | const |
Prints the configuration into a stream.
Definition at line 50 of file NameSelector.cxx.
References DefaultName, DefaultResponse(), util::empty(), known_names, rsAccepted, rsRejected, and rsThrow.
Referenced by operator()().
|
protected |
Fills name_set with an item.
name_set | set to be modified |
item | name directive |
A name set is modified according to the instruction in the items. An identifier may represent either a single literal item or a set name; it can appear in two forms:
The directives in items are:
Definition at line 144 of file NameSelector.cxx.
References ClearAllName, ClearNameSet(), definitions, FindDefinition(), InsertItem(), and ParseMode().
Referenced by AddFirstName(), BuildNameSet(), and ParseName().
|
protected |
Returns the list of queried names whose response is answer.
Definition at line 191 of file NameSelector.cxx.
References DefaultName, LookupResponse(), and query_registry.
Referenced by AcceptedNames(), and RejectedNames().
NameSelector::Response_t testing::NameSelector::Query | ( | Name_t | name | ) | const |
Returns the response for the specified name (does not throw)
Definition at line 32 of file NameSelector.cxx.
References LookupResponse(), and query_registry.
Referenced by Accepted(), and AddToDefinition().
|
inline |
Returns whether the name is rejected as bad.
Definition at line 146 of file NameSelector.h.
References Accepted().
|
inline |
Returns a list of names that were rejected.
Definition at line 161 of file NameSelector.h.
References QueriedWithStatus(), and rsRejected.
|
inline |
Sets the default answer for names that are not registered.
Definition at line 65 of file NameSelector.h.
References DefaultName, and known_names.
Referenced by NameSelector().
|
static |
name instructing to delete all names
Definition at line 173 of file NameSelector.h.
Referenced by ProcessItem().
|
static |
name representing the default
Definition at line 172 of file NameSelector.h.
Referenced by ClearNameSet(), DefaultResponse(), DoCheckQueryRegistry(), PrintConfiguration(), QueriedWithStatus(), and SetDefaultResponse().
|
protected |
a set of definitions
Definition at line 192 of file NameSelector.h.
Referenced by AddToDefinition(), Define(), FindDefinition(), and ProcessItem().
|
protected |
list of known names, with category
Definition at line 190 of file NameSelector.h.
Referenced by Clear(), DefaultResponse(), DoCheckQueryRegistry(), LookupResponse(), Parse(), ParseName(), ParseNames(), PrintConfiguration(), and SetDefaultResponse().
|
mutableprotected |
record of all the queries
Definition at line 194 of file NameSelector.h.
Referenced by ClearQueryRegistry(), DoCheckQueryRegistry(), QueriedWithStatus(), and Query().