KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parameters.h
Go to the documentation of this file.
1 #ifndef PARAMETERS_H_
2 #define PARAMETERS_H_
3 
11 #include <string>
12 
13 #include "spear/Wide.h"
14 #include "spear/StringMap.h"
15 
16 namespace spear {
17 
18 class Parameters {
19 
20  public:
21 
25  static void read(const std::string & file, bool overwrite = false);
26 
37  static int read(int argc, char ** argv);
38 
39  static void display(OStream & os);
40 
41  static void set(
42  const String &name,
43  const String &value
44  )
45  {
46  _parameters.set(name.c_str(), value);
47  }
48 
53  static bool get(
54  const String& name,
55  String& value,
56  bool useEnvironment = true
57  );
58 
59 #ifdef USE_UNICODE
60 
61  static bool get(
62  const String& name,
63  std::string& value,
64  bool useEnvironment = true
65  );
66 #endif
67 
69  static bool get(
70  const String& name,
71  double& value,
72  bool useEnvironment = true
73  );
74 
76  static bool get(
77  const String& name,
78  int& value,
79  bool useEnvironment = true
80  );
81 
82  static bool contains(const String & name)
83  {
84  return _parameters.contains(name.c_str());
85  }
86 
87 private:
88 
89  static bool readNameValue(
90  const String& arg,
91  String& name,
92  String& value,
93  bool defaultValue = false
94  );
95 
96  static bool substitute(
97  const String& raw,
98  String& value);
99 
101  static int findQuote(
102  const String& input,
103  int offset);
104 
105  static spear::StringMap<String> _parameters;
106 };
107 
108 }
109 
110 #endif
static void display(OStream &os)
Definition: Parameters.cc:325
static void read(const std::string &file, bool overwrite=false)
Definition: Parameters.cc:34
Definition: Parameters.h:18
#define OStream
Definition: Wide.h:38
static bool contains(const String &name)
Definition: Parameters.h:82
static void set(const String &name, const String &value)
Definition: Parameters.h:41
#define String
Definition: Wide.h:36
bool contains(const Char *key) const
Definition: StringMap.h:106
bool set(const Char *key, const T &value)
Definition: StringMap.h:57