Web Analytics Made Easy - Statcounter
Skip to content

Class SBCContainerVector#

template <class T>

ClassList > SBCContainerVector

This template class describes an extensible array. More...

  • #include <SBCContainerVector.hpp>

Classes#

Type Name
class const_iterator
class const_reverse_iterator
class iterator
class reverse_iterator

Public Functions#

Type Name
SBCContainerVector ()
Constructs an empty vector.
SBCContainerVector (unsigned int n)
Constructs a vector of reserved size n .
SBCContainerVector (unsigned int n, unsigned int c, const T & t)
Constructs a vector of reserved size n and current sizec , filled with copies oft .
SBCContainerVector (T * a, unsigned int n)
Constructs a vector from an array.
SBCContainerVector (const SBCContainerVector & vector)
Copy constructor.
SBCContainerVector (SBCContainerVector && vector)
Move constructor.
SBCContainerVector (std::initializer_list< T > list)
Constructor using the initializer list.
unsigned int allocatedSize () const
Returns the allocated size (in memory) of the vector.
T & back ()
Returns a reference to the last element.
T const & back () const
Returns a reference to the last element.
iterator begin ()
Returns an iterator that points to the beginning of the vector.
const_iterator begin () const
Returns an iterator that points to the beginning of the vector.
void clear ()
Empties the vector.
bool contains (const T & t)
Returns true when the vector contains t .
bool empty () const
Returns true if and only if the vector is empty.
iterator end ()
Returns an iterator that points to the end of the vector.
const_iterator end () const
Returns an iterator that points to the end of the vector.
void free ()
Frees the memory allocated for the vector.
T & front ()
Returns a reference to the last element.
T const & front () const
Returns a reference to the last element.
T & getElement (unsigned int i)
Returns a reference to element i .
T const & getElement (unsigned int i) const
Returns a reference to element i .
unsigned int getMemoryFootPrint () const
Returns the memory footprint of the vector.
T * getPointer (unsigned int i)
Returns a pointer to element i .
T const * getPointer (unsigned int i) const
Returns a pointer to element i .
void insert (unsigned int i, const T & t)
Inserts t at positioni if possible. If an element was present at positioni , it is pushed at the back of the vector.
void insertLinear (unsigned int i, const T & t)
bool operator!= (const SBCContainerVector & other)
Returns whether this vector is different from an other vector.
SBCContainerVector & operator= (const SBCContainerVector & vector)
Copy assignment.
SBCContainerVector & operator= (SBCContainerVector && vector)
Move assignment.
SBCContainerVector & operator= (std::initializer_list< T > list)
Assignment using the initializer list.
bool operator== (const SBCContainerVector & other)
Returns whether this vector is equal to an other vector.
T & operator[] (unsigned int i)
Returns a reference to element i .
T const & operator[] (unsigned int i) const
Returns a reference to element i .
void pop_back ()
Removes the last element from the vector.
void print (unsigned int offset=0) const
Prints the vector.
void push_back (const T & t)
Appends t to the vector.
reverse_iterator rbegin ()
Returns a reverse iterator that points to the reverse beginning of the vector.
const_reverse_iterator rbegin () const
Returns a reverse iterator that points to the reverse beginning of the vector.
void remove (unsigned int i)
Removes element i from the vector, and replaces it with the last element.
void removeAll (const T & t)
Removes all t from the vector. The vector is reordered as when applying multiple remove operations.
void removeLinear (unsigned int i)
void removeLinear (unsigned int first, unsigned int last)
reverse_iterator rend ()
Returns a reverse iterator that points to the reverse end of the vector.
const_reverse_iterator rend () const
Returns a reverse iterator that points to the reverse end of the vector.
void resize (unsigned int newSize)
Resize to size n .
void setArray (T * newArray, unsigned int newSize)
build from array
unsigned int size () const
Returns the size of the vector.
virtual ~SBCContainerVector ()
Destructs the vector.

Detailed Description#

SBCContainerVector is a lightweight template class to handle vectors of values, i.e. contiguous arrays of values. Its functionality is similar to the std::vector class. SBVector provides const and non-const iterators and reverse iterators:

SBVector<SBAtom*> v;

// add atoms

for (unsigned int i = 0; i<10; i++)
    v.push_back(new SBAtom(SBElement::Carbon));

// print atoms positions (version 1)

for (unsigned int i = 0; i<10; i++)
    v[i]->getPosition().print();

// print atoms positions (version 2)

for (SBVector<SBAtom*>::iterator i = v.begin(); i != v.end(); i++)
    (*i)->getPosition().print();

// print atoms positions (version 3)

SB_FOR(SBAtom* atom, v) 
    atom->getPosition().print();

Note that, in accordance with the behavior of buffers, indexers, etc., the insert function has a amortized constant time complexity, as it pushes back the replaced element to the end of the vector.

Short name: SBVector

See also: SB_FOR

Public Functions Documentation#

function SBCContainerVector [1/7]#

Constructs an empty vector.

inline SBCContainerVector::SBCContainerVector () 


function SBCContainerVector [2/7]#

Constructs a vector of reserved size n .

inline SBCContainerVector::SBCContainerVector (
    unsigned int n
) 


function SBCContainerVector [3/7]#

Constructs a vector of reserved size n and current sizec , filled with copies oft .

inline SBCContainerVector::SBCContainerVector (
    unsigned int n,
    unsigned int c,
    const T & t
) 


function SBCContainerVector [4/7]#

Constructs a vector from an array.

inline SBCContainerVector::SBCContainerVector (
    T * a,
    unsigned int n
) 


function SBCContainerVector [5/7]#

Copy constructor.

inline SBCContainerVector::SBCContainerVector (
    const SBCContainerVector & vector
) 


function SBCContainerVector [6/7]#

Move constructor.

inline SBCContainerVector::SBCContainerVector (
    SBCContainerVector && vector
) 


function SBCContainerVector [7/7]#

Constructor using the initializer list.

inline SBCContainerVector::SBCContainerVector (
    std::initializer_list< T > list
) 


function allocatedSize#

Returns the allocated size (in memory) of the vector.

inline unsigned int SBCContainerVector::allocatedSize () const


function back [1/2]#

Returns a reference to the last element.

inline T & SBCContainerVector::back () 


function back [2/2]#

Returns a reference to the last element.

inline T const & SBCContainerVector::back () const


function begin [1/2]#

Returns an iterator that points to the beginning of the vector.

inline iterator SBCContainerVector::begin () 


function begin [2/2]#

Returns an iterator that points to the beginning of the vector.

inline const_iterator SBCContainerVector::begin () const


function clear#

Empties the vector.

inline void SBCContainerVector::clear () 


function contains#

Returns true when the vector contains t .

inline bool SBCContainerVector::contains (
    const T & t
) 


function empty#

Returns true if and only if the vector is empty.

inline bool SBCContainerVector::empty () const


function end [1/2]#

Returns an iterator that points to the end of the vector.

inline iterator SBCContainerVector::end () 


function end [2/2]#

Returns an iterator that points to the end of the vector.

inline const_iterator SBCContainerVector::end () const


function free#

Frees the memory allocated for the vector.

inline void SBCContainerVector::free () 


function front [1/2]#

Returns a reference to the last element.

inline T & SBCContainerVector::front () 


function front [2/2]#

Returns a reference to the last element.

inline T const & SBCContainerVector::front () const


function getElement [1/2]#

Returns a reference to element i .

inline T & SBCContainerVector::getElement (
    unsigned int i
) 


function getElement [2/2]#

Returns a reference to element i .

inline T const & SBCContainerVector::getElement (
    unsigned int i
) const


function getMemoryFootPrint#

Returns the memory footprint of the vector.

inline unsigned int SBCContainerVector::getMemoryFootPrint () const


function getPointer [1/2]#

Returns a pointer to element i .

inline T * SBCContainerVector::getPointer (
    unsigned int i
) 


function getPointer [2/2]#

Returns a pointer to element i .

inline T const * SBCContainerVector::getPointer (
    unsigned int i
) const


function insert#

Inserts t at positioni if possible. If an element was present at positioni , it is pushed at the back of the vector.

inline void SBCContainerVector::insert (
    unsigned int i,
    const T & t
) 


function insertLinear#

inline void SBCContainerVector::insertLinear (
    unsigned int i,
    const T & t
) 

Inserts t at position i if possible. If an element was present at position i, this element and all following elements are moved. This operation has a linear complexity, and may invalidate iterators.


function operator!=#

Returns whether this vector is different from an other vector.

inline bool SBCContainerVector::operator!= (
    const SBCContainerVector & other
) 


function operator=#

Copy assignment.

inline SBCContainerVector & SBCContainerVector::operator= (
    const SBCContainerVector & vector
) 


function operator=#

Move assignment.

inline SBCContainerVector & SBCContainerVector::operator= (
    SBCContainerVector && vector
) 


function operator=#

Assignment using the initializer list.

inline SBCContainerVector & SBCContainerVector::operator= (
    std::initializer_list< T > list
) 


function operator==#

Returns whether this vector is equal to an other vector.

inline bool SBCContainerVector::operator== (
    const SBCContainerVector & other
) 


function operator[]#

Returns a reference to element i .

inline T & SBCContainerVector::operator[] (
    unsigned int i
) 


function operator[]#

Returns a reference to element i .

inline T const & SBCContainerVector::operator[] (
    unsigned int i
) const


function pop_back#

Removes the last element from the vector.

inline void SBCContainerVector::pop_back () 


function print#

Prints the vector.

inline void SBCContainerVector::print (
    unsigned int offset=0
) const


function push_back#

Appends t to the vector.

inline void SBCContainerVector::push_back (
    const T & t
) 


function rbegin [1/2]#

Returns a reverse iterator that points to the reverse beginning of the vector.

inline reverse_iterator SBCContainerVector::rbegin () 


function rbegin [2/2]#

Returns a reverse iterator that points to the reverse beginning of the vector.

inline const_reverse_iterator SBCContainerVector::rbegin () const


function remove#

Removes element i from the vector, and replaces it with the last element.

inline void SBCContainerVector::remove (
    unsigned int i
) 


function removeAll#

Removes all t from the vector. The vector is reordered as when applying multiple remove operations.

inline void SBCContainerVector::removeAll (
    const T & t
) 


function removeLinear [1/2]#

inline void SBCContainerVector::removeLinear (
    unsigned int i
) 

Removes element i from the vector. If elements are present after position i, these elements are moved. This operation has a linear complexity, and may invalidate iterators.


function removeLinear [2/2]#

inline void SBCContainerVector::removeLinear (
    unsigned int first,
    unsigned int last
) 

Removes all elements between (and including) positions first and last. If elements are present after position last, these elements are moved. This operation has a linear complexity, and may invalidate iterators.


function rend [1/2]#

Returns a reverse iterator that points to the reverse end of the vector.

inline reverse_iterator SBCContainerVector::rend () 


function rend [2/2]#

Returns a reverse iterator that points to the reverse end of the vector.

inline const_reverse_iterator SBCContainerVector::rend () const


function resize#

Resize to size n .

inline void SBCContainerVector::resize (
    unsigned int newSize
) 


function setArray#

build from array

inline void SBCContainerVector::setArray (
    T * newArray,
    unsigned int newSize
) 


function size#

Returns the size of the vector.

inline unsigned int SBCContainerVector::size () const


function ~SBCContainerVector#

Destructs the vector.

inline virtual SBCContainerVector::~SBCContainerVector ()