sficl  Current version
Public Member Functions | Private Attributes | List of all members
SfiVectorLite< T > Class Template Reference

A light version of std::vector that allows push_back and clear without unnecessary memory operations. More...

#include <SfiVectorLite.h>

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

Public Member Functions

 SfiVectorLite (int size=0)
 Initializes the vector to the given size. More...
 
 SfiVectorLite (const SfiVectorLite< T > &vec)
 Copy constructor. More...
 
 ~SfiVectorLite ()
 
T & operator[] (int i)
 Returns the i-th element of the vector. Can be used as an l-value. More...
 
const T & operator[] (int i) const
 Returns the i-th element of the vector. More...
 
int size () const
 Returns the size of the vector. More...
 
int length () const
 Returns the size of the vector. More...
 
int capacity () const
 Returns the vector's storage capacity. More...
 
void reserve (size_t size)
 Resizes the underlying vector, but does not change the perceived size. More...
 
void resize (size_t size)
 Resizes the vector storage and adds/removes the elements appropriately. More...
 
void pack ()
 Resizes the vector to the current number of elements. More...
 
void clear ()
 Sets the number of elements to zero without releasing the memory. Use pack() to also release the memory. More...
 
void push_back (const T &t)
 Appends t to the end of the vector. More...
 
SfiVectorLite< T > & operator= (const SfiVectorLite< T > &vec)
 Copies the contents of vec into the vector. More...
 

Private Attributes

vector< T > m_data
 The storage for internal data. More...
 
size_t m_count
 The number of elements in the vector. More...
 

Detailed Description

template<typename T>
class SfiVectorLite< T >

A light version of std::vector that allows push_back and clear without unnecessary memory operations.

The intended purpose is a vector that grows by calling push_back() and then clears by calling clear(). In the regular vector, the clear operation releases allocated memory. In this implementation, only the perceived size of the vector is changed, while any memory remains and will be reused on subsequent calls to push_back(). The memory can be released by calling pack().

Definition at line 45 of file SfiVectorLite.h.

Constructor & Destructor Documentation

template<typename T>
SfiVectorLite< T >::SfiVectorLite ( int  size = 0)
inlineexplicit

Initializes the vector to the given size.

Definition at line 56 of file SfiVectorLite.h.

template<typename T>
SfiVectorLite< T >::SfiVectorLite ( const SfiVectorLite< T > &  vec)
inline

Copy constructor.

Definition at line 62 of file SfiVectorLite.h.

template<typename T>
SfiVectorLite< T >::~SfiVectorLite ( )
inline

Definition at line 68 of file SfiVectorLite.h.

Member Function Documentation

template<typename T>
int SfiVectorLite< T >::capacity ( ) const
inline

Returns the vector's storage capacity.

If the vector is attached to external storage, returns the external storage capacity.

Definition at line 101 of file SfiVectorLite.h.

template<typename T>
void SfiVectorLite< T >::clear ( )
inline

Sets the number of elements to zero without releasing the memory. Use pack() to also release the memory.

Definition at line 130 of file SfiVectorLite.h.

Referenced by SfiDelimitedRecordSTD::clear(), and SfiDelimitedRecordSTD::split().

template<typename T>
int SfiVectorLite< T >::length ( ) const
inline

Returns the size of the vector.

Definition at line 94 of file SfiVectorLite.h.

template<typename T>
SfiVectorLite<T>& SfiVectorLite< T >::operator= ( const SfiVectorLite< T > &  vec)
inline

Copies the contents of vec into the vector.

Definition at line 150 of file SfiVectorLite.h.

template<typename T>
T& SfiVectorLite< T >::operator[] ( int  i)
inline

Returns the i-th element of the vector. Can be used as an l-value.

Definition at line 73 of file SfiVectorLite.h.

template<typename T>
const T& SfiVectorLite< T >::operator[] ( int  i) const
inline

Returns the i-th element of the vector.

Definition at line 78 of file SfiVectorLite.h.

template<typename T>
void SfiVectorLite< T >::pack ( )
inline

Resizes the vector to the current number of elements.

Can be used to free unused space after removing elements or resizing the vector down.

Definition at line 124 of file SfiVectorLite.h.

template<typename T>
void SfiVectorLite< T >::push_back ( const T &  t)
inline

Appends t to the end of the vector.

Definition at line 136 of file SfiVectorLite.h.

Referenced by SfiDelimitedRecordSTD::split().

template<typename T>
void SfiVectorLite< T >::reserve ( size_t  size)
inline

Resizes the underlying vector, but does not change the perceived size.

Definition at line 107 of file SfiVectorLite.h.

Referenced by SfiDelimitedRecordSTD::SfiDelimitedRecordSTD().

template<typename T>
void SfiVectorLite< T >::resize ( size_t  size)
inline

Resizes the vector storage and adds/removes the elements appropriately.

Definition at line 115 of file SfiVectorLite.h.

template<typename T>
int SfiVectorLite< T >::size ( ) const
inline

Member Data Documentation

template<typename T>
size_t SfiVectorLite< T >::m_count
private
template<typename T>
vector<T> SfiVectorLite< T >::m_data
private

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