diff options
author | Josh Blum | 2013-07-07 00:25:35 -0700 |
---|---|---|
committer | Josh Blum | 2013-07-07 00:25:35 -0700 |
commit | a8f263d94f8eb772a3a334aa5bb08c6e30b996ec (patch) | |
tree | bb9baa13d27d7d0150a6ee6c52add5288b502a0d /lib/callable.cpp | |
parent | 2001959902f85723c289e3f942ec2e49954a04bc (diff) | |
download | sandhi-a8f263d94f8eb772a3a334aa5bb08c6e30b996ec.tar.gz sandhi-a8f263d94f8eb772a3a334aa5bb08c6e30b996ec.tar.bz2 sandhi-a8f263d94f8eb772a3a334aa5bb08c6e30b996ec.zip |
gras: restore property access w/ json
Diffstat (limited to 'lib/callable.cpp')
-rw-r--r-- | lib/callable.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/callable.cpp b/lib/callable.cpp index 385715a..f52d604 100644 --- a/lib/callable.cpp +++ b/lib/callable.cpp @@ -1,6 +1,7 @@ // Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. #include <gras/callable.hpp> +#include <boost/foreach.hpp> #include <boost/shared_ptr.hpp> #include <stdexcept> #include <map> @@ -8,6 +9,7 @@ using namespace gras; typedef std::map<std::string, boost::shared_ptr<CallableRegistryEntry> > CallableRegistry; +typedef std::pair<std::string, boost::shared_ptr<CallableRegistryEntry> > CallableRegistryPair; Callable::Callable(void) { @@ -19,6 +21,24 @@ Callable::~Callable(void) _call_registry.reset(); } +std::vector<std::string> Callable::get_registered_keys(void) const +{ + CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry.get()); + std::vector<std::string> keys; + BOOST_FOREACH(const CallableRegistryPair &p, (*cr)) + { + keys.push_back(p.first); + } + return keys; +} + +void Callable::unregister_call(const std::string &key) +{ + CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry.get()); + if (cr->count(key) == 0) throw std::invalid_argument("Callable - no method registered for key: " + key); + cr->erase(key); +} + void Callable::_register_call(const std::string &key, void *entry) { CallableRegistry *cr = reinterpret_cast<CallableRegistry *>(_call_registry.get()); @@ -28,9 +48,8 @@ void Callable::_register_call(const std::string &key, void *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); + if (cr->count(key) == 0) throw std::invalid_argument("Callable - no method registered for key: " + key); + return (*cr)[key]->call(args); } CallableRegistryEntry::CallableRegistryEntry(void) |