stromx  0.8.0
ReadAccess.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_READACCESS_H
18 #define STROMX_RUNTIME_READACCESS_H
19 
20 #include <memory>
21 #include "stromx/runtime/Data.h"
22 #include "stromx/runtime/DataContainer.h"
23 #include "stromx/runtime/Exception.h"
24 
25 namespace stromx
26 {
27  namespace runtime
28  {
29  namespace impl
30  {
31  class ReadAccessImpl;
32  }
33 
40  class STROMX_RUNTIME_API ReadAccess
41  {
42  public:
45 
53  explicit ReadAccess(const DataContainer & data);
54 
65  ReadAccess(const DataContainer & data, const unsigned int timeout);
66 
68  bool empty() const { return m_impl.get() == 0; }
69 
76  template<typename data_t>
77  const data_t & get() const
78  {
79  try
80  {
81  return data_cast<data_t>(get());
82  }
83  catch(std::bad_cast &)
84  {
85  throw BadCast();
86  }
87  }
88 
94  const Data & get() const;
95 
97  void release();
98 
99  private:
100  std::tr1::shared_ptr<impl::ReadAccessImpl> m_impl;
101  };
102  }
103 }
104 
105 #endif // STROMX_RUNTIME_READACCESS_H
ReadAccess()
Definition: ReadAccess.h:44
Abstract data object.
Definition: Data.h:53
Container which manages the life-cycle of data objects.
Definition: DataContainer.h:43
Read access to a data container.
Definition: ReadAccess.h:40
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
bool empty() const
Definition: ReadAccess.h:68
An impossible cast was attempted.
Definition: Exception.h:183
const data_t & data_cast(ConstDataRef &data)
Definition: ConstDataRef.h:97