LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
testing::NameSelector Class Reference

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...
 

Detailed Description

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.

Member Typedef Documentation

Type of list of definitions.

Definition at line 185 of file NameSelector.h.

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.

list of names

Definition at line 41 of file NameSelector.h.

using testing::NameSelector::QueryRegistry_t = std::map<Name_t, size_t>
protected

Type of query counters.

Definition at line 188 of file NameSelector.h.

Member Enumeration Documentation

Possible responses.

Enumerator
rsRejected 

rejected

rsAccepted 

accepted

rsThrow 

throw art::Exception (art::errors::Configuration)

rsDefault 

Definition at line 44 of file NameSelector.h.

44  {
45  rsRejected,
46  rsAccepted,
47  rsThrow,
48  rsDefault = rsAccepted
49  } Response_t;
Response_t
Possible responses.
Definition: NameSelector.h:44
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:47

Constructor & Destructor Documentation

testing::NameSelector::NameSelector ( Response_t  default_answer = rsDefault)
inline

Constructor: an empty selector with a default answer for unknown names.

Definition at line 54 of file NameSelector.h.

References SetDefaultResponse().

54 { SetDefaultResponse(default_answer); }
void SetDefaultResponse(Response_t default_answer)
Sets the default answer for names that are not registered.
Definition: NameSelector.h:65
template<typename LIST >
testing::NameSelector::NameSelector ( LIST const &  items,
Response_t  default_answer = rsDefault 
)
inline

Constructor: Parse()s the specified items.

Definition at line 58 of file NameSelector.h.

References Parse().

59  : NameSelector(default_answer)
60  {
61  Parse(items);
62  }
NameSelector(Response_t default_answer=rsDefault)
Constructor: an empty selector with a default answer for unknown names.
Definition: NameSelector.h:54
void Parse(LIST const &items)
Parses the names in the list and adds them to the selector.
Definition: NameSelector.h:79

Member Function Documentation

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().

40  {
41  Response_t response = Query(name);
42  if (response == rsThrow) {
44  << "NameSelector: name '" << name << "' not configured.";
45  }
46  return response == rsAccepted;
47  } // NameSelector::Accepted()
Response_t
Possible responses.
Definition: NameSelector.h:44
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:47
Response_t Query(Name_t name) const
Returns the response for the specified name (does not throw)
Names_t testing::NameSelector::AcceptedNames ( ) const
inline

Returns a list of names that were accepted.

Definition at line 158 of file NameSelector.h.

References QueriedWithStatus(), and rsAccepted.

158 { return QueriedWithStatus(rsAccepted); }
Names_t QueriedWithStatus(Response_t answer) const
Returns the list of queried names whose response is answer.
void testing::NameSelector::AddFirstName ( KnownNames_t name_set,
Name_t  name 
)

Definition at line 104 of file NameSelector.cxx.

References ProcessItem().

105  {
106  ProcessItem(name_set, name);
107  } // NameSelector::AddFirstName<>()
void ProcessItem(KnownNames_t &name_set, Name_t item) const
Fills name_set with an item.
template<typename... NAMES>
void testing::NameSelector::AddFirstName ( KnownNames_t name_set,
Name_t  name,
NAMES...  other_names 
)
protected

Parses the first of the provided names, and recurs.

Definition at line 304 of file NameSelector.h.

Referenced by AddToDefinition(), and ParseNames().

305 {
306  AddFirstName(name_set, name);
307  AddFirstName(name_set, other_names...);
308 } // testing::NameSelector::AddFirstName()
void AddFirstName(KnownNames_t &name_set, Name_t name, NAMES...other_names)
Parses the first of the provided names, and recurs.
Definition: NameSelector.h:304
template<typename... NAMES>
void testing::NameSelector::AddToDefinition ( std::string  set_name,
NAMES...  names 
)
inline

Parses a list of names and add them to the specified definition.

Template Parameters
NAMESName_t-compatible types
Parameters
set_namename of the set to be defined
namesthe 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().

135  {
136  AddFirstName(definitions[set_name], names...);
137  }
void AddFirstName(KnownNames_t &name_set, Name_t name, NAMES...other_names)
Parses the first of the provided names, and recurs.
Definition: NameSelector.h:304
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:192
template<typename LIST >
void testing::NameSelector::BuildNameSet ( KnownNames_t name_set,
LIST const &  items 
) const
protected

Fills name_set with a list of items.

Template Parameters
LISTtype of container of name directives
Parameters
name_setset to be modified
itemsname 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().

291 {
292  for (Name_t item : items)
293  ProcessItem(name_set, item);
294 } // testing::NameSelector::BuildNameSet()
void ProcessItem(KnownNames_t &name_set, Name_t item) const
Fills name_set with an item.
std::string Name_t
type representing a name
Definition: NameSelector.h:40
bool testing::NameSelector::CheckQueryRegistry ( ) const
inline

Checks that no known element with valid response was left unqueried.

Definition at line 168 of file NameSelector.h.

Referenced by ClearQueryRegistry().

168 { return DoCheckQueryRegistry(); }
bool DoCheckQueryRegistry(std::ostream *out=nullptr) const
bool testing::NameSelector::CheckQueryRegistry ( std::ostream &  out) const
inline

Checks that no known element with valid response was left unqueried.

Definition at line 169 of file NameSelector.h.

References DoCheckQueryRegistry().

169 { return DoCheckQueryRegistry(&out); }
bool DoCheckQueryRegistry(std::ostream *out=nullptr) const
void testing::NameSelector::Clear ( )
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.

KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
void ClearNameSet(KnownNames_t &name_set) const
Erases all the names in the selector (default answer is unchanged)
void testing::NameSelector::ClearNameSet ( KnownNames_t name_set) const
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().

180  {
181  KnownNames_t::iterator iName = name_set.begin(), nend = name_set.end();
182  while (iName != nend) {
183  if (iName->first == DefaultName)
184  ++iName;
185  else
186  iName = name_set.erase(iName);
187  } // while
188  } // NameSelector::ClearNameSet()
intermediate_table::iterator iterator
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:172
void testing::NameSelector::ClearQueryRegistry ( )
inline

Reests the query registry.

Definition at line 164 of file NameSelector.h.

References CheckQueryRegistry(), DoCheckQueryRegistry(), and query_registry.

164 { query_registry.clear(); }
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:194
Response_t testing::NameSelector::DefaultResponse ( ) const
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().

149 { return known_names.find(DefaultName)->second.response; }
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:172
template<typename LIST >
void testing::NameSelector::Define ( std::string  set_name,
LIST const &  items 
)

Defines a set.

Template Parameters
LISTtype of list of strings
Parameters
set_namename of the set to be defined
itemsthe 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().

282 {
283  KnownNames_t name_set;
284  BuildNameSet(name_set, items);
285  definitions[set_name] = std::move(name_set);
286 } // testing::NameSelector::Define()
std::map< Name_t, NameResponse_t > KnownNames_t
Information about known names.
Definition: NameSelector.h:182
void BuildNameSet(KnownNames_t &name_set, LIST const &items) const
Fills name_set with a list of items.
Definition: NameSelector.h:290
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:192
bool testing::NameSelector::DoCheckQueryRegistry ( std::ostream *  out = nullptr) const
protected

Definition at line 203 of file NameSelector.cxx.

References DefaultName, known_names, and query_registry.

Referenced by CheckQueryRegistry(), and ClearQueryRegistry().

204  {
205  Names_t missing;
206  for (auto const& elem : known_names) {
207  if (query_registry[elem.first] > 0U) continue;
208  if (elem.first == DefaultName) continue;
209  missing.insert(elem.first);
210  } // for
211  if (out && !missing.empty()) {
212  (*out) << missing.size() << " items not queried:";
213  for (Name_t const& name : missing)
214  (*out) << " " << name;
215  (*out) << std::endl;
216  }
217  return missing.empty();
218  } // NameSelector::CheckQueryRegistry()
std::set< Name_t > Names_t
list of names
Definition: NameSelector.h:41
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:172
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:194
std::string Name_t
type representing a name
Definition: NameSelector.h:40
NameSelector::Definitions_t::const_iterator testing::NameSelector::FindDefinition ( Name_t item) const
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().

163  {
164  bool bForceDef = false;
165  if (!item.empty()) {
166  if (item[0] == '@') {
167  bForceDef = true;
168  item.erase(0, 1);
169  }
170  }
171  Definitions_t::const_iterator iDefinition = definitions.find(item);
172  if ((iDefinition == definitions.end()) && bForceDef) {
173  throw art::Exception(art::errors::LogicError) << "no set named '" << item << "'\n";
174  }
175  return iDefinition;
176  } // NameSelector::FindDefinition()
intermediate_table::const_iterator const_iterator
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:192
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void testing::NameSelector::InsertItem ( KnownNames_t name_set,
Name_t  item,
Response_t  response 
) const
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().

111  {
112  name_set[item] = {response};
113  } // NameSelector::InsertItem()
void testing::NameSelector::InsertItem ( KnownNames_t name_set,
KnownNames_t::value_type  item,
Response_t  response 
) const
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.

119  {
120  // response is the instruction we have about how to add the item
121  // item.second.response is what the default answer for that item is
122  Response_t final_response; // uninitialized
123  switch (response) {
124  case rsAccepted:
125  final_response = item.second.response; // respect the response
126  break;
127  case rsRejected: // flip the response
128  switch (item.second.response) {
129  case rsAccepted: final_response = rsRejected; break;
130  case rsRejected: final_response = rsAccepted; break;
131  default:
133  << __func__ << ": unexpected code flow: invalid added response";
134  } // switch item response
135  break;
136  default:
138  << __func__ << ": unexpected code flow: invalid response";
139  } // switch response
140  InsertItem(name_set, item.first, final_response);
141  } // NameSelector::InsertItem(KnownNames_t::value_type)
Response_t
Possible responses.
Definition: NameSelector.h:44
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void InsertItem(KnownNames_t &name_set, Name_t item, Response_t response) const
Adds an item to the name set, working in specified mode.
NameSelector::Response_t testing::NameSelector::LookupResponse ( Name_t  name) const
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().

97  {
98  KnownNames_t::const_iterator iResponse = known_names.find(name);
99  return (iResponse == known_names.end()) ? DefaultResponse() : iResponse->second.response;
100  } // NameSelector::LookupResponse()
Response_t DefaultResponse() const
Returns the default answer for names that are not registered.
Definition: NameSelector.h:149
intermediate_table::const_iterator const_iterator
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
bool testing::NameSelector::operator() ( Name_t  name) const
inline

Returns whether the name is accepted as good (alias for accept())

Definition at line 152 of file NameSelector.h.

References Accepted(), and PrintConfiguration().

152 { return Accepted(name); }
bool Accepted(Name_t name) const
Returns whether the name is accepted as good.
template<typename LIST >
void testing::NameSelector::Parse ( LIST const &  items)
inline

Parses the names in the list and adds them to the selector.

Template Parameters
LISTtype of list of strings
Parameters
itemsthe 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().

80  {
81  BuildNameSet(known_names, items);
82  }
void BuildNameSet(KnownNames_t &name_set, LIST const &items) const
Fills name_set with a list of items.
Definition: NameSelector.h:290
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
NameSelector::Response_t testing::NameSelector::ParseMode ( Name_t item,
Response_t  default_answer = rsAccepted 
)
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().

223  {
224  if (item[0] == '+') {
225  item.erase(0, 1);
226  return rsAccepted;
227  }
228  if (item[0] == '-') {
229  item.erase(0, 1);
230  return rsRejected;
231  }
232  return default_mode;
233  } // NameSelector::ParseMode()
void testing::NameSelector::ParseName ( Name_t  name)

Parses a name and adds it to the selector.

Parameters
namename 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().

27  {
28  ProcessItem(known_names, name);
29  } // NameSelector::ParseName()
void ProcessItem(KnownNames_t &name_set, Name_t item) const
Fills name_set with an item.
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
template<typename... NAMES>
void testing::NameSelector::ParseNames ( NAMES...  names)
inline

Parses a list of names and adds them to the selector.

Template Parameters
NAMESName_t-compatible types
Parameters
namesthe 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.

102  {
103  AddFirstName(known_names, names...);
104  }
void AddFirstName(KnownNames_t &name_set, Name_t name, NAMES...other_names)
Parses the first of the provided names, and recurs.
Definition: NameSelector.h:304
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
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()().

51  {
52 
53  // resort the known elements
54  std::map<Response_t, Names_t> elements;
55  for (KnownNames_t::value_type const& element : known_names)
56  if (element.first != DefaultName) elements[element.second.response].insert(element.first);
57 
58  size_t nKnownElements = 0;
59  if (!elements[rsAccepted].empty()) {
60  auto const& selected_elements = elements[rsAccepted];
61  Names_t::const_iterator iName = selected_elements.cbegin(), nend = selected_elements.cend();
62  out << " accept " << selected_elements.size() << ": '" << *(iName++) << "'";
63  while (iName != nend)
64  out << ", '" << *(iName++) << "'";
65  out << ";";
66  nKnownElements += selected_elements.size();
67  } // if accepting anything
68  if (!elements[rsRejected].empty()) {
69  auto const& selected_elements = elements[rsRejected];
70  Names_t::const_iterator iName = selected_elements.cbegin(), nend = selected_elements.cend();
71  out << " reject " << selected_elements.size() << ": '" << *(iName++) << "'";
72  while (iName != nend)
73  out << ", '" << *(iName++) << "'";
74  out << ";";
75  nKnownElements += selected_elements.size();
76  } // if accepting anything
77  if (!elements[rsThrow].empty()) {
78  auto const& selected_elements = elements[rsThrow];
79  Names_t::const_iterator iName = selected_elements.cbegin(), nend = selected_elements.cend();
80  out << " throw on " << selected_elements.size() << ": '" << *(iName++) << "'";
81  while (iName != nend)
82  out << ", '" << *(iName++) << "'";
83  out << ";";
84  nKnownElements += selected_elements.size();
85  } // if accepting anything
86  if (nKnownElements > 0) out << " otherwise,";
87  switch (DefaultResponse()) {
88  case rsAccepted: out << " accept everything"; break;
89  case rsRejected: out << " reject everything"; break;
90  case rsThrow: out << " throw on anything"; break;
91  default: out << " I don't know";
92  } // switch
93  } // NameSelector::PrintConfiguration()
Response_t DefaultResponse() const
Returns the default answer for names that are not registered.
Definition: NameSelector.h:149
intermediate_table::const_iterator const_iterator
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:172
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:47
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
void testing::NameSelector::ProcessItem ( KnownNames_t name_set,
Name_t  item 
) const
protected

Fills name_set with an item.

Parameters
name_setset to be modified
itemname 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:

  • "\@identifier": always denotes a set named "identifier"
  • "identifier": if a set named "identifier" exists, the name represents that set; otherwise, it represents a literal item named "identifier"

The directives in items are:

  • "identifier": the element or elements represented by the identifier replace the content of the current set
  • "+identifier": the element or elements represented by the identifier are added to the current set; if the identifier is a predefined set, the elements accepted in the set are added as accepted here, the ones rejected are added as rejected here
  • "-identifier": the element or elements represented by the identifier; if the identifier is a predefined set, the elements accepted in the set are added as rejected here, the ones rejected are added as accepted here

Definition at line 144 of file NameSelector.cxx.

References ClearAllName, ClearNameSet(), definitions, FindDefinition(), InsertItem(), and ParseMode().

Referenced by AddFirstName(), BuildNameSet(), and ParseName().

145  {
146  // special: if this name is actually a directive to clear all
147  if (item == ClearAllName) {
148  ClearNameSet(name_set); // clear everything except the default
149  return;
150  } // if clear all
151  Response_t response = ParseMode(item);
152  Definitions_t::const_iterator iDefinition = FindDefinition(item);
153  if (iDefinition == definitions.end())
154  InsertItem(name_set, item, response);
155  else {
156  for (KnownNames_t::value_type const& element : iDefinition->second)
157  InsertItem(name_set, element, response);
158  }
159  } // NameSelector::ProcessItem()
static Name_t const ClearAllName
name instructing to delete all names
Definition: NameSelector.h:173
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()
intermediate_table::const_iterator const_iterator
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:192
Response_t
Possible responses.
Definition: NameSelector.h:44
void ClearNameSet(KnownNames_t &name_set) const
Erases all the names in the selector (default answer is unchanged)
void InsertItem(KnownNames_t &name_set, Name_t item, Response_t response) const
Adds an item to the name set, working in specified mode.
NameSelector::Names_t testing::NameSelector::QueriedWithStatus ( Response_t  answer) const
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().

192  {
193  NameSelector::Names_t names;
194  for (auto const& query_info : query_registry) {
195  if (query_info.first == DefaultName) continue;
196  if (LookupResponse(query_info.first) != answer) continue;
197  names.insert(query_info.first);
198  } // for
199  return names;
200  } // NameSelector::QueriedWithStatus()
std::set< Name_t > Names_t
list of names
Definition: NameSelector.h:41
Response_t LookupResponse(Name_t name) const
Returns the response for the specified name (does not register query)
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:172
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:194
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().

33  {
34  ++(query_registry[name]);
35  return LookupResponse(name);
36  } // NameSelector::Query()
Response_t LookupResponse(Name_t name) const
Returns the response for the specified name (does not register query)
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:194
bool testing::NameSelector::Rejected ( Name_t  name) const
inline

Returns whether the name is rejected as bad.

Definition at line 146 of file NameSelector.h.

References Accepted().

146 { return !Accepted(name); }
bool Accepted(Name_t name) const
Returns whether the name is accepted as good.
Names_t testing::NameSelector::RejectedNames ( ) const
inline

Returns a list of names that were rejected.

Definition at line 161 of file NameSelector.h.

References QueriedWithStatus(), and rsRejected.

161 { return QueriedWithStatus(rsRejected); }
Names_t QueriedWithStatus(Response_t answer) const
Returns the list of queried names whose response is answer.
void testing::NameSelector::SetDefaultResponse ( Response_t  default_answer)
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().

66  {
67  known_names[DefaultName] = {default_answer};
68  }
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:190
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:172

Member Data Documentation

NameSelector::Name_t const testing::NameSelector::ClearAllName = "!"
static

name instructing to delete all names

Definition at line 173 of file NameSelector.h.

Referenced by ProcessItem().

NameSelector::Name_t const testing::NameSelector::DefaultName = "*"
static

name representing the default

Definition at line 172 of file NameSelector.h.

Referenced by ClearNameSet(), DefaultResponse(), DoCheckQueryRegistry(), PrintConfiguration(), QueriedWithStatus(), and SetDefaultResponse().

Definitions_t testing::NameSelector::definitions
protected

a set of definitions

Definition at line 192 of file NameSelector.h.

Referenced by AddToDefinition(), Define(), FindDefinition(), and ProcessItem().

KnownNames_t testing::NameSelector::known_names
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().

QueryRegistry_t testing::NameSelector::query_registry
mutableprotected

record of all the queries

Definition at line 194 of file NameSelector.h.

Referenced by ClearQueryRegistry(), DoCheckQueryRegistry(), QueriedWithStatus(), and Query().


The documentation for this class was generated from the following files: