Public Types | Public Member Functions | Private Attributes | List of all members
WireCell::ConfigManager Class Reference

#include <ConfigManager.h>

Public Types

typedef std::pair< std::string, std::stringClassInstance
 Return a list of all known configurables. More...
 

Public Member Functions

 ConfigManager ()
 
 ~ConfigManager ()
 
void extend (Configuration more)
 Extend current list of configuration objects with more. More...
 
int add (Configuration &cfg)
 
int add (Configuration &data, const std::string &type, const std::string &name="")
 
Configuration all () const
 Return top-level, aggregate configuration. More...
 
Configuration at (int index) const
 
int index (const std::string &type, const std::string &name="") const
 
int size () const
 Return the number of configuration objects. More...
 
Configuration pop (int ind)
 Remove configuration at given index and return it. More...
 
std::vector< ClassInstanceconfigurables () const
 

Private Attributes

Configuration m_top
 

Detailed Description

Bundle up some policy for handling configuration.

Overall configuration object is a list of configuration objects for each configurable instance.

Each instance configuration is a dict with keys:

Definition at line 20 of file ConfigManager.h.

Member Typedef Documentation

Return a list of all known configurables.

Definition at line 52 of file ConfigManager.h.

Constructor & Destructor Documentation

ConfigManager::ConfigManager ( )

Definition at line 8 of file ConfigManager.cxx.

9  : m_top(Json::arrayValue)
10 {
11 }
ConfigManager::~ConfigManager ( )

Definition at line 12 of file ConfigManager.cxx.

13 {
14 }

Member Function Documentation

int ConfigManager::add ( Configuration cfg)

Definition at line 39 of file ConfigManager.cxx.

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 }
cfg
Definition: dbjson.py:29
int index(const std::string &type, const std::string &name="") const
int ConfigManager::add ( Configuration data,
const std::string type,
const std::string name = "" 
)

Definition at line 49 of file ConfigManager.cxx.

50 {
52  cfg["data"] = payload;
53  cfg["type"] = type;
54  cfg["name"] = name;
55  return add(cfg);
56 }
static QCString name
Definition: declinfo.cpp:673
cfg
Definition: dbjson.py:29
int add(Configuration &cfg)
std::string type(const T &t)
Definition: Type.h:20
Json::Value Configuration
Definition: Configuration.h:50
Configuration WireCell::ConfigManager::all ( ) const
inline

Return top-level, aggregate configuration.

Definition at line 37 of file ConfigManager.h.

37 { return m_top; }
Configuration ConfigManager::at ( int  index) const

Definition at line 58 of file ConfigManager.cxx.

59 {
60  if (ind < 0 || ind >= size()) {
61  return Configuration();
62  }
63  return m_top[ind];
64 }
int size() const
Return the number of configuration objects.
Definition: ConfigManager.h:46
Json::Value Configuration
Definition: Configuration.h:50
std::vector< ConfigManager::ClassInstance > ConfigManager::configurables ( ) const

Definition at line 66 of file ConfigManager.cxx.

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 }
void ConfigManager::extend ( Configuration  more)

Extend current list of configuration objects with more.

Definition at line 16 of file ConfigManager.cxx.

17 {
18  m_top = append(m_top, more);
19 }
Configuration append(Configuration &a, Configuration &b)
Return an array which is composed of the array b appended to the array a.
int ConfigManager::index ( const std::string type,
const std::string name = "" 
) const

Return index of configuration for given class and instance names. If not found, returned index == -1;

Definition at line 22 of file ConfigManager.cxx.

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 }
static QCString name
Definition: declinfo.cpp:673
Configuration ConfigManager::pop ( int  ind)

Remove configuration at given index and return it.

Definition at line 75 of file ConfigManager.cxx.

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 }
int size() const
Return the number of configuration objects.
Definition: ConfigManager.h:46
Json::Value Configuration
Definition: Configuration.h:50
int WireCell::ConfigManager::size ( void  ) const
inline

Return the number of configuration objects.

Definition at line 46 of file ConfigManager.h.

46 { return m_top.size(); }

Member Data Documentation

Configuration WireCell::ConfigManager::m_top
private

Definition at line 21 of file ConfigManager.h.


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