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-2019 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::hashedWordList::rehash()
31 {
32  indices_.clear();
33  forAll(*this, i)
34  {
35  indices_.insert(List<word>::operator[](i), i);
36  }
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 :
44  List<word>()
45 {}
46 
47 
49 :
50  List<word>(names)
51 {
52  rehash();
53 }
54 
55 
57 :
58  List<word>(static_cast<const UList<word>&>(names))
59 {
60  rehash();
61 }
62 
63 
65 :
66  List<word>(move(names)),
67  indices_(move(names.indices_))
68 {}
69 
70 
72 :
73  List<word>(move(names))
74 {
75  rehash();
76 }
77 
78 
80 (
81  const label nNames,
82  const char** names
83 )
84 :
85  List<word>(nNames)
86 {
87  forAll(*this, i)
88  {
89  List<word>::operator[](i) = names[i];
90  }
91 
92  rehash();
93 }
94 
95 
97 (
98  const char** names
99 )
100 {
101  // count names
102  label nNames = 0;
103  for (unsigned i = 0; names[i] && *(names[i]); ++i)
104  {
105  ++nNames;
106  }
107 
108  List<word>::setSize(nNames);
109  forAll(*this, i)
110  {
111  List<word>::operator[](i) = names[i];
112  }
113 
114  rehash();
115 }
116 
117 
119 {
120  is >> *this;
121 }
122 
123 
124 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
125 
127 {
129  indices_.clear();
130 }
131 
132 
134 {
135  const label idx = size();
137  indices_.insert(name, idx);
138 }
139 
140 
142 {
144  rehash();
145 }
146 
147 
148 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
149 
151 {
152  is >> static_cast<List<word>&>(lst);
153  lst.rehash();
154 
155  return is;
156 }
157 
158 
160 {
161  os << static_cast<const List<word>&>(lst);
162  return os;
163 }
164 
165 
166 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
friend Ostream & operator(Ostream &, const UList< T > &)
A wordList with hashed indices for faster lookup by name.
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.
A class for handling words, derived from string.
Definition: word.H:62
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 bool)
Return a word representation of a bool.
Definition: boolIO.C:39
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)