Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JMultiPointer.hh
Go to the documentation of this file.
1#ifndef __JLANG__JMULTIPOINTER__
2#define __JLANG__JMULTIPOINTER__
3
4#include "JLang/JPointer.hh"
5#include "JLang/JTypeList.hh"
6#include "JLang/JNullType.hh"
7
8
9/**
10 * \author mdejong
11 */
12
13namespace JLANG {}
14namespace JPP { using namespace JLANG; }
15
16namespace JLANG {
17
18 /**
19 * General purpose class for multiple pointers.
20 */
21 template<class JClass_t>
23 public JPointer<JClass_t>
24 {
25
26 using JPointer<JClass_t>::get;
27 using JPointer<JClass_t>::reset;
28
29
30 /**
31 * Default constructor.
32 */
34 JPointer<JClass_t>()
35 {}
36
37
38 /**
39 * Constructor.
40 *
41 * \param p pointer to object
42 */
43 JMultiPointer(JClass_t* p) :
44 JPointer<JClass_t>(p)
45 {}
46
47
48 /**
49 * Reset multi-pointer.
50 *
51 * \param pointer multi-pointer
52 */
53 void reset(const JMultiPointer<JClass_t>& pointer)
54 {
55 static_cast<JPointer<JClass_t>&>(*this).reset(static_cast<const JPointer<JClass_t>&>(pointer).get());
56 }
57
58
59 /**
60 * Get single pointer.
61 *
62 * \return pointer
63 */
64 template<class T>
65 T* get() const
66 {
67 return static_cast<const JPointer<T>&>(*this).get();
68 }
69 };
70
71
72 /**
73 * Implementation of multiple pointers for multiple data types.
74 */
75 template<class JHead_t, class JTail_t>
76 struct JMultiPointer< JTypeList<JHead_t, JTail_t> > :
77 public JMultiPointer<JHead_t>,
78 public JMultiPointer<JTail_t>
79 {
80
81 using JMultiPointer<JHead_t>::reset;
82 using JMultiPointer<JTail_t>::reset;
83 using JMultiPointer<JHead_t>::get;
84 using JMultiPointer<JTail_t>::get;
85
86
87 /**
88 * Default constructor.
89 */
91 JMultiPointer<JHead_t>(),
92 JMultiPointer<JTail_t>()
93 {}
94
95
96 /**
97 * Constructor.
98 *
99 * \param first first multi-pointer
100 * \param second second multi-pointer
101 */
103 const JMultiPointer<JTail_t>& second) :
104 JMultiPointer<JHead_t>(first),
105 JMultiPointer<JTail_t>(second)
106 {}
107
108
109 /**
110 * Reset multi-pointer.
111 *
112 * \param pointer multi-pointer
113 */
115 {
116 static_cast<JMultiPointer<JHead_t>&>(*this).reset(pointer);
117 static_cast<JMultiPointer<JTail_t>&>(*this).reset(pointer);
118 }
119
120
121 /**
122 * Reset multi-pointer.
123 *
124 * \param first first multi-pointer
125 * \param second second multi-pointer
126 */
127 void reset(const JMultiPointer<JHead_t>& first,
128 const JMultiPointer<JTail_t>& second)
129 {
130 static_cast<JMultiPointer<JHead_t>&>(*this).reset(first);
131 static_cast<JMultiPointer<JTail_t>&>(*this).reset(second);
132 }
133
134
135 /**
136 * Check validity of pointer.
137 *
138 * \return true if all pointers are not null; else false
139 */
140 bool is_valid() const
141 {
142 return (static_cast<const JMultiPointer<JHead_t>&>(*this).is_valid() &&
143 static_cast<const JMultiPointer<JTail_t>&>(*this).is_valid());
144 }
145
146
147 /**
148 * Get single pointer.
149 *
150 * \return pointer
151 */
152 template<class T>
153 T* get() const
154 {
155 return static_cast<const JPointer<T>&>(*this).get();
156 }
157 };
158
159
160 /**
161 * Terminator class of recursive JMultiPointer class.
162 */
163 template<class JHead_t>
164 struct JMultiPointer< JTypeList<JHead_t, JNullType> > :
165 public JMultiPointer<JHead_t>
166 {
167 /**
168 * Default constructor.
169 */
171 JMultiPointer<JHead_t>()
172 {}
173
174
175 /**
176 * Constructor.
177 *
178 * \param p pointer to object
179 */
180 JMultiPointer(JHead_t* p) :
181 JMultiPointer<JHead_t>(p)
182 {}
183
184
185 /**
186 * Constructor.
187 *
188 * \param pointer multi-pointer
189 */
191 JMultiPointer<JHead_t>(pointer)
192 {}
193 };
194}
195
196#endif
bool is_valid() const
Check validity of pointer.
Template implementation of class that holds pointer to object(s).
Definition JPointer.hh:24
virtual void reset() override
Reset pointer.
Definition JPointer.hh:84
virtual JClass_t * get() const override
Get pointer.
Definition JPointer.hh:64
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JMultiPointer(const JMultiPointer< JHead_t > &pointer)
Constructor.
void reset(const JMultiPointer< JHead_t > &first, const JMultiPointer< JTail_t > &second)
Reset multi-pointer.
void reset(const JMultiPointer< JTypeList< JHead_t, JTail_t > > &pointer)
Reset multi-pointer.
bool is_valid() const
Check validity of pointer.
JMultiPointer(const JMultiPointer< JHead_t > &first, const JMultiPointer< JTail_t > &second)
Constructor.
General purpose class for multiple pointers.
JMultiPointer(JClass_t *p)
Constructor.
T * get() const
Get single pointer.
void reset(const JMultiPointer< JClass_t > &pointer)
Reset multi-pointer.
JMultiPointer()
Default constructor.
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23