diff options
author | Josh Blum | 2013-07-27 19:20:35 -0700 |
---|---|---|
committer | Josh Blum | 2013-07-27 19:20:35 -0700 |
commit | a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42 (patch) | |
tree | 533568f9a549aeae63930b9767a582b4975629f2 /lib | |
parent | 9ee559e8be429e6ca18858de668289cf66e19a0f (diff) | |
download | sandhi-a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42.tar.gz sandhi-a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42.tar.bz2 sandhi-a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42.zip |
gras: added arg check with nice warning to callable and factory
Diffstat (limited to 'lib')
-rw-r--r-- | lib/callable.cpp | 7 | ||||
-rw-r--r-- | lib/factory.cpp | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/callable.cpp b/lib/callable.cpp index a7bc7da..59ada7f 100644 --- a/lib/callable.cpp +++ b/lib/callable.cpp @@ -3,6 +3,7 @@ #include <gras/callable.hpp> #include <boost/foreach.hpp> #include <boost/shared_ptr.hpp> +#include <boost/format.hpp> #include <stdexcept> #include <map> @@ -62,3 +63,9 @@ CallableRegistryEntry::~CallableRegistryEntry(void) { //NOP } + +void CallableRegistryEntry::arg_check(const PMCList &args, const size_t nargs) +{ + if (args.size() != nargs) throw std::runtime_error(str(boost::format( + "callable expected %u arguments but for %u") % nargs % args.size())); +} diff --git a/lib/factory.cpp b/lib/factory.cpp index 5c405f3..35b1b24 100644 --- a/lib/factory.cpp +++ b/lib/factory.cpp @@ -1,6 +1,7 @@ // Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. #include <gras/factory.hpp> +#include <boost/format.hpp> #include <boost/shared_ptr.hpp> #include <boost/thread/mutex.hpp> #include <stdexcept> @@ -18,6 +19,12 @@ FactoryRegistryEntry::~FactoryRegistryEntry(void) //NOP } +void FactoryRegistryEntry::arg_check(const PMCList &args, const size_t nargs) +{ + if (args.size() != nargs) throw std::runtime_error(str(boost::format( + "factory expected %u arguments but for %u") % nargs % args.size())); +} + typedef std::map<std::string, boost::shared_ptr<FactoryRegistryEntry> > FactoryRegistryType; static FactoryRegistryType &get_factory_registry(void) |