SOFA API  caf3b296
Open source framework for multi-physics simuation
sofa::defaulttype::BaseVector Class Referenceabstract

#include <BaseVector.h>

Inheritance diagram for sofa::defaulttype::BaseVector:

Detailed Description

Generic vector API, allowing to fill and use a vector independently of the linear algebra library in use.

Note that accessing values using this class is rather slow and should only be used in codes where the provided genericity is necessary.

Public Member Functions

virtual ~BaseVector ()
 
virtual Index size (void) const =0
 Number of elements. More...
 
virtual SReal element (Index i) const =0
 Read the value of element i. More...
 
virtual void resize (Index dim)=0
 Resize the vector, and reset all values to 0. More...
 
virtual void clear ()=0
 Reset all values to 0. More...
 
virtual void set (Index i, SReal v)=0
 Write the value of element i. More...
 
virtual void add (Index i, SReal v)=0
 Add v to the existing value of element i. More...
 
virtual const floatelements (Index i0, Index n, float *src) const
 Get the values of n elements, starting at element i0, into given float buffer, or return the pointer to the data if the in-memory format is compatible. More...
 
virtual const doubleelements (Index i0, Index n, double *src) const
 Get the values of n elements, starting at element i0, into given double buffer, or return the pointer to the data if the in-memory format is compatible. More...
 
virtual const intelements (Index i0, Index n, int *src) const
 Get the values of n elements, starting at element i0, into given int buffer, or return the pointer to the data if the in-memory format is compatible. More...
 
virtual void set (Index i0, Index n, const float *src)
 Write the values of n float elements, starting at element i0. More...
 
virtual void set (Index i0, Index n, const double *src)
 Write the values of n double elements, starting at element i0. More...
 
virtual void set (Index i0, Index n, const int *src)
 Write the values of n int elements, starting at element i0. More...
 
virtual void add (Index i0, Index n, const float *src)
 Add to the values of n float elements, starting at element i0. More...
 
virtual void add (Index i0, Index n, const double *src)
 Add to the values of n double elements, starting at element i0. More...
 
virtual void add (Index i0, Index n, const int *src)
 Add to the values of n int elements, starting at element i0. More...
 
virtual void clear (Index i)
 Reset the value of element i to 0. More...
 

Protected Member Functions

template<class T >
const T * elementsDefaultImpl (Index i0, Index n, T *buffer) const
 
template<class T >
void setDefaultImpl (Index i0, Index n, const T *src)
 
template<class T >
void addDefaultImpl (Index i0, Index n, const T *src)
 

Friends

std::ostream & operator<< (std::ostream &out, const BaseVector &v)
 

Get information about the content and structure of this vector

enum  ElementType { ELEMENT_UNKNOWN = 0, ELEMENT_FLOAT, ELEMENT_INT }
 
virtual ElementType getElementType () const
 
virtual std::size_t getElementSize () const
 
virtual bool isFull () const
 Return true if this vector is full, i.a. all elements are stored in memory. More...
 
bool isSparse () const
 

Constructor details

virtual sofa::defaulttype::BaseVector::~BaseVector ( )
inlinevirtual

Function details

virtual void sofa::defaulttype::BaseVector::add ( Index  i0,
Index  n,
const float src 
)
inlinevirtual

Add to the values of n float elements, starting at element i0.

virtual void sofa::defaulttype::BaseVector::add ( Index  i0,
Index  n,
const double src 
)
inlinevirtual

Add to the values of n double elements, starting at element i0.

virtual void sofa::defaulttype::BaseVector::add ( Index  i0,
Index  n,
const int src 
)
inlinevirtual

Add to the values of n int elements, starting at element i0.

template<class T >
void sofa::defaulttype::BaseVector::addDefaultImpl ( Index  i0,
Index  n,
const T *  src 
)
inlineprotected
virtual const float* sofa::defaulttype::BaseVector::elements ( Index  i0,
Index  n,
float src 
) const
inlinevirtual

Get the values of n elements, starting at element i0, into given float buffer, or return the pointer to the data if the in-memory format is compatible.

virtual const double* sofa::defaulttype::BaseVector::elements ( Index  i0,
Index  n,
double src 
) const
inlinevirtual

Get the values of n elements, starting at element i0, into given double buffer, or return the pointer to the data if the in-memory format is compatible.

virtual const int* sofa::defaulttype::BaseVector::elements ( Index  i0,
Index  n,
int src 
) const
inlinevirtual

Get the values of n elements, starting at element i0, into given int buffer, or return the pointer to the data if the in-memory format is compatible.

template<class T >
const T* sofa::defaulttype::BaseVector::elementsDefaultImpl ( Index  i0,
Index  n,
T *  buffer 
) const
inlineprotected
virtual std::size_t sofa::defaulttype::BaseVector::getElementSize ( ) const
inlinevirtual
Returns
size of elements stored in this matrix
virtual ElementType sofa::defaulttype::BaseVector::getElementType ( ) const
inlinevirtual
Returns
type of elements stored in this matrix
virtual bool sofa::defaulttype::BaseVector::isFull ( ) const
inlinevirtual

Return true if this vector is full, i.a. all elements are stored in memory.

bool sofa::defaulttype::BaseVector::isSparse ( ) const
inline

Return true if this vector is sparse, i.a. only some of the elements are stored in memory. This is the exact opposite to isFull().

virtual void sofa::defaulttype::BaseVector::set ( Index  i0,
Index  n,
const float src 
)
inlinevirtual

Write the values of n float elements, starting at element i0.

virtual void sofa::defaulttype::BaseVector::set ( Index  i0,
Index  n,
const double src 
)
inlinevirtual

Write the values of n double elements, starting at element i0.

virtual void sofa::defaulttype::BaseVector::set ( Index  i0,
Index  n,
const int src 
)
inlinevirtual

Write the values of n int elements, starting at element i0.

template<class T >
void sofa::defaulttype::BaseVector::setDefaultImpl ( Index  i0,
Index  n,
const T *  src 
)
inlineprotected

Enum details

Enumerator
ELEMENT_UNKNOWN 
ELEMENT_FLOAT 
ELEMENT_INT 

Related details

std::ostream& operator<< ( std::ostream &  out,
const BaseVector v 
)
friend