Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
blockallocator.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 <cstdint>
11#include <list>
12#include <memory>
13#include <utility>
14
15#include <scroom/interface.hh>
16
18{
19 namespace RawPageData
20 {
21 using Ptr = std::shared_ptr<uint8_t>;
22 using WeakPtr = std::weak_ptr<uint8_t>;
23 } // namespace RawPageData
24
25 class BlockInterface;
26
27 class Page
28 {
29 private:
30 std::shared_ptr<BlockInterface> bi;
31 size_t id;
32
33 public:
34 Page(std::shared_ptr<BlockInterface> bi, size_t id);
35
37 };
38
39 using PageList = std::list<Page>;
40
41 class BlockInterface : private Interface
42 {
43 public:
44 using Ptr = std::shared_ptr<BlockInterface>;
45 using WeakPtr = std::weak_ptr<BlockInterface>;
46
47 protected:
48 virtual RawPageData::Ptr get(size_t id) = 0;
49
50 public:
51 virtual PageList getPages() = 0;
52
53 friend class Page;
54 };
55
57 {
58 public:
59 using Ptr = std::shared_ptr<BlockFactoryInterface>;
60
61 virtual BlockInterface::Ptr create(size_t count, size_t size) = 0;
62 };
63
65
67 // implementation
68
69 inline Page::Page(BlockInterface::Ptr bi_, size_t id_)
70 : bi(std::move(bi_))
71 , id(id_)
72 {
73 }
74
75 inline RawPageData::Ptr Page::get() { return bi->get(id); }
76} // namespace Scroom::MemoryBlocks
Definition interface.hh:11
Definition blockallocator.hh:57
std::shared_ptr< BlockFactoryInterface > Ptr
Definition blockallocator.hh:59
virtual BlockInterface::Ptr create(size_t count, size_t size)=0
Definition blockallocator.hh:42
std::weak_ptr< BlockInterface > WeakPtr
Definition blockallocator.hh:45
virtual RawPageData::Ptr get(size_t id)=0
std::shared_ptr< BlockInterface > Ptr
Definition blockallocator.hh:44
Definition blockallocator.hh:28
std::shared_ptr< BlockInterface > bi
Definition blockallocator.hh:30
Page(std::shared_ptr< BlockInterface > bi, size_t id)
Definition blockallocator.hh:69
RawPageData::Ptr get()
Definition blockallocator.hh:75
size_t id
Definition blockallocator.hh:31
std::weak_ptr< uint8_t > WeakPtr
Definition blockallocator.hh:22
std::shared_ptr< uint8_t > Ptr
Definition blockallocator.hh:21
Definition blockallocator.hh:18
std::list< Page > PageList
Definition blockallocator.hh:39
BlockFactoryInterface::Ptr getBlockFactoryInterface()
Definition swapbasedblockallocator.cc:112
STL namespace.
const size_t count
Definition pageprovider-tests.cc:21
BlockInterface::Ptr bi
Definition swap-block-allocator-tests.cc:24