Lumiera  0.pre.03
»edit your freedom«
buffhandle.hpp
Go to the documentation of this file.
1 /*
2  BUFFHANDLE.hpp - Buffer handling support for the render engine
3 
4  Copyright (C)
5  2008, 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 
48 #ifndef ENGINE_BUFFHANDLE_H
49 #define ENGINE_BUFFHANDLE_H
50 
51 
52 #include "lib/error.hpp"
53 #include "lib/hash-value.h"
54 #include "steam/streamtype.hpp"
55 
56 
57 namespace steam {
58 namespace engine {
59  namespace error = lumiera::error;
60 
61  using lib::HashVal;
62 
63  class BuffHandle;
64  class BufferProvider;
65 
66 
67 
77  class BuffDescr
78  {
79  protected:
80  BufferProvider* provider_;
81  HashVal subClassification_;
82 
83  BuffDescr(BufferProvider& manager, HashVal detail)
84  : provider_(&manager)
85  , subClassification_(detail)
86  { }
87 
88  friend class BufferProvider;
89  friend class BuffHandle;
90 
91  public:
92  // using standard copy operations
93 
94  bool verifyValidity() const;
95  size_t determineBufferSize() const;
96 
97  operator HashVal() const { return subClassification_; }
98 
100  uint announce (uint count);
101  BuffHandle lockBuffer();
102  };
103 
104 
105 
106 
112  {
114 
115  BuffDescr descriptor_;
116  Buff* pBuffer_;
117 
118 
119  public:
120  typedef Buff* PBuff;
121 
124  BuffHandle(BuffDescr const& typeInfo, void* storage = 0)
125  : descriptor_(typeInfo)
126  , pBuffer_(static_cast<PBuff>(storage))
127  { }
128 
129  // using standard copy operations
130 
131  explicit operator bool() const { return isValid(); }
132 
133 
134  void emit();
135  void release();
136 
137 
138  template<typename BU>
139  BU& create();
140 
141  template<typename BU>
142  BU& accessAs();
143 
144 
147  Buff&
148  operator* () const
149  {
150  ENSURE (pBuffer_);
151  return *pBuffer_;
152  }
153 
154  bool
155  isValid() const
156  {
157  return bool(pBuffer_)
158  && descriptor_.verifyValidity();
159  }
160 
161  HashVal
162  entryID() const
163  {
164  return HashVal(descriptor_);
165  }
166 
167  size_t
168  size() const
169  {
170  return descriptor_.determineBufferSize();
171  }
172 
173  private:
174  template<typename BU>
175  void takeOwnershipFor();
176  void takeOwnershipFor(BuffDescr const& type);
177 
178  void emergencyCleanup();
179  };
180 
181 
182 
183 
184 }} // namespace steam::engine
185 #endif
Framework for classification of media streams.
An opaque descriptor to identify the type and further properties of a data buffer.
Definition: buffhandle.hpp:77
Steam-Layer implementation namespace root.
uint announce(uint count)
convenience shortcut to start a buffer handling cycle
BuffHandle(BuffDescr const &typeInfo, void *storage=0)
Definition: buffhandle.hpp:124
Lumiera error handling (C++ interface).
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
Interface: a facility providing and managing working buffers for media calculations.
placeholder type for the contents of a data buffer.
Definition: streamtype.hpp:112