All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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 constructor
100 
101  //- Move constructor
103 
104  //- Construct from Istream using given Istream constructor class
105  template<class INew>
106  DictionaryBase(Istream&, const INew&);
107 
108  //- Construct from Istream using default Istream constructor class
110 
111 
112  // Member Functions
113 
114  // Search and lookup
115 
116  //- Search DictionaryBase for given keyword
117  bool found(const word&) const;
118 
119  //- Find and return an entry if present, otherwise return nullptr
120  const T* lookupPtr(const word&) const;
121 
122  //- Find and return an entry if present, otherwise return nullptr
123  T* lookupPtr(const word&);
124 
125  //- Find and return entry
126  const T* lookup(const word&) const;
127 
128  //- Find and return entry
129  T* lookup(const word&);
130 
131  //- Return the table of contents
132  wordList toc() const;
133 
134  //- Return the table of contents as a sorted list
135  wordList sortedToc() const;
136 
137 
138  // Editing
139 
140  //- Add at head of dictionary
141  void insert(const word&, T*);
142 
143  //- Add at tail of dictionary
144  void append(const word&, T*);
145 
146  //- Remove and return entry specified by keyword.
147  // Return nullptr if the keyword was not found.
148  T* remove(const word&);
149 
150  //- Clear the dictionary
151  void clear();
152 
153  //- Transfer the contents of the argument into this DictionaryBase
154  // and annul the argument.
156 
157 
158  // Member Operators
159 
160  void operator=(const DictionaryBase&);
161 
162  //- Find and return entry
163  const T* operator[](const word& key) const
164  {
165  return lookup(key);
166  }
167 
168  //- Find and return entry
169  T* operator[](const word& key)
170  {
171  return lookup(key);
172  }
173 
174 
175  // Ostream operator
176 
177  friend Ostream& operator<< <IDLListType, T>
178  (
179  Ostream&,
181  );
182 };
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #ifdef NoRepository
192  #include "DictionaryBase.C"
193 #endif
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 #endif
198 
199 // ************************************************************************* //
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:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
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.