25# ifndef __BITPIT_LEVELSET_CACHE_HPP__
26# define __BITPIT_LEVELSET_CACHE_HPP__
28#include "levelSetCommon.hpp"
30#include "bitpit_common.hpp"
31#include "bitpit_containers.hpp"
32#include "bitpit_patchkernel.hpp"
51template<
typename key_t>
57 virtual std::unique_ptr<LevelSetCache<key_t>> clone()
const = 0;
59 virtual bool contains(
const key_t &key)
const = 0;
61 template<
typename Keys>
62 std::size_t
erase(
const Keys &keys);
63 virtual std::size_t
erase(
const key_t &key) = 0;
65 virtual void reserve(std::size_t n) = 0;
66 virtual void shrink_to_fit() = 0;
67 virtual void clear() = 0;
69 virtual bool isVolatile()
const = 0;
71 virtual void dump(std::ostream &stream) = 0;
72 virtual void restore(std::istream &stream) = 0;
75 virtual std::size_t getEntryBinarySize()
const = 0;
76 virtual void writeBuffer(
const std::vector<key_t> &keys,
SendBuffer &buffer)
const = 0;
77 virtual void readBuffer(
const std::vector<key_t> &keys,
RecvBuffer &buffer) = 0;
99template<
typename value_t>
114template<
typename value_t>
124 std::reference_wrapper<const value_t> m_value;
138 static const std::vector<bool> m_dummyVector;
142 bool m_useVectorValue;
143 std::vector<bool>::const_reference m_vectorValue;
153template<
typename key_t,
typename value_t>
159 virtual Entry findEntry(
const key_t &key)
const = 0;
160 virtual Entry insertEntry(
const key_t &key,
const value_t &value) = 0;
161 virtual Entry insertEntry(
const key_t &key, value_t &&value) = 0;
173template<
typename key_t,
typename container_t,
typename value_t =
typename container_t::value_type,
typename reference_t = value_t &,
typename const_reference_t = const value_t &>
179 typedef container_t container_type;
180 typedef const key_t &key_type;
181 typedef value_t value_type;
183 typedef reference_t reference;
184 typedef const_reference_t const_reference;
186 typedef typename container_t::iterator iterator;
187 typedef typename container_t::const_iterator const_iterator;
192 const_iterator
cbegin()
const;
193 const_iterator
cend()
const;
195 const_iterator
begin()
const;
196 const_iterator
end()
const;
198 bool contains(
const key_t &key)
const override;
204 reference
at(
const key_t &key);
205 const_reference
at(
const key_t &key)
const;
208 const_reference
operator[](
const key_t &key)
const;
210 virtual iterator find(
const key_t &key) = 0;
211 virtual const_iterator find(
const key_t &key)
const = 0;
213 virtual iterator insert(
const key_t &key,
const value_t &value) = 0;
214 virtual iterator insert(
const key_t &key, value_t &&value) = 0;
223 container_t m_container;
225 template<
typename... Args>
228 virtual key_t getKey(
const const_iterator &itr)
const = 0;
229 virtual reference getValue(
const iterator &itr)
const = 0;
230 virtual const_reference getValue(
const const_iterator &itr)
const = 0;
241template<
typename key_t,
typename container_t>
247 typedef typename Base::key_type key_type;
248 typedef typename Base::value_type value_type;
249 typedef typename Base::container_type container_type;
251 typedef typename Base::iterator iterator;
252 typedef typename Base::const_iterator const_iterator;
254 typedef typename Base::reference reference;
255 typedef typename Base::const_reference const_reference;
259template<
typename key_t,
typename value_t>
261 std::unordered_map<key_t, value_t>,
262 typename std::unordered_map<key_t, value_t>::mapped_type>
266 std::unordered_map<key_t, value_t>,
267 typename std::unordered_map<key_t, value_t>::mapped_type>
270 typedef typename Base::key_type key_type;
271 typedef typename Base::value_type value_type;
272 typedef typename Base::container_type container_type;
274 typedef typename Base::iterator iterator;
275 typedef typename Base::const_iterator const_iterator;
277 typedef typename Base::reference reference;
278 typedef typename Base::const_reference const_reference;
282 std::unique_ptr<LevelSetCache<key_t>> clone()
const override;
284 void reserve(std::size_t n)
override;
285 void shrink_to_fit()
override;
286 void clear()
override;
288 iterator find(
const key_t &key)
override;
289 const_iterator find(
const key_t &key)
const override;
291 iterator insert(
const key_t &key,
const value_t &value)
override;
292 iterator insert(
const key_t &key, value_t &&value)
override;
293 std::size_t
erase(
const key_t &key)
override;
295 bool isVolatile()
const override;
297 void dump(std::ostream &stream)
override;
298 void restore(std::istream &stream)
override;
301 key_t getKey(
const const_iterator &itr)
const override;
302 reference getValue(
const iterator &itr)
const override;
303 const_reference getValue(
const const_iterator &itr)
const override;
307template<
typename key_t,
typename value_t>
309 std::vector<value_t>,
310 typename std::vector<value_t>::value_type,
311 typename std::vector<value_t>::reference,
312 typename std::vector<value_t>::const_reference>
316 std::vector<value_t>,
317 typename std::vector<value_t>::value_type,
318 typename std::vector<value_t>::reference,
319 typename std::vector<value_t>::const_reference>
322 typedef typename Base::key_type key_type;
323 typedef typename Base::value_type value_type;
324 typedef typename Base::container_type container_type;
326 typedef typename Base::iterator iterator;
327 typedef typename Base::const_iterator const_iterator;
329 typedef typename Base::reference reference;
330 typedef typename Base::const_reference const_reference;
334 std::unique_ptr<LevelSetCache<key_t>> clone()
const override;
336 void reserve(std::size_t n)
override;
337 void shrink_to_fit()
override;
338 void clear()
override;
340 iterator find(
const key_t &key)
override;
341 const_iterator find(
const key_t &key)
const override;
343 iterator insert(
const key_t &key,
const value_t &value)
override;
344 iterator insert(
const key_t &key, value_t &&value)
override;
345 std::size_t
erase(
const key_t &key)
override;
347 bool isVolatile()
const override;
349 void dump(std::ostream &stream)
override;
350 void restore(std::istream &stream)
override;
353 key_t getKey(
const const_iterator &itr)
const override;
354 reference getValue(
const iterator &itr)
const override;
355 const_reference getValue(
const const_iterator &itr)
const override;
358 std::vector<bool> m_isCached;
361template<
typename key_t,
typename value_t>
363 PiercedVector<value_t, key_t>,
364 typename PiercedVector<value_t, key_t>::value_type,
365 typename PiercedVector<value_t, key_t>::reference,
366 typename PiercedVector<value_t, key_t>::const_reference>
376 typedef typename Base::key_type key_type;
377 typedef typename Base::value_type value_type;
378 typedef typename Base::container_type container_type;
380 typedef typename Base::iterator iterator;
381 typedef typename Base::const_iterator const_iterator;
383 typedef typename Base::reference reference;
384 typedef typename Base::const_reference const_reference;
388 std::unique_ptr<LevelSetCache<key_t>> clone()
const override;
390 void reserve(std::size_t n)
override;
391 void shrink_to_fit()
override;
392 void clear()
override;
394 iterator find(
const key_t &key)
override;
395 const_iterator find(
const key_t &key)
const override;
397 iterator insert(
const key_t &key,
const value_t &value)
override;
398 iterator insert(
const key_t &key, value_t &&value)
override;
399 std::size_t
erase(
const key_t &key)
override;
401 bool isVolatile()
const override;
403 void dump(std::ostream &stream)
override;
404 void restore(std::istream &stream)
override;
407 key_t getKey(
const const_iterator &itr)
const override;
408 reference getValue(
const iterator &itr)
const override;
409 const_reference getValue(
const const_iterator &itr)
const override;
412template<
typename key_t,
typename value_t>
414 PiercedStorage<value_t, key_t>,
415 typename PiercedStorage<value_t, key_t>::value_type,
416 typename PiercedStorage<value_t, key_t>::reference,
417 typename PiercedStorage<value_t, key_t>::const_reference>
427 typedef typename Base::key_type key_type;
428 typedef typename Base::value_type value_type;
429 typedef typename Base::container_type container_type;
431 typedef typename Base::iterator iterator;
432 typedef typename Base::const_iterator const_iterator;
434 typedef typename Base::reference reference;
435 typedef typename Base::const_reference const_reference;
439 std::unique_ptr<LevelSetCache<key_t>> clone()
const override;
441 void reserve(std::size_t n)
override;
442 void shrink_to_fit()
override;
443 void clear()
override;
445 iterator find(
const key_t &key)
override;
446 const_iterator find(
const key_t &key)
const override;
448 iterator insert(
const key_t &key,
const value_t &value)
override;
449 iterator insert(
const key_t &key, value_t &&value)
override;
450 std::size_t
erase(
const key_t &key)
override;
452 bool isVolatile()
const override;
454 void dump(std::ostream &stream)
override;
455 void restore(std::istream &stream)
override;
458 key_t getKey(
const const_iterator &itr)
const override;
459 reference getValue(
const iterator &itr)
const override;
460 const_reference getValue(
const const_iterator &itr)
const override;
473template<
typename key_t>
479 virtual std::unique_ptr<LevelSetCache<key_t>> create()
const = 0;
492template<
typename key_t,
typename value_t>
507template<
typename key_t,
typename container_t>
522template<
typename key_t,
typename container_t>
528 std::unique_ptr<LevelSetCache<key_t>> create()
const override;
532template<
typename key_t,
typename value_t>
538 std::unique_ptr<LevelSetCache<key_t>> create()
const override;
542template<
typename key_t,
typename value_t>
548 std::unique_ptr<LevelSetCache<key_t>> create()
const override;
552template<
typename key_t,
typename value_t>
558 std::unique_ptr<LevelSetCache<key_t>> create()
const override;
562template<
typename key_t,
typename value_t>
570 std::unique_ptr<LevelSetCache<key_t>> create()
const override;
589template<
typename key_t>
601 Item & operator=(
const Item &other);
602 Item & operator=(
Item &&other) =
default;
613 template<
typename value_t>
615 template<
typename value_t>
619 std::shared_ptr<LevelSetCacheFactory<key_t>> m_factory;
620 mutable std::unique_ptr<LevelSetCache<key_t>> m_cache;
625 typedef key_t key_type;
627 typedef std::vector<Item> Caches;
629 typedef typename Caches::iterator iterator;
630 typedef typename Caches::const_iterator const_iterator;
640 virtual std::unique_ptr<LevelSetCacheCollection<key_t>>
clone()
const;
645 const_iterator
begin()
const;
646 const_iterator
end()
const;
648 const_iterator
cbegin()
const;
649 const_iterator
cend()
const;
651 std::size_t
size()
const;
656 Item &
at(std::size_t index);
657 const Item &
at(std::size_t index)
const;
659 template<
typename container_t,
typename... Args>
660 std::size_t
insert(std::size_t index, Args&&... args);
661 void erase(std::size_t index);
675 typedef Base::key_type key_type;
679 template<
typename value_t>
684 template<
typename container_t,
typename... Args,
typename std::enable_if<std::is_same<bitpit::PiercedStorage<typename container_t::value_type>, container_t>::value>::type * =
nullptr>
685 std::size_t
insert(std::size_t index, Args&&... args);
686 template<
typename container_t,
typename... Args,
typename std::enable_if<!std::is_same<bitpit::PiercedStorage<typename container_t::value_type>, container_t>::value>::type * =
nullptr>
687 std::size_t
insert(std::size_t index, Args&&... args);
696#include "levelSetCache.tpp"
The class ElementCacheCollection allows to store a collection of caches for the elements of a mesh.
std::size_t insert(std::size_t index, Args &&... args)
ElementCacheCollection(const PiercedKernel< key_type > *kernel)
The class LevelSetCacheCollection::Item defines the items stored in a cache collection....
Item(const std::shared_ptr< LevelSetCacheFactory< key_t > > &factory=nullptr)
LevelSetCache< key_t > * getCache(bool allowCreation=true)
LevelSetCache< key_t > * createCache()
The class LevelSetCacheCollection allows to store a collection of caches.
std::size_t insert(std::size_t index, Args &&... args)
void erase(std::size_t index)
Caches m_caches
Caches owned by the collection.
virtual std::unique_ptr< LevelSetCacheCollection< key_t > > clone() const
const_iterator cend() const
Item & operator[](std::size_t index)
Item & at(std::size_t index)
static const std::size_t NULL_CACHE_ID
const_iterator cbegin() const
The class LevelSetCacheFactory provides basic functionalities for cache factories.
The class LevelSetCache is the base class for defining caches.
std::size_t erase(const Keys &keys)
The class LevelSetContainerBaseCacheFactory provides basic functionalities for cache factories.
The class LevelSetContainerBaseCache is the base class for defining caches that stores the values ins...
Entry findEntry(const key_t &key) const override
LevelSetContainerBaseCache(Args &&... args)
void writeBuffer(const std::vector< key_t > &ids, SendBuffer &buffer) const override
const_iterator cbegin() const
Entry insertEntry(const key_t &key, const value_t &value) override
std::size_t getEntryBinarySize() const override
reference at(const key_t &key)
reference operator[](const key_t &key)
void readBuffer(const std::vector< key_t > &ids, RecvBuffer &buffer) override
const_iterator cend() const
bool contains(const key_t &key) const override
The class LevelSetContainerCacheFactory provides basic functionalities for cache factories.
The class LevelSetContainerCache is the class for defining caches that stores the values inside a con...
LevelSetValueCacheBaseEntry(bool valid)
static const value_t m_dummyValue
The class LevelSetValueCacheEntry allows to get read-only access to a value stored in the cache.
LevelSetValueCacheEntry()
const value_t & operator*() const
The class LevelSetValueCacheFactory provides basic functionalities for cache factories.
The class LevelSetCache is the base class for defining caches that store values.
Metafunction for generating a pierced kernel.
Metafunction for generating a pierced storage.
container_t::reference reference
container_t::const_reference const_reference
Metafunction for generating a pierced vector.
PiercedVectorStorage< value_t, id_t >::value_type value_type
Buffer to be used for receive communications.
Buffer to be used for send communications.