summaryrefslogtreecommitdiff
path: root/lib/callable.cpp
diff options
context:
space:
mode:
authorJosh Blum2013-07-05 14:53:22 -0700
committerJosh Blum2013-07-05 14:53:22 -0700
commite23e5f43a97c72f1bf0dd240376bf89ff19f356c (patch)
tree0b41a6808f714eccc380d84d772f3f634eecd53e /lib/callable.cpp
parent086cf85eca88941819909f5877d9558aaa761b72 (diff)
downloadsandhi-e23e5f43a97c72f1bf0dd240376bf89ff19f356c.tar.gz
sandhi-e23e5f43a97c72f1bf0dd240376bf89ff19f356c.tar.bz2
sandhi-e23e5f43a97c72f1bf0dd240376bf89ff19f356c.zip
gras: save callable work compiling w/ minor unit test
Diffstat (limited to 'lib/callable.cpp')
-rw-r--r--lib/callable.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/callable.cpp b/lib/callable.cpp
new file mode 100644
index 0000000..a6417bb
--- /dev/null
+++ b/lib/callable.cpp
@@ -0,0 +1,45 @@
+// 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 = new CallableRegistry();
+}
+
+Callable::~Callable(void)
+{
+ CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry);
+ delete cr;
+}
+
+void Callable::_register_call(const std::string &key, void *entry)
+{
+ CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry);
+ (*cr)[key].reset(reinterpret_cast<CallableRegistryEntry *>(entry));
+}
+
+PMCC Callable::_handle_call(const std::string &key, const std::vector<PMCC> &args)
+{
+ CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry);
+ 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
+}