16#ifndef TRUST_List_included
17#define TRUST_List_included
24#define LIST(_TYPE_) TRUST_List<_TYPE_>
33template<
typename _CLASSE_>
36 using value_type = _CLASSE_;
37 using STLList = std::list<_CLASSE_>;
38 using Iterator =
typename std::list<_CLASSE_>::iterator;
39 using CIterator =
typename std::list<_CLASSE_>::const_iterator;
47 Nom accouverte =
"{", accfermee =
"}", virgule =
",", blanc =
" ";
52 os << accouverte << finl;
53 for (
auto &itr : list_)
56 if (&itr != &list_.back()) os << blanc << virgule << finl;
58 os << finl << accfermee << finl;
65 Nom accouverte =
"{", accfermee =
"}", virgule =
",";
68 if (nom_ == (
const char*)
"vide")
return is;
70 if (nom_ != accouverte) Cerr <<
"Error while reading a list. One expected an opened bracket { to start." << finl,
Process::exit();
77 if (nom_ == accfermee)
return is;
78 if (nom_ != virgule) Cerr << nom_ <<
" one expected a ',' or a '}'" << finl,
Process::exit();
87 Iterator
begin() {
return list_.begin(); }
88 Iterator
end() {
return list_.end(); }
89 const CIterator
begin()
const {
return list_.begin(); }
90 const CIterator
end()
const {
return list_.end(); }
100 int size()
const {
return (
int)list_.size(); }
102 const _CLASSE_&
front()
const {
return list_.front(); }
103 _CLASSE_&
front() {
return list_.front(); }
104 const _CLASSE_&
dernier()
const {
return list_.back(); }
107 void suppr(
const _CLASSE_& t) { list_.remove(t); }
117 _CLASSE_&
add(
const _CLASSE_ &t)
120 return static_cast<_CLASSE_&
>(list_.back());
126 auto it = std::find(list_.begin(), list_.end(), t);
129 if (it == list_.end())
132 it = std::prev(list_.end());
144 for (
auto& itr : list_)
146 if (ind == i)
return itr;
157 for (
auto& itr : list_)
159 if (ind == i)
return itr;
167 const _CLASSE_&
operator[](
const Nom& nom)
const { assert (
size() > 0);
return operator_<_CLASSE_>(nom); }
186 int contient(
const char*
const ch)
const {
return contient_<_CLASSE_>(ch); }
188 int rang(
const char*
const ch)
const {
return rang_<_CLASSE_>(ch); }
189 int rang(
const _CLASSE_ &obj)
const
192 for (
auto &itr : list_)
194 if (itr == obj)
return i;
202 template<
typename _TYPE_> std::enable_if_t<_TYPE_::HAS_POINTER, _CLASSE_&>
203 operator_(
const Nom& nom)
205 for (
auto& itr : list_)
206 if (itr->le_nom() == nom)
return itr;
207 Cerr <<
"TRUST_List : We have not found an object with name " << nom << finl,
throw;
208 return list_.front();
211 template<
typename _TYPE_> std::enable_if_t<_TYPE_::HAS_POINTER, const _CLASSE_&>
212 operator_(
const Nom& nom)
const
214 for (
auto& itr : list_)
215 if (itr->le_nom() == nom)
return itr;
216 Cerr <<
"TRUST_List : We have not found an object with name " << nom << finl,
throw;
217 return list_.front();
220 template<
typename _TYPE_> std::enable_if_t<_TYPE_::HAS_POINTER, int>
221 rang_(
const char*
const ch)
const
225 for (
auto& itr : list_)
227 if (itr->le_nom() == nom)
return ind;
233 template<
typename _TYPE_> std::enable_if_t<_TYPE_::HAS_POINTER, int>
234 contient_(
const char*
const ch)
const
237 for (
auto& itr : list_)
238 if (itr->le_nom() == nom)
return 1;
242 template<
typename _TYPE_> std::enable_if_t<_TYPE_::HAS_POINTER, int>
243 contient_(
const Objet_U& obj)
const
245 for (
auto &itr : list_)
246 if (itr->le_nom() == obj)
return 1;
250 template<
typename _TYPE_> std::enable_if_t<!_TYPE_::HAS_POINTER, _CLASSE_&>
251 operator_(
const Nom& nom)
253 for (
auto& itr : list_)
254 if (itr.le_nom() == nom)
return itr;
255 Cerr <<
"TRUST_List : We have not found an object with name " << nom << finl,
throw;
256 return list_.front();
259 template<
typename _TYPE_> std::enable_if_t<!_TYPE_::HAS_POINTER, const _CLASSE_&>
260 operator_(
const Nom& nom)
const
262 for (
auto& itr : list_)
263 if (itr.le_nom() == nom)
return itr;
264 Cerr <<
"TRUST_List : We have not found an object with name " << nom << finl,
throw;
265 return list_.front();
268 template<
typename _TYPE_> std::enable_if_t<!_TYPE_::HAS_POINTER, int>
269 rang_(
const char*
const ch)
const
273 for (
auto& itr : list_)
275 if (itr.le_nom() == nom)
return ind;
281 template<
typename _TYPE_> std::enable_if_t<!_TYPE_::HAS_POINTER, int>
282 contient_(
const char*
const ch)
const
285 for (
auto& itr : list_)
286 if (itr.le_nom() == nom)
return 1;
290 template<
typename _TYPE_> std::enable_if_t<!_TYPE_::HAS_POINTER, int>
291 contient_(
const Objet_U& obj)
const
293 for (
auto &itr : list_)
294 if (itr.le_nom() == obj)
return 1;
Une chaine de caractere (Nom) en majuscules.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Sortie & printOn(Sortie &os) const override
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
_CLASSE_ & operator()(const Nom &n)
TRUST_List(const _CLASSE_ &t)
int rang(const char *const ch) const
int contient(const char *const ch) const
const _CLASSE_ & operator[](int i) const
const std::list< _CLASSE_ > & get_stl_list() const
_CLASSE_ & add_if_not(const _CLASSE_ &t)
int rang(const _CLASSE_ &obj) const
TRUST_List & operator=(const _CLASSE_ &t)
const _CLASSE_ & front() const
unsigned taille_memoire() const override
const _CLASSE_ & operator[](const Nom &nom) const
_CLASSE_ & add(const _CLASSE_ &t)
TRUST_List & add(const TRUST_List &a_list)
std::list< _CLASSE_ > & get_stl_list()
int duplique() const override
const _CLASSE_ & operator()(const Nom &n) const
int contient(const Objet_U &obj) const
const _CLASSE_ & dernier() const
const CIterator end() const
void suppr(const _CLASSE_ &t)
Entree & readOn(Entree &is) override
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
const CIterator begin() const
const _CLASSE_ & operator()(int i) const
TRUST_List & operator=(const TRUST_List &t)
_CLASSE_ & operator()(int i)
TRUST_List(const TRUST_List &t)
_CLASSE_ & operator[](const Nom &nom)
_CLASSE_ & operator[](int i)