File: parsetreader.h

package info (click to toggle)
wsclean 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,196 kB
  • sloc: cpp: 34,504; ansic: 234; python: 174; makefile: 10
file content (56 lines) | stat: -rw-r--r-- 1,463 bytes parent folder | download
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
#ifndef PARSET_READER_H
#define PARSET_READER_H

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

class ParsetReader
{
public:
	ParsetReader(const std::string& filename);
	ParsetReader(std::istream& stream);
	
	class ParsetEntry
	{
	public:
		ParsetEntry(ParsetEntry&& source) = 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;
	};
	
	const std::string& GetString(const std::string& key) const;
	const std::string& GetStringOr(const std::string& key, const std::string& orValue) const;
	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 GetDouble(const std::string& key) const;
	double GetDoubleOr(const std::string& key, double orValue) const;
	
private:
	void read(std::istream& stream);
	
	std::map<std::string, ParsetEntry> _entries;
};

#endif