Skip to content
Snippets Groups Projects
Commit cc3d21cc authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

DRTVWR-558: Tweak LLEventDispatcher.

Instead of std::map<std::string, boost::shared_ptr>, use std::unique_ptr as
the mapped_type, using emplace() to store new entries. This more correctly
captures the desired semantics: we have no intention of passing around the
pointers in the map, we just want the map to delete them on destruction.

Use std::function instead of boost::function.

(cherry picked from commit 7ba53ef82db5683756e296225f0c8b838420a26e)
parent 8855a82f
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
......@@ -561,9 +561,7 @@ void LLEventDispatcher::addArrayParamsDispatchEntry(const std::string& name,
const invoker_function& invoker,
LLSD::Integer arity)
{
mDispatch.insert(
DispatchMap::value_type(name, DispatchMap::mapped_type(
new ArrayParamsDispatchEntry(desc, invoker, arity))));
mDispatch.emplace(name, new ArrayParamsDispatchEntry(desc, invoker, arity));
}
void LLEventDispatcher::addMapParamsDispatchEntry(const std::string& name,
......@@ -572,18 +570,14 @@ void LLEventDispatcher::addMapParamsDispatchEntry(const std::string& name,
const LLSD& params,
const LLSD& defaults)
{
mDispatch.insert(
DispatchMap::value_type(name, DispatchMap::mapped_type(
new MapParamsDispatchEntry(name, desc, invoker, params, defaults))));
mDispatch.emplace(name, new MapParamsDispatchEntry(name, desc, invoker, params, defaults));
}
/// Register a callable by name
void LLEventDispatcher::add(const std::string& name, const std::string& desc,
const Callable& callable, const LLSD& required)
{
mDispatch.insert(
DispatchMap::value_type(name, DispatchMap::mapped_type(
new LLSDDispatchEntry(desc, callable, required))));
mDispatch.emplace(name, new LLSDDispatchEntry(desc, callable, required));
}
/// Unregister a callable
......
......@@ -56,9 +56,6 @@ static const auto nil_(nil);
static const auto& nil(nil_);
#endif
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/function_types/is_nonmember_callable_builtin.hpp>
......@@ -73,6 +70,9 @@ static const auto& nil(nil_);
#include <boost/mpl/end.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/deref.hpp>
#include <functional> // std::function
#include <memory> // std::unique_ptr
#include <string>
#include <typeinfo>
#include "llevents.h"
#include "llsdutil.h"
......@@ -96,7 +96,7 @@ class LL_COMMON_API LLEventDispatcher
/// Accept any C++ callable with the right signature, typically a
/// boost::bind() expression
typedef boost::function<void(const LLSD&)> Callable;
typedef std::function<void(const LLSD&)> Callable;
/**
* Register a @a callable by @a name. The passed @a callable accepts a
......@@ -293,14 +293,7 @@ class LL_COMMON_API LLEventDispatcher
virtual void call(const std::string& desc, const LLSD& event) const = 0;
virtual LLSD addMetadata(LLSD) const = 0;
};
// Tried using boost::ptr_map<std::string, DispatchEntry>, but ptr_map<>
// wants its value type to be "clonable," even just to dereference an
// iterator. I don't want to clone entries -- if I have to copy an entry
// around, I want it to continue pointing to the same DispatchEntry
// subclass object. However, I definitely want DispatchMap to destroy
// DispatchEntry if no references are outstanding at the time an entry is
// removed. This looks like a job for boost::shared_ptr.
typedef std::map<std::string, boost::shared_ptr<DispatchEntry> > DispatchMap;
typedef std::map<std::string, std::unique_ptr<DispatchEntry> > DispatchMap;
public:
/// We want the flexibility to redefine what data we store per name,
......@@ -363,10 +356,10 @@ class LL_COMMON_API LLEventDispatcher
struct invoker;
// deliver LLSD arguments one at a time
typedef boost::function<LLSD()> args_source;
typedef std::function<LLSD()> args_source;
// obtain args from an args_source to build param list and call target
// function
typedef boost::function<void(const args_source&)> invoker_function;
typedef std::function<void(const args_source&)> invoker_function;
template <typename Function>
invoker_function make_invoker(Function f);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment