MPD  0.20.6
CommandListBuilder.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.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 MPD_COMMAND_LIST_BUILDER_HXX
21 #define MPD_COMMAND_LIST_BUILDER_HXX
22 
23 #include <list>
24 #include <string>
25 
26 #include <assert.h>
27 
32  enum class Mode {
36  DISABLED = -1,
37 
41  ENABLED = false,
42 
46  OK = true,
47  } mode;
48 
52  std::list<std::string> list;
53 
57  size_t size;
58 
59 public:
61  :mode(Mode::DISABLED) {}
62 
66  bool IsActive() const {
67  return mode != Mode::DISABLED;
68  }
69 
73  bool IsOKMode() const {
74  assert(IsActive());
75 
76  return (bool)mode;
77  }
78 
82  void Reset();
83 
87  void Begin(bool ok) {
88  assert(list.empty());
89  assert(mode == Mode::DISABLED);
90 
91  mode = (Mode)ok;
92  size = 0;
93  }
94 
98  bool Add(const char *cmd);
99 
103  std::list<std::string> &&Commit() {
104  assert(IsActive());
105 
106  return std::move(list);
107  }
108 };
109 
110 #endif
bool IsOKMode() const
Is the object in "list_OK" mode?
std::list< std::string > && Commit()
Finishes the list and returns it.
void Begin(bool ok)
Begin building a command list.
bool Add(const char *cmd)
Enabled in normal list mode.
Enabled in "list_OK" mode.
bool IsActive() const
Is a command list currently being built?
void Reset()
Reset the object: delete the list and clear the mode.
The database is disabled, i.e.