MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

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 gcc_pure
49 int ParseInt(unsigned idx) const {
50 assert(idx < size);
51 return ParseCommandArgInt(data[idx]);
52 }
53
54 gcc_pure
55 int ParseInt(unsigned idx, int min_value, int max_value) const {
56 assert(idx < size);
57 return ParseCommandArgInt(data[idx], min_value, max_value);
58 }
59
60 gcc_pure
61 int ParseUnsigned(unsigned idx) const {
62 assert(idx < size);
63 return ParseCommandArgUnsigned(data[idx]);
64 }
65
66 gcc_pure
67 int ParseUnsigned(unsigned idx, unsigned max_value) const {
68 assert(idx < size);
69 return ParseCommandArgUnsigned(data[idx], max_value);
70 }
71
72 gcc_pure
73 bool ParseBool(unsigned idx) const {
74 assert(idx < size);
75 return ParseCommandArgBool(data[idx]);
76 }
77
78 gcc_pure
79 RangeArg ParseRange(unsigned idx) const {
80 assert(idx < size);
81 return ParseCommandArgRange(data[idx]);
82 }
83
84 gcc_pure
85 float ParseFloat(unsigned idx) const {
86 assert(idx < size);
87 return ParseCommandArgFloat(data[idx]);
88 }
89
90 gcc_pure
91 SongTime ParseSongTime(unsigned idx) const {
92 assert(idx < size);
93 return ParseCommandArgSongTime(data[idx]);
94 }
95
96 gcc_pure
97 SignedSongTime ParseSignedSongTime(unsigned idx) const {
98 assert(idx < size);
99 return ParseCommandArgSignedSongTime(data[idx]);
100 }
101
102 gcc_pure
103 int ParseOptional(unsigned idx, int default_value) const {
104 return idx < size
105 ? ParseInt(idx)
106 : default_value;
107 }
108
109 gcc_pure
110 RangeArg ParseOptional(unsigned idx, RangeArg default_value) const {
111 return idx < size
112 ? ParseRange(idx)
113 : default_value;
114 }
115 };
116
117 #endif
check.h
Response
Definition: Response.hxx:31
ParseCommandArgSignedSongTime
gcc_pure SignedSongTime ParseCommandArgSignedSongTime(const char *s)
Chrono.hxx
SongTime
A time stamp within a song.
Definition: Chrono.hxx:31
Request::ParseInt
gcc_pure int ParseInt(unsigned idx, int min_value, int max_value) const
Definition: Request.hxx:55
ParseCommandArgBool
gcc_pure bool ParseCommandArgBool(const char *s)
ArgParser.hxx
Request::ParseOptional
gcc_pure RangeArg ParseOptional(unsigned idx, RangeArg default_value) const
Definition: Request.hxx:110
Request::ParseFloat
gcc_pure float ParseFloat(unsigned idx) const
Definition: Request.hxx:85
Request
Definition: Request.hxx:34
ParseCommandArgSongTime
gcc_pure SongTime ParseCommandArgSongTime(const char *s)
ParseCommandArgInt
gcc_pure int ParseCommandArgInt(const char *s, int min_value, int max_value)
RangeArg
Definition: ArgParser.hxx:45
ConstBuffer< const char * >::size
size_type size
Definition: ConstBuffer.hxx:97
Request::ParseOptional
gcc_pure int ParseOptional(unsigned idx, int default_value) const
Definition: Request.hxx:103
Request::ParseSignedSongTime
gcc_pure SignedSongTime ParseSignedSongTime(unsigned idx) const
Definition: Request.hxx:97
Request::ParseSongTime
gcc_pure SongTime ParseSongTime(unsigned idx) const
Definition: Request.hxx:91
Request::ParseRange
gcc_pure RangeArg ParseRange(unsigned idx) const
Definition: Request.hxx:79
ConstBuffer< const char * >::data
pointer_type data
Definition: ConstBuffer.hxx:96
Request::ParseInt
gcc_pure int ParseInt(unsigned idx) const
Definition: Request.hxx:49
Request::ParseBool
gcc_pure bool ParseBool(unsigned idx) const
Definition: Request.hxx:73
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
ConstBuffer
A reference to a memory area that is read-only.
Definition: FlacPcm.hxx:29
ConstBuffer.hxx
ParseCommandArgFloat
gcc_pure float ParseCommandArgFloat(const char *s)
Request::GetOptional
constexpr const char * GetOptional(unsigned idx, const char *default_value=nullptr) const
Definition: Request.hxx:41
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
ParseCommandArgUnsigned
gcc_pure unsigned ParseCommandArgUnsigned(const char *s, unsigned max_value)
Request::ParseUnsigned
gcc_pure int ParseUnsigned(unsigned idx) const
Definition: Request.hxx:61
Request::ParseUnsigned
gcc_pure int ParseUnsigned(unsigned idx, unsigned max_value) const
Definition: Request.hxx:67
ConstBuffer< const char * >::size_type
size_t size_type
Definition: ConstBuffer.hxx:88
ParseCommandArgRange
gcc_pure RangeArg ParseCommandArgRange(const char *s)