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 *> {
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);
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
SignedSongTime ParseSignedSongTime(unsigned idx) const
Definition: Request.hxx:88
SongTime ParseSongTime(unsigned idx) const
Definition: Request.hxx:83
int ParseUnsigned(unsigned idx, unsigned max_value) const
Definition: Request.hxx:63
A time stamp within a song.
Definition: Chrono.hxx:31
float ParseCommandArgFloat(const char *s)
SongTime ParseCommandArgSongTime(const char *s)
int ParseCommandArgInt(const char *s, int min_value, int max_value)
float ParseFloat(unsigned idx) const
Definition: Request.hxx:78
SignedSongTime ParseCommandArgSignedSongTime(const char *s)
int ParseInt(unsigned idx, int min_value, int max_value) const
Definition: Request.hxx:53
unsigned ParseCommandArgUnsigned(const char *s, unsigned max_value)
int ParseOptional(unsigned idx, int default_value) const
Definition: Request.hxx:93
RangeArg ParseCommandArgRange(const char *s)
RangeArg ParseOptional(unsigned idx, RangeArg default_value) const
Definition: Request.hxx:99
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
constexpr Request(const char *const *argv, size_type n)
Definition: Request.hxx:38
A reference to a memory area that is read-only.
Definition: FlacPcm.hxx:29
bool ParseCommandArgBool(const char *s)
int ParseUnsigned(unsigned idx) const
Definition: Request.hxx:58
int ParseInt(unsigned idx) const
Definition: Request.hxx:48
constexpr const char * GetOptional(unsigned idx, const char *default_value=nullptr) const
Definition: Request.hxx:41
bool ParseBool(unsigned idx) const
Definition: Request.hxx:68
RangeArg ParseRange(unsigned idx) const
Definition: Request.hxx:73