summaryrefslogtreecommitdiff
path: root/commands.h
blob: 78ecf48aec4e0f9fef47e9de125a2ddcd0b3efd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef COMMANDS_H
#define COMMANDS_H

#include "music.h"

#include <boost/function.hpp>
#include <boost/asio.hpp>

#include <string>
#include <vector>
#include <map>
#include <stdexcept>

class Commands;

class CommandException : public std::runtime_error {
	public:
		CommandException(const char *s) : std::runtime_error(s) {};
		CommandException(std::string s) : std::runtime_error(s.c_str()) {};
};

class Commands {
	private:
		typedef boost::function<std::vector<std::string> (Commands*)> Handler;
		std::map<std::string, Handler> handlers;

		typedef boost::function<std::vector<MusicListing::p> (const std::string artist)> FindFunction;
		//! Handlers for the find command.
		std::map<std::string, FindFunction> find_handlers;

		boost::asio::io_service& io_service;
		//! Command arguments.
		std::vector<std::string>& args;

		std::vector<std::string> ls();
		std::vector<std::string> find();
		std::vector<std::string> update();

	public:
		Commands(boost::asio::io_service& io_service, std::vector<std::string>& args);
		std::vector<std::string> operator()();

};

#endif