DictionaryBase.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-2018 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::DictionaryBase
26 
27 Description
28  Base dictionary class templated on both the form of doubly-linked list
29  it uses as well as the type it holds.
30 
31  The double templating allows for the instantiation of forms with or
32  without storage management.
33 
34 Note
35  The IDLListType parameter should itself be a template but this confused
36  gcc 2.95.2 so it has to be instantiated for T when an instantiation of
37  DictionaryBase is requested
38 
39 See also
40  Dictionary and UDictionary
41 
42 SourceFiles
43  DictionaryBase.C
44  DictionaryBaseIO.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef DictionaryBase_H
49 #define DictionaryBase_H
50 
51 #include "HashTable.H"
52 #include "wordList.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Forward declaration of friend functions and operators
60 
61 template<class IDLListType, class T>
62 class DictionaryBase;
63 
64 template<class IDLListType, class T>
65 Ostream& operator<<(Ostream&, const DictionaryBase<IDLListType, T>&);
66 
67 
68 /*---------------------------------------------------------------------------*\
69  Class DictionaryBase Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 template<class IDLListType, class T>
73 class DictionaryBase
74 :
75  public IDLListType
76 {
77 protected:
78 
79  // Protected data
80 
81  //- HashTable of the entries held on the IDLListType for quick lookup
83 
84 
85  // Protected Member functions
86 
87  // Add the IDLListType entries into the HashTable
88  void addEntries();
89 
90 
91 public:
92 
93  // Constructors
94 
95  //- Construct given initial table size
96  DictionaryBase(const label size = 128);
97 
98  //- Copy construct
100 
101  //- Construct from Istream using given Istream constructor class
102  template<class INew>
103  DictionaryBase(Istream&, const INew&);
104 
105  //- Construct from Istream using default Istream constructor class
107 
108 
109  // Member functions
110 
111  // Search and lookup
112 
113  //- Search DictionaryBase for given keyword
114  bool found(const word&) const;
115 
116  //- Find and return an entry if present, otherwise return nullptr
117  const T* lookupPtr(const word&) const;
118 
119  //- Find and return an entry if present, otherwise return nullptr
120  T* lookupPtr(const word&);
121 
122  //- Find and return entry
123  const T* lookup(const word&) const;
124 
125  //- Find and return entry
126  T* lookup(const word&);
127 
128  //- Return the table of contents
129  wordList toc() const;
130 
131  //- Return the table of contents as a sorted list
132  wordList sortedToc() const;
133 
134 
135  // Editing
136 
137  //- Add at head of dictionary
138  void insert(const word&, T*);
139 
140  //- Add at tail of dictionary
141  void append(const word&, T*);
142 
143  //- Remove and return entry specified by keyword.
144  // Return nullptr if the keyword was not found.
145  T* remove(const word&);
146 
147  //- Clear the dictionary
148  void clear();
149 
150  //- Transfer the contents of the argument into this DictionaryBase
151  // and annul the argument.
153 
154 
155  // Member operators
156 
157  void operator=(const DictionaryBase&);
158 
159  //- Find and return entry
160  const T* operator[](const word& key) const
161  {
162  return lookup(key);
163  }
164 
165  //- Find and return entry
166  T* operator[](const word& key)
167  {
168  return lookup(key);
169  }
170 
171 
172  // Ostream operator
173 
174  friend Ostream& operator<< <IDLListType, T>
175  (
176  Ostream&,
178  );
179 };
180 
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 } // End namespace Foam
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 #ifdef NoRepository
189  #include "DictionaryBase.C"
190 #endif
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #endif
195 
196 // ************************************************************************* //
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
Search DictionaryBase for given keyword.
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void operator=(const DictionaryBase &)
wordList sortedToc() const
Return the table of contents as a sorted list.
const T * lookupPtr(const word &) const
Find and return an entry if present, otherwise return nullptr.
wordList toc() const
Return the table of contents.
void append(const word &, T *)
Add at tail of dictionary.
const T * operator[](const word &key) const
Find and return entry.
DictionaryBase(const label size=128)
Construct given initial table size.
void insert(const word &, T *)
Add at head of dictionary.
A class for handling words, derived from string.
Definition: word.H:59
HashTable< T * > hashedTs_
HashTable of the entries held on the IDLListType for quick lookup.
void clear()
Clear the dictionary.
An STL-conforming hash table.
Definition: HashTable.H:62
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void transfer(DictionaryBase< IDLListType, T > &)
Transfer the contents of the argument into this DictionaryBase.
const T * lookup(const word &) const
Find and return entry.
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
Namespace for OpenFOAM.