EUDAQ
 All Classes Namespaces Files Functions Variables Pages
FileNamer.hh
1 #ifndef EUDAQ_INCLUDED_FileNamer
2 #define EUDAQ_INCLUDED_FileNamer
3 
4 #include "eudaq/Utils.hh"
5 #include <string>
6 #include <vector>
7 
8 namespace eudaq {
9 
10  class DLLEXPORT FileNamer {
11  public:
12  FileNamer(const std::string &pattern = "");
13  FileNamer &SetReplace(char opt, const std::string &val);
14  template <typename T> FileNamer &Set(char opt, const T &val);
15  operator std::string() const;
16  static const std::string default_pattern;
17 
18  private:
19  struct part_t {
20  part_t(char n, int l = 0) : name(n), len(l) {}
21  part_t(const std::string &s) : name(0), len(0), str(s) {}
22  char name;
23  int len;
24  std::string str;
25  };
26  std::vector<part_t> m_parts;
27  };
28 
29  template <typename T> FileNamer &FileNamer::Set(char opt, const T &val) {
30  for (size_t i = 0; i < m_parts.size(); ++i) {
31  if (m_parts[i].name == opt) {
32  m_parts[i].str = to_string(val, m_parts[i].len);
33  }
34  }
35  return *this;
36  }
37 }
38 
39 #endif // EUDAQ_INCLUDED_FileNamer
Definition: FileNamer.hh:10
std::string to_string(const T &x, int digits=0)
Definition: Utils.hh:54