Instrument Neutral Distributed Interface INDI  2.0.2
indiproperties.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 #pragma once
19 
20 #include "indiproperty.h"
21 #include "indimacros.h"
22 #include <vector>
23 #include <deque>
24 #include <algorithm>
25 
26 #define INDI_PROPERTIES_BACKWARD_COMPATIBILE
27 namespace INDI
28 {
29 
30 class PropertiesPrivate;
32 {
33  DECLARE_PRIVATE(Properties)
34 
35  public:
36  using iterator = std::deque<INDI::Property>::iterator;
37  using const_iterator = std::deque<INDI::Property>::const_iterator;
38  using reference = std::deque<INDI::Property>::reference;
39  using const_reference = std::deque<INDI::Property>::const_reference;
40  using size_type = std::deque<INDI::Property>::size_type;
41 
42  public:
43  Properties();
44  ~Properties();
45 
46  public:
47  void push_back(const INDI::Property &property);
48  void push_back(INDI::Property &&property);
49  void clear();
50 
51  public:
52  bool empty() const;
53 
54  public:
55  size_type size() const;
56 
57  public:
58  reference at(size_type pos);
59  const_reference at(size_type pos) const;
60 
63 
64  reference front();
65  const_reference front() const;
66 
67  reference back();
68  const_reference back() const;
69 
70  public:
71  iterator begin();
72  iterator end();
73 
74  const_iterator begin() const;
75  const_iterator end() const;
76 
77  public:
78  iterator erase(iterator pos);
80  iterator erase(iterator first, iterator last);
82 
83  template<typename Predicate>
84  iterator erase_if(Predicate predicate);
85 
86  public:
87 #ifdef INDI_PROPERTIES_BACKWARD_COMPATIBILE
89  const INDI::Properties operator *() const;
90 
92  const Properties *operator->() const;
93 
94  operator std::vector<INDI::Property *> *();
95  operator const std::vector<INDI::Property *> *() const;
96 
97  operator Properties *();
98  operator const Properties *() const;
99 #endif
100 
101  protected:
102  std::shared_ptr<PropertiesPrivate> d_ptr;
103  Properties(std::shared_ptr<PropertiesPrivate> dd);
104 };
105 
106 template<typename Predicate>
107 inline Properties::iterator Properties::erase_if(Predicate predicate)
108 {
109  return erase(std::remove_if(begin(), end(), predicate), end());
110 }
111 
112 }
Properties * operator->()
bool empty() const
INDI::Properties operator*()
iterator erase(iterator pos)
std::deque< INDI::Property >::const_iterator const_iterator
reference operator[](size_type pos)
std::deque< INDI::Property >::size_type size_type
std::shared_ptr< PropertiesPrivate > d_ptr
std::deque< INDI::Property >::const_reference const_reference
void push_back(const INDI::Property &property)
reference at(size_type pos)
std::deque< INDI::Property >::reference reference
std::deque< INDI::Property >::iterator iterator
iterator erase_if(Predicate predicate)
size_type size() const
Provides generic container for INDI properties.
Definition: indiproperty.h:48
Namespace to encapsulate INDI client, drivers, and mediator classes.