Belle II Software  release-05-02-19
ConfigFile.h
1 #ifndef _Belle2_ConfigFile_h
2 #define _Belle2_ConfigFile_h
3 
4 #include <string>
5 #include <map>
6 #include <vector>
7 #include <istream>
8 
9 namespace Belle2 {
15  class ConfigFile {
16  public:
17  typedef std::map<std::string, std::string> ValueList;
18 
19  public:
20  ConfigFile() {}
21  ConfigFile(const std::string& file1)
22  {
23  read(file1, true);
24  }
25  ConfigFile(const std::string& file1, const std::string& file2)
26  {
27  read(file1, true);
28  read(file2, true);
29  }
30  ConfigFile(const std::string& file1,
31  const std::string& file2,
32  const std::string& file3)
33  {
34  read(file1, true);
35  read(file2, true);
36  read(file3, true);
37  }
38  ConfigFile(std::istream& is)
39  {
40  read(is);
41  }
42  ~ConfigFile() {}
43 
44  public:
45  void clear();
46  void read(const std::string& filename, bool overload = true);
47  void read(std::istream& is, bool overload = true);
48  bool hasKey(const std::string& label);
49  const std::string get(const std::string& label);
50  int getInt(const std::string& label);
51  bool getBool(const std::string& label);
52  double getFloat(const std::string& label);
53  ValueList& getValues() { return m_value_m; }
54  std::vector<std::string>& getLabels() { return m_label_v; }
55  void add(const std::string& label,
56  const std::string& value, bool overload);
57  void write(const std::string& path);
58  void print();
59 
60  private:
61  const std::string getFilePath(const std::string& filename);
62 
63  private:
64  ValueList m_value_m;
65  std::vector<std::string> m_label_v;
66  std::string m_dir;
67  std::map<std::string, int> m_count;
68 
69  };
70 
71  inline bool ConfigFile::hasKey(const std::string& label)
72  {
73  return m_value_m.find((m_dir.size() > 0) ? m_dir + "." + label : label)
74  != m_value_m.end();
75  }
76 
78 };
79 
80 #endif
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ConfigFile
Definition: ConfigFile.h:15