b2api
B2000++ API Reference Manual, VERSION 4.6
 
Loading...
Searching...
No Matches
b2dictionary.H
Go to the documentation of this file.
1//------------------------------------------------------------------------
2// b2dictionary.H --
3//
4//
5// written by Mathias Doreille
6//
7// Copyright (c) 2004-2012,2017
8// SMR Engineering & Development SA
9// 2502 Bienne, Switzerland
10//
11// All Rights Reserved. Proprietary source code. The contents of
12// this file may not be disclosed to third parties, copied or
13// duplicated in any form, in whole or in part, without the prior
14// written permission of SMR.
15//------------------------------------------------------------------------
16
17#ifndef __B2DICTIONARY_H__
18#define __B2DICTIONARY_H__
19
25#include <complex>
26#include <ostream>
27#include <string>
28#include <vector>
29
30#include "utils/b2csda.H"
31#include "utils/b2exception.H"
32#include "utils/b2object.H"
33
34namespace b2000 {
35
48class Dictionary : public Object {
49public:
50 ~Dictionary() override {}
51
53 virtual bool has_key(const std::string& key) const = 0;
54
56 virtual bool get_bool(const std::string& key) const = 0;
57
60 virtual bool get_bool(const std::string& key, bool default_) const {
61 if (!has_key(key)) { return default_; }
62 return get_bool(key);
63 }
64
66 virtual int get_int(const std::string& key) const = 0;
67
70 virtual int get_int(const std::string& key, int default_) const {
71 if (!has_key(key)) { return default_; }
72 return get_int(key);
73 }
74
76 virtual double get_double(const std::string& key) const = 0;
77
80 virtual double get_double(const std::string& key, double default_) const {
81 if (!has_key(key)) { return default_; }
82 return get_double(key);
83 }
84
86 virtual b2000::csda<double> get_csda_double(const std::string& key) const = 0;
87
90 virtual b2000::csda<double> get_csda_double(
91 const std::string& key, b2000::csda<double> default_) const {
92 if (!has_key(key)) { return default_; }
93 return get_csda_double(key);
94 }
95
97 virtual std::complex<double> get_complex_double(const std::string& key) const = 0;
98
101 virtual std::complex<double> get_complex_double(
102 const std::string& key, std::complex<double> default_) const {
103 if (!has_key(key)) { return default_; }
104 return get_complex_double(key);
105 }
106
108 virtual std::string get_string(const std::string& key) const = 0;
109
112 virtual std::string get_string(const std::string& key, const std::string& default_) const {
113 try {
114 return get_string(key);
115 } catch (std::exception&) { return default_; }
116 return "";
117 }
118
120 template <typename T>
121 inline T get(const std::string& key) const {
123 return T();
124 }
125
128 template <typename T>
129 inline T get(const std::string& key, const T& default_) const {
131 return T();
132 }
133
135 virtual void get(const std::string& key, std::vector<int>& v) const = 0;
136
138 virtual void get(const std::string& key, std::vector<double>& v) const = 0;
139
141 virtual void get(const std::string& key, std::vector<b2000::csda<double> >& v) const = 0;
142
144 virtual void get(const std::string& key, std::vector<std::complex<double> >& v) const = 0;
145
148 virtual void warn_on_non_used_key() const = 0;
149
150 virtual std::string has_string() const { return "?"; }
151
154 static Dictionary& get_empty();
155
157 static type_t type;
158};
159
160std::ostream& operator<<(std::ostream& out, const Dictionary& dictionary);
161
162template <>
163inline std::string Dictionary::get<std::string>(const std::string& key) const {
164 return get_string(key);
165}
166
167template <>
168inline bool Dictionary::get<bool>(const std::string& key) const {
169 return get_bool(key);
170}
171
172template <>
173inline int Dictionary::get<int>(const std::string& key) const {
174 return get_int(key);
175}
176
177template <>
178inline double Dictionary::get<double>(const std::string& key) const {
179 return get_double(key);
180}
181
182template <>
183inline b2000::csda<double> Dictionary::get<b2000::csda<double> >(const std::string& key) const {
184 return get_csda_double(key);
185}
186
187template <>
188inline std::complex<double> Dictionary::get<std::complex<double> >(const std::string& key) const {
189 return get_complex_double(key);
190}
191
192template <>
193inline std::string Dictionary::get<std::string>(
194 const std::string& key, const std::string& default_) const {
195 return get_string(key, default_);
196}
197
198template <>
199inline bool Dictionary::get<bool>(const std::string& key, const bool& default_) const {
200 return get_bool(key, default_);
201}
202
203template <>
204inline int Dictionary::get<int>(const std::string& key, const int& default_) const {
205 return get_int(key, default_);
206}
207
208template <>
209inline double Dictionary::get<double>(const std::string& key, const double& default_) const {
210 return get_double(key, default_);
211}
212
213template <>
214inline b2000::csda<double> Dictionary::get<b2000::csda<double> >(
215 const std::string& key, const b2000::csda<double>& default_) const {
216 return get_csda_double(key, default_);
217}
218
219template <>
220inline std::complex<double> Dictionary::get<std::complex<double> >(
221 const std::string& key, const std::complex<double>& default_) const {
222 return get_complex_double(key, default_);
223}
224
225} // namespace b2000
226
227#endif
#define THROW
Definition b2exception.H:198
Definition b2dictionary.H:48
virtual void get(const std::string &key, std::vector< double > &v) const =0
virtual b2000::csda< double > get_csda_double(const std::string &key, b2000::csda< double > default_) const
Definition b2dictionary.H:90
virtual bool get_bool(const std::string &key) const =0
virtual std::string get_string(const std::string &key) const =0
virtual std::complex< double > get_complex_double(const std::string &key) const =0
virtual void get(const std::string &key, std::vector< b2000::csda< double > > &v) const =0
virtual void warn_on_non_used_key() const =0
virtual double get_double(const std::string &key) const =0
virtual void get(const std::string &key, std::vector< std::complex< double > > &v) const =0
virtual bool get_bool(const std::string &key, bool default_) const
Definition b2dictionary.H:60
virtual int get_int(const std::string &key) const =0
virtual std::string get_string(const std::string &key, const std::string &default_) const
Definition b2dictionary.H:112
virtual std::complex< double > get_complex_double(const std::string &key, std::complex< double > default_) const
Definition b2dictionary.H:101
virtual void get(const std::string &key, std::vector< int > &v) const =0
T get(const std::string &key, const T &default_) const
Definition b2dictionary.H:129
virtual double get_double(const std::string &key, double default_) const
Definition b2dictionary.H:80
virtual int get_int(const std::string &key, int default_) const
Definition b2dictionary.H:70
virtual b2000::csda< double > get_csda_double(const std::string &key) const =0
static Dictionary & get_empty()
Definition b2dictionary.C:78
T get(const std::string &key) const
Definition b2dictionary.H:121
virtual bool has_key(const std::string &key) const =0
Definition b2object.H:340
Definition b2object.H:456
Contains the base classes for implementing Finite Elements.
Definition b2boundary_condition.H:32
GenericException< UnimplementedError_name > UnimplementedError
Definition b2exception.H:314