Instrument Neutral Distributed Interface INDI 2.2.5
indipropertybasic.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 by Pawel Soja <[email protected]>
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#pragma once
20
21#include "indiproperty.h"
22#include "indimacros.h"
23#include <algorithm>
24
25namespace INDI
26{
27
33
34template <typename>
36
37template <typename T>
39{
41 DECLARE_PRIVATE(PropertyBasic)
42 public:
43 using ViewType = T;
44
45 public:
47
48 public:
49 void setDeviceName(const char *name);
50 void setDeviceName(const std::string &name);
51
52 void setName(const char *name);
53 void setName(const std::string &name);
54
55 void setLabel(const char *label);
56 void setLabel(const std::string &label);
57
58 void setGroupName(const char *name);
59 void setGroupName(const std::string &name);
60
61 void setPermission(IPerm permission);
62 void setTimeout(double timeout);
63 void setState(IPState state);
64
65 void setTimestamp(const char *timestamp);
66 void setTimestamp(const std::string &timestamp);
67
68 public:
69 const char *getDeviceName() const;
70 const char *getName() const;
71 const char *getLabel() const;
72 const char *getGroupName() const;
73
74 IPerm getPermission() const;
75 const char *getPermissionAsString() const;
76
77 double getTimeout() const;
78 IPState getState() const;
79 const char *getStateAsString() const;
80
81 const char *getTimestamp() const;
82
83 public:
84 bool isEmpty() const;
85
86 bool isNameMatch(const char *otherName) const;
87 bool isNameMatch(const std::string &otherName) const;
88
89 bool isLabelMatch(const char *otherLabel) const;
90 bool isLabelMatch(const std::string &otherLabel) const;
91
92 public:
97 bool load();
98
103 void save(FILE *f) const;
104
110 bool snoop(XMLEle *root);
111
112 void vapply(const char *format, va_list args) const;
113 void vdefine(const char *format, va_list args) const;
114
115 void apply(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
116 void define(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
117
118 void apply() const;
119 void define() const;
120
121 protected:
122 PropertyView<T> * operator &();
123
124 public:
125 size_t size() const;
126 size_t count() const
127 {
128 return size();
129 }
130
131 public:
132 void reserve(size_t size);
133 void resize(size_t size);
134
135 void shrink_to_fit();
136
137 void push(WidgetView<T> &&item);
138 void push(const WidgetView<T> &item);
139
140 const WidgetView<T> *at(size_t index) const;
141
142 WidgetView<T> &operator[](int index) const;
143
144 public: // STL-style iterators
147 const WidgetView<T> *begin() const;
148 const WidgetView<T> *end() const;
149
150 template <typename Predicate>
151 WidgetView<T> *find_if(Predicate pred)
152 {
153 return std::find_if(begin(), end(), pred);
154 }
155
156 template <typename Predicate>
157 const WidgetView<T> *find_if(Predicate pred) const
158 {
159 return std::find_if(begin(), end(), pred);
160 }
161
162 public:
163 WidgetView<T> *findWidgetByName(const char *name) const;
164 int findWidgetIndexByName(const char *name) const;
165
166 protected:
167 PropertyBasic(PropertyBasicPrivate &dd);
168 PropertyBasic(const std::shared_ptr<PropertyBasicPrivate> &dd);
169
170#ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
171 public: // deprecated
172 INDI_DEPRECATED("Do not use INDI::PropertyXXX as pointer.")
173 INDI::PropertyView<T> *operator->();
174
175 INDI_DEPRECATED("Do not use INDI::PropertyXXX as pointer.")
176 INDI::PropertyView<T> operator*();
177#endif
178};
179
180}
void setDeviceName(const char *name)
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
const char * getDeviceName() const
void setName(const char *name)
bool load()
load Attempt to load property values from configuration file.
WidgetView< T > * begin()
void save(FILE *f) const
save Save property to configuration file.
WidgetView< T > * end()
void vdefine(const char *format, va_list args) const
void resize(size_t size)
void setLabel(const char *label)
const char * getName() const
bool isNameMatch(const char *otherName) const
bool snoop(XMLEle *root)
Inspect the root XML and snoop the property if it exists in the root element.
const char * getGroupName() const
const WidgetView< T > * find_if(Predicate pred) const
WidgetView< T > * find_if(Predicate pred)
const char * getStateAsString() const
const char * getLabel() const
void setPermission(IPerm permission)
void void void apply() const
WidgetView< T > & operator[](int index) const
int findWidgetIndexByName(const char *name) const
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)
Provides generic container for INDI properties.
IPerm
Permission hint, with respect to client.
Definition indiapi.h:181
IPState
Property state.
Definition indiapi.h:158
#define ATTRIBUTE_FORMAT_PRINTF(A, B)
Definition indidevapi.h:140
#define INDI_DEPRECATED(message)
Definition indimacros.h:309
Namespace to encapsulate INDI client, drivers, and mediator classes.
WidgetView< ISwitch > WidgetViewSwitch
WidgetView< ILight > WidgetViewLight
WidgetView< IText > WidgetViewText
WidgetView< IBLOB > WidgetViewBlob
WidgetView< INumber > WidgetViewNumber
Provides decorator for Low-Level IXXXVectorProperty/IXXX.