OSFI-C++  3.9.2
OpenSF Integration Library
ParamReader.h
1 /*
2  * openSF Integration Libraries (OSFI)
3  * Deimos Space, S.L.U.
4  *
5  * This file is part of OSFI. OSFI is free software; you can redistribute it
6  * and/or modify it under the terms of the 'ESA Software Community Licence Permissive' as
7  * published by the European Space Agency; either version 2.4 of the License,
8  * or (at your option) any later version. You should have received a
9  * copy of the 'ESA Software Community Licence Permissive - v2.4' along with this program
10  * or one can be found at <http://eop-cfi.esa.int/index.php/docs-and-mission-data/licensing-documents>.
11  *
12  * @file
13  * @brief OSFI-C++ header that provides class that reads configuration files.
14  */
15 
16 #ifndef _OSFI_CONFM_PARAM_READER_
17 #define _OSFI_CONFM_PARAM_READER_
18 
19 #include <string>
20 #include <map>
21 #include <memory>
22 #include <vector>
23 #include <stdexcept>
24 
25 using namespace std;
26 
27 #include "Parameter.h"
28 #include "ArrayNode.h"
29 
30 struct ltstr
31 {
32  bool operator()(const string& s1, const string& s2) const
33  {
34  return s1.compare(s2) < 0;
35  }
36 };
37 
38 typedef map<string, Parameter, ltstr> t_params_map;
39 
41 struct ParameterParsingException : public std::invalid_argument {
42  ParameterParsingException(const string& msg) : std::invalid_argument(msg) {}
43 };
44 
45 class XMLparser;
46 
73 class ParamReader {
74 public:
75 
88  OSFI_DEPRECATED("Use the single-argument version and then call validate.")
89  ParamReader(const string& xmlFile, const string& xsdFile);
95  ParamReader(const std::string& xmlFile);
96 
98  ParamReader(const ParamReader& other);
99  ParamReader(ParamReader&& other) = default;
100 
105  bool validateAgainst(const std::string& xsdFile) const;
109  bool validateAgainstInternalSchema() const;
110 
115  virtual ~ParamReader();
116 
122  Parameter getParameter(const string& paramName) const;
123 
128  vector<Parameter> getParameters(const string& groupName) const;
129 
133  t_params_map getParameters() const;
134 
140  bool existParameter(const string& paramName) const;
141 
142 
150  void setParameter(const string& paramName, string value);
151 
156  void print() const;
157 
163  Parameter& getParameterRef(const string& path);
164  const Parameter& getParameterRef(const string& path) const;
165 
166 private:
167 
172  t_params_map _params;
173 
174  std::unique_ptr<XMLparser> src_doc;
175 };
176 
177 #endif // _OSFI_CONFM_PARAM_READER_
ParameterParsingException
Definition: ParamReader.h:41
ParamReader
Definition: ParamReader.h:73
Parameter
Definition: Parameter.h:31
ltstr
Definition: ParamReader.h:30
OSFI_DEPRECATED
#define OSFI_DEPRECATED(reason)
Definition: CLP.h:26