33 Struct(
int tag, std::map<std::string, std::vector<double> > &fopt,
34 std::map<std::string, std::vector<std::string> > &copt,
41 int append(
int tag, std::map<std::string, std::vector<double> > &fopt,
42 std::map<std::string, std::vector<std::string> > &copt,
45 if(tag >= 0)
_tag = tag;
47 _fopt.insert(fopt.begin(), fopt.end());
48 _copt.insert(copt.begin(), copt.end());
54 int getMember(std::string &key_member,
double &out,
int index)
const
56 auto it =
_fopt.find(key_member);
57 if(it !=
_fopt.end()) {
58 if(index < (
int)it->second.size()) {
59 out = it->second[index];
73 int getMember(std::string &key_member,
const std::string *&out,
76 auto it =
_copt.find(key_member);
77 if(it !=
_copt.end()) {
78 if(index < (
int)it->second.size()) {
79 out = &it->second[index];
95 auto it =
_fopt.find(key_member);
96 if(it !=
_fopt.end()) {
97 out = it->second.size();
101 auto it =
_copt.find(key_member);
102 if(it !=
_copt.end()) {
103 out = it->second.size();
114 const std::vector<double> *&out_vector)
const
116 auto it =
_fopt.find(key_member);
117 if(it !=
_fopt.end()) {
118 out_vector = &it->second;
122 out_vector =
nullptr;
128 const std::vector<std::string> *&out_vector)
const
130 auto it =
_copt.find(key_member);
131 if(it !=
_copt.end()) {
132 out_vector = &it->second;
136 out_vector =
nullptr;
149 bool flag_comma =
false;
150 for(
auto it_attrib =
_fopt.begin(); it_attrib !=
_fopt.end(); ++it_attrib) {
151 if(!flag_comma && it_attrib !=
_fopt.begin()) flag_comma =
true;
152 if(flag_comma) str +=
", ";
153 str += it_attrib->first +
" ";
155 if(it_attrib->second.size() > 1) str +=
"{ ";
156 for(std::size_t i = 0; i < it_attrib->second.size(); i++) {
158 sprintf(tmp,
"%g", it_attrib->second[i]);
161 if(it_attrib->second.size() > 1) str +=
"}";
163 for(
auto it_attrib =
_copt.begin(); it_attrib !=
_copt.end(); ++it_attrib) {
164 if(!flag_comma && it_attrib !=
_copt.begin()) flag_comma =
true;
165 if(flag_comma) str +=
", ";
166 str += it_attrib->first +
" ";
167 if(it_attrib->second.size() > 1) str +=
"Str[{ ";
168 for(std::size_t i = 0; i < it_attrib->second.size(); i++) {
170 str +=
"\"" + it_attrib->second[i] +
"\"";
172 if(it_attrib->second.size() > 1) str +=
"}]";
179 std::map<std::string, std::vector<double> >
_fopt;
180 std::map<std::string, std::vector<std::string> >
_copt;
183 template <
class K,
class T>
class Map {
190 typename std::map<K, T>::iterator it;
191 if((it =
_map.find(key)) !=
_map.end())
199 typename std::map<K, T>::const_iterator it;
200 if((it =
_map.find(key)) !=
_map.end())
208 inline const std::map<K, T> &
get()
const {
return _map; }
209 inline int count(
const std::string key)
const {
return _map.count(key); }
225 std::map<std::string, std::vector<double> > &fopt,
226 std::map<std::string, std::vector<std::string> > &copt,
230 auto it = fopt.find(
"Tag");
231 if(it != fopt.end()) {
232 tag = (int)it->second[0];
237 if(!append) fopt[
"Tag"].push_back((
double)tag);
248 Map_string_Struct::const_iterator it_st;
249 for(it_st = this->
get().begin(); it_st != this->
get().end(); ++it_st)
250 if(it_st->second.getTag() == tag)
break;
251 if(it_st == this->
get().end())
return 2;
252 key_struct = &it_st->first;
256 void sprint(std::vector<std::string> &strs_out,
260 for(
auto it_st = this->
get().begin(); it_st != this->
get().end(); ++it_st) {
262 strs_out.insert(strs_out.end(), str);
277 int defStruct(std::string &key_namespace, std::string &key_name,
278 std::map<std::string, std::vector<double> > &fopt,
279 std::map<std::string, std::vector<std::string> > &copt,
282 Structs *structs_P = &(*this)[key_namespace];
283 if(structs_P->
count(key_name)) {
285 tag_out = (*structs_P)[key_name].getTag();
295 int getTag(std::string &key_namespace, std::string &key_name,
298 const Structs *structs_P = this->
Find(key_namespace);
299 const Struct *struct_P = (structs_P) ? structs_P->
Find(key_name) :
nullptr;
300 if(structs_P && struct_P) { out = (double)struct_P->
getTag(); }
308 int getMember(std::string &key_namespace, std::string &key_name,
309 std::string &key_member,
double &out,
int index = 0)
const
311 const Structs *structs_P = this->
Find(key_namespace);
312 const Struct *struct_P = (structs_P) ? structs_P->
Find(key_name) :
nullptr;
313 if(structs_P && struct_P) {
314 switch(struct_P->
getMember(key_member, out, index)) {
316 case 1: out = 0.;
return 2;
317 case 2: out = 0.;
return 3;
327 int getMember(std::string &key_namespace, std::string &key_name,
328 std::string &key_member,
const std::string *&out,
331 const Structs *structs_P = this->
Find(key_namespace);
332 const Struct *struct_P = (structs_P) ? structs_P->
Find(key_name) :
nullptr;
333 if(structs_P && struct_P) {
334 switch(struct_P->
getMember(key_member, out, index)) {
336 case 1: out =
nullptr;
return 2;
337 case 2: out =
nullptr;
return 3;
348 std::string &key_member,
int &out)
const
350 const Structs *structs_P = this->
Find(key_namespace);
351 const Struct *struct_P = (structs_P) ? structs_P->
Find(key_name) :
nullptr;
352 if(structs_P && struct_P) {
355 case 1: out = 0;
return 2;
366 std::string &key_member,
367 const std::vector<double> *&out_vector)
const
369 const Structs *structs_P = this->
Find(key_namespace);
370 const Struct *struct_P = (structs_P) ? structs_P->
Find(key_name) :
nullptr;
371 if(structs_P && struct_P) {
375 out_vector =
nullptr;
380 out_vector =
nullptr;
387 std::string &key_member,
388 const std::vector<std::string> *&out_vector)
const
390 const Structs *structs_P = this->
Find(key_namespace);
391 const Struct *struct_P = (structs_P) ? structs_P->
Find(key_name) :
nullptr;
392 if(structs_P && struct_P) {
396 out_vector =
nullptr;
401 out_vector =
nullptr;
408 const std::string *&key_struct)
const
410 const Structs *structs_P = this->
Find(key_namespace);
411 if(structs_P !=
nullptr)
419 const Structs *structs_P = this->
Find(key_namespace);
420 const Struct *struct_P = (structs_P) ? structs_P->
Find(key_name) :
nullptr;
424 void sprint(std::vector<std::string> &strs_out)
const
426 std::vector<std::string> strs;
427 for(
auto it_ns = this->
get().begin(); it_ns != this->
get().end(); ++it_ns) {
429 it_ns->second.sprint(strs, it_ns->first);
430 strs_out.insert(strs_out.end(), strs.begin(), strs.end());