Instrument Neutral Distributed Interface INDI  2.0.2
indipropertybasic.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 by Pawel Soja <kernel32.pl@gmail.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "indipropertybasic.h"
20 #include "indipropertybasic_p.h"
21 #include <cassert>
22 
23 namespace INDI
24 {
25 
26 template <typename T>
28 #ifdef INDI_PROPERTY_RAW_CAST
30  , PropertyPrivate(&this->typedProperty)
31  , raw{false}
32 #else
33  : PropertyPrivate(&property)
34 #endif
35  , widgets(count)
36 {
37  this->typedProperty.setWidgets(widgets.data(), widgets.size());
38 }
39 
40 #ifdef INDI_PROPERTY_RAW_CAST
41 template <typename T>
43  : PropertyContainer<T>{*PropertyView<T>::cast(rawProperty)}
45  , raw{true}
46 { }
47 #endif
48 
49 template <typename T>
51 {
52 #ifdef INDI_PROPERTY_RAW_CAST
53  if (!raw)
54  delete &this->typedProperty;
55 #endif
56 }
57 
58 template <typename T>
60 { }
61 
62 template <typename T>
64  : Property(dd)
65 { }
66 
67 template <typename T>
68 PropertyBasic<T>::PropertyBasic(const std::shared_ptr<PropertyBasicPrivate> &dd)
69  : Property(std::static_pointer_cast<PropertyPrivate>(dd))
70 { }
71 
72 template <typename T>
73 void PropertyBasic<T>::setName(const char *name)
74 {
75  D_PTR(PropertyBasic);
76  d->typedProperty.setName(name);
77 }
78 
79 template <typename T>
80 void PropertyBasic<T>::setName(const std::string &name)
81 {
82  D_PTR(PropertyBasic);
83  d->typedProperty.setName(name);
84 }
85 
86 template <typename T>
87 void PropertyBasic<T>::setLabel(const char *label)
88 {
89  D_PTR(PropertyBasic);
90  d->typedProperty.setLabel(label);
91 }
92 
93 template <typename T>
94 void PropertyBasic<T>::setLabel(const std::string &label)
95 {
96  D_PTR(PropertyBasic);
97  d->typedProperty.setLabel(label);
98 }
99 
100 template <typename T>
101 void PropertyBasic<T>::setGroupName(const char *name)
102 {
103  D_PTR(PropertyBasic);
104  d->typedProperty.setGroupName(name);
105 }
106 
107 template <typename T>
108 void PropertyBasic<T>::setGroupName(const std::string &name)
109 {
110  D_PTR(PropertyBasic);
111  d->typedProperty.setGroupName(name);
112 }
113 
114 template <typename T>
116 {
117  D_PTR(PropertyBasic);
118  d->typedProperty.setPermission(permission);
119 }
120 
121 template <typename T>
122 void PropertyBasic<T>::setTimeout(double timeout)
123 {
125  d->typedProperty.setTimeout(timeout);
126 }
127 
128 template <typename T>
130 {
131  D_PTR(PropertyBasic);
132  d->typedProperty.setState(state);
133 }
134 
135 template <typename T>
136 void PropertyBasic<T>::setTimestamp(const char *timestamp)
137 {
138  D_PTR(PropertyBasic);
139  d->typedProperty.setTimestamp(timestamp);
140 }
141 
142 template <typename T>
143 void PropertyBasic<T>::setTimestamp(const std::string &timestamp)
144 {
145  D_PTR(PropertyBasic);
146  d->typedProperty.setTimestamp(timestamp);
147 }
148 
149 template <typename T>
150 const char *PropertyBasic<T>::getName() const
151 {
152  D_PTR(const PropertyBasic);
153  return d->typedProperty.getName();
154 }
155 
156 template <typename T>
157 const char *PropertyBasic<T>::getLabel() const
158 {
159  D_PTR(const PropertyBasic);
160  return d->typedProperty.getLabel();
161 }
162 
163 template <typename T>
165 {
166  D_PTR(const PropertyBasic);
167  return d->typedProperty.getGroupName();
168 }
169 
170 template <typename T>
172 {
173  D_PTR(const PropertyBasic);
174  return d->typedProperty.getPermission();
175 }
176 
177 template <typename T>
179 {
180  D_PTR(const PropertyBasic);
181  return d->typedProperty.getPermissionAsString();
182 }
183 
184 template <typename T>
186 {
187  D_PTR(const PropertyBasic);
188  return d->typedProperty.getTimeout();
189 }
190 
191 template <typename T>
193 {
194  D_PTR(const PropertyBasic);
195  return d->typedProperty.getState();
196 }
197 
198 template <typename T>
200 {
201  D_PTR(const PropertyBasic);
202  return d->typedProperty.getStateAsString();
203 }
204 
205 template <typename T>
207 {
208  D_PTR(const PropertyBasic);
209  return d->typedProperty.getTimestamp();
210 }
211 
212 template <typename T>
214 {
215  D_PTR(const PropertyBasic);
216  return d->typedProperty.isEmpty();
217 }
218 
219 template <typename T>
220 bool PropertyBasic<T>::isNameMatch(const char *otherName) const
221 {
222  D_PTR(const PropertyBasic);
223  return d->typedProperty.isNameMatch(otherName);
224 }
225 
226 template <typename T>
227 bool PropertyBasic<T>::isNameMatch(const std::string &otherName) const
228 {
229  D_PTR(const PropertyBasic);
230  return d->typedProperty.isNameMatch(otherName);
231 }
232 
233 template <typename T>
234 bool PropertyBasic<T>::isLabelMatch(const char *otherLabel) const
235 {
236  D_PTR(const PropertyBasic);
237  return d->typedProperty.isLabelMatch(otherLabel);
238 }
239 
240 template <typename T>
241 bool PropertyBasic<T>::isLabelMatch(const std::string &otherLabel) const
242 {
243  D_PTR(const PropertyBasic);
244  return d->typedProperty.isLabelMatch(otherLabel);
245 }
246 
247 template <typename T>
248 void PropertyBasic<T>::save(FILE *f) const
249 {
250  D_PTR(const PropertyBasic);
251  d->typedProperty.save(f);
252 }
253 
254 template <typename T>
255 void PropertyBasic<T>::vapply(const char *format, va_list args) const
256 {
257  D_PTR(const PropertyBasic);
258  d->typedProperty.vapply(format, args);
259 }
260 
261 template <typename T>
262 void PropertyBasic<T>::vdefine(const char *format, va_list args) const
263 {
264  D_PTR(const PropertyBasic);
265  d->typedProperty.vdefine(format, args);
266 }
267 
268 template <typename T>
269 void PropertyBasic<T>::apply(const char *format, ...) const
270 {
271  D_PTR(const PropertyBasic);
272  va_list ap;
273  va_start(ap, format);
274  d->typedProperty.vapply(format, ap);
275  va_end(ap);
276 }
277 
278 template <typename T>
279 void PropertyBasic<T>::define(const char *format, ...) const
280 {
281  D_PTR(const PropertyBasic);
282  va_list ap;
283  va_start(ap, format);
284  d->typedProperty.vdefine(format, ap);
285  va_end(ap);
286 }
287 
288 template <typename T>
290 {
291  D_PTR(const PropertyBasic);
292  d->typedProperty.apply();
293 }
294 
295 template <typename T>
297 {
298  D_PTR(const PropertyBasic);
299  d->typedProperty.define();
300 }
301 
302 template <typename T>
304 {
305  D_PTR(const PropertyBasic);
306  return d->typedProperty.findWidgetByName(name);
307 }
308 
309 template <typename T>
310 int PropertyBasic<T>::findWidgetIndexByName(const char *name) const
311 {
312  auto it = findWidgetByName(name);
313  return int(it == nullptr ? -1 : it - begin());
314 }
315 
316 template <typename T>
318 {
319  D_PTR(const PropertyBasic);
320  return d->typedProperty.count();
321 }
322 
323 template <typename T>
324 void PropertyBasic<T>::resize(size_t size)
325 {
326  D_PTR(PropertyBasic);
327 #ifdef INDI_PROPERTY_RAW_CAST
328  assert(d->raw == false);
329 #endif
330  d->widgets.resize(size);
331  d->typedProperty.setWidgets(d->widgets.data(), d->widgets.size());
332 }
333 
334 template <typename T>
335 void PropertyBasic<T>::reserve(size_t size)
336 {
337  D_PTR(PropertyBasic);
338 #ifdef INDI_PROPERTY_RAW_CAST
339  assert(d->raw == false);
340 #endif
341  d->widgets.reserve(size);
342  d->typedProperty.setWidgets(d->widgets.data(), d->widgets.size());
343 }
344 
345 template <typename T>
347 {
348  D_PTR(PropertyBasic);
349 #ifdef INDI_PROPERTY_RAW_CAST
350  assert(d->raw == false);
351 #endif
352  d->widgets.shrink_to_fit();
353  d->typedProperty.setWidgets(d->widgets.data(), d->widgets.size());
354 }
355 
356 template <typename T>
358 {
359  D_PTR(PropertyBasic);
360 #ifdef INDI_PROPERTY_RAW_CAST
361  assert(d->raw == false);
362 #endif
363  item.setParent(&d->typedProperty);
364  d->widgets.push_back(std::move(item));
365  d->typedProperty.setWidgets(d->widgets.data(), d->widgets.size());
366 }
367 
368 template <typename T>
370 {
371  push(std::move(WidgetView<T>(item)));
372 }
373 
374 template <typename T>
375 const WidgetView<T> *PropertyBasic<T>::at(size_t index) const
376 {
377  D_PTR(const PropertyBasic);
378  return d->typedProperty.at(index);
379 }
380 
381 template <typename T>
383 {
384  D_PTR(const PropertyBasic);
385  assert(index >= 0);
386  return *d->typedProperty.at(index);
387 }
388 
389 template <typename T>
391 {
392  D_PTR(PropertyBasic);
393  return d->typedProperty.begin();
394 }
395 
396 template <typename T>
398 {
399  D_PTR(PropertyBasic);
400  return d->typedProperty.end();
401 }
402 
403 template <typename T>
405 {
406  D_PTR(const PropertyBasic);
407  return d->typedProperty.begin();
408 }
409 
410 template <typename T>
412 {
413  D_PTR(const PropertyBasic);
414  return d->typedProperty.end();
415 }
416 
417 template <typename T>
419 {
420  D_PTR(PropertyBasic);
421  return &d->typedProperty;
422 }
423 
424 #ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
425 template <typename T>
427 {
428  D_PTR(PropertyBasic);
429  return static_cast<PropertyView<T> *>(static_cast<INDI::PropertyPrivate*>(d)->property);
430 }
431 
432 template <typename T>
434 {
435  D_PTR(PropertyBasic);
436  return *static_cast<PropertyView<T> *>(static_cast<INDI::PropertyPrivate*>(d)->property);
437 }
438 #endif
439 
445 
446 template class PropertyBasic<IText>;
447 template class PropertyBasic<INumber>;
448 template class PropertyBasic<ISwitch>;
449 template class PropertyBasic<ILight>;
450 template class PropertyBasic<IBLOB>;
451 
452 }
typename WidgetTraits< T >::PropertyType RawPropertyType
void push(WidgetView< T > &&item)
void vapply(const char *format, va_list args) const
void setState(IPState state)
bool isLabelMatch(const char *otherLabel) const
const char * getPermissionAsString() const
WidgetView< T > * findWidgetByName(const char *name) const
void setName(const char *name)
WidgetView< T > * begin()
void save(FILE *f) const
WidgetView< T > * end()
WidgetView< T > & operator[](ssize_t index) const
void vdefine(const char *format, va_list args) const
IPState getState() const
void resize(size_t size)
PropertyView< T > * operator&()
void setLabel(const char *label)
const char * getName() const
bool isNameMatch(const char *otherName) const
INDI::PropertyView< T > * operator->()
const char * getGroupName() const
const char * getStateAsString() const
const char * getLabel() const
void setPermission(IPerm permission)
void void void apply() const
int findWidgetIndexByName(const char *name) const
PropertyBasic(PropertyBasicPrivate &dd)
const WidgetView< T > * at(size_t index) const
const char * getTimestamp() const
void setTimestamp(const char *timestamp)
void setGroupName(const char *name)
void reserve(size_t size)
void setTimeout(double timeout)
INDI::PropertyView< T > operator*()
Provides generic container for INDI properties.
Definition: indiproperty.h:48
IPerm
Permission hint, with respect to client.
Definition: indiapi.h:183
IPState
Property state.
Definition: indiapi.h:160
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: json.h:4973
Provides decorator for Low-Level IXXXVectorProperty/IXXX.
PropertyType * cast()