Return matching named functions when a get_object query finds no matching name object
This commit is contained in:
@@ -18,6 +18,36 @@
|
|||||||
|
|
||||||
namespace dispatchkit
|
namespace dispatchkit
|
||||||
{
|
{
|
||||||
|
class Dispatch_Function : public Proxy_Function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Dispatch_Function(const std::vector<std::pair<std::string, boost::shared_ptr<Proxy_Function> > > &t_funcs)
|
||||||
|
: m_funcs(t_funcs)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Proxy_Function &f) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Dispatch_Function() {}
|
||||||
|
|
||||||
|
virtual Boxed_Value operator()(const std::vector<Boxed_Value> ¶ms)
|
||||||
|
{
|
||||||
|
return dispatch(m_funcs, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::vector<Type_Info> get_param_types()
|
||||||
|
{
|
||||||
|
return std::vector<Type_Info>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::pair<std::string, boost::shared_ptr<Proxy_Function> > > m_funcs;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Dispatch_Engine
|
class Dispatch_Engine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -103,7 +133,14 @@ namespace dispatchkit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, Function_Map::mapped_type> > funcs = get_function_impl(name, false);
|
||||||
|
|
||||||
|
if (funcs.empty())
|
||||||
|
{
|
||||||
throw std::range_error("Object not known: " + name);
|
throw std::range_error("Object not known: " + name);
|
||||||
|
} else {
|
||||||
|
return Boxed_Value(boost::shared_ptr<Proxy_Function>(new Dispatch_Function(funcs)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
@@ -118,19 +155,22 @@ namespace dispatchkit
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<std::string, Function_Map::mapped_type> >
|
std::vector<std::pair<std::string, Function_Map::mapped_type> >
|
||||||
get_function(const std::string &t_name) const
|
get_function_impl(const std::string &t_name, bool include_objects) const
|
||||||
{
|
{
|
||||||
std::vector<std::pair<std::string, Function_Map::mapped_type> > funcs;
|
std::vector<std::pair<std::string, Function_Map::mapped_type> > funcs;
|
||||||
|
|
||||||
|
if (include_objects)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
funcs.insert(funcs.end(),
|
funcs.insert(funcs.end(),
|
||||||
Function_Map::value_type(
|
Function_Map::value_type(
|
||||||
t_name,
|
t_name,
|
||||||
boxed_cast<Function_Map::mapped_type>(get_object(t_name)))
|
boxed_cast<Function_Map::mapped_type>(get_object(t_name)))
|
||||||
);
|
);
|
||||||
} catch (const std::bad_cast &) {
|
} catch (const bad_boxed_cast &) {
|
||||||
} catch (const std::range_error &) {
|
} catch (const std::range_error &) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<Function_Map::const_iterator, Function_Map::const_iterator> range
|
std::pair<Function_Map::const_iterator, Function_Map::const_iterator> range
|
||||||
= m_functions.equal_range(t_name);
|
= m_functions.equal_range(t_name);
|
||||||
@@ -139,6 +179,12 @@ namespace dispatchkit
|
|||||||
return funcs;
|
return funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, Function_Map::mapped_type> >
|
||||||
|
get_function(const std::string &t_name) const
|
||||||
|
{
|
||||||
|
return get_function_impl(t_name, true);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Function_Map::value_type> get_functions() const
|
std::vector<Function_Map::value_type> get_functions() const
|
||||||
{
|
{
|
||||||
return std::vector<Function_Map::value_type>(m_functions.begin(), m_functions.end());
|
return std::vector<Function_Map::value_type>(m_functions.begin(), m_functions.end());
|
||||||
|
Reference in New Issue
Block a user