Map.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  Copyright (C) 2017-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::Map
29 
30 Description
31  A HashTable to objects of type <T> with a label key.
32 
33 Note
34  The Map contents are unordered.
35  When the key order is important, use the sortedToc() method to obtain
36  a list of sorted keys and use that for further access.
37 
38 See also
39  PtrMap
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Foam_Map_H
44 #define Foam_Map_H
45 
46 #include "HashTable.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class Map Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class T>
58 class Map
59 :
60  public HashTable<T, label, Hash<label>>
61 {
62 public:
63 
64  //- The template instance used for this Map
65  typedef Map<T> this_type;
66 
67  //- The template instance used for the parent HashTable
69 
70  using iterator = typename parent_type::iterator;
72 
73 
74  // Constructors
75 
76  //- Default construct: empty without allocation (capacity=0)
77  Map() noexcept = default;
78 
79  //- Construct empty without allocation (capacity=0)
80  explicit Map(const Foam::zero) noexcept
81  :
83  {}
84 
85  //- Construct empty with given initial table capacity
86  explicit Map(const label initialCapacity)
87  :
88  parent_type(initialCapacity)
89  {}
90 
91  //- Construct from Istream (with default initial table capacity)
92  Map(Istream& is)
93  :
94  parent_type(is)
95  {}
96 
97  //- Copy construct
98  Map(const this_type& map)
99  :
100  parent_type(map)
101  {}
102 
103  //- Move construct
104  Map(this_type&& map) noexcept
105  :
106  parent_type(std::move(map))
107  {}
108 
109  //- Construct from key/value pairs in initializer list
110  // By default, uses insert not overwrite semantics for duplicates.
111  Map
112  (
113  std::initializer_list<std::pair<label, T>> map,
114  const bool overwrite = false
115  )
116  :
117  parent_type(map, overwrite)
118  {}
119 
120  //- Construct from key/value pairs
121  // By default, uses insert not overwrite semantics for duplicates.
122  Map
123  (
125  const UList<T>& values,
126  const bool overwrite = false
127  )
128  :
129  parent_type(keys, values, overwrite)
130  {}
131 
132 
133  // Member Operators
134 
135  using parent_type::operator=;
136 
137  //- Copy assignment
138  void operator=(const this_type& rhs)
139  {
141  }
142 
143  //- Move assignment
144  void operator=(this_type&& rhs)
145  {
146  parent_type::operator=(std::move(rhs));
147  }
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Foam
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
HashTable< T, label, Hash< label > > parent_type
The template instance used for the parent HashTable.
Definition: Map.H:65
Forward iterator with const access.
Definition: HashTable.H:1132
typename parent_type::const_iterator const_iterator
Definition: Map.H:68
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
friend Ostream & operator(Ostream &, const HashTable< T, label, Hash< label > > &tbl)
Map() noexcept=default
Default construct: empty without allocation (capacity=0)
Map< T > this_type
The template instance used for this Map.
Definition: Map.H:60
Forward iterator with non-const access.
Definition: HashTable.H:1040
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
void operator=(const this_type &rhs)
Copy assign.
typename parent_type::iterator iterator
Definition: Map.H:67
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
const direction noexcept
Definition: Scalar.H:258
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
const_iterator_pair< const_key_iterator, this_type > keys() const
A const iterator begin/end pair for iterating over keys.
Definition: HashTable.H:1295
void operator=(const this_type &rhs)
Copy assignment.
Definition: Map.H:155
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.