Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
tracking-heap-block-provider.hpp
Go to the documentation of this file.
1/*
2 TRACKING-HEAP-BLOCK-PROVIDER.hpp - plain heap allocating BufferProvider implementation for tests
3
4 Copyright (C)
5 2011, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
33#ifndef STEAM_ENGINE_TRACKING_HEAP_BLOCK_PROVIDER_H
34#define STEAM_ENGINE_TRACKING_HEAP_BLOCK_PROVIDER_H
35
36
37#include "lib/error.hpp"
38#include "lib/hash-value.h"
41
42#include <unordered_map>
43#include <memory>
44
45
46namespace steam {
47namespace engine {
48
49 namespace error = lumiera::error;
50
52 using lib::HashVal;
53
54 namespace diagn {
55
56 using std::unique_ptr;
57
58
64 class Block
66 {
67 unique_ptr<char[]> storage_;
68
70
71 public:
72 explicit
73 Block(size_t bufferSize)
74 : storage_(bufferSize? new char[bufferSize] : NULL)
75 , was_released_(false)
76 { }
77
78 bool
79 was_used() const
80 {
81 return bool(storage_);
82 }
83
84 bool
85 was_closed() const
86 {
87 return was_released_;
88 }
89
90 void*
92 {
93 REQUIRE (storage_, "Block was never prepared for use");
94 return storage_.get();
95 }
96
97 void
99 {
100 was_released_ = true;
101 }
102 };
103
104 class BlockPool;
105
106 using PoolTable = std::unordered_map<HashVal,BlockPool>;
107 }
108
109
120 : public BufferProvider
121 {
122 unique_ptr<diagn::PoolTable> pool_;
124
125 public:
126 /* === BufferProvider interface === */
127
128 virtual uint prepareBuffers (uint count, HashVal typeID) override;
129 virtual BuffHandle provideLockedBuffer (HashVal typeID) override;
130 virtual void mark_emitted (HashVal, LocalTag const&) override;
131 virtual void detachBuffer (HashVal, LocalTag const&, Buff&) override;
132
133 public:
136
137 size_t emittedCnt() const;
138
139 diagn::Block& access_emitted (uint bufferID);
140
141 template<typename TY>
142 TY& accessAs (uint bufferID);
143
144 void markAllEmitted();
145
146 private:
147 bool withinOutputSequence (uint bufferID) const;
148 diagn::BlockPool& getBlockPoolFor (HashVal typeID);
149 diagn::Block* locateBlock (HashVal typeID, void*);
150 diagn::Block* searchInOutSeqeuence (void* storage);
151 };
152
153
154
163 template<typename TY>
164 TY&
166 {
167 if (!withinOutputSequence (bufferID))
168 throw error::Invalid ("Buffer with the given ID not yet emitted");
169
170 diagn::Block& memoryBlock = access_emitted (bufferID);
171 TY* converted = std::launder (reinterpret_cast<TY*> (memoryBlock.accessMemory()));
172
173 REQUIRE (converted);
174 return *converted;
175 }
176
177
178
179
180}} // namespace steam::engine
181#endif
Abstraction to represent buffer management and lifecycle within the render engine.
Simple vector based collection of pointers, managing lifecycle of the pointed-to objects.
placeholder type for the contents of a data buffer.
Handle for a buffer for processing data, abstracting away the actual implementation.
Interface: a facility providing and managing working buffers for media calculations.
an opaque mark to be used by the BufferProvider implementation.
simple BufferProvider implementation with additional allocation tracking.
diagn::Block * locateBlock(HashVal typeID, void *)
virtual void mark_emitted(HashVal, LocalTag const &) override
TY & accessAs(uint bufferID)
convenience shortcut: access the buffer with the given number, then try to convert the raw memory to ...
virtual uint prepareBuffers(uint count, HashVal typeID) override
virtual BuffHandle provideLockedBuffer(HashVal typeID) override
virtual void detachBuffer(HashVal, LocalTag const &, Buff &) override
mark a buffer as officially discarded
Helper for implementing a diagnostic BufferProvider: A block of heap allocated storage,...
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Lumiera error handling (C++ interface).
Hash value types and utilities.
unsigned int uint
Definition integral.hpp:29
return NULL
Definition llist.h:586
size_t HashVal
a STL compatible hash value
Definition hash-value.h:52
LumieraError< LERR_(INVALID)> Invalid
Definition error.hpp:211
std::unordered_map< HashVal, BlockPool > PoolTable
Steam-Layer implementation namespace root.
Managing lifecycle for a collection of objects.