hashedWordList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "hashedWordList.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
31 
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 void Foam::hashedWordList::rehash()
36 {
37  indices_.clear();
38  forAll(*this, i)
39  {
40  indices_.insert(List<word>::operator[](i), i);
41  }
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 :
49  List<word>()
50 {}
51 
52 
54 :
55  List<word>(names)
56 {
57  rehash();
58 }
59 
60 
62 :
63  List<word>(static_cast<const UList<word>&>(names))
64 {
65  rehash();
66 }
67 
68 
70 :
71  List<word>(move(names)),
72  indices_(move(names.indices_))
73 {}
74 
75 
77 :
78  List<word>(move(names))
79 {
80  rehash();
81 }
82 
83 
85 (
86  const label nNames,
87  const char** names
88 )
89 :
90  List<word>(nNames)
91 {
92  forAll(*this, i)
93  {
94  List<word>::operator[](i) = names[i];
95  }
96 
97  rehash();
98 }
99 
100 
102 (
103  const char** names
104 )
105 {
106  // count names
107  label nNames = 0;
108  for (unsigned i = 0; names[i] && *(names[i]); ++i)
109  {
110  ++nNames;
111  }
112 
113  List<word>::setSize(nNames);
114  forAll(*this, i)
115  {
116  List<word>::operator[](i) = names[i];
117  }
118 
119  rehash();
120 }
121 
122 
124 {
125  is >> *this;
126 }
127 
128 
129 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
130 
132 {
134  indices_.clear();
135 }
136 
137 
139 {
140  const label idx = size();
142  indices_.insert(name, idx);
143 }
144 
145 
147 {
149  rehash();
150 }
151 
152 
153 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
154 
156 {
157  is >> static_cast<List<word>&>(lst);
158  lst.rehash();
159 
160  return is;
161 }
162 
163 
165 {
166  os << static_cast<const List<word>&>(lst);
167  return os;
168 }
169 
170 
171 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
void setSize(const label)
Reset size of List.
Definition: List.C:281
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
A wordList with hashed indices for faster lookup by name.
static const hashedWordList null
An empty hashedWordList.
void append(const word &)
Append an element at the end of the list.
void transfer(List< word > &)
Transfer the contents of the argument List into this list.
hashedWordList()
Construct null.
void clear()
Clear the list, i.e. set size to zero.
Motion of the mesh specified as a list of pointMeshMovers.
A class for handling words, derived from string.
Definition: word.H:63
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)