MeVisLab Toolbox Reference
mlDistantObject.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2009, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_DISTANT_OBJECT_H
14#define ML_DISTANT_OBJECT_H
15
16// Local includes
18
20
24
29template <typename T>
31{
32public:
34 typedef T Type;
35
38 explicit DistantObject(T* obj):_object(obj) {}
39
41 DistantObject():_object(nullptr) {}
42
45 _object = obj;
46 return *this;
47 }
48
50 bool isNull() const { return _object==nullptr; }
51
52 bool operator==(const DistantObject<T>& other) const {
53 return _object == other._object;
54 }
55
56 bool operator!=(const DistantObject<T>& other) const {
57 return _object != other._object;
58 }
59
60 bool operator!() const
61 {
62 return _object== nullptr;
63 }
64
65 inline friend bool operator==(const DistantObject<T>& lhs,
66 const T* rhs)
67 {
68 return lhs._object == rhs;
69 }
70 inline friend bool operator==(const T* lhs,
71 const DistantObject<T>& rhs)
72 {
73 return lhs == rhs._object;
74 }
75 inline friend bool operator!=(const DistantObject<T>& lhs,
76 const T* rhs)
77 {
78 return lhs._object != rhs;
79 }
80
81 inline friend bool operator!=(const T* lhs,
82 const DistantObject<T>& rhs)
83 {
84 return lhs != rhs._object;
85 }
86
87private:
89 T* _object;
90};
91
95{
96public:
98 template <typename Distant>
99 static typename Distant::Type* get(const Distant& distant) { return distant._object; }
100};
101
103
104#endif
105
106
@ T
The DistantObjectAccessor can be used to get the value stored in a DistantObject.
static Distant::Type * get(const Distant &distant)
Returns access to the typed object pointer T* stored in DistantObject<T>.
A DistantObject stores the pointer to an object of type T and forbids direct access to the stored poi...
friend bool operator==(const T *lhs, const DistantObject< T > &rhs)
DistantObject & operator=(T *obj)
Assignment from T*.
friend bool operator!=(const T *lhs, const DistantObject< T > &rhs)
bool isNull() const
Returns whether the object is NULL.
bool operator==(const DistantObject< T > &other) const
DistantObject(T *obj)
Constructs a new distant object.
bool operator!=(const DistantObject< T > &other) const
bool operator!() const
DistantObject()
Creates empty distant object.
friend bool operator==(const DistantObject< T > &lhs, const T *rhs)
friend bool operator!=(const DistantObject< T > &lhs, const T *rhs)
T Type
The type of the stored object.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.