Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
StringDictionary.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* String dictionary. */
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
46{
47 public:
48
49 typedef std::map<String, String> StringDictType;
50
51 public:
52
53 Impl() {}
54
55 public:
56
57 StringDictType m_dictionary;
58};
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
74: m_p(new Impl(*rhs.m_p))
75{
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
91add(const String& key, const String& value)
92{
93 m_p->m_dictionary.insert(std::make_pair(key, value));
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
100remove(const String& key)
101{
102 auto i = m_p->m_dictionary.find(key);
103 String value;
104 if (i != m_p->m_dictionary.end()) {
105 value = i->second;
106 m_p->m_dictionary.erase(i);
107 }
108 return value;
109}
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
115find(const String& key, bool throw_exception) const
116{
117 auto i = m_p->m_dictionary.find(key);
118 String value;
119 if (i != m_p->m_dictionary.end())
120 value = i->second;
121 else if (throw_exception)
122 throw BadIndexException();
123 return value;
124}
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
130fill(StringList& keys, StringList& values) const
131{
132 keys.clear();
133 values.clear();
134 for (const auto& x : m_p->m_dictionary) {
135 keys.add(x.first);
136 values.add(x.second);
137 }
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143} // namespace Arcane
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
void clear()
Removes all elements from the collection.
Implementation of the unicode string dictionary.
void fill(StringList &param_names, StringList &values) const
Fills keys and values with the corresponding values from the dictionary.
StringDictionary()
Implementation.
~StringDictionary()
Releases resources.
String remove(const String &key)
Removes the value associated with key.
void add(const String &key, const String &value)
Adds the (key, value) pair to the dictionary.
String find(const String &key, bool throw_exception=false) const
Returns the value associated with key.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
List< String > StringList
Unicode string list.
Definition UtilsTypes.h:509