walberla::pe::BodyStorage Class Reference

Detailed Description

Body storage of the rigid body simulation world.

A BodyStorage is a data structure for storing rigid bodies. It supports efficient insertion and deletion operations.

#include <BodyStorage.h>

+ Inheritance diagram for walberla::pe::BodyStorage:

Public Types

using VectorContainer = std::vector< std::unique_ptr< RigidBody > >
 Container for the bodies contained in the simulation world. More...
 
using ConstVectorContainer = std::vector< std::unique_ptr< const RigidBody > >
 
using size_type = VectorContainer::size_type
 Size type of the body storage. More...
 
using iterator = RigidBodyIterator
 Iterator over non-const bodies. More...
 
using const_iterator = ConstRigidBodyIterator
 Iterator over constant bodies. More...
 
template<typename C >
using cast_iterator = RigidBodyCastIterator< C >
 
template<typename C >
using const_cast_iterator = ConstRigidBodyCastIterator< C >
 

Public Member Functions

Constructors
 BodyStorage ()
 The standard constructor. More...
 
Destructor
 ~BodyStorage ()
 The destructor. More...
 
Utility functions
bool isEmpty () const
 Returns true if the body storage contains no rigid bodies. More...
 
size_type size () const
 Returns the number of rigid bodies contained in the body storage. More...
 
iterator begin ()
 Returns an iterator to the first contained rigid body. More...
 
const_iterator begin () const
 
const_iterator cbegin () const
 Returns a constant iterator to the first contained rigid body. More...
 
iterator end ()
 Returns an iterator just past the last contained rigid body. More...
 
const_iterator end () const
 
const_iterator cend () const
 Returns a constant iterator just past the last contained rigid body. More...
 
template<typename C >
cast_iterator< C > begin ()
 Returns an iterator to the first contained rigid body. More...
 
template<typename C >
const_cast_iterator< C > begin () const
 Returns a constant iterator to the first contained rigid body. More...
 
template<typename C >
const_cast_iterator< C > cbegin () const
 Returns a constant iterator to the first contained rigid body. More...
 
template<typename C >
cast_iterator< C > end ()
 Returns an iterator just past the last contained rigid body. More...
 
template<typename C >
const_cast_iterator< C > end () const
 Returns a constant iterator just past the last contained rigid body. More...
 
template<typename C >
const_cast_iterator< C > cend () const
 Returns a constant iterator just past the last contained rigid body. More...
 
RigidBodyfront ()
 
const RigidBodyfront () const
 
RigidBodyback ()
 
const RigidBodyback () const
 
BodyID at (size_type index)
 Returns a handle to the indexed rigid body. More...
 
ConstBodyID at (size_type index) const
 Returns a constant handle to the indexed rigid body. More...
 
iterator find (id_t sid)
 Finding a rigid body with a certain unique system-specific ID. More...
 
const_iterator find (id_t sid) const
 Finding a rigid body with a certain unique system-specific ID. More...
 
iterator find (ConstBodyID body)
 Finding a specific rigid body in the body storage. More...
 
const_iterator find (ConstBodyID body) const
 Finding a specific rigid body in the body storage. More...
 
void validate ()
 Validating the correctness of the body storage data structure. More...
 
Add/Remove functions
RigidBodyadd (BodyID body)
 Adding a rigid body to the body storage. More...
 
RigidBodyadd (std::unique_ptr< RigidBody > &&body)
 Adding a rigid body to the body storage. More...
 
iterator remove (const id_t sid)
 Removing a rigid body from the body storage. More...
 
iterator remove (BodyID body)
 Removing a rigid body from the body storage. More...
 
const_iterator remove (const_iterator pos)
 Removing a rigid body from the body storage. More...
 
iterator remove (iterator pos)
 Removing a rigid body from the body storage. More...
 
std::unique_ptr< RigidBodyrelease (const id_t sid)
 Release a rigid body from the body storage. More...
 
std::unique_ptr< RigidBodyrelease (BodyID body)
 Release a rigid body from the body storage. More...
 
std::unique_ptr< RigidBodyrelease (const_iterator &pos)
 Release a rigid body from the body storage. More...
 
std::unique_ptr< RigidBodyrelease (iterator &pos)
 Releasing a rigid body from the body storage. More...
 
void clear ()
 Removing all rigid bodies from the body storage. More...
 
Callbacks
void registerAddCallback (const std::string &name, const std::function< void(BodyID)> &func)
 
void deregisterAddCallback (const std::string &name)
 
void clearAddCallbacks ()
 
void registerRemoveCallback (const std::string &name, const std::function< void(BodyID)> &func)
 
void deregisterRemoveCallback (const std::string &name)
 
void clearRemoveCallbacks ()
 

Private Attributes

Member variables
VectorContainer bodies_
 The rigid bodies contained in the simulation world. More...
 
std::map< id_t, size_typebodyIDs_
 The association of system IDs to rigid bodies. More...
 
std::map< std::string, std::function< void(BodyID)> > addCallbacks_
 
std::map< std::string, std::function< void(BodyID)> > removeCallbacks_
 

Additional Inherited Members

- Private Member Functions inherited from walberla::NonCopyable
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Member Typedef Documentation

◆ cast_iterator

◆ const_cast_iterator

◆ const_iterator

Iterator over constant bodies.

◆ ConstVectorContainer

using walberla::pe::BodyStorage::ConstVectorContainer = std::vector< std::unique_ptr<const RigidBody> >

◆ iterator

Iterator over non-const bodies.

◆ size_type

using walberla::pe::BodyStorage::size_type = VectorContainer::size_type

Size type of the body storage.

◆ VectorContainer

using walberla::pe::BodyStorage::VectorContainer = std::vector< std::unique_ptr<RigidBody> >

Container for the bodies contained in the simulation world.

Constructor & Destructor Documentation

◆ BodyStorage()

walberla::pe::BodyStorage::BodyStorage ( )
inlineexplicit

The standard constructor.

◆ ~BodyStorage()

walberla::pe::BodyStorage::~BodyStorage ( )
inline

The destructor.

The destructor clears all rigid bodies from the storage before destructing it.

Member Function Documentation

◆ add() [1/2]

RigidBody & walberla::pe::BodyStorage::add ( BodyID  body)
inline

Adding a rigid body to the body storage.

Parameters
bodyThe new rigid body to be added to the body storage.
Returns
void

This function adds a rigid body to the body storage. Adding bodies with non-unique system ID or adding the same body multiple times results in undefined behaviour. The time complexity is logarithmic unless reallocation occurs.

◆ add() [2/2]

RigidBody & walberla::pe::BodyStorage::add ( std::unique_ptr< RigidBody > &&  body)
inline

Adding a rigid body to the body storage.

Parameters
bodyThe new rigid body to be added to the body storage.
Returns
void

This function adds a rigid body to the body storage. Adding bodies with non-unique system ID or adding the same body multiple times results in undefined behaviour. The time complexity is logarithmic unless reallocation occurs.

◆ at() [1/2]

BodyID walberla::pe::BodyStorage::at ( size_type  index)
inline

Returns a handle to the indexed rigid body.

Parameters
indexAccess index. The index has to be in the range \([0..size-1]\).
Returns
Handle to the accessed rigid body.

Note: No runtime check is performed to ensure the validity of the access index.

◆ at() [2/2]

ConstBodyID walberla::pe::BodyStorage::at ( size_type  index) const
inline

Returns a constant handle to the indexed rigid body.

Parameters
indexAccess index. The index has to be in the range \([0..size-1]\).
Returns
Constant handle to the accessed rigid body.

Note: No runtime check is performed to ensure the validity of the access index.

◆ back() [1/2]

const RigidBody & walberla::pe::BodyStorage::back ( )
inline

◆ back() [2/2]

const RigidBody& walberla::pe::BodyStorage::back ( ) const
inline

◆ begin() [1/4]

BodyStorage::const_iterator walberla::pe::BodyStorage::begin ( )
inline

Returns an iterator to the first contained rigid body.

Returns a constant iterator to the first contained rigid body.

Returns
Iterator to the first contained rigid body.
Constant iterator to the first contained rigid body.

◆ begin() [2/4]

template<typename C >
BodyStorage::cast_iterator< C > walberla::pe::BodyStorage::begin
inline

Returns an iterator to the first contained rigid body.

Returns
Iterator to the first contained rigid body.

◆ begin() [3/4]

const_iterator walberla::pe::BodyStorage::begin ( ) const
inline

◆ begin() [4/4]

template<typename C >
BodyStorage::const_cast_iterator< C > walberla::pe::BodyStorage::begin
inline

Returns a constant iterator to the first contained rigid body.

Returns
Constant iterator to the first contained rigid body.

◆ cbegin() [1/2]

BodyStorage::const_iterator walberla::pe::BodyStorage::cbegin ( ) const
inline

Returns a constant iterator to the first contained rigid body.

Returns
Constant iterator to the first contained rigid body.

◆ cbegin() [2/2]

template<typename C >
BodyStorage::const_cast_iterator< C > walberla::pe::BodyStorage::cbegin
inline

Returns a constant iterator to the first contained rigid body.

Returns
Constant iterator to the first contained rigid body.

◆ cend() [1/2]

BodyStorage::const_iterator walberla::pe::BodyStorage::cend ( ) const
inline

Returns a constant iterator just past the last contained rigid body.

Returns
Constant iterator just past the last contained rigid body.

◆ cend() [2/2]

template<typename C >
BodyStorage::const_cast_iterator< C > walberla::pe::BodyStorage::cend
inline

Returns a constant iterator just past the last contained rigid body.

Returns
Constant iterator just past the last contained rigid body.

◆ clear()

void walberla::pe::BodyStorage::clear ( )
inline

Removing all rigid bodies from the body storage.

Returns
void

This function removes all bodies from the body storage. The rigid bodies do not have to be valid anymore that is they can already be deallocated. Invalidates all iterators of this container.

◆ clearAddCallbacks()

void walberla::pe::BodyStorage::clearAddCallbacks ( )
inline

◆ clearRemoveCallbacks()

void walberla::pe::BodyStorage::clearRemoveCallbacks ( )
inline

◆ deregisterAddCallback()

void walberla::pe::BodyStorage::deregisterAddCallback ( const std::string &  name)
inline

◆ deregisterRemoveCallback()

void walberla::pe::BodyStorage::deregisterRemoveCallback ( const std::string &  name)
inline

◆ end() [1/4]

BodyStorage::const_iterator walberla::pe::BodyStorage::end ( )
inline

Returns an iterator just past the last contained rigid body.

Returns a constant iterator just past the last contained rigid body.

Returns
Iterator just past the last contained rigid body.
Constant iterator just past the last contained rigid body.

◆ end() [2/4]

template<typename C >
BodyStorage::cast_iterator< C > walberla::pe::BodyStorage::end
inline

Returns an iterator just past the last contained rigid body.

Returns
Iterator just past the last contained rigid body.

◆ end() [3/4]

const_iterator walberla::pe::BodyStorage::end ( ) const
inline

◆ end() [4/4]

template<typename C >
BodyStorage::const_cast_iterator< C > walberla::pe::BodyStorage::end
inline

Returns a constant iterator just past the last contained rigid body.

Returns
Constant iterator just past the last contained rigid body.

◆ find() [1/4]

BodyStorage::iterator walberla::pe::BodyStorage::find ( ConstBodyID  body)
inline

Finding a specific rigid body in the body storage.

Parameters
bodyThe given rigid body for the search.
Returns
Iterator to the given rigid body or an iterator just past the end.

This function finds the rigid body in the body storage. In case the rigid body is found, the function returns an iterator to the body. Otherwise, the function returns an iterator just past the end of the last body contained in the body storage.

◆ find() [2/4]

BodyStorage::const_iterator walberla::pe::BodyStorage::find ( ConstBodyID  body) const
inline

Finding a specific rigid body in the body storage.

Parameters
bodyThe given rigid body for the search.
Returns
Constant iterator to the given rigid body or a constant iterator just past the end.

This function finds the rigid body in the body storage. In case the rigid body is found, the function returns a constant iterator to the body. Otherwise, the function returns a constant iterator just past the end of the last body contained in the body storage.

◆ find() [3/4]

BodyStorage::iterator walberla::pe::BodyStorage::find ( id_t  sid)
inline

Finding a rigid body with a certain unique system-specific ID.

Parameters
sidThe unique system-specific ID for the search.
Returns
Iterator to the body with system-specific ID sid or an iterator just past the end.

This function finds the rigid body with the system-specific ID sid. In case the rigid body is found, the function returns an iterator to the body. Otherwise, the function returns an iterator just past the end of the last body contained in the body storage.

◆ find() [4/4]

BodyStorage::const_iterator walberla::pe::BodyStorage::find ( id_t  sid) const
inline

Finding a rigid body with a certain unique system-specific ID.

Parameters
sidThe unique system-specific ID for the search.
Returns
Constant iterator to the body with system-specific ID sid or a constant iterator just past the end.

This function finds the rigid body with the system-specific ID sid. In case the rigid body is found, the function returns a constant iterator to the body. Otherwise, the function returns a constant iterator just past the end of the last body contained in the body storage.

◆ front() [1/2]

const RigidBody & walberla::pe::BodyStorage::front ( )
inline

◆ front() [2/2]

const RigidBody& walberla::pe::BodyStorage::front ( ) const
inline

◆ isEmpty()

bool walberla::pe::BodyStorage::isEmpty ( ) const
inline

Returns true if the body storage contains no rigid bodies.

Returns
true if the body storage is empty, false if it is not.

◆ registerAddCallback()

void walberla::pe::BodyStorage::registerAddCallback ( const std::string &  name,
const std::function< void(BodyID)> &  func 
)
inline

◆ registerRemoveCallback()

void walberla::pe::BodyStorage::registerRemoveCallback ( const std::string &  name,
const std::function< void(BodyID)> &  func 
)
inline

◆ release() [1/4]

std::unique_ptr< RigidBody > walberla::pe::BodyStorage::release ( BodyID  body)
inline

Release a rigid body from the body storage.

Parameters
bodyA handle of the rigid body to be released.
Returns
void

This function releases a body from the body storage. The released rigid body is not destroyed. body must be a valid rigid body pointer and must be registered in the body storage. Invalidates all iterators pointing at or past the element to be released. The time complexity is logarithmic unless reallocation occurs.

◆ release() [2/4]

std::unique_ptr< RigidBody > walberla::pe::BodyStorage::release ( const id_t  sid)
inline

Release a rigid body from the body storage.

Parameters
sidThe system id of the rigid body to be released.
Returns
Iterator to the body after the erased rigid body.

This function releases a body from the body storage. The released rigid body is not destroyed. sid must be a valid rigid body system id and must be registered in the body storage. Invalidates all iterators pointing at or past the element to be released. The time complexity is logarithmic unless reallocation occurs. Last element is swapped to the actual position and length is reduced by 1.

◆ release() [3/4]

std::unique_ptr< RigidBody > walberla::pe::BodyStorage::release ( const_iterator pos)
inline

Release a rigid body from the body storage.

Parameters
posThe position of the rigid body to be released.
Returns
Iterator to the body after the erased rigid body.

This function releases a body from the body storage. The released rigid body is not destroyed. body must be a valid rigid body pointer and must be registered in the body storage. Invalidates all iterators pointing at or past the element to be released. The time complexity is logarithmic unless reallocation occurs.

◆ release() [4/4]

std::unique_ptr< RigidBody > walberla::pe::BodyStorage::release ( iterator pos)
inline

Releasing a rigid body from the body storage.

Parameters
posThe position of the rigid body to be released.
Returns
Iterator to the body after the erased rigid body.

This function releases a body from the body storage. The released rigid body is not destroyed. body must be a valid rigid body pointer and must be registered in the body storage. Invalidates all iterators pointing at or past the element to be released. The time complexity is logarithmic unless reallocation occurs.

◆ remove() [1/4]

BodyStorage::iterator walberla::pe::BodyStorage::remove ( BodyID  body)
inline

Removing a rigid body from the body storage.

Parameters
bodyA handle of the rigid body to be removed.
Returns
void

This function removes a body from the body storage. body must be a valid rigid body pointer and must be registered in the body storage. Invalidates all iterators pointing at or past the element to be removed. The time complexity is logarithmic unless reallocation occurs.

◆ remove() [2/4]

BodyStorage::iterator walberla::pe::BodyStorage::remove ( const id_t  sid)
inline

Removing a rigid body from the body storage.

Parameters
sidThe system id of the rigid body to be removed.
Returns
Iterator to the body after the erased rigid body.

This function removes a body from the body storage. sid must be a valid system id. Invalidates all iterators pointing at or past the element to be removed. The time complexity is logarithmic unless reallocation occurs. The last element is swapped to the actual position and the length is reduced by one.

◆ remove() [3/4]

BodyStorage::const_iterator walberla::pe::BodyStorage::remove ( const_iterator  pos)
inline

Removing a rigid body from the body storage.

Parameters
posThe position of the rigid body to be removed.
Returns
Iterator to the body after the erased rigid body.

This function removes a body from the body storage. pos must be a valid iterator and the rigid body pointer referred to must be valid. Invalidates all iterators pointing at or past the element to be removed. The time complexity is logarithmic unless reallocation occurs.

◆ remove() [4/4]

BodyStorage::iterator walberla::pe::BodyStorage::remove ( iterator  pos)
inline

Removing a rigid body from the body storage.

Parameters
posThe position of the rigid body to be removed.
Returns
Iterator to the body after the erased rigid body.

This function removes a body from the body storage. pos must be a valid iterator and the rigid body pointer referred to must be valid. Invalidates all iterators pointing at or past the element to be removed. The time complexity is logarithmic unless reallocation occurs.

◆ size()

BodyStorage::size_type walberla::pe::BodyStorage::size ( ) const
inline

Returns the number of rigid bodies contained in the body storage.

Returns
The number of rigid bodies.

◆ validate()

void walberla::pe::BodyStorage::validate ( )
inline

Validating the correctness of the body storage data structure.

Returns
void

This function validates the data structure in linear time and space. If validation fails assertions are triggered unless the pe is compiled in release mode.

Member Data Documentation

◆ addCallbacks_

std::map< std::string, std::function<void (BodyID)> > walberla::pe::BodyStorage::addCallbacks_
private

◆ bodies_

VectorContainer walberla::pe::BodyStorage::bodies_
private

The rigid bodies contained in the simulation world.

◆ bodyIDs_

std::map<id_t, size_type> walberla::pe::BodyStorage::bodyIDs_
private

The association of system IDs to rigid bodies.

◆ removeCallbacks_

std::map< std::string, std::function<void (BodyID)> > walberla::pe::BodyStorage::removeCallbacks_
private

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