FEI
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
base
fei_ParameterSet.hpp
1
/*--------------------------------------------------------------------*/
2
/* Copyright 2005 Sandia Corporation. */
3
/* Under the terms of Contract DE-AC04-94AL85000, there is a */
4
/* non-exclusive license for use of this work by or on behalf */
5
/* of the U.S. Government. Export of this program may require */
6
/* a license from the United States Government. */
7
/*--------------------------------------------------------------------*/
8
9
#ifndef _fei_ParameterSet_hpp_
10
#define _fei_ParameterSet_hpp_
11
12
#include "fei_macros.hpp"
13
#include "fei_Param.hpp"
14
15
#include <vector>
16
17
namespace
fei
{
18
46
class
ParameterSet
{
47
public
:
49
ParameterSet
();
50
52
virtual
~ParameterSet
();
53
66
void
add
(
const
Param
& param,
67
bool
maintain_unique_keys=
true
);
68
76
const
Param
*
get
(
const
char
* name)
const
;
77
79
int
size
()
const
;
80
82
class
const_iterator
{
83
public
:
85
const_iterator
() : paramarray_(NULL),
86
dummyParam_((const char*)NULL, (const char*)NULL),
87
offset_(0) {}
88
89
const_iterator
(
int
offset, std::vector<const Param*>* params)
90
: paramarray_(params), dummyParam_((const char*)NULL, (const char*)NULL),
91
offset_(offset)
92
{
93
if
(params != NULL) {
94
if
(params->empty()) {paramarray_ = NULL; offset_ = 0;}
95
}
96
}
97
99
~const_iterator
(){}
100
102
const
Param
&
operator*
()
const
103
{
104
if
(paramarray_ == NULL)
return
(dummyParam_);
105
if
(offset_ >= paramarray_->size())
return
(dummyParam_);
106
return
( *((*paramarray_)[offset_]) );
107
}
108
110
const_iterator
&
operator++
()
111
{
112
if
(paramarray_ != NULL) {
113
if
(offset_ < paramarray_->
size
()) {
114
++offset_;
115
}
116
if
(offset_ == paramarray_->size()) {
117
offset_ = 0;
118
paramarray_ = NULL;
119
}
120
}
121
return
( *
this
);
122
}
123
125
const_iterator
&
operator=
(
const
const_iterator
& src)
126
{
127
paramarray_ = src.paramarray_;
128
offset_ = src.offset_;
129
return
( *
this
);
130
}
131
133
bool
operator==
(
const
const_iterator
& rhs)
134
{
135
return
( paramarray_ == rhs.paramarray_ && offset_ == rhs.offset_ );
136
}
137
139
bool
operator!=
(
const
const_iterator
& rhs)
140
{
141
return
( !(*
this
== rhs) );
142
}
143
144
private
:
145
std::vector<const fei::Param*>* paramarray_;
146
const
fei::Param
dummyParam_;
147
unsigned
offset_;
148
};
149
151
const_iterator
begin
()
const
;
152
154
const_iterator
end
()
const
;
155
159
int
getIntParamValue
(
const
char
* name,
160
int
& paramValue)
const
;
161
166
int
getDoubleParamValue
(
const
char
* name,
167
double
& paramValue)
const
;
168
172
int
getStringParamValue
(
const
char
* name,
173
std::string& paramValue)
const
;
174
178
int
getBoolParamValue
(
const
char
* name,
179
bool
& paramValue)
const
;
180
184
int
getVoidParamValue
(
const
char
* name,
185
const
void
*& paramValue)
const
;
186
187
private
:
188
int
findOffset(
const
fei::Param
* param)
const
;
189
int
findOffset(
const
char
* name)
const
;
190
std::vector<const Param*>* params_;
191
};
//class ParameterSet
192
193
}
//namespace fei
194
195
inline
196
int
fei::ParameterSet::findOffset(
const
char
* name)
const
197
{
198
if
(params_->empty() || name == NULL)
return
( -1 );
199
200
std::vector<const Param*>::const_iterator
201
p_iter = params_->begin(),
202
p_end = params_->end();
203
204
int
i = 0;
205
for
(; p_iter != p_end; ++p_iter, ++i) {
206
const
Param* prm = *p_iter;
207
if
(prm->getName() == name) {
208
return
(i);
209
}
210
}
211
return
(-1);
212
}
213
214
inline
215
int
fei::ParameterSet::findOffset(
const
fei::Param* param)
const
216
{
217
if
(param == NULL)
return
( -1 );
218
219
return
( findOffset( param->
getName
().c_str() ) );
220
}
221
222
inline
223
fei::ParameterSet::const_iterator
fei::ParameterSet::begin
()
const
224
{
225
return
(
const_iterator
(0, params_) );
226
}
227
228
inline
229
fei::ParameterSet::const_iterator
fei::ParameterSet::end
()
const
230
{
231
return
(
const_iterator
(0, NULL) );
232
}
233
234
inline
235
void
fei::ParameterSet::add
(
const
fei::Param
& param,
bool
maintain_unique_keys)
236
{
237
int
index = findOffset(¶m);
238
const
fei::Param
* newparam =
new
fei::Param
(param);
239
if
(index < 0) {
240
params_->push_back(newparam);
241
}
242
else
{
243
if
(maintain_unique_keys) {
244
delete
(*params_)[index];
245
(*params_)[index] = newparam;
246
}
247
else
{
248
params_->push_back(newparam);
249
}
250
}
251
}
252
253
inline
254
int
fei::ParameterSet::size
()
const
255
{
256
return
( params_->size() );
257
}
258
259
inline
260
const
fei::Param
*
fei::ParameterSet::get
(
const
char
* name)
const
261
{
262
if
(params_ == NULL)
return
(NULL);
263
264
int
index = findOffset(name);
265
if
(index < 0)
return
(NULL);
266
return
( (*params_)[index] );
267
}
268
269
#endif
fei::Param
Definition
fei_Param.hpp:23
fei::Param::getName
const std::string & getName() const
Definition
fei_Param.hpp:92
fei::ParameterSet::const_iterator
Definition
fei_ParameterSet.hpp:82
fei::ParameterSet::const_iterator::const_iterator
const_iterator()
Definition
fei_ParameterSet.hpp:85
fei::ParameterSet::const_iterator::operator==
bool operator==(const const_iterator &rhs)
Definition
fei_ParameterSet.hpp:133
fei::ParameterSet::const_iterator::operator*
const Param & operator*() const
Definition
fei_ParameterSet.hpp:102
fei::ParameterSet::const_iterator::operator++
const_iterator & operator++()
Definition
fei_ParameterSet.hpp:110
fei::ParameterSet::const_iterator::const_iterator
const_iterator(int offset, std::vector< const Param * > *params)
Definition
fei_ParameterSet.hpp:89
fei::ParameterSet::const_iterator::operator!=
bool operator!=(const const_iterator &rhs)
Definition
fei_ParameterSet.hpp:139
fei::ParameterSet::const_iterator::operator=
const_iterator & operator=(const const_iterator &src)
Definition
fei_ParameterSet.hpp:125
fei::ParameterSet::const_iterator::~const_iterator
~const_iterator()
Definition
fei_ParameterSet.hpp:99
fei::ParameterSet::size
int size() const
Definition
fei_ParameterSet.hpp:254
fei::ParameterSet::ParameterSet
ParameterSet()
Definition
fei_ParameterSet.cpp:12
fei::ParameterSet::~ParameterSet
virtual ~ParameterSet()
Definition
fei_ParameterSet.cpp:18
fei::ParameterSet::getIntParamValue
int getIntParamValue(const char *name, int ¶mValue) const
Definition
fei_ParameterSet.cpp:28
fei::ParameterSet::getVoidParamValue
int getVoidParamValue(const char *name, const void *¶mValue) const
Definition
fei_ParameterSet.cpp:81
fei::ParameterSet::add
void add(const Param ¶m, bool maintain_unique_keys=true)
Definition
fei_ParameterSet.hpp:235
fei::ParameterSet::get
const Param * get(const char *name) const
Definition
fei_ParameterSet.hpp:260
fei::ParameterSet::end
const_iterator end() const
Definition
fei_ParameterSet.hpp:229
fei::ParameterSet::begin
const_iterator begin() const
Definition
fei_ParameterSet.hpp:223
fei::ParameterSet::getStringParamValue
int getStringParamValue(const char *name, std::string ¶mValue) const
Definition
fei_ParameterSet.cpp:57
fei::ParameterSet::getDoubleParamValue
int getDoubleParamValue(const char *name, double ¶mValue) const
Definition
fei_ParameterSet.cpp:40
fei::ParameterSet::getBoolParamValue
int getBoolParamValue(const char *name, bool ¶mValue) const
Definition
fei_ParameterSet.cpp:69
fei
Definition
fei_ArrayUtils.hpp:16
Generated by
1.17.0