summaryrefslogtreecommitdiff
path: root/lib
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
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')
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/callable.cpp45
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index ab5d886..38216b3 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -41,6 +41,7 @@ list(APPEND GRAS_SOURCES ${apology_sources})
########################################################################
list(APPEND GRAS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/debug.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/callable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/element.cpp
${CMAKE_CURRENT_SOURCE_DIR}/element_uid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sbuffer.cpp
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
+}