diff options
author | Max Kellermann <max@duempel.org> | 2015-08-11 22:18:40 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-08-11 23:02:34 +0200 |
commit | b1480167be487d09ff46bb86ad02041fb28acff1 (patch) | |
tree | d819a825fb82c4258cc17d5f40793409f61600a1 /src/command/Request.hxx | |
parent | e118e958f7f9b87054679ebf6102d6923abbba81 (diff) | |
download | mpd-b1480167be487d09ff46bb86ad02041fb28acff1.tar.gz mpd-b1480167be487d09ff46bb86ad02041fb28acff1.tar.xz mpd-b1480167be487d09ff46bb86ad02041fb28acff1.zip |
command/Request: add parser methods
Wrapper for protocol/ArgParser.cxx.
Diffstat (limited to 'src/command/Request.hxx')
-rw-r--r-- | src/command/Request.hxx | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/command/Request.hxx b/src/command/Request.hxx index 18fdff7f3..38b3c584c 100644 --- a/src/command/Request.hxx +++ b/src/command/Request.hxx @@ -21,14 +21,54 @@ #define MPD_REQUEST_HXX #include "check.h" +#include "protocol/ArgParser.hxx" #include "util/ConstBuffer.hxx" +#include <utility> + +#include <assert.h> + +class Client; + class Request : public ConstBuffer<const char *> { typedef ConstBuffer<const char *> Base; public: constexpr Request(const char *const*argv, size_type n) :Base(argv, n) {} + + constexpr const char *GetOptional(unsigned idx, + const char *default_value=nullptr) const { + return idx < size + ? data[idx] + : default_value; + } + + template<typename T, typename... Args> + bool Parse(unsigned idx, T &value_r, Client &client, + Args&&... args) { + assert(idx < size); + + return ParseCommandArg(client, value_r, data[idx], + std::forward<Args>(args)...); + } + + template<typename T, typename... Args> + bool ParseOptional(unsigned idx, T &value_r, Client &client, + Args&&... args) { + return idx >= size || + Parse(idx, value_r, client, + std::forward<Args>(args)...); + } + + template<typename T, typename... Args> + bool ParseShift(unsigned idx, T &value_r, Client &client, + Args&&... args) { + bool success = Parse(idx, value_r, client, + std::forward<Args>(args)...); + shift(); + return success; + } }; #endif |