Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
MotionPtr< T > Class Template ReferenceA shared_ptr for MotionCommands; provides allocation and access to a MotionCommand, ensuring mutually exclusive access and scope-based deallocation. More...
Inheritance diagram for MotionPtr< T >:
Detailed Descriptiontemplate<class T>
|
Public Member Functions | |
MotionPtr () | |
Constructor, defaults to an empty SharedObject instance and will retain the allocation once it is created. | |
MotionPtr (const SharedObject< T > obj) | |
Constructor, adopts a reference to obj, and will retain the reference between additions to the motion manager. | |
~MotionPtr () | |
Destructor, if this holds the last non-motion manager reference to the motion, removes it from the motion manager. | |
operator const SharedObject< T > & () const | |
Automatically exposes the underlying shared object so you can pass it to SharedObject-based functions (e.g. BehaviorBase::addMotion() or MotionManager::addPersistentMotion()). | |
operator MMAccessor< T > () const | |
Automatically create MMAccessor instance for mutual-exclusion access. | |
MMAccessor< T > | operator-> () const |
Forward smart-pointer style access to MMAccessor; this is the secret to one-line locking. | |
MMAccessor< T > | operator* () const |
Forward smart-pointer style access to MMAccessor, just for completeness vs. operator->, which is what you'll want to use. | |
MotionPtr & | operator= (const SharedObject< T > &obj) |
Reassigns the motion reference; henceforth shall share the region with obj (shallow copy). | |
MotionPtr & | operator= (const MotionPtr &wr) const |
Reassigns the motion reference; henceforth shall share the region with wr (shallow copy). | |
virtual MotionManager::MC_ID | getID () const |
Returns the motion command ID associated with the motion, or MotionManager::invalid_MC_ID if the motion is not allocated or otherwise not registered with the motion manager. | |
void | clear () |
Removes the reference to the current motion memory region. | |
bool | allocated () const |
Returns true if the motion is non-NULL. | |
bool | active () const |
Returns true if the motion is registered with the motion manager (i.e. it is both allocated and has a valid MC_ID). | |
bool | retain () const |
Returns retained. | |
void | retain (bool r) |
Sets retained. | |
Protected Member Functions | |
virtual void | useResource (Data &) |
marks the resource as in use | |
virtual void | releaseResource (Data &) |
releases the resource | |
virtual void | processEvent (const EventBase &event) |
We only listen for motion deactivate events if not retained, so if we get a call here we should clear the reference. | |
Protected Attributes | |
SharedObject< T > | mcObj |
Maintains the reference to the motion's shared memory region. | |
std::stack< MotionManager::MC_ID > | checkouts |
Retains a history of useResource() calls, to be released by matching releaseResource() calls. | |
bool | retained |
If false, clears the motion instance each time it is removed from the motion manager, and then recreate it if a future access occurs. |
Constructor, defaults to an empty SharedObject instance and will retain the allocation once it is created.
Definition at line 11 of file MotionPtr.h.
MotionPtr< T >::MotionPtr | ( | const SharedObject< T > | obj | ) |
Constructor, adopts a reference to obj, and will retain the reference between additions to the motion manager.
Definition at line 13 of file MotionPtr.h.
Destructor, if this holds the last non-motion manager reference to the motion, removes it from the motion manager.
Definition at line 15 of file MotionPtr.h.
bool MotionPtr< T >::active | ( | ) | const |
Returns true if the motion is registered with the motion manager (i.e. it is both allocated and has a valid MC_ID).
Definition at line 84 of file MotionPtr.h.
bool MotionPtr< T >::allocated | ( | ) | const |
Returns true if the motion is non-NULL.
Definition at line 81 of file MotionPtr.h.
Referenced by MotionPtr< HeadPointerMC >::processEvent().
void MotionPtr< T >::clear | ( | ) |
Removes the reference to the current motion memory region.
A new one will be created with the default constructor if a future access is attempted.
Definition at line 78 of file MotionPtr.h.
Referenced by LookAtMarkers::Search::doEvent().
virtual MotionManager::MC_ID MotionPtr< T >::getID | ( | ) | const [virtual] |
Returns the motion command ID associated with the motion, or MotionManager::invalid_MC_ID if the motion is not allocated or otherwise not registered with the motion manager.
Definition at line 70 of file MotionPtr.h.
MotionPtr< T >::operator const SharedObject< T > & | ( | ) | const |
Automatically exposes the underlying shared object so you can pass it to SharedObject-based functions (e.g. BehaviorBase::addMotion() or MotionManager::addPersistentMotion()).
Definition at line 30 of file MotionPtr.h.
MotionPtr< T >::operator MMAccessor< T > | ( | ) | const |
Automatically create MMAccessor instance for mutual-exclusion access.
This lets you assign the MotionPtr to a MMAccessor, so that the lock persists under the new scope and name. You could also use MarkScope with the MotionPtr.
Definition at line 38 of file MotionPtr.h.
MMAccessor<T> MotionPtr< T >::operator* | ( | ) | const |
Forward smart-pointer style access to MMAccessor, just for completeness vs. operator->, which is what you'll want to use.
This is actually a little syntactically wrong, because operator*() should return a reference vs. operator->'s pointer, but then we would lose the locking guarantee.
Definition at line 49 of file MotionPtr.h.
MMAccessor<T> MotionPtr< T >::operator-> | ( | ) | const |
Forward smart-pointer style access to MMAccessor; this is the secret to one-line locking.
Keep in mind you can use MarkScope with the MotionPtr to retain the lock over the course of multiple accesses
Definition at line 45 of file MotionPtr.h.
Reassigns the motion reference; henceforth shall share the region with wr (shallow copy).
Internal reference counting by the shared memory region will keep everything happy :)
Definition at line 67 of file MotionPtr.h.
MotionPtr& MotionPtr< T >::operator= | ( | const SharedObject< T > & | obj | ) |
Reassigns the motion reference; henceforth shall share the region with obj (shallow copy).
Internal reference counting by the shared memory region will keep everything happy :)
Definition at line 53 of file MotionPtr.h.
virtual void MotionPtr< T >::processEvent | ( | const EventBase & | event | ) | [protected, virtual] |
We only listen for motion deactivate events if not retained, so if we get a call here we should clear the reference.
Implements EventListener.
Definition at line 118 of file MotionPtr.h.
void MotionPtr< T >::retain | ( | bool | r | ) |
Sets retained.
Definition at line 90 of file MotionPtr.h.
bool MotionPtr< T >::retain | ( | ) | const |
Returns retained.
Definition at line 87 of file MotionPtr.h.
std::stack<MotionManager::MC_ID> MotionPtr< T >::checkouts [protected] |
Retains a history of useResource() calls, to be released by matching releaseResource() calls.
This solves the problem of removing a motion while it is locked... the removal clears the ID value in mcObj, thus we need to store it here so we can checkin (unlock) the motion later. Using a stack lets us handle recursively re-adding the motion and receiving a new ID while still locked under the original ID.
Definition at line 141 of file MotionPtr.h.
SharedObject<T> MotionPtr< T >::mcObj [protected] |
Maintains the reference to the motion's shared memory region.
Definition at line 135 of file MotionPtr.h.
Referenced by MotionPtr< HeadPointerMC >::processEvent().
If false, clears the motion instance each time it is removed from the motion manager, and then recreate it if a future access occurs.
If true, the reference on mcObj will be retained between additions to the motion manager, which is the default behavior.
Definition at line 145 of file MotionPtr.h.
Tekkotsu v5.1CVS |
Generated Mon May 9 04:59:13 2016 by Doxygen 1.6.3 |