iMSTK
Interactive Medical Simulation Toolkit
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
imstk::DataArray< T > Class Template Reference

Simple dynamic array implementation that also supports event posting and viewing/facade. More...

#include <imstkDataArray.h>

Inheritance diagram for imstk::DataArray< T >:
Inheritance graph
[legend]
Collaboration diagram for imstk::DataArray< T >:
Collaboration graph
[legend]

Classes

class  const_iterator
 
class  iterator
 

Public Types

using ScalarType = T
 
using ValueType = T
 
- Public Types inherited from imstk::EventObject
using Observer = std::tuple< bool, std::weak_ptr< EventObject >, std::function< void(Event *)> >
 

Public Member Functions

 DataArray ()
 Constructs an empty data array DataArray will never have capacity < 1.
 
 DataArray (const int size)
 Constructs a data array.
 
template<typename U >
 DataArray (std::initializer_list< U > list)
 Constructs from intializer list.
 
 DataArray (const DataArray &other)
 Copy Constructor. More...
 
 DataArray (DataArray &&other)
 
void resize (const int size) override
 Resize data array to hold exactly size number of values.
 
void fill (const T &val)
 Fill the array with the specified value.
 
virtual void squeeze ()
 Resize to current size.
 
void push_back (const T &val)
 Append the data array to hold the new value, resizes if neccesary.
 
void push_back (const T &&val)
 
void reserve (const int capacity) override
 Allocates extra capacity, for the number of values, conservative reallocate.
 
T * getPointer ()
 
void * getVoidPointer () override
 Returns void pointer to data.
 
T & operator[] (const size_t pos)
 
const T & operator[] (const size_t pos) const
 
T & at (const size_t pos)
 
const T & at (const size_t pos) const
 
template<typename U >
DataArray< T > & operator= (std::initializer_list< U > list)
 Allow initialization from initializer list, ie: DataArray<int> arr = { 1, 2 }.
 
DataArrayoperator= (const DataArray &other)
 
void setData (T *ptr, const int size)
 Computes the range of a component of the vectors elements. More...
 
virtual int getNumberOfComponents () const override
 Returns the number of components.
 
template<typename N >
DataArray< N > cast ()
 Cast array to specific c++ type.
 
std::shared_ptr< AbstractDataArraycast (ScalarTypeId type) override
 Cast array to the IMSTK type on the abstract interface.
 
std::unique_ptr< DataArray< T > > clone ()
 Polymorphic clone, shadows the declaration in the superclasss but returns own type.
 
iterator begin ()
 begin(), end() to mirror std::vector
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
- Public Member Functions inherited from imstk::AbstractDataArray
 AbstractDataArray (const int size)
 
virtual ~AbstractDataArray ()
 Ensure all observers are disconnected.
 
 SIGNAL (AbstractDataArray, modified)
 
void clear ()
 Resizes to 0.
 
int size () const
 Get number of values/tuples.
 
ScalarTypeId getScalarType () const
 Returns the scalar type of this array.
 
int getCapacity () const
 Return the capacity of the array.
 
void postModified ()
 emits signal to all observers, informing them on the current address in memory and size of array
 
std::unique_ptr< AbstractDataArrayclone ()
 polymorphic clone() function, utilize this to get a copy of the array without casting to the expected array type
 
- Public Member Functions inherited from imstk::EventObject
template<typename T >
void postEvent (const T &e)
 Emits the event Direct observers will be immediately called, in sync Queued observers will receive the Command in their queue for later execution, reciever must implement doEvent.
 
template<typename T >
void queueEvent (const T &e)
 Queues event directly to this.
 
void doEvent ()
 Do an event, if none exists return.
 
void doAllEvents ()
 Do all the events in the event queue.
 
void foreachEvent (std::function< void(Command cmd)> func)
 Thread safe loop over all event commands, one can implement a custom handler.
 
void rforeachEvent (std::function< void(Command cmd)> func)
 thread safe reverse loop over all event commands, one can implement a custom handler
 
void clearEvents ()
 Removes all events from queue cleans up copies of the event.
 

Static Public Attributes

static constexpr int NumComponents = 1
 

Protected Attributes

bool m_mapped
 
T * m_data
 
- Protected Attributes inherited from imstk::AbstractDataArray
ScalarTypeId m_scalarType
 
int m_size
 
int m_capacity
 
- Protected Attributes inherited from imstk::EventObject
ParallelUtils::SpinLock eventQueueLock
 
std::deque< CommandeventQueue
 
std::vector< std::pair< std::string, std::vector< Observer > > > queuedObservers
 
std::vector< std::pair< std::string, std::vector< Observer > > > directObservers
 

Additional Inherited Members

- Protected Member Functions inherited from imstk::AbstractDataArray
void setType (const ScalarTypeId type)
 

Detailed Description

template<typename T>
class imstk::DataArray< T >

Simple dynamic array implementation that also supports event posting and viewing/facade.

Definition at line 22 of file imstkDataArray.h.

Constructor & Destructor Documentation

◆ DataArray()

template<typename T>
imstk::DataArray< T >::DataArray ( const DataArray< T > &  other)
inline

Copy Constructor.

Note
The Copy constructor does not copy the event subscribers of this object

Definition at line 159 of file imstkDataArray.h.

Member Function Documentation

◆ at() [1/2]

template<typename T>
T& imstk::DataArray< T >::at ( const size_t  pos)
inline
Returns
the item at the given position
Note
as opposed to the std::vector bounds checking is only done when IMSTK_CHECK_ARRAY_RANGE is set

Definition at line 328 of file imstkDataArray.h.

◆ at() [2/2]

template<typename T>
const T& imstk::DataArray< T >::at ( const size_t  pos) const
inline
Returns
the item at the given position
Note
as opposed to the std::vector bounds checking is only done when IMSTK_CHECK_ARRAY_RANGE is set

Definition at line 340 of file imstkDataArray.h.

◆ setData()

template<typename T>
void imstk::DataArray< T >::setData ( T *  ptr,
const int  size 
)
inline

Computes the range of a component of the vectors elements.

: Use the array as a facade to anothers memory

Parameters

Definition at line 414 of file imstkDataArray.h.

Here is the caller graph for this function:

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