SOFA plugin: image  master
Open source framework for multi-physics simuation
sofa::helper::NoPreallocationVector< T > Class Template Reference

#include <Containers.h>

Detailed Description

template<class T>
class sofa::helper::NoPreallocationVector< T >

minimalist vector with a tight memory array the particularity is not to pre-allocate (no unused memory is allocated without a user choice) not efficient to add an entry (since it must resize the array)

Protected Attributes

T * _array
 the array where to store the entries More...
 
size_t _size
 the array size More...
 

Public Member Functions

 NoPreallocationVector ()
 default constructor, no allocation, no initialization More...
 
 NoPreallocationVector (size_t size)
 given allocation, no initialization More...
 
 ~NoPreallocationVector ()
 default destructor More...
 
 NoPreallocationVector (const NoPreallocationVector< T > &c)
 copy constructor More...
 
void clear ()
 free memory More...
 
void operator= (const NoPreallocationVector< T > &c)
 clone More...
 
bool operator== (const NoPreallocationVector< T > &c) const
 comparison More...
 
bool operator!= (const NoPreallocationVector< T > &c) const
 difference More...
 
void push_back (const T &v)
 
void resize (size_t newSize)
 
void resizeAndKeep (size_t newSize)
 already-existing data is preserved More...
 
int find (const T &v) const
 
bool isPresent (const T &v) const
 
int getOffset (const T *v) const
 
T & operator[] (size_t index)
 entry accessor More...
 
const T & operator[] (size_t index) const
 entry const accessor More...
 
T & first ()
 first entry accessor More...
 
const T & first () const
 first entry const accessor More...
 
T & last ()
 last entry accessor More...
 
const T & last () const
 last entry const accessor More...
 
size_t size () const
 
bool empty () const
 
void fill (const T &v)
 fill all array entries with the given value v More...
 

Friends

std::istream & operator>> (std::istream &in, NoPreallocationVector< T > &)
 read More...
 
std::ostream & operator<< (std::ostream &out, const NoPreallocationVector< T > &)
 write More...
 

Attribute details

◆ _array

template<class T >
T* sofa::helper::NoPreallocationVector< T >::_array
protected

the array where to store the entries

◆ _size

template<class T >
size_t sofa::helper::NoPreallocationVector< T >::_size
protected

the array size

Constructor details

◆ NoPreallocationVector() [1/3]

template<class T >
sofa::helper::NoPreallocationVector< T >::NoPreallocationVector ( )
inline

default constructor, no allocation, no initialization

◆ NoPreallocationVector() [2/3]

template<class T >
sofa::helper::NoPreallocationVector< T >::NoPreallocationVector ( size_t  size)
inline

given allocation, no initialization

◆ ~NoPreallocationVector()

template<class T >
sofa::helper::NoPreallocationVector< T >::~NoPreallocationVector ( )
inline

default destructor

◆ NoPreallocationVector() [3/3]

template<class T >
sofa::helper::NoPreallocationVector< T >::NoPreallocationVector ( const NoPreallocationVector< T > &  c)
inline

copy constructor

Function details

◆ clear()

template<class T >
void sofa::helper::NoPreallocationVector< T >::clear ( )
inline

free memory

◆ empty()

template<class T >
bool sofa::helper::NoPreallocationVector< T >::empty ( ) const
inline
Returns
true iff the vector is empty (no entry)

◆ fill()

template<class T >
void sofa::helper::NoPreallocationVector< T >::fill ( const T &  v)
inline

fill all array entries with the given value v

◆ find()

template<class T >
int sofa::helper::NoPreallocationVector< T >::find ( const T &  v) const
inline
Returns
the index of the first occurrence, if !present
-1

◆ first() [1/2]

template<class T >
T& sofa::helper::NoPreallocationVector< T >::first ( )
inline

first entry accessor

◆ first() [2/2]

template<class T >
const T& sofa::helper::NoPreallocationVector< T >::first ( ) const
inline

first entry const accessor

◆ getOffset()

template<class T >
int sofa::helper::NoPreallocationVector< T >::getOffset ( const T *  v) const
inline
Returns
the index of the occurrence, if !present
-1

◆ isPresent()

template<class T >
bool sofa::helper::NoPreallocationVector< T >::isPresent ( const T &  v) const
inline
Returns
true iff v is present

◆ last() [1/2]

template<class T >
T& sofa::helper::NoPreallocationVector< T >::last ( )
inline

last entry accessor

◆ last() [2/2]

template<class T >
const T& sofa::helper::NoPreallocationVector< T >::last ( ) const
inline

last entry const accessor

◆ operator!=()

template<class T >
bool sofa::helper::NoPreallocationVector< T >::operator!= ( const NoPreallocationVector< T > &  c) const
inline

difference

◆ operator=()

template<class T >
void sofa::helper::NoPreallocationVector< T >::operator= ( const NoPreallocationVector< T > &  c)
inline

clone

◆ operator==()

template<class T >
bool sofa::helper::NoPreallocationVector< T >::operator== ( const NoPreallocationVector< T > &  c) const
inline

comparison

◆ operator[]() [1/2]

template<class T >
T& sofa::helper::NoPreallocationVector< T >::operator[] ( size_t  index)
inline

entry accessor

◆ operator[]() [2/2]

template<class T >
const T& sofa::helper::NoPreallocationVector< T >::operator[] ( size_t  index) const
inline

entry const accessor

◆ push_back()

template<class T >
void sofa::helper::NoPreallocationVector< T >::push_back ( const T &  v)
inline

add a entry at the end

Warning
this has bad performances, since resizing/reallocating the array is necessary

◆ resize()

template<class T >
void sofa::helper::NoPreallocationVector< T >::resize ( size_t  newSize)
inline
Warning
data is lost

◆ resizeAndKeep()

template<class T >
void sofa::helper::NoPreallocationVector< T >::resizeAndKeep ( size_t  newSize)
inline

already-existing data is preserved

◆ size()

template<class T >
size_t sofa::helper::NoPreallocationVector< T >::size ( ) const
inline
Returns
the entry number (effective and allocated)

Related details

◆ operator<<

template<class T >
std::ostream& operator<< ( std::ostream &  out,
const NoPreallocationVector< T > &   
)
friend

write

Warning
does nothing for now, just needed to put a NoPreallocationVector in a Data

◆ operator>>

template<class T >
std::istream& operator>> ( std::istream &  in,
NoPreallocationVector< T > &   
)
friend

read

Warning
does nothing for now, just needed to put a NoPreallocationVector in a Data