MPD  0.20.6
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  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);
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
gcc_pure SignedSongTime ParseCommandArgSignedSongTime(const char *s)
A time stamp within a song.
Definition: Chrono.hxx:31
gcc_pure int ParseInt(unsigned idx, int min_value, int max_value) const
Definition: Request.hxx:55
gcc_pure bool ParseCommandArgBool(const char *s)
gcc_pure RangeArg ParseOptional(unsigned idx, RangeArg default_value) const
Definition: Request.hxx:110
gcc_pure float ParseFloat(unsigned idx) const
Definition: Request.hxx:85
gcc_pure SongTime ParseCommandArgSongTime(const char *s)
gcc_pure int ParseCommandArgInt(const char *s, int min_value, int max_value)
gcc_pure int ParseOptional(unsigned idx, int default_value) const
Definition: Request.hxx:103
gcc_pure SignedSongTime ParseSignedSongTime(unsigned idx) const
Definition: Request.hxx:97
gcc_pure SongTime ParseSongTime(unsigned idx) const
Definition: Request.hxx:91
gcc_pure RangeArg ParseRange(unsigned idx) const
Definition: Request.hxx:79
gcc_pure int ParseInt(unsigned idx) const
Definition: Request.hxx:49
gcc_pure bool ParseBool(unsigned idx) const
Definition: Request.hxx:73
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
gcc_pure float ParseCommandArgFloat(const char *s)
constexpr const char * GetOptional(unsigned idx, const char *default_value=nullptr) const
Definition: Request.hxx:41
#define gcc_pure
Definition: Compiler.h:116
gcc_pure unsigned ParseCommandArgUnsigned(const char *s, unsigned max_value)
gcc_pure int ParseUnsigned(unsigned idx) const
Definition: Request.hxx:61
gcc_pure int ParseUnsigned(unsigned idx, unsigned max_value) const
Definition: Request.hxx:67
gcc_pure RangeArg ParseCommandArgRange(const char *s)