Sayonara Player
Set.h
1/* Set.h */
2
3/* Copyright (C) 2011-2020 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() : std::set<T>() {}
44 Set(const T& singleElement) :
45 Set()
46 {
47 this->insert(singleElement);
48 }
49
55 {
56 QList<T> ret;
57 for(auto it=this->cbegin(); it!=this->cend(); it++){
58 ret << *it;
59 }
60 return ret;
61 }
62
63
68 bool isEmpty() const
69 {
70 return (this->size() == 0);
71 }
72
73
78 T first() const
79 {
80 return *(this->begin());
81 }
82
88 bool contains(const T& value) const
89 {
90 auto it = this->find(value);
91 return (it != this->end());
92 }
93
98 void remove(const T& value)
99 {
100 auto it = this->find(value);
101 if(it != this->end()){
102 this->erase(it);
103 }
104 }
105
106 Util::Set<T>& operator<<(const T& t){
107 this->insert(t);
108 return *this;
109 }
110
111 template<template <typename> class A>
112 Util::Set<T>& operator<<(const A<T>& container)
113 {
114 for(const T& t : container)
115 {
116 this->insert(t);
117 }
118
119 return *this;
120 }
121
122 int count() const
123 {
124 return static_cast<int>(this->size());
125 }
126 };
127}
128
129#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:44
bool contains(const T &value) const
check, if set contains a specific value
Definition: Set.h:88
bool isEmpty() const
Definition: Set.h:68
QList< T > toList() const
converts the set to a list. The order is random
Definition: Set.h:54
T first() const
get copy of first element
Definition: Set.h:78
void remove(const T &value)
removes every item that matches value
Definition: Set.h:98
Helper functions.
Definition: Utils.h:38