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-2020 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 public:
73 
74  // Constructors
75 
76  //- Construct null
78 
79  //- Copy constructor
81 
82  //- Move constructor
84 
85  //- Construct from list of names
86  hashedWordList(const UList<word>& names);
87 
88  //- Move constructor transferring the parameter contents
89  hashedWordList(List<word>&& names);
90 
91  //- Construct from number and list of names
92  hashedWordList(const label nNames, const char** names);
93 
94  //- Construct from a nullptr-terminated list of names
95  hashedWordList(const char** names);
96 
97  //- Construct from Istream
99 
100 
101  // Member Functions
102 
103  //- Clear the list, i.e. set size to zero.
104  void clear();
105 
106  //- Append an element at the end of the list
107  void append(const word&);
108 
109  //- Does the list contain the specified name
110  inline bool found(const word&) const;
111 
112  //- Transfer the contents of the argument List into this list
113  // and annul the argument list.
114  void transfer(List<word>&);
115 
116 
117  // Member Operators
118 
119  //- Assignment operator
120  inline void operator=(const hashedWordList&);
121 
122  //- Move assignment operator
123  inline void operator=(hashedWordList&&);
124 
125  //- Assignment operator from list of names
126  inline void operator=(const UList<word>& names);
127 
128  //- Return name corresponding to specified index
129  inline const word& operator[](const label index) const;
130 
131  //- Return index corresponding to specified name
132  inline label operator[](const word&) const;
133 
134 
135  // Istream operators
136 
138  friend Ostream& operator<<(Ostream&, const hashedWordList&);
139 };
140 
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 } // End namespace Foam
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #include "hashedWordListI.H"
149 
150 #endif
151 
152 // ************************************************************************* //
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
bool found(const word &) const
Does the list contain the specified name.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void operator=(const hashedWordList &)
Assignment operator.
const word & operator[](const label index) const
Return name corresponding to specified index.
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
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.
An STL-conforming hash table.
Definition: HashTable.H:61
friend Istream & operator>>(Istream &, hashedWordList &)
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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void clear()
Clear the list, i.e. set size to zero.
friend Ostream & operator<<(Ostream &, const hashedWordList &)
A wordList with hashed indices for faster lookup by name.
Ostream & operator<<(Ostream &, const ensightPart &)
hashedWordList()
Construct null.
Namespace for OpenFOAM.