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 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 NULL-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 contains(const word&) const;
108 
109  //- Transfer the contents of the argument List into this list
110  // and annul the argument list.
111  void transfer(List<word>&);
112 
113 
114  // Member Operators
115 
116  //- Assignment operator from list of names
117  inline void operator=(const UList<word>& names);
118 
119  //- Assignment operator.
120  inline void operator=(const hashedWordList&);
121 
122  //- Return name corresponding to specified index
123  inline const word& operator[](const label index) const;
124 
125  //- Return index corresponding to specified name
126  inline label operator[](const word&) const;
127 
128 
129  // Istream operators
130 
132  friend Ostream& operator<<(Ostream&, const hashedWordList&);
133 };
134 
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #include "hashedWordListI.H"
143 
144 #endif
145 
146 // ************************************************************************* //
void append(const word &)
Append an element at the end of the list.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
bool contains(const word &) const
Does the list contain the specified name.
const word & operator[](const label index) const
Return name corresponding to specified index.
void transfer(List< word > &)
Transfer the contents of the argument List into this 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:60
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A wordList with hashed indices for faster lookup by name.
hashedWordList()
Construct null.
A class for handling words, derived from string.
Definition: word.H:59
void operator=(const UList< word > &names)
Assignment operator from list of names.
friend Ostream & operator<<(Ostream &, const hashedWordList &)
friend Istream & operator>>(Istream &, hashedWordList &)
An STL-conforming hash table.
Definition: HashTable.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
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
void clear()
Clear the list, i.e. set size to zero.
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144