MarlinTrk  2.2.0
ConfigFlags.h
1 #ifndef ConfigFlags_h
2 #define ConfigFlags_h
3 
4 #include <string>
5 #include <iostream>
6 #include <exception>
7 #include <map>
8 
9 namespace MarlinTrk {
10 
11  class ConfigFlags ;
12 
13  inline std::ostream& operator<<(std::ostream& os, const ConfigFlags& cf) ;
14 
15  class ConfigFlags{
16 
17  friend std::ostream& operator<<(std::ostream& os, const ConfigFlags& flags) ;
18 
19  typedef std::pair<std::string, bool> Flag ;
20  typedef std::map< unsigned, Flag > Map ;
21 
22 
23  public:
24 
30 
31  ~ConfigFlags(){}
32 
33 
34  void registerOption( unsigned key, const std::string& name, bool defaultValue=false ){
35 
36  _map[ key ] = std::make_pair( name , defaultValue ) ;
37  }
38 
39  bool option(unsigned key) const {
40 
41  Map::const_iterator it = _map.find( key ) ;
42 
43  if( it == _map.end() )
44  return false ;
45 
46  return it->second.second ;
47  }
48 
49  bool operator[](unsigned key) const {
50  return option( key ) ;
51  }
52 
53  void setOption(unsigned key , bool val) {
54 
55  Map::iterator it = _map.find( key ) ;
56 
57  if( it !=_map.end() )
58  it->second.second = val ;
59  }
60 
61 
62  std::string& optionName(unsigned key) {
63 
64  static std::string empty("UNKNOWN") ;
65 
66  Map::iterator it = _map.find( key ) ;
67 
68  if( it == _map.end() )
69  return empty ;
70 
71  return it->second.first ;
72  }
73 
74  protected:
75  Map _map ;
76 
77  };
78 
79 
80  inline std::ostream& operator<<(std::ostream& os, const MarlinTrk::ConfigFlags& cf) {
81 
82  for( ConfigFlags::Map::const_iterator it = cf._map.begin(); it != cf._map.end() ; ++it){
83 
84  os << " option: " << it->second.first << "\t: " << it->second.second << std::endl ;
85  }
86 
87  return os ;
88  }
89 
90 } // namespace
91 
92 
93 #endif
94 
ConfigFlags()
Helper class that holds a number of boolean properties for configuration.
Definition: ConfigFlags.h:29
Definition: ConfigFlags.h:15