cxcparamx-2.0  2.0.3
simple.h
1 // -*-c++-*-
2 
3 #ifndef CXCPARAMX_SIMPLE_H
4 #define CXCPARAMX_SIMPLE_H
5 
6 #include <memory>
7 #include <string>
8 
9 #include <Exception/Exception.h>
10 
11 namespace cxcparamx {
12 
13  using std::string;
14 
15 
16  class simple {
17 
18  public:
19 
20  simple( int argc, char** argv, const string& mode = "rw" );
21  simple( const string& filename, int argc, char** argv, const string& mode = "rw" );
22 
23  void get( const string& name, float& value ) const;
24  void get( const string& name, double& value ) const;
25  void get( const string& name, short& value ) const;
26  void get( const string& name, int& value ) const;
27  void get( const string& name, long& value ) const;
28  void get( const string& name, bool& value ) const;
29  void get( const string& name, string& value ) const;
30 
31  float getf( const string& name ) const;
32  double getd( const string& name ) const;
33  short gets( const string& name ) const;
34  int geti( const string& name ) const;
35  long getl( const string& name ) const;
36  bool getb( const string& name ) const;
37  string getstr( const string& name ) const;
38 
39  bool access( const string& name ) const;
40 
41 
42  struct ParamFileImpl;
43  using pParamFileImpl = std::unique_ptr<ParamFileImpl, void(*)(ParamFileImpl*)>;
44 
45  private:
46 
47  simple( simple& ) = delete;
48  simple& operator=( simple& ) = delete;
49 
50  void access_t( const string& name ) const;
51 
52  pParamFileImpl pf;
53 
54  string filename;
55  };
56 
57 }
58 
59 #endif // ! CXCPARAMX_SIMPLE_H
Definition: simple.h:16
string getstr(const string &name) const
Return a parameter value as an string.
Definition: simple.cc:261
simple(int argc, char **argv, const string &mode="rw")
Constructor with file name taken from argv[0].
Definition: simple.cc:60
short gets(const string &name) const
Return a parameter value as a short.
Definition: simple.cc:213
long getl(const string &name) const
Return a parameter value as a long.
Definition: simple.cc:235
int geti(const string &name) const
Return a parameter value as an int.
Definition: simple.cc:224
void get(const string &name, float &value) const
Retrieve a parameter value into a float.
Definition: simple.cc:93
bool getb(const string &name) const
Return a parameter value as an bool.
Definition: simple.cc:250
double getd(const string &name) const
Return a parameter value as a double.
Definition: simple.cc:201
float getf(const string &name) const
Return a parameter value as a float.
Definition: simple.cc:190