blob: cd783fc687a1e67465fce257e2e647565fe1fd19 (
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
|
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
#include <gras/callable.hpp>
#include <boost/shared_ptr.hpp>
#include <stdexcept>
#include <map>
using namespace gras;
typedef std::map<std::string, boost::shared_ptr<CallableRegistryEntry> > CallableRegistry;
Callable::Callable(void)
{
_call_registry.reset(new CallableRegistry());
}
Callable::~Callable(void)
{
_call_registry.reset();
}
void Callable::_register_call(const std::string &key, void *entry)
{
CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry.get());
(*cr)[key].reset(reinterpret_cast<CallableRegistryEntry *>(entry));
}
PMCC Callable::_handle_call(const std::string &key, const PMCC *args)
{
CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry.get());
boost::shared_ptr<CallableRegistryEntry> entry = (*cr)[key];
if (not entry) throw std::invalid_argument("Callable: no method registered for key: " + key);
return entry->call(args);
}
CallableRegistryEntry::CallableRegistryEntry(void)
{
//NOP
}
CallableRegistryEntry::~CallableRegistryEntry(void)
{
//NOP
}
|