OpenWalnut  1.4.0
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
WGEGroupNode Class Reference

Class to wrap around the osg Group node and providing a thread safe add/removal mechanism. More...

#include <WGEGroupNode.h>

+ Inheritance diagram for WGEGroupNode:

Classes

struct  ChildOperation
 A struct denoting an operation on this group. More...
 
class  SafeUpdaterCallback
 Update callback which inserts and removes nodes from m_childRemovalQueue and m_childInsertionQueue to the group node. More...
 

Public Types

typedef
WPredicateHelper::ArbitraryPredicateBase
< osg::ref_ptr< osg::Node >
const > 
NodePredicate
 The base type of predicate. More...
 

Public Member Functions

 WGEGroupNode ()
 Default constructor. More...
 
void insert (osg::ref_ptr< osg::Node > node)
 Adds the specified node to the child list of this node in a safe manner. More...
 
void remove (osg::ref_ptr< osg::Node > node)
 Removes the specified node from this group in a thread safe manner. More...
 
void remove_if (boost::shared_ptr< WGEGroupNode::NodePredicate > predicate)
 Removes a node if the specified predicate evaluates to true. More...
 
void clear ()
 Removes all children from this node. More...
 

Protected Types

enum  ChildOperationType { INSERT = 0, REMOVE, REMOVE_IF, CLEAR }
 The type of operation to perform. More...
 

Protected Member Functions

virtual ~WGEGroupNode ()
 Destructor. More...
 

Protected Attributes

osg::ref_ptr< SafeUpdaterCallbackm_nodeUpdater
 Node callback used to update this root node. More...
 
std::queue< boost::shared_ptr
< ChildOperation > > 
m_childOperationQueue
 Queue of childs that need to be added/removed during the next update cycle. More...
 
boost::shared_mutex m_childOperationQueueLock
 Lock used for inserting and removing childs into the child insertion/removal queue. More...
 
bool m_childOperationQueueDirty
 Flag denoting whether the m_childOperationQueue should be considered during the next update of the node. More...
 
bool m_removeAll
 True whenever all child nodes should be removed. More...
 

Detailed Description

Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.

Please be sure to use addUpdateCallback() to set your own update callbacks instead of setUpdateCallback, as this class already has set a callback, which would be overwritten by a subsequent call to setUpdateCallback(). It is derived from osg::MatrixTransform to allow easy transformations of a whole bunch of nodes.

Definition at line 46 of file WGEGroupNode.h.

Member Typedef Documentation

typedef WPredicateHelper::ArbitraryPredicateBase< osg::ref_ptr< osg::Node > const > WGEGroupNode::NodePredicate

The base type of predicate.

Use a specific WPredicateHelper::ArbitraryPredicate instance. For details, see WPredicateHelper::ArbitraryPredicateBase.

Definition at line 75 of file WGEGroupNode.h.

Member Enumeration Documentation

The type of operation to perform.

Enumerator
REMOVE 

insert the specified node

REMOVE_IF 

remove the specified node

CLEAR 

remove all items where the predicate evaluates to true

clear group node completely

Definition at line 122 of file WGEGroupNode.h.

Constructor & Destructor Documentation

WGEGroupNode::WGEGroupNode ( )

Default constructor.

Definition at line 33 of file WGEGroupNode.cpp.

References m_nodeUpdater.

WGEGroupNode::~WGEGroupNode ( )
protectedvirtual

Destructor.

Definition at line 49 of file WGEGroupNode.cpp.

Member Function Documentation

void WGEGroupNode::clear ( )

Removes all children from this node.

Definition at line 78 of file WGEGroupNode.cpp.

References CLEAR, m_childOperationQueue, m_childOperationQueueDirty, and m_childOperationQueueLock.

void WGEGroupNode::insert ( osg::ref_ptr< osg::Node >  node)

Adds the specified node to the child list of this node in a safe manner.

OSG officially requires nodes to be added exclusively during update callbacks. Using this method it is ensured to be added during update cycle.

Parameters
nodethe node to add.
Notes:
the node may not be added instantly. So do not assume that containsNode ( node ) will return true.

Definition at line 54 of file WGEGroupNode.cpp.

References m_childOperationQueue, m_childOperationQueueDirty, and m_childOperationQueueLock.

Referenced by WGEOffscreenRenderNode::addGeometryRenderPass(), WGEOffscreenRenderNode::addRenderPass(), WGEBorderLayout::WGEBorderLayout(), and WGEOffscreenRenderNode::WGEOffscreenRenderNode().

void WGEGroupNode::remove ( osg::ref_ptr< osg::Node >  node)

Removes the specified node from this group in a thread safe manner.

It returns if the node has been removed.

Parameters
nodethe node to remove

Definition at line 62 of file WGEGroupNode.cpp.

References m_childOperationQueue, m_childOperationQueueDirty, m_childOperationQueueLock, and REMOVE.

void WGEGroupNode::remove_if ( boost::shared_ptr< WGEGroupNode::NodePredicate predicate)

Removes a node if the specified predicate evaluates to true.

See also
WPredicateHelper::ArbitraryPredicate for details.
Parameters
predicatethe predicate.

Definition at line 70 of file WGEGroupNode.cpp.

References m_childOperationQueue, m_childOperationQueueDirty, m_childOperationQueueLock, and REMOVE_IF.

Member Data Documentation

std::queue< boost::shared_ptr< ChildOperation > > WGEGroupNode::m_childOperationQueue
protected

Queue of childs that need to be added/removed during the next update cycle.

It is a pair per operation, where the bool is denoting removal or insertion.

Definition at line 171 of file WGEGroupNode.h.

Referenced by clear(), insert(), WGEGroupNode::SafeUpdaterCallback::operator()(), remove(), and remove_if().

bool WGEGroupNode::m_childOperationQueueDirty
protected

Flag denoting whether the m_childOperationQueue should be considered during the next update of the node.

Definition at line 181 of file WGEGroupNode.h.

Referenced by clear(), insert(), WGEGroupNode::SafeUpdaterCallback::operator()(), remove(), and remove_if().

boost::shared_mutex WGEGroupNode::m_childOperationQueueLock
protected

Lock used for inserting and removing childs into the child insertion/removal queue.

Definition at line 176 of file WGEGroupNode.h.

Referenced by clear(), insert(), WGEGroupNode::SafeUpdaterCallback::operator()(), remove(), and remove_if().

osg::ref_ptr< SafeUpdaterCallback > WGEGroupNode::m_nodeUpdater
protected

Node callback used to update this root node.

Definition at line 117 of file WGEGroupNode.h.

Referenced by WGEGroupNode().

bool WGEGroupNode::m_removeAll
protected

True whenever all child nodes should be removed.

Definition at line 186 of file WGEGroupNode.h.

Referenced by WGEGroupNode::SafeUpdaterCallback::operator()().


The documentation for this class was generated from the following files: