PtrDictionary.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::PtrDictionary
28 
29 Description
30  Template dictionary class which manages the storage associated with it.
31 
32  It is derived from DictionaryBase instantiated on a memory managed form of
33  intrusive doubly-linked list of <T>.
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Foam_PtrDictionary_H
38 #define Foam_PtrDictionary_H
39 
40 #include "DictionaryBase.H"
41 #include "DLPtrList.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class PtrDictionary Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 template<class T>
53 class PtrDictionary
54 :
55  public DictionaryBase<DLPtrList<T>, T>
56 {
57 public:
58 
59  //- The template instance used for the dictionary content
61 
62 
63  // Constructors
64 
65  //- Default construct: empty without allocation (capacity=0).
66  PtrDictionary() = default;
67 
68  //- Construct empty with initial table capacity
69  explicit PtrDictionary(const label initialCapacity)
70  :
71  dict_type(initialCapacity)
72  {}
73 
74  //- Copy construct
76  :
78  {}
79 
80  //- Construct from Istream using given Istream constructor class
81  template<class INew>
82  PtrDictionary(Istream& is, const INew& inew)
83  :
84  dict_type(is, inew)
85  {}
86 
87  //- Construct from Istream
88  explicit PtrDictionary(Istream& is)
89  :
90  dict_type(is)
91  {}
92 
93 
94  // Member Operators
95 
96  //- Find and return entry
97  const T& operator[](const word& key) const
98  {
99  return *(dict_type::lookup(key));
100  }
101 
102  //- Find and return entry
103  T& operator[](const word& key)
104  {
105  return *(dict_type::lookup(key));
106  }
107 };
108 
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 } // End namespace Foam
113 
114 #endif
115 
116 // ************************************************************************* //
Template dictionary class which manages the storage associated with it.
Definition: PtrDictionary.H:46
dictionary dict
Non-intrusive doubly-linked pointer list.
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
const T & operator[](const word &key) const
Find and return entry.
A class for handling words, derived from Foam::string.
Definition: word.H:63
DictionaryBase< DLPtrList< T >, T > dict_type
The template instance used for the dictionary content.
Definition: PtrDictionary.H:55
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const T * lookup(const word &keyword) const
Find and return entry, FatalError on failure.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:46
PtrDictionary()=default
Default construct: empty without allocation (capacity=0).
Namespace for OpenFOAM.