MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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> class DistantObject
30{
31public:
33 typedef T Type;
34
37 explicit DistantObject(T* obj)
38 : _object(obj)
39 {}
40
43 : _object(nullptr)
44 {}
45
48 {
49 _object = obj;
50 return *this;
51 }
52
54 bool isNull() const
55 {
56 return _object == nullptr;
57 }
58
60 {
61 return _object == other._object;
62 }
63
65 {
66 return _object != other._object;
67 }
68
69 bool operator!() const
70 {
71 return _object == nullptr;
72 }
73
74 inline friend bool operator==(const DistantObject<T>& lhs, const T* rhs)
75 {
76 return lhs._object == rhs;
77 }
78 inline friend bool operator==(const T* lhs, const DistantObject<T>& rhs)
79 {
80 return lhs == rhs._object;
81 }
82 inline friend bool operator!=(const DistantObject<T>& lhs, const T* rhs)
83 {
84 return lhs._object != rhs;
85 }
86
87 inline friend bool operator!=(const T* lhs, const DistantObject<T>& rhs)
88 {
89 return lhs != rhs._object;
90 }
91
92private:
94 T* _object;
95};
96
100{
101public:
103 template <typename Distant> static typename Distant::Type* get(const Distant& distant)
104 {
105 return distant._object;
106 }
107};
108
110
111#endif
@ 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.