Sayonara Player
Set.h
1 /* Set.h */
2 
3 /* Copyright (C) 2011-2017 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 
27 namespace SP {
28 
29  template<typename T>
30 
35  class Set :
36  public std::set<T>
37  {
38  public:
39 
40  Set() : std::set<T>() {}
45  Set(const T& one_element) :
46  Set()
47  {
48  this->insert(one_element);
49  }
50 
51 
56  QList<T> toList() const
57  {
58  QList<T> ret;
59  for(auto it=this->cbegin(); it!=this->cend(); it++){
60  ret << *it;
61  }
62  return ret;
63  }
64 
65 
70  bool isEmpty() const
71  {
72  return (this->size() == 0);
73  }
74 
75 
80  T first() const
81  {
82  return *(this->begin());
83  }
84 
90  bool contains(const T& value) const
91  {
92  auto it = this->find(value);
93  return (it != this->end());
94  }
95 
100  void remove(const T& value)
101  {
102  auto it = this->find(value);
103  if(it != this->end()){
104  this->erase(it);
105  }
106  }
107 
108  SP::Set<T>& operator<<(const T& t){
109  this->insert(t);
110  return *this;
111  }
112 
113  int count() const
114  {
115  return static_cast<int>(this->size());
116  }
117  };
118 }
119 
120 #endif // SET_H
void remove(const T &value)
removes every item that matches value
Definition: Set.h:100
bool contains(const T &value) const
check, if set contains a specific value
Definition: Set.h:90
T first() const
get copy of first element
Definition: Set.h:80
Set namespace defines the setting: Which key and which type.
Definition: SettingKey.h:230
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
Set(const T &one_element)
Constructs a set with a single element.
Definition: Set.h:45
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:38
Definition: org_mpris_media_player2_adaptor.h:20