diff options
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 |