MPD: command/Request.hxx Source File

MPD 0.20.18

Request.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_REQUEST_HXX
21 #define MPD_REQUEST_HXX
22
23 #include "check.h"
24 #include "protocol/ArgParser.hxx"
25 #include "Chrono.hxx"
26 #include "util/ConstBuffer.hxx"
27
28 #include <utility>
29
30 #include <assert.h>
31
32 class Response;
33
34 class Request : public ConstBuffer<const char *> {
35 typedef ConstBuffer<const char *> Base;
36
37 public:
38 constexpr Request(const char *const*argv, size_type n)
39 :Base(argv, n) {}
40
41 constexpr const char *GetOptional(unsigned idx,
42 const char *default_value=nullptr) const {
43 return idx < size
44 ? data[idx]
45 : default_value;
46 }
47
48 int ParseInt(unsigned idx) const {
49 assert(idx < size);
50 return ParseCommandArgInt(data[idx]);
51 }
52
53 int ParseInt(unsigned idx, int min_value, int max_value) const {
54 assert(idx < size);
55 return ParseCommandArgInt(data[idx], min_value, max_value);
56 }
57
58 int ParseUnsigned(unsigned idx) const {
59 assert(idx < size);
60 return ParseCommandArgUnsigned(data[idx]);
61 }
62
63 int ParseUnsigned(unsigned idx, unsigned max_value) const {
64 assert(idx < size);
65 return ParseCommandArgUnsigned(data[idx], max_value);
66 }
67
68 bool ParseBool(unsigned idx) const {
69 assert(idx < size);
70 return ParseCommandArgBool(data[idx]);
71 }
72
73 RangeArg ParseRange(unsigned idx) const {
74 assert(idx < size);
75 return ParseCommandArgRange(data[idx]);
76 }
77
78 float ParseFloat(unsigned idx) const {
79 assert(idx < size);
80 return ParseCommandArgFloat(data[idx]);
81 }
82
83 SongTime ParseSongTime(unsigned idx) const {
84 assert(idx < size);
85 return ParseCommandArgSongTime(data[idx]);
86 }
87
88 SignedSongTime ParseSignedSongTime(unsigned idx) const {
89 assert(idx < size);
90 return ParseCommandArgSignedSongTime(data[idx]);
91 }
92
93 int ParseOptional(unsigned idx, int default_value) const {
94 return idx < size
95 ? ParseInt(idx)
96 : default_value;
97 }
98
99 RangeArg ParseOptional(unsigned idx, RangeArg default_value) const {
100 return idx < size
101 ? ParseRange(idx)
102 : default_value;
103 }
104 };
105
106 #endif
check.h
Response
Definition: Response.hxx:31
Chrono.hxx
Request::ParseOptional
RangeArg ParseOptional(unsigned idx, RangeArg default_value) const
Definition: Request.hxx:99
Request::ParseFloat
float ParseFloat(unsigned idx) const
Definition: Request.hxx:78
SongTime
A time stamp within a song.
Definition: Chrono.hxx:31
ParseCommandArgFloat
float ParseCommandArgFloat(const char *s)
Request::ParseSignedSongTime
SignedSongTime ParseSignedSongTime(unsigned idx) const
Definition: Request.hxx:88
Request::ParseBool
bool ParseBool(unsigned idx) const
Definition: Request.hxx:68
ArgParser.hxx
ParseCommandArgSongTime
SongTime ParseCommandArgSongTime(const char *s)
ParseCommandArgInt
int ParseCommandArgInt(const char *s, int min_value, int max_value)
Request
Definition: Request.hxx:34
Request::ParseInt
int ParseInt(unsigned idx, int min_value, int max_value) const
Definition: Request.hxx:53
Request::ParseInt
int ParseInt(unsigned idx) const
Definition: Request.hxx:48
Request::ParseUnsigned
int ParseUnsigned(unsigned idx) const
Definition: Request.hxx:58
ParseCommandArgSignedSongTime
SignedSongTime ParseCommandArgSignedSongTime(const char *s)
Request::ParseOptional
int ParseOptional(unsigned idx, int default_value) const
Definition: Request.hxx:93
RangeArg
Definition: ArgParser.hxx:41
ConstBuffer< const char *>::size
size_type size
Definition: ConstBuffer.hxx:97
Request::GetOptional
constexpr const char * GetOptional(unsigned idx, const char *default_value=nullptr) const
Definition: Request.hxx:41
ParseCommandArgUnsigned
unsigned ParseCommandArgUnsigned(const char *s, unsigned max_value)
ConstBuffer< const char *>::data
pointer_type data
Definition: ConstBuffer.hxx:96
ParseCommandArgRange
RangeArg ParseCommandArgRange(const char *s)
SignedSongTime
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
Request::Request
constexpr Request(const char *const *argv, size_type n)
Definition: Request.hxx:38
Request::ParseRange
RangeArg ParseRange(unsigned idx) const
Definition: Request.hxx:73
ConstBuffer
A reference to a memory area that is read-only.
Definition: FlacPcm.hxx:29
ParseCommandArgBool
bool ParseCommandArgBool(const char *s)
ConstBuffer.hxx
ConstBuffer< const char *>::size_type
size_t size_type
Definition: ConstBuffer.hxx:88
Request::ParseUnsigned
int ParseUnsigned(unsigned idx, unsigned max_value) const
Definition: Request.hxx:63
Request::ParseSongTime
SongTime ParseSongTime(unsigned idx) const
Definition: Request.hxx:83