Arcane  v4.1.2.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
StringDictionary.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* StringDictionary.cc (C) 2000-2025 */
9/* */
10/* Dictionnaire de chaînes de caractères. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/common/StringDictionary.h"
15
16#include "arccore/base/String.h"
17#include "arccore/common/List.h"
18
19#include <map>
20#include <exception>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
32: public std::exception
33{
34};
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38/*!
39 * \internal
40 \brief Implémentation du dictionnaire de chaîne unicode.
41
42 L'implémentation utilise la classe map de la STL.
43*/
45{
46 public:
47
48 typedef std::map<String, String> StringDictType;
49
50 public:
51
52 Impl() {}
53
54 public:
55
56 StringDictType m_dictionary;
57};
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
64: m_p(new Impl())
65{
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
73: m_p(new Impl(*rhs.m_p))
74{
75}
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
82{
83 delete m_p;
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
90add(const String& key, const String& value)
91{
92 m_p->m_dictionary.insert(std::make_pair(key, value));
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
99remove(const String& key)
100{
101 auto i = m_p->m_dictionary.find(key);
102 String value;
103 if (i != m_p->m_dictionary.end()) {
104 value = i->second;
105 m_p->m_dictionary.erase(i);
106 }
107 return value;
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
114find(const String& key, bool throw_exception) const
115{
116 auto i = m_p->m_dictionary.find(key);
117 String value;
118 if (i != m_p->m_dictionary.end())
119 value = i->second;
120 else if (throw_exception)
121 throw BadIndexException();
122 return value;
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
129fill(StringList& keys, StringList& values) const
130{
131 keys.clear();
132 values.clear();
133 for (const auto& x : m_p->m_dictionary) {
134 keys.add(x.first);
135 values.add(x.second);
136 }
137}
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
142} // namespace Arcane
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
void clear()
Supprime tous les éléments de la collection.
void fill(StringList &param_names, StringList &values) const
Remplit keys et values avec les valeurs correspondantes du dictionnaire.
StringDictionary()
Implémentation.
~StringDictionary()
Libère les ressources.
String remove(const String &key)
Supprime la valeur associée à key.
void add(const String &key, const String &value)
Ajoute le couple (key,value) au dictionnaire.
String find(const String &key, bool throw_exception=false) const
Retourne la valeur associée à key.
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
List< String > StringList
Tableau de chaînes de caractères unicode.
Definition UtilsTypes.h:513