Options.hh
Go to the documentation of this file.
1 # pragma once
2 
3 #include <sstream>
4 
5 class TString;
6 
7 namespace boca
8 {
9 
10 namespace detail
11 {
12 
13 template <typename>
14 struct IsBool : std::false_type {};
15 
16 template <>
17 struct IsBool<bool> : std::true_type {};
18 
19 template<typename Value_>
20 using OnlyIfNotBool = typename std::enable_if < !IsBool<Value_>::value >::type;
21 
22 }
23 
29 class Options
30 {
31 
32 public:
33 
34  Options();
35 
36  Options(Options const& options) = default;
37 
38  Options(std::string const &string, bool do_it = true);
39 
40  template<typename Value_, typename = detail::OnlyIfNotBool<Value_>>
41  Options(std::string const &string, Value_ value)
42  {
43  Add(string, value);
44  }
45 
46  template<typename Value_>
47  Options(std::string const &string, Value_ value, std::string const &unit)
48  {
49  Add(string, value, unit);
50  }
51 
52  void Add(std::string const &string, bool do_it = true);
53 
54  template<typename Value_>
55  void Add(std::string const &string, Value_ value)
56  {
57  Separator();
58  options_ << string << "=" << value;
59  }
60 
61  template<typename Value_>
62  void Add(std::string const &string, Value_ value, std::string const &unit)
63  {
64  Separator();
65  options_ << string << "=" << value << unit;
66  }
67 
68  std::string str() const;
69 
70  operator std::string() const;
71 
72  operator TString() const;
73 
74 private:
75 
76  void Separator();
77 
78  std::stringstream options_;
79 
80  bool first_ = true;
81 
82 };
83 
84 }
void Add(std::string const &string, Value_ value, std::string const &unit)
Definition: Options.hh:62
Options(std::string const &string, Value_ value, std::string const &unit)
Definition: Options.hh:47
void Add(std::string const &string, Value_ value)
Definition: Options.hh:55
Definition: Options.hh:14
Options(std::string const &string, Value_ value)
Definition: Options.hh:41
Key-value-pair options.
Definition: Options.hh:29
Boosted Collider Analysis.
Definition: Analysis.hh:15
typename std::enable_if< !IsBool< Value_ >::value >::type OnlyIfNotBool
Definition: Options.hh:20