Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
UserDataList.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* UserDataList.cc (C) 2000-2012 */
9/* */
10/* Gère une liste de données utilisateurs. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/UserDataList.h"
17#include "arcane/utils/String.h"
18#include "arcane/utils/TraceInfo.h"
19#include "arcane/utils/ArgumentException.h"
20#include "arcane/utils/IUserData.h"
21
22#include <map>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27ARCANE_BEGIN_NAMESPACE
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
33{
34 public:
35 typedef std::map<String,IUserData*> MapType;
36 MapType m_list;
37};
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42UserDataList::
43UserDataList()
44: m_p(new Impl())
45{
46}
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
53{
54 clear();
55 delete m_p;
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
62clear()
63{
64 Impl::MapType::const_iterator begin = m_p->m_list.begin();
65 Impl::MapType::const_iterator end = m_p->m_list.end();
66 for( ; begin!=end; ++begin )
67 begin->second->notifyDetach();
68 m_p->m_list.clear();
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
75setData(const String& name,IUserData* ud)
76{
77 Impl::MapType::const_iterator i = m_p->m_list.find(name);
78 if (i!=m_p->m_list.end())
79 throw ArgumentException(A_FUNCINFO,String::format("key '{0}' already exists",name));
80 m_p->m_list.insert(std::make_pair(name,ud));
81 ud->notifyAttach();
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
88data(const String& name,bool allow_null) const
89{
90 Impl::MapType::const_iterator i = m_p->m_list.find(name);
91 if (i==m_p->m_list.end()){
92 if (allow_null)
93 return 0;
94 throw ArgumentException(A_FUNCINFO,String::format("key '{0}' not found",name));
95 }
96 return i->second;
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
103removeData(const String& name,bool allow_null)
104{
105 Impl::MapType::iterator i = m_p->m_list.find(name);
106 if (i==m_p->m_list.end()){
107 if (allow_null)
108 return;
109 throw ArgumentException(A_FUNCINFO,String::format("key '{0}' not found",name));
110 }
111 i->second->notifyDetach();
112 m_p->m_list.erase(i);
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118ARCANE_END_NAMESPACE
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
Interface pour une donnée utilisateur attachée à un autre objet.
Definition IUserData.h:31
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
virtual void clear()
Supprime toutes les données utilisateurs.
virtual void removeData(const String &name, bool allow_null=false)
Supprime la donnée associèe au nom name.
virtual IUserData * data(const String &name, bool allow_null=false) const
Donnée associée à name.
virtual void setData(const String &name, IUserData *ud)
Positionne le user-data associé au nom name.
~UserDataList()
Libère les ressources.
Exception lorsqu'un argument est invalide.
Chaîne de caractères unicode.