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.
function SBCContainerVector [2/7]#
Constructs a vector of reserved size n
.
function SBCContainerVector [3/7]#
Constructs a vector of reserved size n
and current sizec
, filled with copies oft
.
function SBCContainerVector [4/7]#
Constructs a vector from an array.
function SBCContainerVector [5/7]#
Copy constructor.
function SBCContainerVector [6/7]#
Move constructor.
function SBCContainerVector [7/7]#
Constructor using the initializer list.
function allocatedSize#
Returns the allocated size (in memory) of the vector.
function back [1/2]#
Returns a reference to the last element.
function back [2/2]#
Returns a reference to the last element.
function begin [1/2]#
Returns an iterator that points to the beginning of the vector.
function begin [2/2]#
Returns an iterator that points to the beginning of the vector.
function clear#
Empties the vector.
function contains#
Returns true when the vector contains t
.
function empty#
Returns true if and only if the vector is empty.
function end [1/2]#
Returns an iterator that points to the end of the vector.
function end [2/2]#
Returns an iterator that points to the end of the vector.
function free#
Frees the memory allocated for the vector.
function front [1/2]#
Returns a reference to the last element.
function front [2/2]#
Returns a reference to the last element.
function getElement [1/2]#
Returns a reference to element i
.
function getElement [2/2]#
Returns a reference to element i
.
function getMemoryFootPrint#
Returns the memory footprint of the vector.
function getPointer [1/2]#
Returns a pointer to element i
.
function getPointer [2/2]#
Returns a pointer to element i
.
function insert#
Inserts t
at positioni
if possible. If an element was present at positioni
, it is pushed at the back of the vector.
function insertLinear#
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.
function operator=#
Copy assignment.
function operator=#
Move assignment.
function operator=#
Assignment using the initializer list.
function operator==#
Returns whether this vector is equal to an other
vector.
function operator[]#
Returns a reference to element i
.
function operator[]#
Returns a reference to element i
.
function pop_back#
Removes the last element from the vector.
function print#
Prints the vector.
function push_back#
Appends t
to the vector.
function rbegin [1/2]#
Returns a reverse iterator that points to the reverse beginning of the vector.
function rbegin [2/2]#
Returns a reverse iterator that points to the reverse beginning of the vector.
function remove#
Removes element i
from the vector, and replaces it with the last element.
function removeAll#
Removes all t
from the vector. The vector is reordered as when applying multiple remove operations.
function removeLinear [1/2]#
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]#
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.
function rend [2/2]#
Returns a reverse iterator that points to the reverse end of the vector.
function resize#
Resize to size n
.
function setArray#
build from array
function size#
Returns the size of the vector.
function ~SBCContainerVector#
Destructs the vector.