32#ifndef DRAIN_STRING_MATCHER_LIST
33#define DRAIN_STRING_MATCHER_LIST
41#include <drain/Sprinter.h>
42#include <drain/String.h>
43#include "StringMatcher.h"
51template <
class T=std::
string>
58 typedef std::list<T> list_t;
68 template <
typename ... TT>
106 StringMatcherList operator=(
const std::initializer_list<matcher_t> &l){
127 void setKeys(
const StringMatcherList<matcher_t> & l){
129 for (
const matcher_t & key: l) {
130 this->push_back(key);
135 void setKeys(
const std::initializer_list<T2> & l){
137 for (
const T2 & entry: l) {
143 void setKeys(
const std::list<T2> & l){
145 for (
const T2 & key: l) {
156 template <
typename ...TT>
157 void setKeys(
const std::string & arg,
const TT & ... args){
165 template <
typename ...TT>
167 void addKey(
const matcher_t & arg,
const TT & ... args){
179 bool test(
const std::string & key,
bool defaultResult =
true)
const;
181 const matcher_t & retrieve(
const std::string & key)
const;
186 return !this->empty();
191 const list_t & getList()
const {
196 void toStream(std::ostream & ostr)
const {
229 std::vector<std::string> argv;
232 for (
const std::string & arg: argv){
247 if (matcher.empty()){
253 for (
const matcher_t & m: *
this){
260 this->push_back(matcher);
276 return defaultResult;
279 for (
const auto & k: *
this){
294 const matcher_t empty;
300 for (
const auto & matcher: *this){
314std::ostream & operator<<(std::ostream & ostr,
const StringMatcherList<T> & selector){
315 selector.toStream(ostr);
319typedef StringMatcherList<StringMatcher> KeySelector;
static std::ostream & sequenceToStream(std::ostream &ostr, const T &x, const SprinterLayout &layout)
Convenience: if sequence type (array, list, set, map) not given, assume array.
Definition Sprinter.h:321
static const SprinterLayout cmdLineLayout
Simulates how arguments are given to command line options.
Definition Sprinter.h:248
Utility for selecting a quantity label Applied by DataSelector.
Definition StringMatcherList.h:52
void adaptKey(const matcher_t &s)
Definition StringMatcherList.h:245
StringMatcherList(const TT &... args)
Basic constructor.
Definition StringMatcherList.h:70
void insertKeys(const std::string &args)
Define the list of accepted quantities as a string.
Definition StringMatcherList.h:226
virtual ~StringMatcherList()
Initialiser constructor.
Definition StringMatcherList.h:98
bool test(const std::string &key, bool defaultResult=true) const
Check if key is accepted.
Definition StringMatcherList.h:273
void addKey(const matcher_t &arg, const TT &... args)
Append keys to existing list.matcher_t.
Definition StringMatcherList.h:167
void setKeys(const std::string &arg, const TT &... args)
Define the list of accepted quantities.
Definition StringMatcherList.h:157
StringMatcherList(const StringMatcherList< T > &l)
Copy constructor. Copies the list of quantities.
Definition StringMatcherList.h:78
General-purpose key matcher: tests string equality, or regExp, if defined as such.
Definition StringMatcher.h:58
Definition DataSelector.cpp:1277
DRAIN_TYPENAME(void)
Add a specialization for each type of those you want to support.