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>
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... | |
RigidBody & | front () |
const RigidBody & | front () const |
RigidBody & | back () |
const RigidBody & | back () 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 | |
RigidBody & | add (BodyID body) |
Adding a rigid body to the body storage. More... | |
RigidBody & | add (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< RigidBody > | release (const id_t sid) |
Release a rigid body from the body storage. More... | |
std::unique_ptr< RigidBody > | release (BodyID body) |
Release a rigid body from the body storage. More... | |
std::unique_ptr< RigidBody > | release (const_iterator &pos) |
Release a rigid body from the body storage. More... | |
std::unique_ptr< RigidBody > | release (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_type > | bodyIDs_ |
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 | |
using walberla::pe::BodyStorage::cast_iterator = RigidBodyCastIterator<C> |
using walberla::pe::BodyStorage::const_cast_iterator = ConstRigidBodyCastIterator<C> |
Iterator over constant bodies.
using walberla::pe::BodyStorage::ConstVectorContainer = std::vector< std::unique_ptr<const RigidBody> > |
Iterator over non-const bodies.
using walberla::pe::BodyStorage::size_type = VectorContainer::size_type |
Size type of the body storage.
using walberla::pe::BodyStorage::VectorContainer = std::vector< std::unique_ptr<RigidBody> > |
Container for the bodies contained in the simulation world.
|
inlineexplicit |
The standard constructor.
|
inline |
The destructor.
The destructor clears all rigid bodies from the storage before destructing it.
Adding a rigid body to the body storage.
body | The new rigid body to be added to the body storage. |
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.
Adding a rigid body to the body storage.
body | The new rigid body to be added to the body storage. |
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.
Returns a handle to the indexed rigid body.
index | Access index. The index has to be in the range \([0..size-1]\). |
Note: No runtime check is performed to ensure the validity of the access index.
|
inline |
Returns a constant handle to the indexed rigid body.
index | Access index. The index has to be in the range \([0..size-1]\). |
Note: No runtime check is performed to ensure the validity of the access index.
|
inline |
|
inline |
|
inline |
Returns an iterator to the first contained rigid body.
Returns a constant iterator to the first contained rigid body.
|
inline |
Returns an iterator to the first contained rigid body.
|
inline |
|
inline |
Returns a constant iterator to the first contained rigid body.
|
inline |
Returns a constant iterator to the first contained rigid body.
|
inline |
Returns a constant iterator to the first contained rigid body.
|
inline |
Returns a constant iterator just past the last contained rigid body.
|
inline |
Returns a constant iterator just past the last contained rigid body.
|
inline |
Removing all rigid bodies from the body storage.
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.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns an iterator just past the last contained rigid body.
Returns a constant iterator just past the last contained rigid body.
|
inline |
Returns an iterator just past the last contained rigid body.
|
inline |
|
inline |
Returns a constant iterator just past the last contained rigid body.
|
inline |
Finding a specific rigid body in the body storage.
body | The given rigid body for the search. |
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.
|
inline |
Finding a specific rigid body in the body storage.
body | The given rigid body for the search. |
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.
|
inline |
Finding a rigid body with a certain unique system-specific ID.
sid | The unique system-specific ID for the search. |
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.
|
inline |
Finding a rigid body with a certain unique system-specific ID.
sid | The unique system-specific ID for the search. |
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.
|
inline |
|
inline |
|
inline |
Returns true if the body storage contains no rigid bodies.
|
inline |
|
inline |
Release a rigid body from the body storage.
body | A handle of the rigid body to be released. |
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 a rigid body from the body storage.
sid | The system id of the rigid body to be released. |
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.
|
inline |
Release a rigid body from the body storage.
pos | The position of the rigid body to be released. |
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.
Releasing a rigid body from the body storage.
pos | The position of the rigid body to be released. |
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.
|
inline |
Removing a rigid body from the body storage.
body | A handle of the rigid body to be removed. |
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.
|
inline |
Removing a rigid body from the body storage.
sid | The system id of the rigid body to be removed. |
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.
|
inline |
Removing a rigid body from the body storage.
pos | The position of the rigid body to be removed. |
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.
|
inline |
Removing a rigid body from the body storage.
pos | The position of the rigid body to be removed. |
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.
|
inline |
Returns the number of rigid bodies contained in the body storage.
|
inline |
Validating the correctness of the body storage data structure.
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.
|
private |
|
private |
The rigid bodies contained in the simulation world.
The association of system IDs to rigid bodies.
|
private |