stromx  0.8.0
DataRef.h
1 /*
2  * Copyright 2012 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_DATAREF_H
18 #define STROMX_RUNTIME_DATAREF_H
19 
20 #include "stromx/runtime/DataInterface.h"
21 
22 #ifdef __GNUG__
23  #include <tr1/memory>
24 #else
25  #include <memory>
26 #endif
27 
28 namespace stromx
29 {
30  namespace runtime
31  {
32  class Data;
33 
34  namespace impl
35  {
36  class SynchronizedOperatorKernel;
37  }
38 
48  class STROMX_RUNTIME_API DataRef : public DataInterface
49  {
50  friend class Data;
51  friend class ConstDataRef;
52 
53  public:
58  DataRef() {}
59 
64  explicit DataRef(Data* data);
65 
67  DataRef(const Data &data);
68 
70  operator Data&() { return *m_data; }
71 
76  bool isNull() const { return 0 == m_data.get(); }
77 
79  const std::tr1::shared_ptr<Data> & ptr() const { return m_data; }
80 
81  virtual const Version & version() const;
82  virtual const std::string & type() const;
83  virtual const std::string & package() const;
84  virtual const VariantHandle & variant() const;
85 
86  bool isVariant(const VariantInterface & v) const;
87  virtual Data* clone() const;
88 
89  virtual void serialize(OutputProvider & out) const;
90  virtual void deserialize(InputProvider & in, const Version & version);
91 
92  private:
93  std::tr1::shared_ptr<Data> m_data;
94  };
95 
101  template<typename data_t>
102  data_t & data_cast(DataRef & data)
103  {
104  return data_cast<data_t>((Data &)(data));
105  }
106  }
107 }
108 
109 #endif // STROMX_RUNTIME_DATAREF_H
A version of an operator or data type.
Definition: Version.h:46
Abstract data object.
Definition: Data.h:53
Definition: VariantHandle.h:34
const std::tr1::shared_ptr< Data > & ptr() const
Definition: DataRef.h:79
Reference to a data object.
Definition: DataRef.h:48
Provides functions to serialize data to strings and files.
Definition: OutputProvider.h:27
Abstract description of a data variant.
Definition: VariantInterface.h:40
Provides functions to deserialize data from strings and files.
Definition: InputProvider.h:27
Reference to a constant data object.
Definition: ConstDataRef.h:44
DataRef()
Definition: DataRef.h:58
bool isNull() const
Definition: DataRef.h:76
Version version()
Returns the version of the stromx runtime library.
Definition: Runtime.cpp:54
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
Common interface of data objects or references to data objects.
Definition: DataInterface.h:32
const data_t & data_cast(ConstDataRef &data)
Definition: ConstDataRef.h:97