stromx  0.8.0
WriteAccess.h
1 /*
2 * Copyright 2011 Matthias Fuchs
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #ifndef STROMX_RUNTIME_WRITEACCESS_H
18 #define STROMX_RUNTIME_WRITEACCESS_H
19 
20 #ifdef __GNUG__
21  #include <tr1/memory>
22 #else
23  #include <memory>
24 #endif
25 
26 #include "stromx/runtime/Data.h"
27 #include "stromx/runtime/DataContainer.h"
28 #include "stromx/runtime/Exception.h"
29 
30 namespace stromx
31 {
32  namespace runtime
33  {
34  namespace impl
35  {
36  class WriteAccessImpl;
37  }
38 
45  class STROMX_RUNTIME_API WriteAccess
46  {
47  public:
50 
59  explicit WriteAccess(const DataContainer & data);
60 
72  WriteAccess(const DataContainer & data, const unsigned int timeout);
73 
75  bool empty() const { return m_impl.get() == 0; }
76 
83  template<typename data_t>
84  data_t & get() const
85  {
86  try
87  {
88  return data_cast<data_t>(get());
89  }
90  catch(std::bad_cast &)
91  {
92  throw BadCast();
93  }
94  }
95 
101  Data & get() const;
102 
104  void release();
105 
106  private:
107  std::tr1::shared_ptr<impl::WriteAccessImpl> m_impl;
108  };
109  }
110 }
111 
112 #endif // STROMX_RUNTIME_WRITEACCESS_H
Abstract data object.
Definition: Data.h:53
Container which manages the life-cycle of data objects.
Definition: DataContainer.h:43
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
bool empty() const
Definition: WriteAccess.h:75
Write access to a data container.
Definition: WriteAccess.h:45
WriteAccess()
Definition: WriteAccess.h:49
An impossible cast was attempted.
Definition: Exception.h:183
const data_t & data_cast(ConstDataRef &data)
Definition: ConstDataRef.h:97