Sayonara Player
Loading...
Searching...
No Matches
Set.h
1/* Set.h */
2
3/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef SET_H
22#define SET_H
23
24#include <set>
25#include <QList>
26
27namespace Util
28{
29 template<typename T>
30
35 class Set :
36 public std::set<T>
37 {
38 public:
39 Set() :
40 std::set<T>() {}
41
46 Set(const T& singleElement) :
47 Set()
48 {
49 this->insert(singleElement);
50 }
51
57 {
58 QList<T> ret;
59 for(auto it = this->cbegin(); it != this->cend(); it++)
60 {
61 ret << *it;
62 }
63 return ret;
64 }
65
70 bool isEmpty() const
71 {
72 return (this->size() == 0);
73 }
74
79 T first() const
80 {
81 return *(this->begin());
82 }
83
89 bool contains(const T& value) const
90 {
91 auto it = this->find(value);
92 return (it != this->end());
93 }
94
99 void remove(const T& value)
100 {
101 auto it = this->find(value);
102 if(it != this->end())
103 {
104 this->erase(it);
105 }
106 }
107
108 Util::Set<T>& operator<<(const T& t)
109 {
110 this->insert(t);
111 return *this;
112 }
113
114 template<template<typename> class A>
115 Util::Set<T>& operator<<(const A<T>& container)
116 {
117 for(const T& t: container)
118 {
119 this->insert(t);
120 }
121
122 return *this;
123 }
124
125 int count() const
126 {
127 return static_cast<int>(this->size());
128 }
129 };
130}
131
132#endif // SET_H
Definition: EngineUtils.h:33
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:37
Set(const T &singleElement)
Constructs a set with a single element.
Definition: Set.h:46
bool contains(const T &value) const
check, if set contains a specific value
Definition: Set.h:89
bool isEmpty() const
Definition: Set.h:70
QList< T > toList() const
converts the set to a list. The order is random
Definition: Set.h:56
T first() const
get copy of first element
Definition: Set.h:79
void remove(const T &value)
removes every item that matches value
Definition: Set.h:99
Helper functions.
Definition: MetaTypeRegistry.h:25