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) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
56 #ifndef ENGINE_BUFFHANDLE_H
57 #define ENGINE_BUFFHANDLE_H
58 
59 
60 #include "lib/error.hpp"
61 #include "lib/hash-value.h"
62 #include "steam/streamtype.hpp"
63 
64 
65 namespace steam {
66 namespace engine {
67  namespace error = lumiera::error;
68 
69  using lib::HashVal;
70 
71  class BuffHandle;
72  class BufferProvider;
73 
74 
75 
86  {
87  protected:
88  BufferProvider* provider_;
89  HashVal subClassification_;
90 
91  BufferDescriptor(BufferProvider& manager, HashVal detail)
92  : provider_(&manager)
93  , subClassification_(detail)
94  { }
95 
96  friend class BufferProvider;
97  friend class BuffHandle;
98 
99  public:
100  // using standard copy operations
101 
102  bool verifyValidity() const;
103  size_t determineBufferSize() const;
104 
105  operator HashVal() const { return subClassification_; }
106  };
107 
108 
109 
110 
116  {
118 
119  BufferDescriptor descriptor_;
120  Buff* pBuffer_;
121 
122 
123  public:
124  typedef Buff* PBuff;
125 
128  BuffHandle(BufferDescriptor const& typeInfo, void* storage = 0)
129  : descriptor_(typeInfo)
130  , pBuffer_(static_cast<PBuff>(storage))
131  { }
132 
133  // using standard copy operations
134 
135  explicit operator bool() const { return isValid(); }
136 
137 
138  void emit();
139  void release();
140 
141 
142  template<typename BU>
143  BU& create();
144 
145  template<typename BU>
146  BU& accessAs();
147 
148 
151  Buff&
152  operator* () const
153  {
154  ENSURE (pBuffer_);
155  return *pBuffer_;
156  }
157 
158  bool
159  isValid() const
160  {
161  return bool(pBuffer_)
162  && descriptor_.verifyValidity();
163  }
164 
165  HashVal
166  entryID() const
167  {
168  return HashVal(descriptor_);
169  }
170 
171  size_t
172  size() const
173  {
174  return descriptor_.determineBufferSize();
175  }
176 
177  private:
178  template<typename BU>
179  void takeOwnershipFor();
180  void takeOwnershipFor(BufferDescriptor const& type);
181 
182  void emergencyCleanup();
183  };
184 
185 
186 
187 
188 }} // namespace steam::engine
189 #endif
Framework for classification of media streams.
Steam-Layer implementation namespace root.
BuffHandle(BufferDescriptor const &typeInfo, void *storage=0)
Definition: buffhandle.hpp:128
An opaque descriptor to identify the type and further properties of a data buffer.
Definition: buffhandle.hpp:85
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:115
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
Interface: a facility providing and managing working buffers for media calculations.
placeholder type for the contents of a data buffer.
Definition: streamtype.hpp:121