16#include <Entree_complete.h>
17#include <Objet_a_lire.h>
23Objet_a_lire::Objet_a_lire() : int_a_lire(nullptr), tid_a_lire(nullptr), double_a_lire(nullptr), obj_a_lire(nullptr), objet_lu(nullptr),
24 arrofint_a_lire(nullptr), arrofdouble_a_lire(nullptr), flag_a_lire(nullptr) { }
150 const auto& list = n.get_stl_list();
151 auto itr = list.begin();
155 for ( ; itr != list.end(); ++itr) names.add(*itr);
160 if (mot ==
name)
return 1;
161 for (
const auto& itr : names)
173 int size = names.size();
174 for (
int i = size - 1; i >= 0; i--)
197 dictionnaire_params.add(
ptrParam());
198 ptrParam& ptr = dictionnaire_params[dictionnaire_params.size() - 1];
226 Cerr <<
"get_value not coded for this case" << finl;
241T convert(std::string val);
243template <>
int convert<int>(std::string val)
245 return std::stoi(val);
247template <>
double convert<double>(std::string val)
249 return std::stod(val);
251template <> std::string convert<std::string>(std::string val)
256void expect_word(
Entree& is, std::string word)
262 Cerr <<
Nom(
"From expect_word in Objet_a_lire.cpp: Expected to read: ") + word << finl;
263 Cerr <<
Nom(
"Found: ") + read << finl;
270std::vector<T> read_vec_impl(
273 std::function<T(
Entree&, std::string )> read_value,
274 int expected_size = -1)
291 vec.push_back(read_value(is, token));
293 catch (std::exception& e)
295 Cerr <<
"In keyword " << motcle
296 <<
", invalid value led to exception: " << e.what() << finl;
306 else if (token !=
"]")
308 Cerr <<
"In keyword " << motcle
309 <<
", expected ',' or ']', found: " << token << finl;
320 size = std::stoi(first);
324 Cerr <<
"In keyword " << motcle
325 <<
", expected '[' or an integer size, found: " << first << finl;
329 if (expected_size >= 0 && size != expected_size)
331 Cerr <<
"In keyword " << motcle <<
", declared size " << size
332 <<
" does not match expected size " << expected_size << finl;
336 vec.reserve(
static_cast<size_t>(size));
337 for (
int i = 0; i < size; i++)
343 vec.push_back(read_value(is, token));
345 catch (std::exception& e)
347 Cerr <<
"In keyword " << motcle
348 <<
", invalid value led to exception: " << e.what() << finl;
356 if (expected_size >= 0 && (
int)vec.size() != expected_size)
358 Cerr <<
"In keyword " << motcle <<
", read " << vec.size()
359 <<
" elements but expected " << expected_size << finl;
367std::vector<T> read_vec_any(
Motcle const& motcle,
Entree& is,
int expected_size = -1)
369 return read_vec_impl<T>(motcle, is,
370 [](
Entree& , std::string first_token) -> T
372 return convert<T>(first_token);
376std::vector<DerObjU> read_vec_derObjU(
Motcle const& motcle,
Entree& is,
int expected_size = -1)
378 return read_vec_impl<DerObjU>(motcle, is,
379 [](
Entree& is_in, std::string type_str) -> DerObjU
382 obj.
typer(type_str.c_str());
389std::map<std::string, T> read_map_impl(
392 std::function<T(
Entree&, std::string )> read_value)
394 std::map<std::string, T> map;
396 expect_word(is,
"{");
402 if (key ==
"}") {
return map;}
404 bool with_colon_and_comma =
false;
406 std::string first_token;
409 bool has_colon = (first_token ==
":");
412 with_colon_and_comma =
true;
413 std::string actual_first;
415 first_token = actual_first;
418 T val = read_value(is, first_token);
422 if (map.find(key)!=map.end())
424 Cerr <<
"Duplicate key '" << key <<
"' found for param: " << motcle << finl;
429 if (with_colon_and_comma)
442 if (sep ==
"}")
break;
443 else if (sep ==
",") is >> key;
446 Cerr <<
"In keyword " << motcle
447 <<
", expected to read either a comma (,) or closing brace (}). Found "
452 if (key ==
"}")
break;
455 expect_word(is,
":");
458 std::string next_first;
462 val = read_value(is, next_first);
464 catch (std::exception& e)
466 Cerr <<
"In keyword " << motcle
467 <<
", invalid value led to exception: " << e.what() << finl;
476 if (key ==
"}")
break;
478 std::string next_first;
483 val = read_value(is, next_first);
485 catch (std::exception& e)
487 Cerr <<
"In keyword " << motcle
488 <<
", invalid value led to exception: " << e.what() << finl;
498std::map<std::string, T> read_map_any(
Motcle const& motcle,
Entree& is)
500 return read_map_impl<T>(motcle, is,
501 [](
Entree& , std::string first_token) -> T
503 return convert<T>(first_token);
507std::map<std::string, DerObjU> read_map_derObjU(
Motcle const& motcle,
Entree& is)
509 return read_map_impl<DerObjU>(motcle, is,
510 [](
Entree& is_in, std::string type_str) -> DerObjU
513 obj.
typer(type_str.c_str());
541 Cerr <<
"Error while reading parameter " <<
name <<
"\n Found: " << motlu <<
"\n Expected one on these keywords: " <<
dictionnaire_noms << finl;
546 ptrParam& ptr = dictionnaire_params[rang];
557 is >> (*double_a_lire);
560 is >> (*string_a_lire);
566 (*flag_a_lire) =
true;
569 ret = (*objet_lu).lire_motcle_non_standard(motcle, is);
572 Cerr <<
"Error while reading keyword: '" << motcle <<
"'. Not recognized!" << finl;
581 type_complet += the_type;
583 is2 >> (*obj_a_lire);
592 for (
int i = 0; i < size; i++)
602 for (
int i = 0; i < size; i++)
649 auto read = read_map_derObjU(motcle, is);
654 Cerr <<
"Invalid parameter type" << finl;
This class behaves like EChaine until the end of the string is reached.
Class defining operators and methods for all reading operation in an input flow (file,...
A character string (Nom) in uppercase.
class Nom: a character string for naming TRUST objects.
Objet_U * typer(const char *nom_type)
Tries to create an instance of type "type".
Base class for TRUST objects (Objet_U).
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
void set_map_obj_initializer(map_obj_initializer_t)
void set_objet(Objet_U *)
void set_map_int(std::map< std::string, int > *)
void set_tid(trustIdType *)
std::string * string_a_lire
std::function< void(std::map< std::string, DerObjU > &)> map_obj_initializer_t
void set_double(double *)
void read(const Motcle &keyword, Entree &is)
void set_vec_int(std::vector< int > *)
void set_vec_dbl(std::vector< double > *)
void set_vec_obj_initializer(vec_obj_initializer_t)
int comprend_name(Motcle &mot) const
void set_map_str(std::map< std::string, std::string > *)
void set_arrofint(ArrOfInt *)
std::vector< int > * vec_int_a_lire
void set_nature(Objet_a_lire::Nature n)
ArrOfInt * arrofint_a_lire
void set_map_dbl(std::map< std::string, double > *)
std::map< std::string, int > * map_int_a_lire
Motcles dictionnaire_noms
std::vector< double > * vec_double_a_lire
void set_arrofdouble(ArrOfDouble *)
ArrOfDouble * arrofdouble_a_lire
ArrOfInt dictionnaire_valeurs
std::vector< std::string > * vec_str_a_lire
std::function< void(std::vector< DerObjU > &)> vec_obj_initializer_t
ptrParam & add_dict(const char *, int, const char *=0)
Nom get_names_message() const
std::map< std::string, std::string > * map_str_a_lire
void set_non_std(Objet_U *)
void set_vec_str(std::vector< std::string > *)
std::map< std::string, double > * map_double_a_lire
bool is_type_simple() const
vec_obj_initializer_t vec_obj_initializer
map_obj_initializer_t map_obj_initializer
void set_name(const LIST(Nom)&n)
const Nom & get_name() const
Param & create_param(const char *)
void set_string(std::string *)
Objet_a_lire::Nature nature
Helper class to factorize the readOn method of Objet_U classes.
int lire_avec_accolades_depuis(Entree &is)
Parse the parameter block { ... } from is.
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Base class for output streams.
_SIZE_ size_array() const
const Objet_U & valeur() const
ptrParam class: contains a name and a reference to an int, double, flag, an Objet_U to read,...
void create(const char *)