14 string sys_type, sys_def;
15 string data_def, data_id, data_type, data_info;
23parameter::parameter(
string line) {
24 stringstream sst(line);
38 string sys_type, sys_def, sys_file;
41 object(
string type,
string def,
string file);
42 object(
string type,
string def);
44 int ic(
string type,
string def);
47 double fp(
string symb);
48 vector<double> vctp(
string symb);
49 string sp(
string symb);
50 vector<string> svct(
string symb);
51 void fval_p(
string symb,
double val);
52 void sval_p(
string symb,
string val);
53 void vct_fp(
string symb, vector<double> vct);
54 void vct_sp(
string symb, vector<string> vct);
57string get_parameter_value(vector<parameter> &par,
string sys_type,
string sys_def,
62 for (
size_t np = 0; np < par.size(); np++) {
63 if (par[np].sys_type == sys_type && par[np].sys_def == sys_def &&
64 par[np].data_id == data_id) {
65 string val = par[np].str[par[np].pos];
67 if (par[np].pos < par[np].str.size() - 1) {
68 par[np].pos = par[np].pos + 1;
80void print_parameter_value(vector<parameter> &p,
string sys_type,
string sys_def,
83 for (
size_t np = 0; np < p.size(); np++) {
84 if (p[np].sys_type == sys_type && p[np].sys_def == sys_def &&
85 p[np].data_id == data_id) {
87 cout << p[np].sys_type <<
" " << p[np].sys_def <<
" " << p[np].data_def <<
" "
88 << p[np].data_id <<
" " << p[np].str[p[np].pos] << endl;
92 cout <<
"none found" << endl;
96void export_parameter(vector<parameter> &par,
string data_def,
string sys_type,
97 string sys_def,
string data_id,
string val) {
100 for (
size_t np = 0; np < par.size(); np++) {
101 if (par[np].sys_type == sys_type && par[np].sys_def == sys_def &&
102 par[np].data_id == data_id) {
103 par[np].str.push_back(val);
104 par[np].pos = par[np].str.size() - 1;
108 if (found ==
false) {
111 p.data_def = data_def;
112 p.sys_type = sys_type;
115 p.str.push_back(val);
123void get_parameters(vector<parameter> &par,
string sys_type,
string sys_def,
127 p_file.open(input_file);
128 if (!p_file.good()) {
129 cout <<
"input file not found " << endl;
135 string line_txt, type, def, txt, str;
137 bool par_set_found =
false, sys_found =
false;
140 getline(p_file, line_txt);
141 stringstream sst(line_txt);
144 if (type == sys_type && def == sys_def) {
148 while (!par_set_found) {
149 getline(p_file, line_txt);
150 stringstream sst(line_txt);
153 if (txt ==
"input" || txt ==
"prop" || txt ==
"output") {
154 p.sys_type = sys_type;
159 bool str_complete =
false;
162 vector<char> cstr(str.begin(), str.end());
163 if (!str_complete && cstr[0] !=
'#') {
164 p.str.push_back(str);
166 if (cstr[0] ==
'#') {
169 if (str_complete && cstr[0] !=
'#') {
170 p.data_info = str +
" ";
180 if (txt !=
"input" && txt !=
"output" && txt !=
"prop") {
181 par_set_found =
true;
194void export_output_parameters(
object &obj,
string file) {
195 ofstream output_parameters(file);
197 for (
size_t np = 0; np < obj.p.size(); np++) {
198 if (obj.p[np].data_def ==
"output") {
199 output_parameters << obj.p[np].sys_type <<
" " << obj.p[np].sys_def <<
" "
200 << obj.p[np].data_id;
202 for (
size_t ns = 0; ns < obj.p[np].str.size(); ns++) {
203 output_parameters <<
" " << obj.p[np].str[ns];
205 output_parameters << endl;
209 output_parameters.close();
212void print_parameters(vector<parameter> &p) {
213 cout <<
"no. parameters: " << p.size() << endl;
214 for (
size_t np = 0; np < p.size(); np++) {
215 cout << p[np].sys_type <<
" " << p[np].sys_def <<
" " << p[np].data_def <<
" "
218 for (
size_t ns = 0; ns < p[np].str.size(); ns++) {
219 cout <<
" " << p[np].str[ns];
225double fp(vector<parameter> &par,
string sys_type,
string sys_def,
string data_id) {
226 if (get_parameter_value(par, sys_type, sys_def, data_id) ==
"null") {
229 return atof(get_parameter_value(par, sys_type, sys_def, data_id).c_str());
232string sp(vector<parameter> &par,
string sys_type,
string sys_def,
string data_id) {
233 return get_parameter_value(par, sys_type, sys_def, data_id);
236vector<double> fp_vct(vector<parameter> &par,
string sys_type,
string sys_def,
240 for (
size_t np = 0; np < par.size(); np++) {
241 if (par[np].sys_type == sys_type && par[np].sys_def == sys_def &&
242 par[np].data_id == data_id) {
243 for (
size_t n = 0; n < par[np].str.size(); n++) {
244 vct.push_back(atof(par[np].str[n].c_str()));
254vector<string> sp_vct(vector<parameter> &par,
string sys_type,
string sys_def,
258 for (
size_t np = 0; np < par.size(); np++) {
259 if (par[np].sys_type == sys_type && par[np].sys_def == sys_def &&
260 par[np].data_id == data_id) {
261 for (
size_t n = 0; n < par[np].str.size(); n++) {
262 vct.push_back(par[np].str[n]);
268 if (found ==
false) {
274void fval_p(vector<parameter> &par,
string data_def,
string sys_type,
string sys_def,
275 string data_id,
double val) {
276 export_parameter(par, data_def, sys_type, sys_def, data_id, to_string(val));
279void sval_p(vector<parameter> &par,
string data_def,
string sys_type,
string sys_def,
280 string data_id,
string val) {
281 export_parameter(par, data_def, sys_type, sys_def, data_id, val);
284void fvct_p(vector<parameter> &par,
string data_def,
string sys_type,
string sys_def,
285 string data_id, vector<double> val) {
288 for (
size_t np = 0; np < par.size(); np++) {
289 if (par[np].sys_type == sys_type && par[np].sys_def == sys_def &&
290 par[np].data_id == data_id) {
292 for (
size_t n = 0; n < val.size(); n++) {
293 par[np].str.push_back(to_string(val[n]));
299 if (found ==
false) {
302 p.data_def = data_def;
303 p.sys_type = sys_type;
307 for (
size_t n = 0; n < val.size(); n++) {
308 p.str.push_back(to_string(val[n]));
316void svct_p(vector<parameter> &par,
string data_def,
string sys_type,
string sys_def,
317 string data_id, vector<string> val) {
320 for (
size_t np = 0; np < par.size(); np++) {
321 if (par[np].sys_type == sys_type && par[np].sys_def == sys_def &&
322 par[np].data_id == data_id) {
324 for (
size_t n = 0; n < val.size(); n++) {
325 par[np].str.push_back(val[n]);
331 if (found ==
false) {
334 p.data_def = data_def;
335 p.sys_type = sys_type;
339 for (
size_t n = 0; n < val.size(); n++) {
340 p.str.push_back(val[n]);
348object::object(
string type,
string def,
string file) {
352 get_parameters(p, type, def, file);
355object::object(
string type,
string def) {
358 if (type ==
"equipment") {
359 get_parameters(p, type, def, DIR +
"Database/Equipment_database");
361 if (type ==
"consumable") {
362 get_parameters(p, type, def, DIR +
"Database/Consumables_database");
364 if (type ==
"solid_residue") {
365 get_parameters(p, type, def, DIR +
"Database/Consumables_database");
369int object::ic(
string type,
string def) {
370 for (
size_t n = 0; n < c.size(); n++) {
371 if (c[n].sys_type == type && c[n].sys_def == def) {
378int object::ip(
string symb) {
380 for (
size_t np = 0; np < p.size(); np++) {
381 if (p[np].data_id == symb) {
389bool object::bp(
string symb) {
391 for (
size_t np = 0; np < p.size(); np++) {
392 if (p[np].data_id == symb) {
400double object::fp(
string symb) {
401 string val = get_parameter_value(p, sys_type, sys_def, symb);
405 return atof(val.c_str());
407string object::sp(
string symb) {
return get_parameter_value(p, sys_type, sys_def, symb); }
409vector<double> object::vctp(
string symb) {
return fp_vct(p, sys_type, sys_def, symb); }
411vector<string> object::svct(
string symb) {
return sp_vct(p, sys_type, sys_def, symb); }
413void object::fval_p(
string symb,
double val) {
414 if (divide_string(symb,
'-').size() == 1) {
415 export_parameter(p,
"prop", sys_type, sys_def, symb, to_string(val));
417 if (divide_string(symb,
'-').size() == 2) {
418 export_parameter(p, divide_string(symb,
'-')[0], sys_type, sys_def,
419 divide_string(symb,
'-')[1], to_string(val));
423void object::sval_p(
string symb,
string val) {
424 if (divide_string(symb,
'-').size() == 1) {
425 export_parameter(p,
"prop", sys_type, sys_def, symb, val);
427 if (divide_string(symb,
'-').size() == 2) {
428 export_parameter(p, divide_string(symb,
'-')[0], sys_type, sys_def,
429 divide_string(symb,
'-')[1], val);
433void object::vct_fp(
string symb, vector<double> vct) {
434 if (divide_string(symb,
'-').size() == 1) {
435 fvct_p(p,
"prop", sys_type, sys_def, symb, vct);
437 if (divide_string(symb,
'-').size() == 2) {
438 fvct_p(p, divide_string(symb,
'-')[0], sys_type, sys_def, divide_string(symb,
'-')[1],
443void object::vct_sp(
string symb, vector<string> vct) {
444 if (divide_string(symb,
'-').size() == 1) {
445 svct_p(p,
"prop", sys_type, sys_def, symb, vct);
447 if (divide_string(symb,
'-').size() == 2) {
448 svct_p(p, divide_string(symb,
'-')[0], sys_type, sys_def, divide_string(symb,
'-')[1],
453void transfer_parameter(
string symb,
object from,
object &to) {
454 to.p.push_back(from.p[from.ip(symb)]);
Definition Parameters.cpp:36
Definition Parameters.cpp:12