Scroom  0.14
blockallocator.hh
Go to the documentation of this file.
1 /*
2  * Scroom - Generic viewer for 2D data
3  * Copyright (C) 2009-2022 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 <utility>
13 
14 #include <boost/shared_ptr.hpp>
15 #include <boost/weak_ptr.hpp>
16 
17 #include <scroom/interface.hh>
18 
20 {
21  namespace RawPageData
22  {
23  using Ptr = boost::shared_ptr<uint8_t>;
24  using WeakPtr = boost::weak_ptr<uint8_t>;
25  } // namespace RawPageData
26 
27  class BlockInterface;
28 
29  class Page
30  {
31  private:
32  boost::shared_ptr<BlockInterface> bi;
33  size_t id;
34 
35  public:
36  Page(boost::shared_ptr<BlockInterface> bi, size_t id);
37 
39  };
40 
41  using PageList = std::list<Page>;
42 
43  class BlockInterface : private Interface
44  {
45  public:
46  using Ptr = boost::shared_ptr<BlockInterface>;
47  using WeakPtr = boost::weak_ptr<BlockInterface>;
48 
49  protected:
50  virtual RawPageData::Ptr get(size_t id) = 0;
51 
52  public:
53  virtual PageList getPages() = 0;
54 
55  friend class Page;
56  };
57 
59  {
60  public:
61  using Ptr = boost::shared_ptr<BlockFactoryInterface>;
62 
63  virtual BlockInterface::Ptr create(size_t count, size_t size) = 0;
64  };
65 
67 
69  // implementation
70 
71  inline Page::Page(BlockInterface::Ptr bi_, size_t id_)
72  : bi(std::move(bi_))
73  , id(id_)
74  {
75  }
76 
77  inline RawPageData::Ptr Page::get() { return bi->get(id); }
78 } // namespace Scroom::MemoryBlocks
Scroom::MemoryBlocks::BlockFactoryInterface::create
virtual BlockInterface::Ptr create(size_t count, size_t size)=0
Scroom::MemoryBlocks::Page
Definition: blockallocator.hh:29
Scroom::MemoryBlocks::BlockInterface
Definition: blockallocator.hh:43
Scroom::MemoryBlocks::BlockInterface::getPages
virtual PageList getPages()=0
Scroom::MemoryBlocks::Page::id
size_t id
Definition: blockallocator.hh:33
Scroom::MemoryBlocks::BlockInterface::WeakPtr
boost::weak_ptr< BlockInterface > WeakPtr
Definition: blockallocator.hh:47
Scroom::MemoryBlocks::RawPageData::Ptr
boost::shared_ptr< uint8_t > Ptr
Definition: blockallocator.hh:23
Scroom::MemoryBlocks::RawPageData::WeakPtr
boost::weak_ptr< uint8_t > WeakPtr
Definition: blockallocator.hh:24
Scroom::MemoryBlocks::BlockInterface::Ptr
boost::shared_ptr< BlockInterface > Ptr
Definition: blockallocator.hh:46
Scroom::MemoryBlocks::PageList
std::list< Page > PageList
Definition: blockallocator.hh:41
Scroom::MemoryBlocks::getBlockFactoryInterface
BlockFactoryInterface::Ptr getBlockFactoryInterface()
Definition: swapbasedblockallocator.cc:112
Scroom::MemoryBlocks::BlockInterface::get
virtual RawPageData::Ptr get(size_t id)=0
Scroom::MemoryBlocks::Page::Page
Page(boost::shared_ptr< BlockInterface > bi, size_t id)
Definition: blockallocator.hh:71
Scroom::MemoryBlocks
Definition: blockallocator.hh:19
Scroom::MemoryBlocks::Page::bi
boost::shared_ptr< BlockInterface > bi
Definition: blockallocator.hh:32
Interface
Definition: interface.hh:10
Scroom::MemoryBlocks::BlockFactoryInterface::Ptr
boost::shared_ptr< BlockFactoryInterface > Ptr
Definition: blockallocator.hh:61
Scroom::MemoryBlocks::Page::get
RawPageData::Ptr get()
Definition: blockallocator.hh:77
Scroom::MemoryBlocks::BlockFactoryInterface
Definition: blockallocator.hh:58
interface.hh