Instrument Neutral Distributed Interface INDI  1.9.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 <algorithm>
23 
24 namespace INDI
25 {
26 
32 
33 template <typename>
35 
36 template <typename T>
38 {
40  DECLARE_PRIVATE(PropertyBasic)
41 public:
43 
44 public:
45  void setName(const char *name);
46  void setName(const std::string &name);
47 
48  void setLabel(const char *label);
49  void setLabel(const std::string &label);
50 
51  void setGroupName(const char *name);
52  void setGroupName(const std::string &name);
53 
54  void setPermission(IPerm permission);
55  void setTimeout(double timeout);
56  void setState(IPState state);
57 
58  void setTimestamp(const char *timestamp);
59  void setTimestamp(const std::string &timestamp);
60 
61 public:
62  const char *getName() const;
63  const char *getLabel() const;
64  const char *getGroupName() const;
65 
66  IPerm getPermission() const;
67  const char *getPermissionAsString() const;
68 
69  double getTimeout() const;
70  IPState getState() const;
71  const char *getStateAsString() const;
72 
73  const char *getTimestamp() const;
74 
75 public:
76  bool isEmpty() const;
77 
78  bool isNameMatch(const char *otherName) const;
79  bool isNameMatch(const std::string &otherName) const;
80 
81  bool isLabelMatch(const char *otherLabel) const;
82  bool isLabelMatch(const std::string &otherLabel) const;
83 
84 public:
85  void save(FILE *f) const;
86 
87  void vapply(const char *format, va_list args) const;
88  void vdefine(const char *format, va_list args) const;
89 
90  void apply(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
91  void define(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
92 
93  void apply() const;
94  void define() const;
95 
96 public:
98 
99 public:
100  size_t size() const;
101 
102 public:
103  void reserve(size_t size);
104  void resize(size_t size);
105 
106  void shrink_to_fit();
107 
108  void push(WidgetView<T> &&item);
109  void push(const WidgetView<T> &item);
110 
111  const WidgetView<T> *at(size_t index) const;
112 
113  WidgetView<T> &operator[](size_t index) const;
114 
115 public: // STL-style iterators
116  WidgetView<T> *begin();
117  WidgetView<T> *end();
118  const WidgetView<T> *begin() const;
119  const WidgetView<T> *end() const;
120 
121  template <typename Predicate>
122  WidgetView<T> *find_if(Predicate pred)
123  { return std::find_if(begin(), end(), pred); }
124 
125  template <typename Predicate>
126  const WidgetView<T> *find_if(Predicate pred) const
127  { return std::find_if(begin(), end(), pred); }
128 
129 public:
130  WidgetView<T> *findWidgetByName(const char *name) const;
131  int findWidgetIndexByName(const char *name) const;
132 
133 protected:
134  PropertyBasic(PropertyBasicPrivate &dd);
135 };
136 
137 }
INDI::PropertyBasic::at
const WidgetView< T > * at(size_t index) const
Definition: indipropertybasic.cpp:338
INDI::PropertyBasic::reserve
void reserve(size_t size)
Definition: indipropertybasic.cpp:307
IPState
IPState
Property state.
Definition: indiapi.h:158
INDI::PropertyBasic::isNameMatch
bool isNameMatch(const char *otherName) const
Definition: indipropertybasic.cpp:194
INDI::WidgetView< ILight >
Definition: indipropertyview.h:436
INDI::PropertyBasic::vapply
void vapply(const char *format, va_list args) const
Definition: indipropertybasic.cpp:229
INDI::PropertyBasic::end
WidgetView< T > * end()
Definition: indipropertybasic.cpp:359
INDI::PropertyBasic::setName
void setName(const char *name)
Definition: indipropertybasic.cpp:47
timestamp
const char * timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Definition: indicom.c:334
INDI::PropertyBasic::setGroupName
void setGroupName(const char *name)
Definition: indipropertybasic.cpp:75
INDI::PropertyBasic::getTimestamp
const char * getTimestamp() const
Definition: indipropertybasic.cpp:180
INDI::PropertyBasic::findWidgetIndexByName
int findWidgetIndexByName(const char *name) const
Definition: indipropertybasic.cpp:284
INDI::PropertyBasic::getTimeout
double getTimeout() const
Definition: indipropertybasic.cpp:159
INDI::PropertyBasic::vdefine
void vdefine(const char *format, va_list args) const
Definition: indipropertybasic.cpp:236
INDI::PropertyBasic::push
void push(WidgetView< T > &&item)
Definition: indipropertybasic.cpp:323
INDI::PropertyBasic::PropertyBasic
PropertyBasic(PropertyBasicPrivate &dd)
Definition: indipropertybasic.cpp:42
INDI::PropertyBasic::setTimeout
void setTimeout(double timeout)
Definition: indipropertybasic.cpp:96
INDI::Property
Provides generic container for INDI properties.
Definition: indiproperty.h:43
INDI::PropertyBasic::size
size_t size() const
Definition: indipropertybasic.cpp:291
INDI::PropertyBasicPrivateTemplate
Definition: indipropertybasic.h:34
INDI::PropertyBasic::getPermission
IPerm getPermission() const
Definition: indipropertybasic.cpp:145
INDI::PropertyBasic::getName
const char * getName() const
Definition: indipropertybasic.cpp:124
INDI::PropertyBasic::getStateAsString
const char * getStateAsString() const
Definition: indipropertybasic.cpp:173
INDI::PropertyBasic::begin
WidgetView< T > * begin()
Definition: indipropertybasic.cpp:352
INDI::PropertyBasic::~PropertyBasic
~PropertyBasic()
Definition: indipropertybasic.cpp:38
INDI::WidgetView
Definition: indipropertyview.h:38
INDI::PropertyBasic::setTimestamp
void setTimestamp(const char *timestamp)
Definition: indipropertybasic.cpp:110
INDI::PropertyBasic::setLabel
void setLabel(const char *label)
Definition: indipropertybasic.cpp:61
INDI::WidgetView< IBLOB >
Definition: indipropertyview.h:493
INDI::PropertyBasic::operator&
PropertyView< T > * operator&()
Definition: indipropertybasic.cpp:380
INDI::PropertyBasic::apply
void void void apply() const
Definition: indipropertybasic.cpp:263
IPerm
IPerm
Permission hint, with respect to client.
Definition: indiapi.h:181
INDI::PropertyBasic::operator[]
WidgetView< T > & operator[](size_t index) const
Definition: indipropertybasic.cpp:345
INDI::PropertyBasic::getLabel
const char * getLabel() const
Definition: indipropertybasic.cpp:131
INDI::WidgetView< ISwitch >
Definition: indipropertyview.h:379
INDI::PropertyBasic::findWidgetByName
WidgetView< T > * findWidgetByName(const char *name) const
Definition: indipropertybasic.cpp:277
INDI::PropertyView< T >
INDI::PropertyBasic::find_if
WidgetView< T > * find_if(Predicate pred)
Definition: indipropertybasic.h:122
indiproperty.h
INDI::PropertyBasic::setPermission
void setPermission(IPerm permission)
Definition: indipropertybasic.cpp:89
INDI::PropertyBasic::shrink_to_fit
void shrink_to_fit()
Definition: indipropertybasic.cpp:315
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::PropertyBasic
Definition: indipropertybasic.h:37
INDI::PropertyBasic::resize
void resize(size_t size)
Definition: indipropertybasic.cpp:298
ATTRIBUTE_FORMAT_PRINTF
#define ATTRIBUTE_FORMAT_PRINTF(A, B)
Definition: indidevapi.h:140
INDI::PropertyBasic::setState
void setState(IPState state)
Definition: indipropertybasic.cpp:103
INDI::PropertyBasic::isEmpty
bool isEmpty() const
Definition: indipropertybasic.cpp:187
INDI::PropertyBasic::getState
IPState getState() const
Definition: indipropertybasic.cpp:166
INDI::PropertyBasic::save
void save(FILE *f) const
Definition: indipropertybasic.cpp:222
INDI::PropertyBasic::getPermissionAsString
const char * getPermissionAsString() const
Definition: indipropertybasic.cpp:152
INDI::WidgetView< IText >
Definition: indipropertyview.h:256
INDI::PropertyBasic::define
void define() const
Definition: indipropertybasic.cpp:270
INDI::PropertyBasic::isLabelMatch
bool isLabelMatch(const char *otherLabel) const
Definition: indipropertybasic.cpp:208
INDI::WidgetView< INumber >
Definition: indipropertyview.h:312
INDI::PropertyBasic::find_if
const WidgetView< T > * find_if(Predicate pred) const
Definition: indipropertybasic.h:126
INDI::PropertyBasic::getGroupName
const char * getGroupName() const
Definition: indipropertybasic.cpp:138