Ariles
generic_pointer.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2017-2018 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @brief
9 */
10 
11 
12 namespace ariles2
13 {
14  template <class t_Entry>
15  bool isMissing(const ARILES2_POINTER_TYPE<t_Entry> &entry)
16  {
17  return (PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(entry));
18  }
19 } // namespace ariles2
20 
21 
22 namespace ariles2
23 {
24  namespace read
25  {
26  template <class t_Visitor, typename t_Entry>
27  void apply_read(
28  t_Visitor &reader,
29  ARILES2_POINTER_TYPE<t_Entry> &entry,
30  const typename t_Visitor::Parameters &parameters)
31  {
33  const bool is_null = reader.startPointer(parameters);
34  if (is_null)
35  {
37  }
38  else
39  {
41  apply_read(reader, *entry, parameters);
42  }
43  reader.endPointer(is_null);
44  }
45  } // namespace read
46 } // namespace ariles2
47 
48 
49 namespace ariles2
50 {
51  namespace write
52  {
53  template <class t_Visitor, typename t_Entry>
55  t_Visitor &writer,
56  const ARILES2_POINTER_TYPE<t_Entry> &entry,
57  const typename t_Visitor::Parameters &param)
58  {
60 
61  const bool is_null = PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(entry);
62 
63  writer.startPointer(is_null, param);
64  if (not is_null)
65  {
66  apply_write(writer, *entry, param);
67  }
68  writer.endPointer(is_null);
69  }
70  } // namespace write
71 } // namespace ariles2
72 
73 
74 namespace ariles2
75 {
76  namespace compare
77  {
78  template <class t_Visitor, typename t_Entry>
80  t_Visitor &visitor,
81  const ARILES2_POINTER_TYPE<t_Entry> &left,
82  const ARILES2_POINTER_TYPE<t_Entry> &right,
83  const typename t_Visitor::Parameters &param)
84  {
86  if (PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(left))
87  {
88  if (not PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(right))
89  {
90  visitor.equal_ = false;
91  }
92  }
93  else
94  {
95  if (PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(right))
96  {
97  visitor.equal_ = false;
98  }
99  else
100  {
101  apply_compare(visitor, *left, *right, param);
102  }
103  }
104  }
105  } // namespace compare
106 } // namespace ariles2
107 
108 
109 namespace ariles2
110 {
111  namespace defaults
112  {
113  template <class t_Visitor, typename t_Entry>
115  const t_Visitor & /*visitor*/,
116  ARILES2_POINTER_TYPE<t_Entry> &entry,
117  const typename t_Visitor::Parameters & /*param*/)
118  {
121  }
122  } // namespace defaults
123 } // namespace ariles2
124 
125 
126 namespace ariles2
127 {
128  namespace process
129  {
130  template <class t_Visitor, typename t_Entry>
132  const t_Visitor &visitor,
133  ARILES2_POINTER_TYPE<t_Entry> &entry,
134  const typename t_Visitor::Parameters &param)
135  {
137  if (not(PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(entry)))
138  {
139  apply_process(visitor, *entry, param);
140  }
141  }
142  } // namespace process
143 } // namespace ariles2
144 
145 
146 namespace ariles2
147 {
148  namespace copyfrom
149  {
150  template <class t_Visitor, typename t_Entry>
152  t_Visitor &visitor,
153  ARILES2_POINTER_TYPE<t_Entry> &left,
154  const ARILES2_POINTER_TYPE<t_Entry> &right,
155  const typename t_Visitor::Parameters &param)
156  {
158  if (param.deep_copy_)
159  {
160  if (PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(right))
161  {
163  }
164  else
165  {
166  if (PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(left))
167  {
169  }
170 
171  apply_copyfrom(visitor, *left, *right, param);
172  }
173  }
174  else
175  {
176  left = right;
177  }
178  }
179 
180  template <class t_Visitor, typename t_Left, typename t_Right>
182  t_Visitor &visitor,
183  ARILES2_POINTER_TYPE<t_Left> &left,
184  const ARILES2_POINTER_TYPE<t_Right> &right,
185  const typename t_Visitor::Parameters &param)
186  {
188  if (param.deep_copy_)
189  {
190  if (PointerHandler<ARILES2_POINTER_TYPE<t_Right>>::isNull(right))
191  {
193  }
194  else
195  {
196  if (PointerHandler<ARILES2_POINTER_TYPE<t_Left>>::isNull(left))
197  {
199  }
200 
201  apply_copyfrom(visitor, *left, *right, param);
202  }
203  }
204  else
205  {
206  if (PointerHandler<ARILES2_POINTER_TYPE<t_Right>>::isNull(right))
207  {
209  }
210  else
211  {
212  CPPUT_THROW("Shallow copies of pointers of different types are not supported.");
213  }
214  }
215  }
216  } // namespace copyfrom
217 
218 
219  namespace copyto
220  {
221  template <class t_Visitor, typename t_Entry>
223  t_Visitor &visitor,
224  const ARILES2_POINTER_TYPE<t_Entry> &left,
225  ARILES2_POINTER_TYPE<t_Entry> &right,
226  const typename t_Visitor::Parameters &param)
227  {
229  if (param.deep_copy_)
230  {
231  if (PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(left))
232  {
234  }
235  else
236  {
237  if (PointerHandler<ARILES2_POINTER_TYPE<t_Entry>>::isNull(right))
238  {
240  }
241 
242  apply_copyto(visitor, *left, *right, param);
243  }
244  }
245  else
246  {
247  right = left;
248  }
249  }
250 
251  template <class t_Visitor, typename t_Left, typename t_Right>
253  t_Visitor &visitor,
254  const ARILES2_POINTER_TYPE<t_Left> &left,
255  ARILES2_POINTER_TYPE<t_Right> &right,
256  const typename t_Visitor::Parameters &param)
257  {
259  if (param.deep_copy_)
260  {
261  if (PointerHandler<ARILES2_POINTER_TYPE<t_Left>>::isNull(left))
262  {
264  }
265  else
266  {
267  if (PointerHandler<ARILES2_POINTER_TYPE<t_Right>>::isNull(right))
268  {
270  }
271 
272  apply_copyto(visitor, *left, *right, param);
273  }
274  }
275  else
276  {
277  if (PointerHandler<ARILES2_POINTER_TYPE<t_Left>>::isNull(left))
278  {
280  }
281  else
282  {
283  CPPUT_THROW("Shallow copies of pointers of different types are not supported.");
284  }
285  }
286  }
287  } // namespace copyto
288 } // namespace ariles2
289 
290 #undef ARILES2_POINTER_HANDLER
291 #undef ARILES2_POINTER_TYPE
#define CPPUT_THROW(...)
Definition: exception.h:19
void apply_compare(t_Visitor &visitor, const t_Left &left, const t_Right &right, const typename t_Visitor::Parameters &param)
Definition: basic.h:140
void apply_copyfrom(t_Visitor &visitor, t_Left &left, const t_Right &right, const typename t_Visitor::Parameters &param)
Definition: basic.h:307
void apply_copyto(t_Visitor &visitor, const t_Left &left, t_Right &right, const typename t_Visitor::Parameters &param)
Definition: basic.h:353
visitor::Parameters Parameters
Definition: count.h:26
void apply_defaults(const t_Visitor &visitor, t_Entry &entry, const typename t_Visitor::Parameters &param, ARILES2_IS_BASE_ENABLER(ariles2::defaults::Base, t_Entry))
Definition: basic.h:232
void apply_process(const t_Visitor &visitor, t_Entry &entry, const typename t_Visitor::Parameters &param)
Definition: basic.h:289
void apply_read(t_Visitor &visitor, t_Entry &entry, const typename t_Visitor::Parameters &parameters, ARILES2_IS_BASE_ENABLER(ariles2::read::Base, t_Entry))
Definition: basic.h:21
void apply_write(t_Visitor &writer, const t_Entry &entry, const typename t_Visitor::Parameters &parameters, ARILES2_IS_BASE_ENABLER(ariles2::write::Base, t_Entry))
Definition: basic.h:82
Definition: basic.h:17
bool isMissing(const ARILES2_POINTER_TYPE< t_Entry > &entry)
#define CPPUT_TRACE_FUNCTION
Definition: trace.h:126