blob: a095a1f218e2dd2c47384e4ebf5b0599edf6ceab (
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
|
#include "stdafx.h"
#include "subcommanddispatcher.h"
#include <libcommon/string.h>
#include <libcommon/error.h>
#include <sstream>
#include <utility>
void SubcommandDispatcher::addSubcommand(const std::wstring &command, Handler handler)
{
m_commands.insert(std::make_pair(command, handler));
}
void SubcommandDispatcher::dispatch(const std::wstring &command, const std::vector<std::wstring> &arguments)
{
auto selectedCommand = m_commands.find(command);
if (m_commands.end() == selectedCommand)
{
std::wstringstream ss;
ss << L"Unsupported subcommand '" << command << "'. Cannot complete request.";
THROW_ERROR(common::string::ToAnsi(ss.str()).c_str());
}
selectedCommand->second(common::string::SplitKeyValuePairs(arguments));
}
|