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 | Copyright (C) 2011-2015 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>
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 NULL
117  const T* lookupPtr(const word&) const;
118 
119  //- Find and return an entry if present, otherwise return NULL
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 
132  // Editing
133 
134  //- Add at head of dictionary
135  void insert(const word&, T*);
136 
137  //- Add at tail of dictionary
138  void append(const word&, T*);
139 
140  //- Remove and return entry specified by keyword.
141  // Return NULL if the keyword was not found.
142  T* remove(const word&);
143 
144  //- Clear the dictionary
145  void clear();
146 
147  //- Transfer the contents of the argument into this DictionaryBase
148  // and annul the argument.
150 
151 
152  // Member operators
153 
154  void operator=(const DictionaryBase&);
155 
156  //- Find and return entry
157  const T* operator[](const word& key) const
158  {
159  return lookup(key);
160  }
161 
162  //- Find and return entry
163  T* operator[](const word& key)
164  {
165  return lookup(key);
166  }
167 
168 
169  // Ostream operator
170 
171  friend Ostream& operator<< <IDLListType, T>
172  (
173  Ostream&,
175  );
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #ifdef NoRepository
186 # include "DictionaryBase.C"
187 #endif
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #endif
192 
193 // ************************************************************************* //
Foam::DictionaryBase::operator=
void operator=(const DictionaryBase &)
Definition: DictionaryBase.C:252
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
HashTable.H
Foam::DictionaryBase::toc
wordList toc() const
Return the table of contents.
Definition: DictionaryBase.C:172
Foam::DictionaryBase::operator[]
const T * operator[](const word &key) const
Find and return entry.
Definition: DictionaryBase.H:156
Foam::DictionaryBase::lookupPtr
const T * lookupPtr(const word &) const
Find and return an entry if present, otherwise return NULL.
Foam::DictionaryBase::addEntries
void addEntries()
Definition: DictionaryBase.C:31
wordList.H
Foam::DictionaryBase::append
void append(const word &, T *)
Add at tail of dictionary.
Definition: DictionaryBase.C:203
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
Foam::DictionaryBase::insert
void insert(const word &, T *)
Add at head of dictionary.
Definition: DictionaryBase.C:193
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:59
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::DictionaryBase::DictionaryBase
DictionaryBase(const label size=128)
Construct given initial table size.
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::DictionaryBase::remove
T * remove(const word &)
Remove and return entry specified by keyword.
Definition: DictionaryBase.C:212
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
DictionaryBase.C
Foam::HashTable< T * >
Foam::DictionaryBase::hashedTs_
HashTable< T * > hashedTs_
HashTable of the entries held on the IDLListType for quick lookup.
Definition: DictionaryBase.H:81
Foam::DictionaryBase::clear
void clear()
Clear the dictionary.
Definition: DictionaryBase.C:230
Foam::DictionaryBase::operator[]
T * operator[](const word &key)
Find and return entry.
Definition: DictionaryBase.H:162
Foam::List
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
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:61
Foam::DictionaryBase::lookup
const T * lookup(const word &) const
Find and return entry.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::DictionaryBase::found
bool found(const word &) const
Search DictionaryBase for given keyword.
Definition: DictionaryBase.C:93
Foam::DictionaryBase::transfer
void transfer(DictionaryBase< IDLListType, T > &)
Transfer the contents of the argument into this DictionaryBase.
Definition: DictionaryBase.C:239