hashedWordList.H
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 Class
25  Foam::hashedWordList
26 
27 Description
28  A wordList with hashed indices for faster lookup by name.
29 
30 SourceFiles
31  hashedWordListI.H
32  hashedWordList.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef hashedWordList_H
37 #define hashedWordList_H
38 
39 #include "wordList.H"
40 #include "HashTable.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 class hashedWordList;
48 
49 // Forward declaration of friend functions and operators
50 Istream& operator>>(Istream&, hashedWordList&);
51 Ostream& operator<<(Ostream&, const hashedWordList&);
52 
53 
54 /*---------------------------------------------------------------------------*\
55  Class hashedWordList Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class hashedWordList
59 :
60  public List<word>
61 {
62  // Private Data
63 
64  HashTable<label, word> indices_;
65 
66 
67  // Private Member Functions
68 
69  //- Rebuild the hash of indices
70  void rehash();
71 
72 
73 public:
74 
75  // Static Data Members
76 
77  //- An empty hashedWordList
78  static const hashedWordList null;
79 
80 
81  // Constructors
82 
83  //- Construct null
85 
86  //- Copy constructor
88 
89  //- Move constructor
91 
92  //- Construct from list of names
93  hashedWordList(const UList<word>& names);
94 
95  //- Move constructor transferring the parameter contents
96  hashedWordList(List<word>&& names);
97 
98  //- Construct from number and list of names
99  hashedWordList(const label nNames, const char** names);
100 
101  //- Construct from a nullptr-terminated list of names
102  hashedWordList(const char** names);
103 
104  //- Construct from Istream
106 
107 
108  // Member Functions
109 
110  //- Clear the list, i.e. set size to zero.
111  void clear();
112 
113  //- Append an element at the end of the list
114  void append(const word&);
115 
116  //- Does the list contain the specified name
117  inline bool found(const word&) const;
118 
119  //- Transfer the contents of the argument List into this list
120  // and annul the argument list.
121  void transfer(List<word>&);
122 
123 
124  // Member Operators
125 
126  //- Assignment operator
127  inline void operator=(const hashedWordList&);
128 
129  //- Move assignment operator
130  inline void operator=(hashedWordList&&);
131 
132  //- Assignment operator from list of names
133  inline void operator=(const UList<word>& names);
134 
135  //- Return name corresponding to specified index
136  inline const word& operator[](const label index) const;
137 
138  //- Return index corresponding to specified name
139  inline label operator[](const word&) const;
140 
141 
142  // Istream operators
143 
145  friend Ostream& operator<<(Ostream&, const hashedWordList&);
146 };
147 
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace Foam
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #include "hashedWordListI.H"
156 
157 #endif
158 
159 // ************************************************************************* //
An STL-conforming hash table.
Definition: HashTable.H:127
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
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
A wordList with hashed indices for faster lookup by name.
bool found(const word &) const
Does the list contain the specified name.
friend Ostream & operator<<(Ostream &, const hashedWordList &)
void operator=(const hashedWordList &)
Assignment operator.
void append(const word &)
Append an element at the end of the list.
friend Istream & operator>>(Istream &, hashedWordList &)
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.
const word & operator[](const label index) const
Return name corresponding to specified index.
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
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
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)