Belle II Software  release-08-01-10
ConfigFile.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #ifndef _Belle2_ConfigFile_h
9 #define _Belle2_ConfigFile_h
10 
11 #include <string>
12 #include <map>
13 #include <vector>
14 #include <istream>
15 
16 namespace Belle2 {
22  class ConfigFile {
23  public:
24  typedef std::map<std::string, std::string> ValueList;
25 
26  public:
27  ConfigFile() {}
28  ConfigFile(const std::string& file1)
29  {
30  read(file1, true);
31  }
32  ConfigFile(const std::string& file1, const std::string& file2)
33  {
34  read(file1, true);
35  read(file2, true);
36  }
37  ConfigFile(const std::string& file1,
38  const std::string& file2,
39  const std::string& file3)
40  {
41  read(file1, true);
42  read(file2, true);
43  read(file3, true);
44  }
45  ConfigFile(std::istream& is)
46  {
47  read(is);
48  }
49  ~ConfigFile() {}
50 
51  public:
52  void clear();
53  void read(const std::string& filename, bool overload = true);
54  void read(std::istream& is, bool overload = true);
55  bool hasKey(const std::string& label);
56  const std::string get(const std::string& label);
57  int getInt(const std::string& label);
58  bool getBool(const std::string& label);
59  double getFloat(const std::string& label);
60  ValueList& getValues() { return m_value_m; }
61  std::vector<std::string>& getLabels() { return m_label_v; }
62  void add(const std::string& label,
63  const std::string& value, bool overload);
64  void write(const std::string& path);
65  void print();
66 
67  private:
68  const std::string getFilePath(const std::string& filename);
69 
70  private:
71  ValueList m_value_m;
72  std::vector<std::string> m_label_v;
73  std::string m_dir;
74  std::map<std::string, int> m_count;
75 
76  };
77 
78  inline bool ConfigFile::hasKey(const std::string& label)
79  {
80  return m_value_m.find((m_dir.size() > 0) ? m_dir + "." + label : label)
81  != m_value_m.end();
82  }
83 
85 };
86 
87 #endif
Abstract base class for different kinds of events.