Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
bookkeeping.hh
Go to the documentation of this file.
1/*
2 * Scroom - Generic viewer for 2D data
3 * Copyright (C) 2009-2026 Kees-Jan Dijkzeul
4 *
5 * SPDX-License-Identifier: LGPL-2.1
6 */
7
8#pragma once
9
10#include <list>
11#include <map>
12#include <memory>
13
14#include <boost/noncopyable.hpp>
15
16#include <scroom/stuff.hh>
17#include <scroom/utilities.hh>
18
20{
23
24 namespace Detail
25 {
26 class TokenImpl;
27 class TokenAddition;
28
29 template <typename V>
30 class ValueType;
31
32 template <typename V>
33 class LValue;
34
35 template <typename K, typename V>
36 struct MapType
37 {
38 using Type = typename std::map<K, std::weak_ptr<Detail::ValueType<V>>>;
39 };
40
41 template <typename K, typename V>
42 struct MapType<std::weak_ptr<K>, V>
43 {
44 using Type = typename Scroom::Utils::WeakKeyMap<std::weak_ptr<K>, std::weak_ptr<Detail::ValueType<V>>>;
45 };
46
47 } // namespace Detail
48
49 class Token : public std::shared_ptr<Detail::TokenImpl>
50 {
51 public:
52 explicit Token(const std::shared_ptr<Detail::TokenImpl>& t);
53 explicit Token(const std::weak_ptr<Detail::TokenImpl>& t);
54 Token();
55 explicit Token(const Stuff& s);
56 explicit Token(const StuffList& l);
57
58 void add(const Stuff& s) const;
59 void add(const StuffList& l) const;
60 void merge(Token& rhs) const;
61 void merge(StuffList& l) const;
62
63 public:
64 Detail::TokenAddition operator+(const Stuff& rhs) const;
65 Token const& operator+=(const Stuff& rhs) const;
66 };
67
68 using WeakToken = std::weak_ptr<Detail::TokenImpl>;
69
70 template <typename K, typename V>
71 class MapBase
72 : public virtual Scroom::Utils::Base
73 , public boost::noncopyable
74 {
75 private:
77
79 mutable boost::mutex mut;
80
81 public:
82 Token reserve(const K& k);
83 Token reReserve(const K& k);
84 void remove(const K& k);
85 void remove(const K& k, const WeakToken& t);
86 Detail::LValue<V> at(const K& k);
87 void set(const K& k, const V& v);
88 V get(const K& k);
89 std::list<K> keys() const;
90 std::list<V> values() const;
91 };
92
93 template <typename K, typename V>
94 class Map : public MapBase<K, V>
95 {
96 public:
97 using Ptr = std::shared_ptr<Map<K, V>>;
98
99 public:
100 static Ptr create();
101 };
102
103} // namespace Scroom::Bookkeeping
104
barrier2 V()
Definition bookkeepingimpl.hh:139
Definition bookkeepingimpl.hh:18
Definition bookkeepingimpl.hh:51
Definition bookkeepingimpl.hh:118
Definition bookkeeping.hh:74
void remove(const K &k)
Definition bookkeepingimpl.hh:283
V get(const K &k)
Definition bookkeepingimpl.hh:332
MapType map
Definition bookkeeping.hh:78
Token reReserve(const K &k)
Definition bookkeepingimpl.hh:228
void set(const K &k, const V &v)
Definition bookkeepingimpl.hh:313
Detail::LValue< V > at(const K &k)
Definition bookkeepingimpl.hh:295
typename Detail::MapType< K, V >::Type MapType
Definition bookkeeping.hh:76
Token reserve(const K &k)
Definition bookkeepingimpl.hh:210
boost::mutex mut
Definition bookkeeping.hh:79
std::list< V > values() const
Definition bookkeepingimpl.hh:362
std::list< K > keys() const
Definition bookkeepingimpl.hh:350
Definition bookkeeping.hh:95
std::shared_ptr< Map< K, V > > Ptr
Definition bookkeeping.hh:97
static Ptr create()
Definition bookkeepingimpl.hh:424
Definition bookkeeping.hh:50
Token()
Definition bookkeepingimpl.hh:174
Token const & operator+=(const Stuff &rhs) const
Definition bookkeepingimpl.hh:201
void merge(Token &rhs) const
Definition bookkeepingimpl.hh:195
Detail::TokenAddition operator+(const Stuff &rhs) const
Definition bookkeepingimpl.hh:199
Definition utilities.hh:34
PageList const l
Definition compression-tests.cc:33
Definition color.hh:26
Definition bookkeeping.hh:20
std::weak_ptr< Detail::TokenImpl > WeakToken
Definition bookkeeping.hh:68
std::map< K, V, std::owner_less< K > > WeakKeyMap
Definition utilities.hh:118
std::shared_ptr< void > Stuff
Definition stuff.hh:17
std::list< Stuff > StuffList
Definition stuff.hh:19
STL namespace.
typename Scroom::Utils::WeakKeyMap< std::weak_ptr< K >, std::weak_ptr< Detail::ValueType< V > > > Type
Definition bookkeeping.hh:44
Definition bookkeeping.hh:37
typename std::map< K, std::weak_ptr< Detail::ValueType< V > > > Type
Definition bookkeeping.hh:38
ThreadPool t(0)
t add()
BitmapSurface::Ptr const s
Definition transformpresentation_test.cc:70