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,
37  boost::forward_traversal_tag> {
38  public:
40 
41  protected:
42  friend class ParameterCollector;
43 
44  inline const_iterator(const ParameterCollector *collector,
45  std::vector<std::string>::const_iterator begin,
46  std::vector<std::string>::const_iterator end,
47  bool special = false, 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
55  { return iter_ == other.iter_; }
56 
57  void next();
58 
59  typedef std::pair<std::vector<std::string>::const_iterator,
60  std::vector<std::string>::const_iterator> IterPair;
61 
63  std::ostream *dump_;
64  bool special_;
65  std::vector<IterPair> iter_;
67  };
68 
69  // start iterating over blocks listed in "parameterSets"
70  const_iterator begin() const;
71  const_iterator begin(std::ostream &dump) const;
72 
73  // start iterating over contents of this particular vstring block
74  const_iterator begin(const std::string &block) const;
75  const_iterator begin(const std::string &block, std::ostream &dump) const;
76 
77  // the iterator to mark the end of a loop
78  const_iterator end() const { return const_iterator(); }
79 
80  // this replaces ${...} with environment variables
81  // needed for ThePEG because you need full path to repository
82  static std::string resolve(const std::string &line);
83 
84 private:
85  friend class const_iterator;
86 
87  std::map<std::string, std::vector<std::string> > contents_;
88 };
89 
90 } // namespace gen
91 
92 #endif // gen_ParameterCollector_h
static std::string resolve(const std::string &line)
bool equal(const const_iterator &other) const
#define nullptr
std::pair< std::vector< std::string >::const_iterator, std::vector< std::string >::const_iterator > IterPair
const std::string & dereference() const
std::map< std::string, std::vector< std::string > > contents_
const_iterator end() const
const_iterator begin() const