ConfigManager.cxx
Go to the documentation of this file.
3 
4 
5 using namespace std;
6 using namespace WireCell;
7 
8 ConfigManager::ConfigManager()
9  : m_top(Json::arrayValue)
10 {
11 }
13 {
14 }
15 
17 {
18  m_top = append(m_top, more);
19 }
20 
21 
23 {
24  int ind = -1;
25  for (auto c : m_top) {
26  ++ind;
27  if (get<string>(c, "type") != type) {
28  continue;
29  }
30  if (get<string>(c, "name") != name) {
31  continue;
32  }
33  return ind;
34  }
35  return -1;
36 
37 }
38 
40 {
41  int ind = this->index(get<string>(cfg, "type"), get<string>(cfg, "name"));
42  if (ind < 0) {
43  ind = m_top.size();
44  }
45  m_top[ind] = cfg;
46  return ind;
47 }
48 
50 {
52  cfg["data"] = payload;
53  cfg["type"] = type;
54  cfg["name"] = name;
55  return add(cfg);
56 }
57 
59 {
60  if (ind < 0 || ind >= size()) {
61  return Configuration();
62  }
63  return m_top[ind];
64 }
65 
66 std::vector<ConfigManager::ClassInstance> ConfigManager::configurables() const
67 {
68  std::vector<ConfigManager::ClassInstance> ret;
69  for (auto c : m_top) {
70  ret.push_back(make_pair(get<string>(c, "type"), get<string>(c, "name")));
71  }
72  return ret;
73 }
74 
76 {
77  if (ind < 0 || ind >= size()) {
78  return Configuration();
79  }
80  Configuration ret;
81  Configuration reduced(Json::arrayValue);
82  int siz = size();
83  for (int i=0; i<siz; ++i) {
84  if (i == ind) {
85  ret = m_top[i];
86  }
87  else {
88  reduced.append(m_top[i]);
89  }
90  }
91  m_top = reduced;
92  return ret;
93 }
static QCString name
Definition: declinfo.cpp:673
std::vector< ClassInstance > configurables() const
std::string string
Definition: nybbler.cc:12
STL namespace.
cfg
Definition: dbjson.py:29
void extend(Configuration more)
Extend current list of configuration objects with more.
int size() const
Return the number of configuration objects.
Definition: ConfigManager.h:46
Configuration at(int index) const
int add(Configuration &cfg)
Definition: Main.h:22
int index(const std::string &type, const std::string &name="") const
std::string type(const T &t)
Definition: Type.h:20
Configuration append(Configuration &a, Configuration &b)
Return an array which is composed of the array b appended to the array a.
Json::Value Configuration
Definition: Configuration.h:50
Configuration pop(int ind)
Remove configuration at given index and return it.