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
37 explicit DistantObject(T* obj):_object(obj) {}
38
40 DistantObject():_object(nullptr) {}
41
44 _object = obj;
45 return *this;
46 }
47
49 bool isNull() const { return _object==nullptr; }
50
51 bool operator==(const DistantObject<T>& other) const {
52 return _object == other._object;
53 }
54
55 bool operator!=(const DistantObject<T>& other) const {
56 return _object != other._object;
57 }
58
59 bool operator!() const
60 {
61 return _object== nullptr;
62 }
63
64 inline friend bool operator==(const DistantObject<T>& lhs,
65 const T* rhs)
66 {
67 return lhs._object == rhs;
68 }
69 inline friend bool operator==(const T* lhs,
70 const DistantObject<T>& rhs)
71 {
72 return lhs == rhs._object;
73 }
74 inline friend bool operator!=(const DistantObject<T>& lhs,
75 const T* rhs)
76 {
77 return lhs._object != rhs;
78 }
79
80 inline friend bool operator!=(const T* lhs,
81 const DistantObject<T>& rhs)
82 {
83 return lhs != rhs._object;
84 }
85
86private:
88 T* _object;
89};
90
94{
95public:
97 template <typename Distant>
98 static typename Distant::Type* get(const Distant& distant) { return distant._object; }
99};
100
102
103#endif
104
105
@ T
The DistantObjectAccessor can be used to get the value stored in a DistantObject, it should only be u...
static Distant::Type * get(const Distant &distant)
Get 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 if the object is NULL.
bool operator==(const DistantObject< T > &other) const
DistantObject(T *obj)
Construct a new distant object (make it explicit to avoid auto-conversion).
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.