ncmpc  0.31
Completion.hxx
Go to the documentation of this file.
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2018 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef COMPLETION_HXX
21 #define COMPLETION_HXX
22 
23 #include <set>
24 #include <string>
25 
26 class Completion {
27 protected:
28  using List = std::set<std::string>;
30 
31 public:
32  Completion() = default;
33 
34  Completion(const Completion &) = delete;
35  Completion &operator=(const Completion &) = delete;
36 
37  bool empty() const {
38  return list.empty();
39  }
40 
41  void clear() {
42  list.clear();
43  }
44 
45  template<typename T>
46  void emplace(T &&value) {
47  list.emplace(std::forward<T>(value));
48  }
49 
50  template<typename T>
51  void remove(T &&value) {
52  auto i = list.find(std::forward<T>(value));
53  if (i != list.end())
54  list.erase(i);
55  }
56 
57  struct Range {
58  using const_iterator = List::const_iterator;
60 
61  bool operator==(const Range other) const {
62  return _begin == other._begin && _end == other._end;
63  }
64 
65  bool operator!=(const Range other) const {
66  return !(*this == other);
67  }
68 
70  return _begin;
71  }
72 
73  const_iterator end() const {
74  return _end;
75  }
76  };
77 
78  struct Result {
79  std::string new_prefix;
80 
82  };
83 
84  Result Complete(const std::string &prefix) const;
85 
86  virtual void Pre(const char *value) = 0;
87  virtual void Post(const char *value, Range range) = 0;
88 };
89 
90 #endif
Completion & operator=(const Completion &)=delete
virtual void Pre(const char *value)=0
Definition: Completion.hxx:26
virtual void Post(const char *value, Range range)=0
const_iterator end() const
Definition: Completion.hxx:73
Definition: Completion.hxx:57
List::const_iterator const_iterator
Definition: Completion.hxx:58
List list
Definition: Completion.hxx:29
Range range
Definition: Completion.hxx:81
bool operator==(const Range other) const
Definition: Completion.hxx:61
std::set< std::string > List
Definition: Completion.hxx:28
const_iterator _begin
Definition: Completion.hxx:59
Definition: Completion.hxx:78
void emplace(T &&value)
Definition: Completion.hxx:46
bool operator!=(const Range other) const
Definition: Completion.hxx:65
Result Complete(const std::string &prefix) const
Completion()=default
bool empty() const
Definition: Completion.hxx:37
std::string new_prefix
Definition: Completion.hxx:79
void clear()
Definition: Completion.hxx:41
const_iterator _end
Definition: Completion.hxx:59
const_iterator begin() const
Definition: Completion.hxx:69