LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 36 of file NameSelector.h.

Member Typedef Documentation

Type of list of definitions.

Definition at line 180 of file NameSelector.h.

Information about known names.

Definition at line 177 of file NameSelector.h.

using testing::NameSelector::Name_t = std::string

type representing a name

Definition at line 39 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 40 of file NameSelector.h.

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

Type of query counters.

Definition at line 183 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 43 of file NameSelector.h.

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

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 55 of file NameSelector.h.

References SetDefaultResponse().

56  { 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 60 of file NameSelector.h.

References Parse().

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

Member Function Documentation

bool testing::NameSelector::Accepted ( Name_t  name) const

Returns whether the name is accepted as good.

Definition at line 38 of file NameSelector.cxx.

References art::errors::Configuration, Query(), rsAccepted, and rsThrow.

Referenced by AddToDefinition(), operator()(), and Rejected().

38  {
39  Response_t response = Query(name);
40  if (response == rsThrow) {
42  << "NameSelector: name '" << name << "' not configured.";
43  }
44  return response == rsAccepted;
45  } // NameSelector::Accepted()
Response_t
Possible responses.
Definition: NameSelector.h:43
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:46
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 150 of file NameSelector.h.

References QueriedWithStatus(), and rsAccepted.

150 { 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 108 of file NameSelector.cxx.

References InsertItem(), and ProcessItem().

108  {
109  ProcessItem(name_set, name);
110  } // 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 306 of file NameSelector.h.

Referenced by AddToDefinition(), BuildNameSet(), and ParseNames().

307 {
308  AddFirstName(name_set, name);
309  AddFirstName(name_set, other_names...);
310 } // 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:306
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 127 of file NameSelector.h.

References Accepted(), AddFirstName(), definitions, and Query().

128  { AddFirstName(definitions[set_name], names...); }
void AddFirstName(KnownNames_t &name_set, Name_t name, NAMES...other_names)
Parses the first of the provided names, and recurs.
Definition: NameSelector.h:306
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:187
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 291 of file NameSelector.h.

References AddFirstName(), and ProcessItem().

Referenced by Define(), and Parse().

292 {
293  for (Name_t item: items) 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:39
bool testing::NameSelector::CheckQueryRegistry ( ) const
inline

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

Definition at line 160 of file NameSelector.h.

Referenced by ClearQueryRegistry().

160 { 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 161 of file NameSelector.h.

References DoCheckQueryRegistry().

162  { 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 100 of file NameSelector.h.

References ClearNameSet(), Define(), and known_names.

KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
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 188 of file NameSelector.cxx.

References DefaultName, and QueriedWithStatus().

Referenced by Clear(), and ProcessItem().

188  {
189  KnownNames_t::iterator iName = name_set.begin(), nend = name_set.end();
190  while (iName != nend) {
191  if (iName->first == DefaultName) ++iName;
192  else iName = name_set.erase(iName);
193  } // while
194  } // NameSelector::ClearNameSet()
intermediate_table::iterator iterator
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
void testing::NameSelector::ClearQueryRegistry ( )
inline

Reests the query registry.

Definition at line 156 of file NameSelector.h.

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

156 { query_registry.clear(); }
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:189
Response_t testing::NameSelector::DefaultResponse ( ) const
inline

Returns the default answer for names that are not registered.

Definition at line 140 of file NameSelector.h.

References DefaultName, and known_names.

Referenced by LookupResponse(), and PrintConfiguration().

141  { return known_names.find(DefaultName)->second.response; }
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
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().

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

Definition at line 213 of file NameSelector.cxx.

References DefaultName, known_names, ParseMode(), and query_registry.

Referenced by CheckQueryRegistry(), ClearQueryRegistry(), and QueriedWithStatus().

214  {
215  Names_t missing;
216  for (auto const& elem: known_names) {
217  if (query_registry[elem.first] > 0U) continue;
218  if (elem.first == DefaultName) continue;
219  missing.insert(elem.first);
220  } // for
221  if (out && !missing.empty()) {
222  (*out) << missing.size() << " items not queried:";
223  for (Name_t const& name: missing) (*out) << " " << name;
224  (*out) << std::endl;
225  }
226  return missing.empty();
227  } // NameSelector::CheckQueryRegistry()
std::set< Name_t > Names_t
list of names
Definition: NameSelector.h:40
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:189
std::string Name_t
type representing a name
Definition: NameSelector.h:39
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 169 of file NameSelector.cxx.

References definitions, and art::errors::LogicError.

Referenced by ProcessItem().

170  {
171  bool bForceDef = false;
172  if (!item.empty()) {
173  if (item[0] == '@') {
174  bForceDef = true;
175  item.erase(0, 1);
176  }
177  }
178  Definitions_t::const_iterator iDefinition = definitions.find(item);
179  if ((iDefinition == definitions.end()) && bForceDef) {
181  << "no set named '" << item << "'\n";
182  }
183  return iDefinition;
184  } // NameSelector::FindDefinition()
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:187
intermediate_table::const_iterator const_iterator
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 115 of file NameSelector.cxx.

Referenced by AddFirstName(), InsertItem(), and ProcessItem().

116  {
117  name_set[item] = { response };
118  } // 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 123 of file NameSelector.cxx.

References InsertItem(), art::errors::LogicError, rsAccepted, and rsRejected.

125  {
126  // response is the instruction we have about how to add the item
127  // item.second.response is what the default answer for that item is
128  Response_t final_response; // uninitialized
129  switch (response) {
130  case rsAccepted:
131  final_response = item.second.response; // respect the response
132  break;
133  case rsRejected: // flip the response
134  switch (item.second.response) {
135  case rsAccepted: final_response = rsRejected; break;
136  case rsRejected: final_response = rsAccepted; break;
137  default:
139  << __func__ << ": unexpected code flow: invalid added response";
140  } // switch item response
141  break;
142  default:
144  << __func__ << ": unexpected code flow: invalid response";
145  } // switch response
146  InsertItem(name_set, item.first, final_response);
147  } // NameSelector::InsertItem(KnownNames_t::value_type)
Response_t
Possible responses.
Definition: NameSelector.h:43
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 99 of file NameSelector.cxx.

References DefaultResponse(), and known_names.

Referenced by QueriedWithStatus(), and Query().

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

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

Definition at line 144 of file NameSelector.h.

References Accepted(), and PrintConfiguration().

144 { 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 77 of file NameSelector.h.

References BuildNameSet(), known_names, and ParseName().

Referenced by NameSelector().

77 { BuildNameSet(known_names, items); }
void BuildNameSet(KnownNames_t &name_set, LIST const &items) const
Fills name_set with a list of items.
Definition: NameSelector.h:291
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
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 232 of file NameSelector.cxx.

References rsAccepted, and rsRejected.

Referenced by DoCheckQueryRegistry(), and ProcessItem().

233  {
234  if (item[0] == '+') {
235  item.erase(0, 1);
236  return rsAccepted;
237  }
238  if (item[0] == '-') {
239  item.erase(0, 1);
240  return rsRejected;
241  }
242  return default_mode;
243  } // 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 25 of file NameSelector.cxx.

References known_names, and ProcessItem().

Referenced by Parse().

25  {
26  ProcessItem(known_names, name);
27  } // 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:185
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 97 of file NameSelector.h.

References AddFirstName(), and known_names.

97 { AddFirstName(known_names, names...); }
void AddFirstName(KnownNames_t &name_set, Name_t name, NAMES...other_names)
Parses the first of the provided names, and recurs.
Definition: NameSelector.h:306
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
void testing::NameSelector::PrintConfiguration ( std::ostream &  out) const

Prints the configuration into a stream.

Definition at line 49 of file NameSelector.cxx.

References DefaultName, DefaultResponse(), known_names, rsAccepted, rsRejected, and rsThrow.

Referenced by operator()().

49  {
50 
51  // resort the known elements
52  std::map<Response_t, Names_t> elements;
53  for (KnownNames_t::value_type const& element: known_names)
54  if (element.first != DefaultName)
55  elements[element.second.response].insert(element.first);
56 
57  size_t nKnownElements = 0;
58  if (!elements[rsAccepted].empty()) {
59  auto const& selected_elements = elements[rsAccepted];
60  Names_t::const_iterator iName = selected_elements.cbegin(),
61  nend = selected_elements.cend();
62  out << " accept " << selected_elements.size()
63  << ": '" << *(iName++) << "'";
64  while (iName != nend) 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(),
71  nend = selected_elements.cend();
72  out << " reject " << selected_elements.size()
73  << ": '" << *(iName++) << "'";
74  while (iName != nend) out << ", '" << *(iName++) << "'";
75  out << ";";
76  nKnownElements += selected_elements.size();
77  } // if accepting anything
78  if (!elements[rsThrow].empty()) {
79  auto const& selected_elements = elements[rsThrow];
80  Names_t::const_iterator iName = selected_elements.cbegin(),
81  nend = selected_elements.cend();
82  out << " throw on " << selected_elements.size()
83  << ": '" << *(iName++) << "'";
84  while (iName != nend) out << ", '" << *(iName++) << "'";
85  out << ";";
86  nKnownElements += selected_elements.size();
87  } // if accepting anything
88  if (nKnownElements > 0) out << " otherwise,";
89  switch (DefaultResponse()) {
90  case rsAccepted: out << " accept everything"; break;
91  case rsRejected: out << " reject everything"; break;
92  case rsThrow: out << " throw on anything"; break;
93  default: out << " I don't know";
94  } // switch
95  } // NameSelector::PrintConfiguration()
Response_t DefaultResponse() const
Returns the default answer for names that are not registered.
Definition: NameSelector.h:140
intermediate_table::const_iterator const_iterator
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:46
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 151 of file NameSelector.cxx.

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

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

151  {
152  // special: if this name is actually a directive to clear all
153  if (item == ClearAllName) {
154  ClearNameSet(name_set); // clear everything except the default
155  return;
156  } // if clear all
157  Response_t response = ParseMode(item);
158  Definitions_t::const_iterator iDefinition = FindDefinition(item);
159  if (iDefinition == definitions.end()) InsertItem(name_set, item, response);
160  else {
161  for (KnownNames_t::value_type const& element: iDefinition->second)
162  InsertItem(name_set, element, response);
163  }
164  } // NameSelector::ProcessItem()
static Name_t const ClearAllName
name instructing to delete all names
Definition: NameSelector.h:167
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()
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:187
Response_t
Possible responses.
Definition: NameSelector.h:43
intermediate_table::const_iterator const_iterator
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 199 of file NameSelector.cxx.

References DefaultName, DoCheckQueryRegistry(), LookupResponse(), and query_registry.

Referenced by AcceptedNames(), ClearNameSet(), and RejectedNames().

200  {
201  NameSelector::Names_t names;
202  for (auto const& query_info: query_registry) {
203  if (query_info.first == DefaultName) continue;
204  if (LookupResponse(query_info.first) != answer) continue;
205  names.insert(query_info.first);
206  } // for
207  return names;
208  } // NameSelector::QueriedWithStatus()
std::set< Name_t > Names_t
list of names
Definition: NameSelector.h:40
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:166
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:189
NameSelector::Response_t testing::NameSelector::Query ( Name_t  name) const

Returns the response for the specified name (does not throw)

Definition at line 31 of file NameSelector.cxx.

References LookupResponse(), and query_registry.

Referenced by Accepted(), and AddToDefinition().

31  {
32  ++(query_registry[name]);
33  return LookupResponse(name);
34  } // 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:189
bool testing::NameSelector::Rejected ( Name_t  name) const
inline

Returns whether the name is rejected as bad.

Definition at line 137 of file NameSelector.h.

References Accepted().

137 { 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 153 of file NameSelector.h.

References QueriedWithStatus(), and rsRejected.

153 { 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  { known_names[DefaultName] = { default_answer }; }
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166

Member Data Documentation

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

name instructing to delete all names

Definition at line 167 of file NameSelector.h.

Referenced by ProcessItem().

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

name representing the default

Definition at line 166 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 187 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 185 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 189 of file NameSelector.h.

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


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