stromx  0.8.0
ConstDataRef.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_CONSTDATAREF_H
18 #define STROMX_RUNTIME_CONSTDATAREF_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  class DataRef;
34 
44  class STROMX_RUNTIME_API ConstDataRef : public DataInterface
45  {
46  friend class DataRefTest;
47 
48  public:
54 
59  explicit ConstDataRef(const Data* data);
60 
65  explicit ConstDataRef(const DataRef & dataRef);
66 
68  operator const Data&() { return *m_data; }
69 
74  bool isNull() const { return bool(m_data); }
75 
76  virtual const Version & version() const;
77  virtual const std::string & type() const;
78  virtual const std::string & package() const;
79  virtual const VariantHandle & variant() const;
80 
81  bool isVariant(const VariantInterface & v) const;
82  virtual Data* clone() const;
83 
84  virtual void serialize(OutputProvider & out) const;
85  virtual void deserialize(InputProvider & in, const Version & version);
86 
87  private:
88  std::tr1::shared_ptr<const Data> m_data;
89  };
90 
96  template<typename data_t>
97  const data_t & data_cast(ConstDataRef & data)
98  {
99  return data_cast<data_t>((const Data &)(data));
100  }
101  }
102 }
103 
104 #endif // STROMX_RUNTIME_CONSTDATAREF_H
A version of an operator or data type.
Definition: Version.h:46
Abstract data object.
Definition: Data.h:53
Definition: VariantHandle.h:34
Reference to a data object.
Definition: DataRef.h:48
ConstDataRef()
Definition: ConstDataRef.h:53
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
Version version()
Returns the version of the stromx runtime library.
Definition: Runtime.cpp:54
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
bool isNull() const
Definition: ConstDataRef.h:74
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