Serial-TCP/IPbridge  1.0
config_parser.h
Go to the documentation of this file.
1 
12 #ifndef CONFIG_PARSER_H
13 #define CONFIG_PARSER_H
14 
15 #include <string>
16 #include <map>
17 
18 #include "base_exception.h"
19 
43 class ConfigParser {
44  public:
48  class ParsingError: public BaseException {
49  public:
50  explicit ParsingError(const std::string &errorMessage):
51  BaseException(errorMessage) {}
52  };
53 
55  typedef std::map<std::string, std::string> ParsedConfig;
56 
57  public:
70  static ParsedConfig parse(const std::string &rawConfig);
71 
72  private:
81  static bool isValidOptionChar(char c);
82 
91  static bool isValidValueChar(char c);
92 
93  // Disable ctor, dtor, copy ctor and assignment operator since this
94  // is a static helper class
95  ConfigParser();
96  ConfigParser(const ConfigParser &);
98  ~ConfigParser();
99 };
100 
101 #endif // #ifndef CONFIG_PARSER_H
102 
103 // End of file config_parser.h
static bool isValidOptionChar(char c)
Checks whether the selected character is a valid part of an option name.
Configuration parser.
Definition: config_parser.h:43
static ParsedConfig parse(const std::string &rawConfig)
Parses a configuration from the selected string.
static bool isValidValueChar(char c)
Checks whether the selected character is a valid part of an option value.
BaseException class - declarations.
Base exception class for all project exceptions.
Definition: base_exception.h:23
std::map< std::string, std::string > ParsedConfig
Option -> values mapping.
Definition: config_parser.h:55
ConfigParser & operator=(const ConfigParser &)
This exception is thrown if there is an error during parsing.
Definition: config_parser.h:48
ParsingError(const std::string &errorMessage)
Definition: config_parser.h:50