File: parsetreader.h

package info (click to toggle)
wsclean 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,968 kB
  • sloc: cpp: 85,742; python: 3,526; sh: 245; makefile: 21
file content (94 lines) | stat: -rw-r--r-- 2,645 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef PARSET_READER_H
#define PARSET_READER_H

#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <vector>

#ifdef HAVE_EVERYBEAM
#include <EveryBeam/aterms/parsetprovider.h>
#endif  // HAVE_EVERYBEAM

namespace wsclean {

#ifdef HAVE_EVERYBEAM
/**
 * @brief Parses the parameter settings (parset) related to the
 * aterm settings in an EveryBeam-acceptable format.
 *
 */
class ParsetReader : public everybeam::aterms::ParsetProvider {
#else
/**
 * @brief Parses the parameter settings (parset) related to the
 * aterm settings.
 *
 */
class ParsetReader {
#endif  // HAVE_EVERYBEAM
 public:
  ParsetReader(const std::string& filename);
  ParsetReader(std::istream& stream);

  class ParsetEntry {
   public:
    ParsetEntry(ParsetEntry&&) = default;
    enum Type { String, StringList };
    ParsetEntry(const std::string& line);
    bool operator<(const ParsetEntry& rhs) const { return _key < rhs._key; }
    const std::string& Key() const { return _key; }
    const std::string& GetStringValue() const;
    const std::vector<std::string>& GetStringListValue() const;

   private:
    struct Value {
      virtual ~Value() {}
    };
    struct StringValue : public Value {
      std::string _value;
    };
    struct StringListValue : public Value {
      std::vector<std::string> _value;
    };

    std::string _key;
    std::unique_ptr<Value> _value;
  };

#ifdef HAVE_EVERYBEAM
  std::string GetString(const std::string& key) const final override;
  std::string GetStringOr(const std::string& key,
                          const std::string& orValue) const final override;
  std::vector<std::string> GetStringList(
      const std::string& key) const final override;

  bool GetBool(const std::string& key) const final override;
  bool GetBoolOr(const std::string& key, bool orValue) const final override;

  double GetDoubleOr(const std::string& key,
                     double orValue) const final override;
#else
  std::string GetString(const std::string& key) const;
  std::string GetStringOr(const std::string& key,
                          const std::string& orValue) const;
  std::vector<std::string> GetStringList(const std::string& key) const;

  bool GetBool(const std::string& key) const;
  bool GetBoolOr(const std::string& key, bool orValue) const;

  double GetDoubleOr(const std::string& key, double orValue) const;
#endif  // HAVE_EVERYBEAM
  // GetDouble is not implemented (and needed) in ParsetProvider
  double GetDouble(const std::string& key) const;

 private:
  void read(std::istream& stream);

  std::map<std::string, ParsetEntry> _entries;
};

}  // namespace wsclean

#endif