Instrument Neutral Distributed Interface INDI  2.0.2
indipropertybasic.h
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 #pragma once
20 
21 #include "indiproperty.h"
22 #include "indimacros.h"
23 #include <algorithm>
24 
25 namespace INDI
26 {
27 
33 
34 template <typename>
36 
37 template <typename T>
39 {
41  DECLARE_PRIVATE(PropertyBasic)
42  public:
43  using ViewType = T;
44 
45  public:
47 
48  public:
49  void setName(const char *name);
50  void setName(const std::string &name);
51 
52  void setLabel(const char *label);
53  void setLabel(const std::string &label);
54 
55  void setGroupName(const char *name);
56  void setGroupName(const std::string &name);
57 
58  void setPermission(IPerm permission);
59  void setTimeout(double timeout);
60  void setState(IPState state);
61 
62  void setTimestamp(const char *timestamp);
63  void setTimestamp(const std::string &timestamp);
64 
65  public:
66  const char *getName() const;
67  const char *getLabel() const;
68  const char *getGroupName() const;
69 
70  IPerm getPermission() const;
71  const char *getPermissionAsString() const;
72 
73  double getTimeout() const;
74  IPState getState() const;
75  const char *getStateAsString() const;
76 
77  const char *getTimestamp() const;
78 
79  public:
80  bool isEmpty() const;
81 
82  bool isNameMatch(const char *otherName) const;
83  bool isNameMatch(const std::string &otherName) const;
84 
85  bool isLabelMatch(const char *otherLabel) const;
86  bool isLabelMatch(const std::string &otherLabel) const;
87 
88  public:
89  void save(FILE *f) const;
90 
91  void vapply(const char *format, va_list args) const;
92  void vdefine(const char *format, va_list args) const;
93 
94  void apply(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
95  void define(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
96 
97  void apply() const;
98  void define() const;
99 
100  protected:
101  PropertyView<T> * operator &();
102 
103  public:
104  size_t size() const;
105  size_t count() const { return size(); }
106 
107  public:
108  void reserve(size_t size);
109  void resize(size_t size);
110 
111  void shrink_to_fit();
112 
113  void push(WidgetView<T> &&item);
114  void push(const WidgetView<T> &item);
115 
116  const WidgetView<T> *at(size_t index) const;
117 
118  WidgetView<T> &operator[](ssize_t index) const;
119 
120  public: // STL-style iterators
121  WidgetView<T> *begin();
122  WidgetView<T> *end();
123  const WidgetView<T> *begin() const;
124  const WidgetView<T> *end() const;
125 
126  template <typename Predicate>
127  WidgetView<T> *find_if(Predicate pred)
128  {
129  return std::find_if(begin(), end(), pred);
130  }
131 
132  template <typename Predicate>
133  const WidgetView<T> *find_if(Predicate pred) const
134  {
135  return std::find_if(begin(), end(), pred);
136  }
137 
138  public:
139  WidgetView<T> *findWidgetByName(const char *name) const;
140  int findWidgetIndexByName(const char *name) const;
141 
142  protected:
143  PropertyBasic(PropertyBasicPrivate &dd);
144  PropertyBasic(const std::shared_ptr<PropertyBasicPrivate> &dd);
145 
146 #ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
147  public: // deprecated
148  INDI_DEPRECATED("Do not use INDI::PropertyXXX as pointer.")
149  INDI::PropertyView<T> *operator->();
150 
151  INDI_DEPRECATED("Do not use INDI::PropertyXXX as pointer.")
152  INDI::PropertyView<T> operator*();
153 #endif
154 };
155 
156 }
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
WidgetView< T > * find_if(Predicate pred)
void resize(size_t size)
void setLabel(const char *label)
const char * getName() const
bool isNameMatch(const char *otherName) const
const WidgetView< T > * find_if(Predicate pred) const
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)
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
#define ATTRIBUTE_FORMAT_PRINTF(A, B)
Definition: indidevapi.h:139
#define INDI_DEPRECATED(message)
Definition: indimacros.h:162
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.