Lumiera  0.pre.03
»edityourfreedom«
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 
50 #ifndef ENGINE_BUFFHANDLE_H
51 #define ENGINE_BUFFHANDLE_H
52 
53 
54 #include "lib/error.hpp"
55 #include "lib/hash-value.h"
56 #include "proc/streamtype.hpp"
57 
58 
59 namespace proc {
60 namespace engine {
61 
62  namespace error = lumiera::error;
63  using error::LERR_(LIFECYCLE);
64 
65  using lib::HashVal;
66 
67  class BuffHandle;
68  class BufferProvider;
69 
70 
71 
82  {
83  protected:
86 
88  : provider_(&manager)
89  , subClassification_(detail)
90  { }
91 
92  friend class BufferProvider;
93  friend class BuffHandle;
94 
95  public:
96  // using standard copy operations
97 
98  bool verifyValidity() const;
99  size_t determineBufferSize() const;
100 
101  operator HashVal() const { return subClassification_; }
102  };
103 
104 
105 
106 
112  {
114 
116  Buff* pBuffer_;
117 
118 
119  public:
120  typedef Buff* PBuff;
121 
124  BuffHandle(BufferDescriptor 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(BufferDescriptor const& type);
177 
178  void emergencyCleanup();
179  };
180 
181 
182 
183 
184 }} // namespace proc::engine
185 #endif
ChPredicate isValid(is_alnum() or is_any_of("-_.+$'()@"))
characters to be retained
Framework for classification of media streams.
HashVal entryID() const
Definition: buffhandle.hpp:162
placeholder type for the contents of a data buffer.
Definition: streamtype.hpp:121
BufferDescriptor(BufferProvider &manager, HashVal detail)
Definition: buffhandle.hpp:87
An opaque descriptor to identify the type and further properties of a data buffer.
Definition: buffhandle.hpp:81
Interface: a facility providing and managing working buffers for media calculations.
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:111
BuffHandle(BufferDescriptor const &typeInfo, void *storage=0)
Definition: buffhandle.hpp:124
#define LERR_(_NAME_)
Definition: error.hpp:58
Offset operator*(Offset const &distance, INT factor)
Definition: timevalue.hpp:341
StreamType::ImplFacade::DataBuffer Buff
Definition: buffhandle.hpp:113
Lumiera error handling (C++ interface).
Hash value types and utilities.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
BufferDescriptor descriptor_
Definition: buffhandle.hpp:115
ENSURE(r==&pq)