initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Dictionaries / DictionaryBase / DictionaryBase.H
blobb80240310622e57cf2752076ecfbe31f1e95413f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::DictionaryBase
28 Description
29     Base dictionary class templated on both the form of doubly-linked list
30     it uses as well as the type it holds.
32     The double templating allows for the instantiation of forms with or
33     without storage management.
35 Note
36     The IDLListType parameter should itself be a template but this confused
37     gcc 2.95.2 so it has to be instantiated for T when an instantiation of
38     DictionaryBase is requested
40 See Also
41     Dictionary and UDictionary
43 SourceFiles
44     DictionaryBase.C
45     DictionaryBaseIO.C
47 \*---------------------------------------------------------------------------*/
49 #ifndef DictionaryBase_H
50 #define DictionaryBase_H
52 #include "HashTable.H"
53 #include "wordList.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 namespace Foam
60 // Forward declaration of friend functions and operators
62 template<class IDLListType, class T>
63 class DictionaryBase;
65 template<class IDLListType, class T>
66 Ostream& operator<<(Ostream&, const DictionaryBase<IDLListType, T>&);
69 /*---------------------------------------------------------------------------*\
70                       Class DictionaryBase Declaration
71 \*---------------------------------------------------------------------------*/
73 template<class IDLListType, class T>
74 class DictionaryBase
76     public IDLListType
78     // Private data
80         //- HashTable of the entries held on the IDLListType for quick lookup
81         HashTable<T*> hashedTs_;
84     // Private Member functions
86         // Add the IDLListType entries into the HashTable
87         void addEntries();
90 public:
92     // Constructors
94         //- Null constructor
95         DictionaryBase();
97         //- Copy construct
98         DictionaryBase(const DictionaryBase&);
100         //- Construct from Istream using given Istream constructor class
101         template<class INew>
102         DictionaryBase(Istream&, const INew&);
104         //- Construct from Istream using default Istream constructor class
105         DictionaryBase(Istream&);
108     // Member functions
110         // Search and lookup
112             //- Search DictionaryBase for given keyword
113             bool found(const word&) const;
115             //- Find and return an entry if present, otherwise return NULL
116             const T* lookupPtr(const word&) const;
118             //- Find and return an entry if present, otherwise return NULL
119             T* lookupPtr(const word&);
121             //- Find and return entry
122             const T* lookup(const word&) const;
124             //- Find and return entry
125             T* lookup(const word&);
127             //- Return the table of contents
128             wordList toc() const;
131         // Editing
133             //- Add at head of dictionary
134             void insert(const word&, T*);
136             //- Add at tail of dictionary
137             void append(const word&, T*);
139             //- Remove and return entry specified by keyword.
140             //  Return NULL if the keyword was not found.
141             T* remove(const word&);
143             //- Clear the dictionary
144             void clear();
146             //- Transfer the contents of the argument into this DictionaryBase
147             //  and annull the argument.
148             void transfer(DictionaryBase<IDLListType, T>&);
150     // Member operators
152         void operator=(const DictionaryBase&);
154         //- Find and return entry
155         const T* operator[](const word& key) const
156         {
157             return lookup(key);
158         }
160         //- Find and return entry
161         T* operator[](const word& key)
162         {
163             return lookup(key);
164         }
167     // Ostream operator
169         friend Ostream& operator<< <IDLListType, T>
170         (
171             Ostream&,
172             const DictionaryBase<IDLListType, T>&
173         );
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 } // End namespace Foam
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 #ifdef NoRepository
184 #   include "DictionaryBase.C"
185 #endif
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 #endif
191 // ************************************************************************* //