Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
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,
  rsRejected, rsAccepted, rsThrow, rsDefault = rsAccepted
}
 Possible responses. More...
 
enum  Response_t {
  rsRejected, rsAccepted, rsThrow, rsDefault = rsAccepted,
  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 >
 
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...
 
 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
 
bool CheckQueryRegistry () const
 Checks that no known element with valid response was left unqueried. More...
 
bool CheckQueryRegistry (std::ostream &out) const
 

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

using testing::NameSelector::Definitions_t = std::map<Name_t, KnownNames_t>
protected

Type of list of definitions.

Definition at line 180 of file NameSelector.h.

using testing::NameSelector::Definitions_t = std::map<Name_t, KnownNames_t>
protected

Type of list of definitions.

Definition at line 181 of file NameSelector.h.

using testing::NameSelector::KnownNames_t = std::map<Name_t, NameResponse_t>
protected

Information about known names.

Definition at line 177 of file NameSelector.h.

using testing::NameSelector::KnownNames_t = std::map<Name_t, NameResponse_t>
protected

Information about known names.

Definition at line 178 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::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::NameList = std::initializer_list<Name_t>

Definition at line 52 of file NameSelector.h.

using testing::NameSelector::Names_t = std::set<Name_t>

list of names

Definition at line 40 of file NameSelector.h.

using testing::NameSelector::Names_t = std::set<Name_t>

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

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

Type of query counters.

Definition at line 184 of file NameSelector.h.

Member Enumeration Documentation

enum testing::NameSelector::Response_t

Possible responses.

Enumerator
rsRejected 

rejected

rsAccepted 

accepted

rsThrow 

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

rsDefault 
rsRejected 

rejected

rsAccepted 

accepted

rsThrow 

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

rsDefault 

Definition at line 43 of file NameSelector.h.

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

Possible responses.

Enumerator
rsRejected 

rejected

rsAccepted 

accepted

rsThrow 

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

rsDefault 
rsRejected 

rejected

rsAccepted 

accepted

rsThrow 

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

rsDefault 

Definition at line 44 of file NameSelector.h.

44  {
45  rsRejected, ///< rejected
46  rsAccepted, ///< accepted
47  rsThrow, ///< throw art::Exception (art::errors::Configuration)
48  rsDefault = rsAccepted
49  } 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.

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.

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
testing::NameSelector::NameSelector ( Response_t  default_answer = rsDefault)
inline

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

Definition at line 56 of file NameSelector.h.

57  { 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 61 of file NameSelector.h.

62  : NameSelector(default_answer)
63  { 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.

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

Returns whether the name is accepted as good.

Names_t testing::NameSelector::AcceptedNames ( ) const
inline

Returns a list of names that were accepted.

Definition at line 150 of file NameSelector.h.

150 { return QueriedWithStatus(rsAccepted); }
Names_t QueriedWithStatus(Response_t answer) const
Returns the list of queried names whose response is answer.
Names_t testing::NameSelector::AcceptedNames ( ) const
inline

Returns a list of names that were accepted.

Definition at line 151 of file NameSelector.h.

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

108  {
109  ProcessItem(name_set, name);
110  } // NameSelector::AddFirstName<>()
static QCString name
Definition: declinfo.cpp:673
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.

307 {
308  AddFirstName(name_set, name);
309  AddFirstName(name_set, other_names...);
310 } // testing::NameSelector::AddFirstName()
static QCString name
Definition: declinfo.cpp:673
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::AddFirstName ( KnownNames_t name_set,
Name_t  name,
NAMES...  other_names 
)
protected

Parses the first of the provided names, and recurs.

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.

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
static std::vector< std::string > const names
Definition: FragmentType.hh:8
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 128 of file NameSelector.h.

129  { 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
static std::vector< std::string > const names
Definition: FragmentType.hh:8
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.

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

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.

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

Definition at line 161 of file NameSelector.h.

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

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

Definition at line 161 of file NameSelector.h.

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

Definition at line 162 of file NameSelector.h.

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

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::Clear ( void  )
inline

Erases all the names in the selector (default answer is unchanged)

Definition at line 101 of file NameSelector.h.

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.

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::ClearNameSet ( KnownNames_t name_set) const
protected

Erases all the names in the selector (default answer is unchanged)

void testing::NameSelector::ClearQueryRegistry ( )
inline

Reests the query registry.

Definition at line 156 of file NameSelector.h.

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

Reests the query registry.

Definition at line 157 of file NameSelector.h.

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

141  { return known_names.find(DefaultName)->second.response; }
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
Response_t testing::NameSelector::DefaultResponse ( ) const
inline

Returns the default answer for names that are not registered.

Definition at line 141 of file NameSelector.h.

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

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
def move(depos, offset)
Definition: depos.py:107
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.

bool testing::NameSelector::DoCheckQueryRegistry ( std::ostream *  out = nullptr) const
protected

Definition at line 213 of file NameSelector.cxx.

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()
static QCString name
Definition: declinfo.cpp:673
std::set< Name_t > Names_t
list of names
Definition: NameSelector.h:40
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
QueryRegistry_t query_registry
record of all the queries
Definition: NameSelector.h:189
QTextStream & endl(QTextStream &s)
std::string Name_t
type representing a name
Definition: NameSelector.h:39
bool testing::NameSelector::DoCheckQueryRegistry ( std::ostream *  out = nullptr) const
protected
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.

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()
intermediate_table::const_iterator const_iterator
Definitions_t definitions
a set of definitions
Definition: NameSelector.h:187
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Definitions_t::const_iterator testing::NameSelector::FindDefinition ( Name_t item) const
protected

Strips set specifier and returns iterator to the definition, or end()

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.

116  {
117  name_set[item] = { response };
118  } // NameSelector::InsertItem()
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.

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 122 of file NameSelector.cxx.

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

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.

99  {
101  return (iResponse == known_names.end())?
102  DefaultResponse(): iResponse->second.response;
103  } // NameSelector::LookupResponse()
static QCString name
Definition: declinfo.cpp:673
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
Response_t testing::NameSelector::LookupResponse ( Name_t  name) const
protected

Returns the response for the specified name (does not register query)

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.

144 { return Accepted(name); }
static QCString name
Definition: declinfo.cpp:673
bool Accepted(Name_t name) const
Returns whether the name is accepted as good.
bool testing::NameSelector::operator() ( Name_t  name) const
inline

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

Definition at line 145 of file NameSelector.h.

145 { return Accepted(name); }
static QCString name
Definition: declinfo.cpp:673
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.

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

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

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

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.

25  {
27  } // NameSelector::ParseName()
static QCString name
Definition: declinfo.cpp:673
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
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.

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.

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
static std::vector< std::string > const names
Definition: FragmentType.hh:8
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 98 of file NameSelector.h.

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
static std::vector< std::string > const names
Definition: FragmentType.hh:8
void testing::NameSelector::PrintConfiguration ( std::ostream &  out) const

Prints the configuration into a stream.

Definition at line 49 of file NameSelector.cxx.

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
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:46
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
void testing::NameSelector::PrintConfiguration ( std::ostream &  ) const

Prints the configuration into a stream.

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 152 of file NameSelector.cxx.

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

200  {
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
static std::vector< std::string > const names
Definition: FragmentType.hh:8
Names_t testing::NameSelector::QueriedWithStatus ( Response_t  answer) const
protected

Returns the list of queried names whose response is answer.

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.

31  {
32  ++(query_registry[name]);
33  return LookupResponse(name);
34  } // NameSelector::Query()
static QCString name
Definition: declinfo.cpp:673
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
Response_t testing::NameSelector::Query ( Name_t  name) const

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

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.

137 { return !Accepted(name); }
static QCString name
Definition: declinfo.cpp:673
bool Accepted(Name_t name) const
Returns whether the name is accepted as good.
bool testing::NameSelector::Rejected ( Name_t  name) const
inline

Returns whether the name is rejected as bad.

Definition at line 138 of file NameSelector.h.

138 { return !Accepted(name); }
static QCString name
Definition: declinfo.cpp:673
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.

153 { return QueriedWithStatus(rsRejected); }
Names_t QueriedWithStatus(Response_t answer) const
Returns the list of queried names whose response is answer.
Names_t testing::NameSelector::RejectedNames ( ) const
inline

Returns a list of names that were rejected.

Definition at line 154 of file NameSelector.h.

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

66  { known_names[DefaultName] = { default_answer }; }
static Name_t const DefaultName
name representing the default
Definition: NameSelector.h:166
KnownNames_t known_names
list of known names, with category
Definition: NameSelector.h:185
void testing::NameSelector::SetDefaultResponse ( Response_t  default_answer)
inline

Sets the default answer for names that are not registered.

Definition at line 66 of file NameSelector.h.

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

Member Data Documentation

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

name instructing to delete all names

Definition at line 167 of file NameSelector.h.

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

name representing the default

Definition at line 166 of file NameSelector.h.

Definitions_t testing::NameSelector::definitions
protected

a set of definitions

Definition at line 187 of file NameSelector.h.

KnownNames_t testing::NameSelector::known_names
protected

list of known names, with category

Definition at line 185 of file NameSelector.h.

QueryRegistry_t testing::NameSelector::query_registry
mutableprotected

record of all the queries

Definition at line 189 of file NameSelector.h.


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