DictionaryBase.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::DictionaryBase
28 
29 Description
30  Base dictionary class templated on both the form of doubly-linked list
31  it uses as well as the type it holds.
32 
33  The double templating allows for the instantiation of forms with or
34  without storage management.
35 
36 Note
37  The IDLListType parameter should itself be a template but this confused
38  gcc 2.95.2 so it has to be instantiated for T when an instantiation of
39  DictionaryBase is requested
40 
41 See also
42  Dictionary and UDictionary
43 
44 SourceFiles
45  DictionaryBase.C
46  DictionaryBaseIO.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef DictionaryBase_H
51 #define DictionaryBase_H
52 
53 #include "HashTable.H"
54 #include "wordList.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declarations
62 
63 template<class IDLListType, class T>
64 class DictionaryBase;
65 
66 template<class IDLListType, class T>
68 
69 
70 /*---------------------------------------------------------------------------*\
71  Class DictionaryBase Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 template<class IDLListType, class T>
75 class DictionaryBase
76 :
77  public IDLListType
78 {
79 protected:
80 
81  // Protected data
82 
83  //- HashTable of the entries held on the IDLListType for quick lookup
85 
86 
87  // Protected Member functions
88 
89  // Add the IDLListType entries into the HashTable
90  void addEntries();
91 
92 
93 public:
94 
95  // Constructors
96 
97  //- Construct with given or default (128) table capacity
98  explicit DictionaryBase(const label size = 128);
99 
100  //- Copy construct
102 
103  //- Construct from Istream using given Istream constructor class
104  template<class INew>
105  DictionaryBase(Istream& is, const INew& inew);
106 
107  //- Construct from Istream using default Istream constructor class
108  DictionaryBase(Istream& is);
109 
110 
111  // Member Functions
112 
113  // Search and lookup
114 
115  //- Search for given keyword
116  bool found(const word& keyword) const;
117 
118  //- Find and return an entry if present, otherwise return nullptr
119  const T* lookupPtr(const word& keyword) const;
120 
121  //- Find and return an entry if present, otherwise return nullptr
122  T* lookupPtr(const word& keyword);
123 
124  //- Find and return entry
125  const T* lookup(const word& keyword) const;
126 
127  //- Find and return entry
128  T* lookup(const word& keyword);
129 
130  //- Return the table of contents (as a sorted list)
131  wordList toc() const;
132 
133  //- Return the table of contents as a sorted list
134  wordList sortedToc() const;
135 
136  //- Return table of contents sorted using the specified comparator
137  template<class Compare>
138  wordList sortedToc(const Compare& comp) const;
139 
140 
141  // Editing
142 
143  //- Add at head of dictionary
144  void insert(const word& keyword, T*);
145 
146  //- Add at tail of dictionary
147  void append(const word& keyword, T*);
148 
149  //- Remove and return entry specified by keyword.
150  // Return nullptr if the keyword was not found.
151  T* remove(const word& keyword);
152 
153  //- Clear the dictionary
154  void clear();
155 
156  //- Transfer the contents of the argument into this DictionaryBase
157  // and annul the argument.
159 
160 
161  // Member Operators
162 
163  //- Copy assigment
164  void operator=(const DictionaryBase&);
165 
166  //- Find and return entry
167  const T* operator[](const word& key) const
168  {
169  return lookup(key);
170  }
171 
172  //- Find and return entry
173  T* operator[](const word& key)
174  {
175  return lookup(key);
176  }
177 
178 
179  // Ostream Operator
180 
181  friend Ostream& operator<< <IDLListType, T>
182  (
183  Ostream&,
185  );
186 };
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #ifdef NoRepository
196  #include "DictionaryBase.C"
197 #endif
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 #endif
202 
203 // ************************************************************************* //
Foam::DictionaryBase::operator=
void operator=(const DictionaryBase &)
Copy assigment.
Definition: DictionaryBase.C:249
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
HashTable.H
Foam::DictionaryBase::toc
wordList toc() const
Return the table of contents (as a sorted list)
Definition: DictionaryBase.C:160
Foam::DictionaryBase::operator[]
const T * operator[](const word &key) const
Find and return entry.
Definition: DictionaryBase.H:166
Foam::DictionaryBase::transfer
void transfer(DictionaryBase< IDLListType, T > &dict)
Transfer the contents of the argument into this DictionaryBase.
Definition: DictionaryBase.C:231
Foam::DictionaryBase::addEntries
void addEntries()
Definition: DictionaryBase.C:34
wordList.H
Foam::DictionaryBase::sortedToc
wordList sortedToc() const
Return the table of contents as a sorted list.
Definition: DictionaryBase.C:170
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:51
Foam::label
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:62
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::DictionaryBase::DictionaryBase
DictionaryBase(const label size=128)
Construct with given or default (128) table capacity.
Definition: DictionaryBase.C:46
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::DictionaryBase::remove
T * remove(const word &keyword)
Remove and return entry specified by keyword.
Definition: DictionaryBase.C:206
Foam::DictionaryBase::found
bool found(const word &keyword) const
Search for given keyword.
Definition: DictionaryBase.C:90
Foam::DictionaryBase::append
void append(const word &keyword, T *)
Add at tail of dictionary.
Definition: DictionaryBase.C:197
Foam::DictionaryBase::lookup
const T * lookup(const word &keyword) const
Find and return entry.
Definition: DictionaryBase.C:128
dict
dictionary dict
Definition: searchingEngine.H:14
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
DictionaryBase.C
Foam::HashTable< T * >
Foam::DictionaryBase::insert
void insert(const word &keyword, T *)
Add at head of dictionary.
Definition: DictionaryBase.C:188
Foam::DictionaryBase::lookupPtr
const T * lookupPtr(const word &keyword) const
Find and return an entry if present, otherwise return nullptr.
Definition: DictionaryBase.C:98
Foam::DictionaryBase::hashedTs_
HashTable< T * > hashedTs_
HashTable of the entries held on the IDLListType for quick lookup.
Definition: DictionaryBase.H:83
Foam::DictionaryBase::clear
void clear()
Clear the dictionary.
Definition: DictionaryBase.C:222
Foam::DictionaryBase::operator[]
T * operator[](const word &key)
Find and return entry.
Definition: DictionaryBase.H:172
Foam::List< word >
Foam::DictionaryBase
Base dictionary class templated on both the form of doubly-linked list it uses as well as the type it...
Definition: DictionaryBase.H:63
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102