CMS 3D CMS Logo

ParameterCollector.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 
5 // class ParameterCollector provides a tool to parse blocks of PSets
6 // like "PythiaParameters" where one can list blocks of vstrings to be
7 // parsed inside another vstring named "parameterSets". It is also
8 // extended to allow nesting of blocks using "+block" statements
9 // (something which is heavily used for Herwig++).
10 // arbitrary vstring blocks can also be explicitly retrieved by name.
11 
12 #ifndef gen_ParameterCollector_h
13 #define gen_ParameterCollector_h
14 
15 #include <ostream>
16 #include <vector>
17 #include <string>
18 #include <map>
19 
20 #include <boost/iterator/iterator_facade.hpp>
21 
23 
24 namespace gen {
25 
27  public:
31 
32  // this iterator makes begin()/end() look like it was
33  // looping over a simple vector<string>
34 
36  : public boost::iterator_facade<const_iterator, const std::string, boost::forward_traversal_tag> {
37  public:
38  const_iterator() : collector_(nullptr), dump_(nullptr) {}
39 
40  protected:
41  friend class ParameterCollector;
42 
43  inline const_iterator(const ParameterCollector *collector,
44  std::vector<std::string>::const_iterator begin,
45  std::vector<std::string>::const_iterator end,
46  bool special = false,
47  std::ostream *dump = nullptr);
48 
49  private:
51 
52  void increment();
53  const std::string &dereference() const { return cache_; }
54  bool equal(const const_iterator &other) const { return iter_ == other.iter_; }
55 
56  void next();
57 
58  typedef std::pair<std::vector<std::string>::const_iterator, std::vector<std::string>::const_iterator> IterPair;
59 
61  std::ostream *dump_;
62  bool special_;
63  std::vector<IterPair> iter_;
65  };
66 
67  // start iterating over blocks listed in "parameterSets"
68  const_iterator begin() const;
69  const_iterator begin(std::ostream &dump) const;
70 
71  // start iterating over contents of this particular vstring block
72  const_iterator begin(const std::string &block) const;
73  const_iterator begin(const std::string &block, std::ostream &dump) const;
74 
75  // the iterator to mark the end of a loop
76  const_iterator end() const { return const_iterator(); }
77 
78  // this replaces ${...} with environment variables
79  // needed for ThePEG because you need full path to repository
80  static std::string resolve(const std::string &line);
81 
82  private:
83  friend class const_iterator;
84 
85  std::map<std::string, std::vector<std::string> > contents_;
86  };
87 
88 } // namespace gen
89 
90 #endif // gen_ParameterCollector_h
static std::string resolve(const std::string &line)
const_iterator begin() const
const_iterator end() const
const std::string & dereference() const
bool equal(const const_iterator &other) const
std::pair< std::vector< std::string >::const_iterator, std::vector< std::string >::const_iterator > IterPair
std::map< std::string, std::vector< std::string > > contents_