Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
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/* List of '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 that returns the pointer ptr if it is not null or throws an exception if it is null.
void resize(Int64 s)
Changes the number of elements in the array to s.
Integer count() const
Number of elements in the collection.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
StringList toStringList() const
Converts the instance to 'StringList'.
void add(const String &str)
Adds str to the list of strings.
String operator[](Int32 index) const
Returns the i-th string.
Int32 size() const
Number of elements.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
List< String > StringList
Unicode string list.
Definition UtilsTypes.h:509
std::int32_t Int32
Signed integer type of 32 bits.