TagRules.cxx
Go to the documentation of this file.
2 
3 /* nb:
4  typedef std::string tag_t;
5  typedef std::string match_t;
6  typedef std::unordered_set<tag_t> tagset_t;
7  typedef std::pair<std::regex, tagset_t> rule_t;
8  typedef std::vector<rule_t> ruleset_t;
9  */
10 
11 #include <regex>
12 
13 using namespace WireCell;
14 
15 
17 {
18  if (std::regex_match(tag, rule.first)) {
19  return rule.second;
20  }
21  return tagset_t{};
22 }
23 
25  tagrules::tagset_t& ret, bool all)
26 {
27  bool found = false;
28  for (const auto& rule : rs) {
29  auto ts = tagrules::match(tag, rule);
30  if (ts.empty()) {
31  continue;
32  }
33  ret.insert(ts.begin(), ts.end());
34  if (all) {
35  found = true;
36  continue;
37  }
38  return true;
39  }
40  return found;
41 }
42 
44 {
46  for (auto tag : ts) {
48  if (match(tag, rs, one, all)) {
49  ret.insert(one.begin(), one.end());
50  }
51  }
52  return ret;
53 }
54 
55 
56 
57 
58 
59 
60 
62 {
63  if (jcfg.empty() or !jcfg.isArray()) {
64  return;
65  }
66 
67  const int nrss = jcfg.size();
68 
69  // Note: JSON is in name-major order, C++ index-major.
70  for (int ind=0; ind<nrss; ++ind) {
71  auto jone = jcfg[ind];
72  for (auto name : jone.getMemberNames()) {
73  auto& rsv = m_rulesets[name]; // eg, "frame" or "trace"
74  rsv.resize(nrss);
75  rsv[ind] = convert<tagrules::ruleset_t>(jone[name]);
76  }
77  }
78 }
79 
81  const tagrules::tag_t& tag)
82 {
83  const auto& rsv = m_rulesets[name];
84  if (rsv.empty() or ind >= rsv.size()) {
85  return tagrules::tagset_t{};
86  }
87  const auto& rs = rsv[ind];
89  ts.insert(tag);
90  return tagrules::transform(ts, rs);
91 }
static QCString name
Definition: declinfo.cpp:673
std::pair< std::regex, tagset_t > rule_t
Definition: TagRules.h:49
std::unordered_set< tag_t > tagset_t
Definition: TagRules.h:48
std::string string
Definition: nybbler.cc:12
tagset_t match(const tag_t &tag, const rule_t &rs)
Definition: TagRules.cxx:16
tagset_t transform(const tagset_t &ts, const ruleset_t &rs, bool all_rules=true)
Definition: TagRules.cxx:43
std::vector< rule_t > ruleset_t
Definition: TagRules.h:50
std::unordered_map< std::string, std::vector< ruleset_t > > m_rulesets
Definition: TagRules.h:71
Definition: Main.h:22
static QInternalList< QTextCodec > * all
Definition: qtextcodec.cpp:63
tagset_t transform(size_t ind, const std::string &name, const tag_t &tag)
Definition: TagRules.cxx:80
Json::Value Configuration
Definition: Configuration.h:50
void configure(const Configuration &cfg)
Definition: TagRules.cxx:61
std::string tag_t
Definition: TagRules.h:46