hashedWordList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 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>(names)
67 {
68  rehash();
69 }
70 
71 
73 (
74  const label nNames,
75  const char** names
76 )
77 :
78  List<word>(nNames)
79 {
80  forAll(*this, i)
81  {
82  List<word>::operator[](i) = names[i];
83  }
84 
85  rehash();
86 }
87 
88 
90 (
91  const char** names
92 )
93 {
94  // count names
95  label nNames = 0;
96  for (unsigned i = 0; names[i] && *(names[i]); ++i)
97  {
98  ++nNames;
99  }
100 
101  List<word>::setSize(nNames);
102  forAll(*this, i)
103  {
104  List<word>::operator[](i) = names[i];
105  }
106 
107  rehash();
108 }
109 
110 
112 {
113  is >> *this;
114 }
115 
116 
117 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
118 
120 {
122  indices_.clear();
123 }
124 
125 
127 {
128  const label idx = size();
129  List<word>::append(name);
130  indices_.insert(name, idx);
131 }
132 
133 
135 {
137  rehash();
138 }
139 
140 
141 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
142 
144 {
145  is >> static_cast<List<word>&>(lst);
146  lst.rehash();
147 
148  return is;
149 }
150 
151 
153 {
154  os << static_cast<const List<word>&>(lst);
155  return os;
156 }
157 
158 
159 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
friend Ostream & operator(Ostream &, const UList< T > &)
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:124
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
void transfer(List< word > &)
Transfer the contents of the argument List into this list.
void append(const word &)
Append an element at the end of the list.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
void clear()
Clear the list, i.e. set size to zero.
void setSize(const label)
Reset size of List.
Definition: List.C:281
A wordList with hashed indices for faster lookup by name.
Ostream & operator<<(Ostream &, const ensightPart &)
label size() const
Return the number of elements in the UList.
Definition: ListI.H:170
hashedWordList()
Construct null.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342