Arcane  v3.14.10.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-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/* StringDictionary.cc (C) 2000-2020 */
9/* */
10/* Dictionnaire de chaînes de caractères. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/StringDictionary.h"
15#include "arcane/utils/String.h"
16#include "arcane/utils/StringList.h"
17
18#include <map>
19#include <exception>
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
31: public std::exception
32{
33};
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37/*!
38 * \internal
39 \brief Implémentation du dictionnaire de chaîne unicode.
40
41 L'implémentation utilise la classe map de la STL.
42*/
44{
45 public:
46 typedef std::map<String,String> StringDictType;
47 public:
48 Impl() {}
49 public:
50 StringDictType m_dictionary;
51};
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
58: m_p(new Impl())
59{
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
67: m_p(new Impl(*rhs.m_p))
68{
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
76{
77 delete m_p;
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
84add(const String& key,const String& value)
85{
86 m_p->m_dictionary.insert(std::make_pair(key,value));
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
93remove(const String& key)
94{
95 auto i = m_p->m_dictionary.find(key);
96 String value;
97 if (i!=m_p->m_dictionary.end()){
98 value = i->second;
99 m_p->m_dictionary.erase(i);
100 }
101 return value;
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
108find(const String& key,bool throw_exception) const
109{
110 auto i = m_p->m_dictionary.find(key);
111 String value;
112 if (i!=m_p->m_dictionary.end())
113 value = i->second;
114 else if (throw_exception)
115 throw BadIndexException();
116 return value;
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
123fill(StringList& keys,StringList& values) const
124{
125 keys.clear();
126 values.clear();
127 for( const auto& x : m_p->m_dictionary ){
128 keys.add(x.first);
129 values.add(x.second);
130 }
131}
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136} // End namespace Arcane
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
void clear()
Supprime tous les éléments de la collection.
Definition Collection.h:68
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 -*-