Scopira  20080306
scopira::tool::hybrid_array< T, RES > Class Template Reference

#include <array.h>

Public Types

typedef T data_type
 
typedef T * iterator
 
typedef const T * const_iterator
 

Public Member Functions

 hybrid_array (void)
 
 hybrid_array (size_t len)
 
 hybrid_array (const hybrid_array &rhs)
 
 hybrid_array (const_array_view< T > rhs)
 
 ~hybrid_array ()
 Destructor.
 
void resize (size_t newlen)
 
T * array (void)
 
const T * array (void) const
 
T * c_array (void)
 
const T * c_array (void) const
 
iterator begin (void)
 
iterator end (void)
 
const_iterator begin (void) const
 
const_iterator end (void) const
 
hybrid_arrayoperator= (const hybrid_array &rhs)
 
hybrid_arrayoperator= (const_array_view< T > rhs)
 
void clear (void)
 
void clear_zero (void)
 
size_t size (void) const
 
bool empty (void) const
 
void set (size_t idx, const T &v)
 
const T & get (size_t idx) const
 
T & get (size_t idx)
 
const T & operator[] (size_t idx) const
 
T & operator[] (size_t idx)
 

Protected Attributes

fixed_array< T, RES > dm_fixed
 
basic_array< T > dm_basic
 
T * dm_ary
 
size_t dm_len
 

Detailed Description

template<class T, size_t RES>
class scopira::tool::hybrid_array< T, RES >

This is a resizable array (like basic_array) thay uses an internal fixed_array (non-heap using) buffer if possible. Very useful for when the array's size rarely exceeds a certain (relativly small) size, and if it does, it'll switch to keep allocation.

Note, that this class does some internally duplication. You should probably only use this for simple, smaller types.

RES is the fixed_array reserve size – after this, the heap will be used.

Author
Aleksander Demko

Constructor & Destructor Documentation

◆ hybrid_array() [1/4]

template<class T , size_t RES>
scopira::tool::hybrid_array< T, RES >::hybrid_array ( void  )

Default constructor: makes a 0-length array.

Author
Aleksander Demko

◆ hybrid_array() [2/4]

template<class T , size_t RES>
scopira::tool::hybrid_array< T, RES >::hybrid_array ( size_t  len)
explicit

Initialization constructor - makes a array of the given size. Each object will be initializaed via its default constructor (thus primitives will have undefined values).

Parameters
lenthe length of the new array

References scopira::tool::hybrid_array< T, RES >::resize().

◆ hybrid_array() [3/4]

◆ hybrid_array() [4/4]

Member Function Documentation

◆ array() [1/2]

template<class T, size_t RES>
T* scopira::tool::hybrid_array< T, RES >::array ( void  )
inline

Raw access to the array

Author
Aleksander Demko

◆ array() [2/2]

template<class T, size_t RES>
const T* scopira::tool::hybrid_array< T, RES >::array ( void  ) const
inline

Raw access to the array

Author
Aleksander Demko

◆ begin() [1/2]

template<class T, size_t RES>
iterator scopira::tool::hybrid_array< T, RES >::begin ( void  )
inline

◆ begin() [2/2]

template<class T, size_t RES>
const_iterator scopira::tool::hybrid_array< T, RES >::begin ( void  ) const
inline

STL-like iteration

Author
Aleksander Demko

◆ c_array() [1/2]

template<class T, size_t RES>
T* scopira::tool::hybrid_array< T, RES >::c_array ( void  )
inline

Raw access to the array

Author
Aleksander Demko

◆ c_array() [2/2]

template<class T, size_t RES>
const T* scopira::tool::hybrid_array< T, RES >::c_array ( void  ) const
inline

Raw access to the array

Author
Aleksander Demko

◆ clear()

template<class T, size_t RES>
void scopira::tool::hybrid_array< T, RES >::clear ( void  )
inline

Does a resize(0)

Author
Aleksander Demko

◆ clear_zero()

template<class T, size_t RES>
void scopira::tool::hybrid_array< T, RES >::clear_zero ( void  )
inline

Clears all the array values to binary 0. Does not resize the array. This is dangerous on non-POD classes.

Author
Aleksander Demko

◆ empty()

template<class T, size_t RES>
bool scopira::tool::hybrid_array< T, RES >::empty ( void  ) const
inline

Is the array empty (0 length)?

Author
Aleksander Demko

Referenced by scopira::tool::hybrid_array< T, RES >::hybrid_array().

◆ end() [1/2]

template<class T, size_t RES>
iterator scopira::tool::hybrid_array< T, RES >::end ( void  )
inline

◆ end() [2/2]

template<class T, size_t RES>
const_iterator scopira::tool::hybrid_array< T, RES >::end ( void  ) const
inline

STL-like iteration

Author
Aleksander Demko

◆ get() [1/2]

template<class T, size_t RES>
const T& scopira::tool::hybrid_array< T, RES >::get ( size_t  idx) const
inline

Individual element setter

Author
Aleksander Demko

◆ get() [2/2]

template<class T, size_t RES>
T& scopira::tool::hybrid_array< T, RES >::get ( size_t  idx)
inline

Individual element setter

Author
Aleksander Demko

◆ operator=() [1/2]

template<class T , size_t RES>
scopira::tool::hybrid_array< T, RES > & scopira::tool::hybrid_array< T, RES >::operator= ( const hybrid_array< T, RES > &  rhs)

◆ operator=() [2/2]

◆ operator[]() [1/2]

template<class T, size_t RES>
const T& scopira::tool::hybrid_array< T, RES >::operator[] ( size_t  idx) const
inline

Nice reference access

Author
Aleksander Demko

◆ operator[]() [2/2]

template<class T, size_t RES>
T& scopira::tool::hybrid_array< T, RES >::operator[] ( size_t  idx)
inline

Nice reference access

Author
Aleksander Demko

◆ resize()

template<class T , size_t RES>
void scopira::tool::hybrid_array< T, RES >::resize ( size_t  newlen)

Resizes the array. Please note the following: 1) If the new size is the current size, nothing will be done. 2) Resizes are destructive. All old values will be lost, and a new array is constructed (following the initialization rules specified in the constructor description)

Parameters
newlenthe new length
Author
Aleksander Demko

References scopira::tool::fixed_array< T, N >::c_array().

Referenced by scopira::tool::hybrid_array< T, RES >::hybrid_array(), and scopira::tool::hybrid_array< T, RES >::operator=().

◆ set()

template<class T, size_t RES>
void scopira::tool::hybrid_array< T, RES >::set ( size_t  idx,
const T &  v 
)
inline

Individual element setter

Author
Aleksander Demko

◆ size()

template<class T, size_t RES>
size_t scopira::tool::hybrid_array< T, RES >::size ( void  ) const
inline

Gets the size of the array

Author
Aleksander Demko

Referenced by scopira::tool::hybrid_array< T, RES >::hybrid_array().


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