www.cemf.ir
Map.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #ifndef __Map_hpp__
23 #define __Map_hpp__
24 
25 
26 #include <map>
27 
28 #include "types.hpp"
29 #include "iOstream.hpp"
30 
31 
32 namespace pFlow
33 {
34 
35 template<class Key, class T, class Compare = std::less<Key> >
36 class Map
37 :
38  public std::map<Key, T, Compare>
39 {
40 public:
41 
43 
44  using mapType = std::map<Key, T, Compare>;
45 
46  using iterator = typename mapType::iterator;
47 
48  using constIterator = typename mapType::const_iterator;
49 
50  using reference = typename mapType::reference;
51 
52  using constReference= typename mapType::const_reference;
53 
54  using initList = typename std::initializer_list<T>;
55 
56  using keyType = typename mapType::key_type;
57 
58  using mappedType = typename mapType::mapped_type;
59 
60  using valueType = typename mapType::value_type;
61 
62  // - type info
63  TypeInfoTemplateNV11("Map", Key);
64 
66 
67  // Empty Map
68  Map()
69  {}
70 
71  // - with initList
73  :
74  mapType(lst)
75  {}
76 
77  // - Copy construct
78  Map(const MapType & src)
79  :
80  mapType(src)
81  {}
82 
83  // - Move construct
84  Map( MapType&& src)
85  :
86  mapType(std::move(src))
87  {}
88 
89  // - Copy assignment
90  MapType& operator=(const MapType& rhs)
91  {
92  mapType::operator=(rhs);
93  return *this;
94  }
95 
96  // - Move assignment
98  {
99  mapType::operator=( std::move(rhs));
100  return *this;
101  }
102 
104  {
105  return makeUnique<MapType>(*this);
106  }
107 
109  {
110  return new MapType(*this);
111  }
112 
114  {
115  this->clear();
116  }
117 
118 
120 
121  // Insert an item with copy operation
122  bool insertIf(const keyType& k, const mappedType & v);
123 
124  // insert an item with move operation
125  bool insertIf( keyType&& k, mappedType && v);
126 
127  // search for a key
128  bool search(const keyType k) const;
129 
130  std::pair<iterator, bool> findIf(const keyType& k);
131 
132  const std::pair<constIterator, bool> findIf(const keyType& k) const;
133 
134 };
135 
136 
137 template<typename T>
139 
140 template<typename T>
142 
143 template<typename T>
145 
146 template<typename T>
148 
149 template<typename T>
151 
152 
153 
154 template<typename T>
155 inline iOstream& printKeys(iOstream& os, const wordMap<T> & m);
156 
157 template<typename T>
158 inline iOstream& printKeys(iOstream& os, const uint64Map<T> & m);
159 
160 template<typename T>
161 inline iOstream& printKeys(iOstream& os, const uint32Map<T> & m);
162 
163 template<typename T>
164 inline iOstream& printKeys(iOstream& os, const int32Map<T> & m);
165 
166 template<typename T>
167 inline iOstream& printKeys(iOstream& os, const int64Map<T> & m);
168 
169 
170 #include "MapI.hpp"
171 
172 } // pFlow
173 
174 #endif
pFlow::Map::Map
Map(const MapType &src)
Definition: Map.hpp:78
pFlow::Map< pFlow::IOobject * >::constReference
typename mapType::const_reference constReference
Definition: Map.hpp:52
pFlow::Map< pFlow::IOobject * >::iterator
typename mapType::iterator iterator
Definition: Map.hpp:46
pFlow::Map::~Map
~Map()
Definition: Map.hpp:113
pFlow::Map< pFlow::IOobject * >::mapType
std::map< pFlow::IOobject *, T, std::less< pFlow::IOobject * > > mapType
Definition: Map.hpp:44
pFlow::Map::Map
Map(initList lst)
Definition: Map.hpp:72
types.hpp
pFlow::Map::TypeInfoTemplateNV11
TypeInfoTemplateNV11("Map", Key)
pFlow::Map::operator=
MapType & operator=(const MapType &rhs)
Definition: Map.hpp:90
pFlow::Map< pFlow::IOobject * >::initList
typename std::initializer_list< T > initList
Definition: Map.hpp:54
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::Map::clone
uniquePtr< MapType > clone() const
Definition: Map.hpp:103
pFlow::Map< pFlow::IOobject * >::mappedType
typename mapType::mapped_type mappedType
Definition: Map.hpp:58
pFlow
Definition: demGeometry.hpp:27
pFlow::Map::Map
Map(MapType &&src)
Definition: Map.hpp:84
pFlow::Map< pFlow::IOobject * >::keyType
typename mapType::key_type keyType
Definition: Map.hpp:56
pFlow::Map::Map
Map()
Definition: Map.hpp:68
pFlow::Map< pFlow::IOobject * >::reference
typename mapType::reference reference
Definition: Map.hpp:50
pFlow::Map< pFlow::IOobject * >::constIterator
typename mapType::const_iterator constIterator
Definition: Map.hpp:48
pFlow::Map::insertIf
bool insertIf(const keyType &k, const mappedType &v)
Definition: MapI.hpp:23
pFlow::Map< pFlow::IOobject * >::valueType
typename mapType::value_type valueType
Definition: Map.hpp:60
pFlow::Map::findIf
std::pair< iterator, bool > findIf(const keyType &k)
Definition: MapI.hpp:47
pFlow::Map::MapType
Map< Key, T, Compare > MapType
Definition: Map.hpp:42
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlow::Map
Definition: Map.hpp:36
pFlow::Map::clonePtr
MapType * clonePtr() const
Definition: Map.hpp:108
pFlow::Map::search
bool search(const keyType k) const
Definition: MapI.hpp:40
iOstream.hpp
MapI.hpp
m
uint32 m
Definition: NBSLoop.hpp:22
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::Map::operator=
MapType & operator=(MapType &&rhs)
Definition: Map.hpp:97