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 
43  Set() :
44  std::set<T>()
45  {}
46 
51  Set(const T& one_element) :
52  Set()
53  {
54  this->insert(one_element);
55  }
56 
57 
62  QList<T> toList() const
63  {
64  QList<T> ret;
65  for(auto it=this->begin(); it!=this->end(); it++){
66  ret << *it;
67  }
68  return ret;
69  }
70 
71 
76  bool isEmpty() const
77  {
78  return (this->size() == 0);
79  }
80 
81 
86  T first() const
87  {
88  return *(this->begin());
89  }
90 
96  bool contains(const T& value) const
97  {
98  auto it = this->find(value);
99  return (it != this->end());
100  }
101 
106  void remove(const T& value)
107  {
108  auto it = this->find(value);
109  if(it != this->end()){
110  this->erase(it);
111  }
112  }
113 
114  SP::Set<T>& operator<<(const T& t){
115  this->insert(t);
116  return *this;
117  }
118 
119  int count() const
120  {
121  return static_cast<int>(this->size());
122  }
123  };
124 }
125 
126 #endif // SET_H
Set()
Standard constructor.
Definition: Set.h:43
bool contains(const T &value) const
check, if set contains a specific value
Definition: Set.h:96
Definition: AbstractPlaylist.h:33
T first() const
get copy of first element
Definition: Set.h:86
Set namespace defines the setting: Which key and which type.
Definition: SettingKey.h:216
bool isEmpty() const
Definition: Set.h:76
QList< T > toList() const
converts the set to a list. The order is random
Definition: Set.h:62
Set(const T &one_element)
Constructs a set with a single element.
Definition: Set.h:51
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:36
Definition: org_mpris_media_player2_adaptor.h:20