NDS3  1.0.0
API reference manual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
iniFileParserImpl.h
1 /*
2  * Nominal Device Support v3 (NDS3)
3  *
4  * Copyright (c) 2015 Cosylab d.d.
5  *
6  * For more information about the license please refer to the license.txt
7  * file included in the distribution.
8  */
9 
10 #ifndef NDSINIFILEPARSERIMPL_H
11 #define NDSINIFILEPARSERIMPL_H
12 
13 #include <map>
14 #include <string>
15 #include <list>
16 
17 namespace nds
18 {
19 
20 class IniFileParserImpl
21 {
22 public:
23  IniFileParserImpl(std::istream& inputStream);
24 
25  ~IniFileParserImpl();
26 
36  const std::string& getString(const std::string& section, const std::string& key, const std::string& defaultValue) const;
37 
38  bool keyExists(const std::string& section, const std::string& key) const;
39 
40  typedef std::list<std::string> sectionsList_t;
41  sectionsList_t getSections() const;
42 
43 private:
44 
45  typedef std::pair<std::string, std::string> keyValue_t;
46 
47  static std::string trim(const std::string& string);
48 
49  static std::string getSection(const std::string& line);
50 
51  static size_t findFirstUnescapedChar(const std::string& string, const char findChar, const size_t startPosition = 0);
52 
53  static keyValue_t getKeyValue(const std::string& line);
54 
55  typedef std::map<std::string, std::string> keyValueMap_t;
56  typedef std::map<std::string, keyValueMap_t> sectionKeyMap_t;
57 
58  sectionKeyMap_t m_sections;
59 };
60 
61 }
62 
63 #endif // NDSINIFILEPARSERIMPL_H