Open Lighting Architecture: include/ola/rdm/UIDSet.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
UIDSet.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * UIDSet.h
17 * A Set of UIDs
18 * Copyright (C) 2005 Simon Newton
19 */
20
28
29#ifndef INCLUDE_OLA_RDM_UIDSET_H_
30#define INCLUDE_OLA_RDM_UIDSET_H_
31
32#include <ola/rdm/UID.h>
33#include <algorithm>
34#include <iomanip>
35#include <set>
36#include <string>
37
38namespace ola {
39namespace rdm {
40
48 class UIDSet {
49 public:
53 typedef std::set<UID>::const_iterator Iterator;
54
58 UIDSet() {}
59
64 UIDSet(const UIDSet &other):
65 m_uids(other.m_uids) {
66 }
67
71 UIDSet& operator=(const UIDSet &other) {
72 if (this != &other) {
73 m_uids = other.m_uids;
74 }
75 return *this;
76 }
77
81 void Clear() {
82 m_uids.clear();
83 }
84
89 unsigned int Size() const {
90 return m_uids.size();
91 }
92
97 bool Empty() const {
98 return m_uids.empty();
99 }
100
105 void AddUID(const UID &uid) {
106 m_uids.insert(uid);
107 }
108
113 void RemoveUID(const UID &uid) {
114 m_uids.erase(uid);
115 }
116
122 bool Contains(const UID &uid) const {
123 return m_uids.find(uid) != m_uids.end();
124 }
125
131 UIDSet Union(const UIDSet &other) {
132 std::set<UID> result;
133 set_union(m_uids.begin(),
134 m_uids.end(),
135 other.Begin(),
136 other.End(),
137 inserter(result, result.begin()));
138 return UIDSet(result);
139 }
140
144 Iterator Begin() const {
145 return m_uids.begin();
146 }
147
151 Iterator End() const {
152 return m_uids.end();
153 }
154
160 UIDSet SetDifference(const UIDSet &other) {
161 std::set<UID> difference;
162 std::set_difference(m_uids.begin(),
163 m_uids.end(),
164 other.m_uids.begin(),
165 other.m_uids.end(),
166 std::inserter(difference, difference.begin()));
167 return UIDSet(difference);
168 }
169
174 bool operator==(const UIDSet &other) const {
175 return m_uids == other.m_uids;
176 }
177
182 bool operator!=(const UIDSet &other) const {
183 return !(*this == other);
184 }
185
190 std::string ToString() const {
191 std::ostringstream str;
192 std::set<UID>::const_iterator iter;
193 for (iter = m_uids.begin(); iter != m_uids.end(); ++iter) {
194 if (iter != m_uids.begin())
195 str << ",";
196 str << *iter;
197 }
198 return str.str();
199 }
200
206 friend std::ostream& operator<< (std::ostream &out, const UIDSet &uid_set) {
207 return out << uid_set.ToString();
208 }
209
210 private:
211 std::set<UID> m_uids;
212
213 explicit UIDSet(const std::set<UID> uids) {
214 m_uids = uids;
215 }
216};
217} // namespace rdm
218} // namespace ola
219#endif // INCLUDE_OLA_RDM_UIDSET_H_
UID.h
A RDM unique identifier (UID).
ola::client::UIDSet::UIDSet
UIDSet()
Construct an empty set.
Definition UIDSet.h:58
ola::rdm::UID
Represents a RDM UID.
Definition UID.h:57
ola::rdm::UIDSet::UIDSet
UIDSet(const UIDSet &other)
Copy constructor.
Definition UIDSet.h:64
ola::rdm::UIDSet::Contains
bool Contains(const UID &uid) const
Check if the set contains a UID.
Definition UIDSet.h:122
ola::rdm::UIDSet::Size
unsigned int Size() const
Return the number of UIDs in the set.
Definition UIDSet.h:89
ola::rdm::UIDSet::RemoveUID
void RemoveUID(const UID &uid)
Remove a UID from the set.
Definition UIDSet.h:113
ola::rdm::UIDSet::SetDifference
UIDSet SetDifference(const UIDSet &other)
Return the UIDs in this set that don't exist in other.
Definition UIDSet.h:160
ola::rdm::UIDSet::Clear
void Clear()
Remove all members from the set.
Definition UIDSet.h:81
ola::rdm::UIDSet::operator<<
friend std::ostream & operator<<(std::ostream &out, const UIDSet &uid_set)
A helper function to write a UIDSet to an ostream.
Definition UIDSet.h:206
ola::rdm::UIDSet::operator!=
bool operator!=(const UIDSet &other) const
Inequality operator.
Definition UIDSet.h:182
ola::rdm::UIDSet::Iterator
std::set< UID >::const_iterator Iterator
the Iterator for a UIDSets
Definition UIDSet.h:53
ola::rdm::UIDSet::Union
UIDSet Union(const UIDSet &other)
Return the union of this set and another UIDSet.
Definition UIDSet.h:131
ola::rdm::UIDSet::ToString
std::string ToString() const
Convert a UIDSet to a human readable string.
Definition UIDSet.h:190
ola::rdm::UIDSet::operator==
bool operator==(const UIDSet &other) const
Equality operator.
Definition UIDSet.h:174
ola::rdm::UIDSet::UIDSet
UIDSet()
Construct an empty set.
Definition UIDSet.h:58
ola::rdm::UIDSet::AddUID
void AddUID(const UID &uid)
Add a UID to the set.
Definition UIDSet.h:105
ola::rdm::UIDSet::operator=
UIDSet & operator=(const UIDSet &other)
Assignment operator.
Definition UIDSet.h:71
ola::rdm::UIDSet::End
Iterator End() const
Return an Iterator to one-pass-the-last member of the set.
Definition UIDSet.h:151
ola::rdm::UIDSet::Empty
bool Empty() const
Return whether the UID set is empty.
Definition UIDSet.h:97
ola::rdm::UIDSet::Begin
Iterator Begin() const
Return an Iterator to the first member of the set.
Definition UIDSet.h:144
ola::rdm
PLASA E1.20 Remote Device Management.
Definition AckTimerResponder.cpp:38
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44