Lumiera  0.pre.03
»edit your freedom«
buffer-provider.hpp
Go to the documentation of this file.
1 /*
2  BUFFER-PROVIDER.hpp - Abstraction for Buffer management during playback/render
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 
32 #ifndef STEAM_ENGINE_BUFFR_PROVIDER_H
33 #define STEAM_ENGINE_BUFFR_PROVIDER_H
34 
35 
36 #include "lib/error.hpp"
37 #include "lib/symbol.hpp"
38 #include "lib/hash-value.h"
40 //#include "steam/engine/engine-ctx.hpp"
43 #include "lib/nocopy.hpp"
44 
45 #include <utility>
46 #include <memory>
47 
48 
49 namespace steam {
50 namespace engine {
51 
52  using lib::Literal;
53  using std::unique_ptr;
54  using std::forward;
55 
56 
57  class BufferMetadata;
58 
59 
60  LUMIERA_ERROR_DECLARE (BUFFER_MANAGEMENT);
61 
62 
77  {
78  unique_ptr<BufferMetadata> meta_;
79 
80 
81  protected: /* === for Implementation by concrete providers === */
82 
85 
86  BufferProvider (Literal implementationID);
87 
88  virtual uint prepareBuffers (uint count, HashVal typeID) =0;
89 
90  virtual BuffHandle provideLockedBuffer (HashVal typeID) =0;
91  virtual void mark_emitted (HashVal, LocalTag const&) =0;
92  virtual void detachBuffer (HashVal, LocalTag const&, Buff&) =0;
93 
94 
95  public:
96  virtual ~BufferProvider();
97 
98 
99  uint announce (uint count, BuffDescr const&);
100 
102  void emitBuffer (BuffHandle const&);
103  void releaseBuffer (BuffHandle const&);
104 
105  template<typename BU, typename...ARGS>
106  BuffHandle lockBufferFor (ARGS ...args);
107 
109  void attachTypeHandler (BuffHandle const& target, BuffDescr const& reference);
110 
111  void emergencyCleanup (BuffHandle const& target, bool invokeDtor =false);
112 
113 
115  BuffDescr getDescriptorFor(size_t storageSize=0);
116  BuffDescr getDescriptorFor(size_t storageSize, TypeHandler specialTreatment);
117 
118  template<typename BU, typename...ARGS>
119  BuffDescr getDescriptor (ARGS ...args);
120 
121 
122 
123  /* === API for BuffHandle internal access === */
124 
125  bool verifyValidity (BuffDescr const&) const;
126  size_t getBufferSize (HashVal typeID) const;
127 
128  protected:
129  BuffHandle buildHandle (HashVal typeID, Buff* storage, LocalTag const& =LocalTag::UNKNOWN);
130 
131  bool was_created_by_this_provider (BuffDescr const&) const;
132  };
133 
134 
135 
136 
137  /* === Implementation === */
138 
146  template<typename BU, typename...ARGS>
147  BuffHandle
149  {
150  BuffDescr attach_object_automatically = getDescriptor<BU> (forward<ARGS> (args)...);
151  return lockBuffer (attach_object_automatically);
152  }
153 
154 
159  template<typename BU, typename...ARGS>
160  BuffDescr
162  {
163  return getDescriptorFor (sizeof(BU), TypeHandler::create<BU> (forward<ARGS> (args)...));
164  }
165 
166 
167 }} // namespace steam::engine
168 #endif /*STEAM_ENGINE_BUFFR_PROVIDER_H*/
bool verifyValidity(BuffDescr const &) const
uint announce(uint count, BuffDescr const &)
BufferProvider API: declare in advance the need for working buffers.
void attachTypeHandler(BuffHandle const &target, BuffDescr const &reference)
allow for attaching and owing an object within an already created buffer
void releaseBuffer(BuffHandle const &)
BufferProvider API: declare done and detach.
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
A marker data type used in metadata / buffer management of the render engine.
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:76
void emergencyCleanup(BuffHandle const &target, bool invokeDtor=false)
An opaque descriptor to identify the type and further properties of a data buffer.
Definition: buffhandle.hpp:77
an opaque mark to be used by the BufferProvider implementation.
Steam-Layer implementation namespace root.
BuffDescr getDescriptorFor(size_t storageSize=0)
describe the kind of buffer managed by this provider
Mix-Ins to allow or prohibit various degrees of copying and cloning.
BuffDescr getDescriptor(ARGS ...args)
define a "buffer type" for automatically creating an instance of the template type embedded into the ...
Marker types to indicate a literal string and a Symbol.
LUMIERA_ERROR_DECLARE(BUFFER_MANAGEMENT)
Problem providing working buffers.
BuffHandle lockBuffer(BuffDescr const &)
BufferProvider API: retrieve a single buffer for exclusive use.
A front-end to support the buffer management within the render nodes.
Helper holding a pair of type-build-up and destruction functors.
BufferProvider(Literal implementationID)
build a new provider instance, managing a family of buffers.
Lumiera error handling (C++ interface).
BuffHandle lockBufferFor(ARGS ...args)
convenience shortcut: prepare and claim ("lock") a buffer suitable to hold an object of the given typ...
static const LocalTag UNKNOWN
Marker when no distinct local key is given.
Hash value types and utilities.
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:111
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:52
virtual ~BufferProvider()
this is an ABC
A pair of functors to maintain a datastructure within a buffer.
Interface: a facility providing and managing working buffers for media calculations.
BuffHandle buildHandle(HashVal typeID, Buff *storage, LocalTag const &=LocalTag::UNKNOWN)
callback from implementation to build and enrol a BufferHandle, to be returned to the client as resul...
void emitBuffer(BuffHandle const &)
BufferProvider API: state transition to emitted state.
placeholder type for the contents of a data buffer.
Definition: streamtype.hpp:112