Arcane  v4.1.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
StringVector.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/* StringVector.cc (C) 2000-2026 */
9/* */
10/* Liste de 'String'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/common/StringVector.h"
15
16#include "arccore/base/String.h"
17
18#include "arccore/common/Array.h"
19#include "arccore/common/List.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
31{
32 public:
33
34 UniqueArray<String> m_values;
35};
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40void StringVector::
41_checkNeedCreate()
42{
43 if (!m_p)
44 m_p = new Impl();
45}
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
50StringVector::
51StringVector(const StringList& string_list)
52{
53 Int32 n = string_list.count();
54 if (n == 0)
55 return;
56 _checkNeedCreate();
57 m_p->m_values.resize(n);
58 for (Int32 i = 0; i < n; ++i)
59 m_p->m_values[i] = string_list[i];
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65StringVector::
66StringVector(const StringVector& rhs)
67{
68 if (rhs.m_p)
69 m_p = new Impl(*rhs.m_p);
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75StringVector::
76StringVector(StringVector&& rhs) noexcept
77: m_p(rhs.m_p)
78{
79 rhs.m_p = nullptr;
80}
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85StringVector& StringVector::
86operator=(const StringVector& rhs)
87{
88 if (&rhs != this) {
89 Impl* new_mp = nullptr;
90 if (rhs.m_p)
91 new_mp = new Impl(*rhs.m_p);
92 delete m_p;
93 m_p = new_mp;
94 }
95 return (*this);
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101StringVector::
102~StringVector()
103{
104 delete m_p;
105}
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
111size() const
112{
113 return (m_p ? m_p->m_values.size() : 0);
114}
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
120add(const String& str)
121{
122 _checkNeedCreate();
123 m_p->m_values.add(str);
124}
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
130operator[](Int32 index) const
131{
133 return m_p->m_values[index];
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
140toStringList() const
141{
142 StringList sl;
143 if (!m_p)
144 return sl;
145 ConstArrayView<String> v = m_p->m_values;
146 Int32 nb_string = v.size();
147 sl.resize(nb_string);
148 for (Int32 i = 0; i < nb_string; ++i)
149 sl[i] = v[i];
150 return sl;
151}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156} // namespace Arcane
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
#define ARCCORE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
Integer count() const
Nombre d'éléments de la collection.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
StringList toStringList() const
Converti l'instance en 'StringList'.
void add(const String &str)
Ajoute str à la liste des chaînes de caractères.
String operator[](Int32 index) const
Retourne la i-ème chaîne de caractères.
Int32 size() const
Nombre d'éléments.
Chaîne de caractères unicode.
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- 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:509
std::int32_t Int32
Type entier signé sur 32 bits.