hashedWordList.H
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 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  //- Construct from list of names
83  hashedWordList(const UList<word>& names);
84 
85  //- Construct by transferring the parameter contents
86  hashedWordList(const Xfer<List<word>>& names);
87 
88  //- Construct from number and list of names
89  hashedWordList(const label nNames, const char** names);
90 
91  //- Construct from a nullptr-terminated list of names
92  hashedWordList(const char** names);
93 
94  //- Construct from Istream
96 
97 
98  // Member Functions
99 
100  //- Clear the list, i.e. set size to zero.
101  void clear();
102 
103  //- Append an element at the end of the list
104  void append(const word&);
105 
106  //- Does the list contain the specified name
107  inline bool found(const word&) const;
108 
109  //- Does the list contain the specified name
110  inline bool contains(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 from list of names
120  inline void operator=(const UList<word>& names);
121 
122  //- Assignment operator.
123  inline void operator=(const hashedWordList&);
124 
125  //- Return name corresponding to specified index
126  inline const word& operator[](const label index) const;
127 
128  //- Return index corresponding to specified name
129  inline label operator[](const word&) const;
130 
131 
132  // Istream operators
133 
135  friend Ostream& operator<<(Ostream&, const hashedWordList&);
136 };
137 
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 } // End namespace Foam
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 #include "hashedWordListI.H"
146 
147 #endif
148 
149 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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:60
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void operator=(const UList< word > &names)
Assignment operator from list of names.
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:62
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:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
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 &)
bool contains(const word &) const
Does the list contain the specified name.
hashedWordList()
Construct null.
Namespace for OpenFOAM.