OSFI-C++  3.10.0
OpenSF Integration Library
ParamReader.h
Go to the documentation of this file.
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 
17 #ifndef OSFI_CONFM_PARAM_READER
18 #define OSFI_CONFM_PARAM_READER
19 
20 #include <string>
21 #include <map>
22 #include <memory>
23 #include <vector>
24 #include <stdexcept>
25 
26 using namespace std;
27 
28 #include "Parameter.h"
29 #include "ArrayNode.h"
30 
31 // TODO: this is performing the same comparison as std::less which is the default third argument to map anyway!
32 struct ltstr
33 {
34  bool operator()(const string& s1, const string& s2) const
35  {
36  return s1.compare(s2) < 0;
37  }
38 };
39 
40 typedef map<string, Parameter, ltstr> t_params_map;
41 
43 struct ParameterParsingException : public std::invalid_argument {
44  ParameterParsingException(const string& msg) : std::invalid_argument(msg) {}
45 };
46 
47 class XMLparser;
48 
67 class ParamReader {
68 public:
69 
82  OSFI_DEPRECATED("Use the single-argument version and then call validate.")
83  ParamReader(const string& xmlFile, const string& xsdFile);
89  ParamReader(const std::string& xmlFile);
90 
92  ParamReader(const ParamReader& other);
93  ParamReader(ParamReader&& other) = default;
94 
99  bool validateAgainst(const std::string& xsdFile) const;
103  bool validateAgainstInternalSchema() const;
104 
109  virtual ~ParamReader();
110 
117  Parameter getParameter(const string& paramName) const;
118 
125  vector<Parameter> getParameters(const string& groupName) const;
126 
130  t_params_map getParameters() const;
131 
137  bool existParameter(const string& paramName) const;
138 
139 
147  void setParameter(const string& paramName, string value);
148 
150  void print() const;
151 
157  Parameter& getParameterRef(const string& path);
159  const Parameter& getParameterRef(const string& path) const;
160 
161 private:
162 
166  t_params_map _params;
168  std::unique_ptr<XMLparser> src_doc;
169 };
170 
171 #endif // OSFI_CONFM_PARAM_READER
#define OSFI_DEPRECATED(reason)
Definition: CLP.h:25
OSFI-C++ header that declares the class that represents parameters in a configuration file.
Definition: ParamReader.h:67
Definition: Parameter.h:33
Definition: ParamReader.h:43
Definition: ParamReader.h:33