35 #ifndef ACTIONLIB__MANAGED_LIST_H_ 36 #define ACTIONLIB__MANAGED_LIST_H_ 39 #include <boost/thread.hpp> 40 #include <boost/shared_ptr.hpp> 41 #include <boost/weak_ptr.hpp> 83 iterator(
typename std::list<TrackedElem>::iterator it)
85 typename std::list<TrackedElem>::iterator
it_;
96 : it_(it), deleter_(deleter), guard_(guard)
104 "ManagedList: The DestructionGuard associated with this list has already been destructed. You must delete all list handles before deleting the ManagedList");
164 ROS_ERROR_NAMED(
"actionlib",
"getElem() should not see invalid handles");
173 ROS_ERROR_NAMED(
"actionlib",
"getElem() should not see invalid handles");
185 ROS_ERROR_NAMED(
"actionlib",
"operator== should not see invalid handles");
189 ROS_ERROR_NAMED(
"actionlib",
"operator== should not see invalid RHS handles");
191 return it_ == rhs.
it_;
224 Handle
add(
const T &
elem, CustomDeleter custom_deleter,
227 TrackedElem tracked_t;
228 tracked_t.elem =
elem;
230 typename std::list<TrackedElem>::iterator list_it =
list_.insert(
list_.end(), tracked_t);
231 iterator managed_it = iterator(list_it);
233 ElemDeleter deleter(managed_it, custom_deleter, guard);
236 list_it->handle_tracker_ = tracker;
238 return Handle(tracker, managed_it);
263 if (it_->handle_tracker_.expired()) {
264 ROS_ERROR_NAMED(
"actionlib",
"Tried to create a handle to a list elem with refcount 0");
269 return Handle(tracker, *
this);
274 #endif // ACTIONLIB__MANAGED_LIST_H_
Handle createHandle()
Creates a refcounted Handle from an iterator.
Handle & operator=(const Handle &rhs)
iterator(typename std::list< TrackedElem >::iterator it)
const T & operator->() const
std::list< TrackedElem > list_
std::list< TrackedElem >::iterator it_
T & getElem()
get the list element that this handle points to fails/asserts if this is an empty handle ...
bool isProtected()
Checks if the ScopedProtector successfully protected the DestructionGuard.
Handle add(const T &elem)
Add an element to the back of the ManagedList.
boost::function< void(iterator)> CustomDeleter
Handle()
Construct an empty handle.
void erase(iterator it)
Removes an element from the ManagedList.
boost::shared_ptr< DestructionGuard > guard_
void defaultDeleter(iterator it)
#define ROS_DEBUG_NAMED(name,...)
wrapper around an STL list to help with reference counting Provides handles elements in an STL list...
bool operator==(const iterator &rhs) const
void reset()
stop tracking the list element with this handle, even though the Handle hasn't gone out of scope ...
const T & getElem() const
bool operator!=(const iterator &rhs) const
boost::shared_ptr< void > handle_tracker_
boost::weak_ptr< void > handle_tracker_
Handle(const boost::shared_ptr< void > &handle_tracker, iterator it)
#define ROS_ERROR_NAMED(name,...)
const T & operator*() const
ElemDeleter(iterator it, CustomDeleter deleter, const boost::shared_ptr< DestructionGuard > &guard)
Protects a DestructionGuard until this object goes out of scope.
bool operator==(const Handle &rhs) const
Checks if two handles point to the same list elem.
Handle add(const T &elem, CustomDeleter custom_deleter, const boost::shared_ptr< DestructionGuard > &guard)
Add an element to the back of the ManagedList, along with a Custom deleter.