libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


Public Types | Public Member Functions | Protected Attributes | List of all members
libcoyotl::array< Type > Class Template Reference

A STL-compatible array class. More...

#include <array.h>

Public Types

typedef Type value_type
 Type of an array element.
 
typedef Type * pointer
 type of a pointer to an element
 
typedef const Type * const_pointer
 Type of a constant pointer to an element.
 
typedef Type & reference
 Type of a reference to an element.
 
typedef const Type & const_reference
 Type of a constant reference to an element.
 
typedef ptrdiff_t difference_type
 Difference type between two element pointers.
 
typedef size_t size_type
 Size type for indexing array elements.
 
typedef Type * iterator
 Iterator type.
 
typedef const Type * const_iterator
 Constant iterator type.
 
typedef Type * reverse_iterator
 Reverse iterator type.
 
typedef const Type * const_reverse_iterator
 Constant reverse iterator type.
 

Public Member Functions

 array (size_t a_length)
 Default constructor. More...
 
 array (size_t a_length, const Type &a_init_value)
 Initialization constructor. More...
 
 array (const array< Type > &a_source)
 Copy constructor. More...
 
 array (size_t a_length, const Type *a_carray)
 Create from C-style array. More...
 
virtual ~array () throw ()
 Virtual destructor. More...
 
arrayoperator= (const array< Type > &a_source) throw ()
 Assignment operator. More...
 
arrayoperator= (const Type &a_value) throw ()
 Assign value to all elements. More...
 
arrayoperator= (const Type *a_carray) throw ()
 Assign from C-style array. More...
 
const Type * c_array () const throw ()
 Conversion to C-style array. More...
 
Type & operator[] (size_t n) throw (LIBCOYOTL_ARRAY_EXCEPTIONS)
 Element access. More...
 
Type operator[] (size_t n) const throw (LIBCOYOTL_ARRAY_EXCEPTIONS)
 Element access, constant array. More...
 
void append (const array< Type > &a_array)
 Appending arrays. More...
 
iterator begin () throw ()
 Obtain beginning-of-sequence iterator. More...
 
const_iterator begin () const throw ()
 Obtain beginning-of-sequence iterator, constant array. More...
 
iterator end () throw ()
 Obtain end-of-sequence iterator. More...
 
const_iterator end () const throw ()
 Obtain end-of-sequence iterator, constant array. More...
 
iterator rbegin () throw ()
 Obtain beginning-of-sequence reverse iterator. More...
 
const_iterator rbegin () const throw ()
 Obtain beginning-of-sequence reverse iterator, constant array. More...
 
iterator rend () throw ()
 Obtain end-of-sequence reverse iterator. More...
 
const_iterator rend () const throw ()
 Obtain end-of-sequence reverse iterator, constant array. More...
 
bool operator== (const array< Type > &a_comparand) const throw ()
 Equals operator. More...
 
bool operator!= (const array< Type > &a_comparand) const throw ()
 Inequality operator. More...
 
bool operator< (const array< Type > &a_comparand) const throw ()
 Less-than operator. More...
 
bool operator<= (const array< Type > &a_comparand) const throw ()
 Less-than-or-equal-to operator. More...
 
bool operator> (const array< Type > &a_comparand) const throw ()
 Greater-than operator. More...
 
bool operator>= (const array< Type > &a_comparand) const throw ()
 Greater-than-or-equal-to operator. More...
 
void swap (array< Type > &a_source) throw ()
 Exchanges the corresponding elements of two arrays. More...
 
size_t size () const throw ()
 Number of elements. More...
 
size_t max_size () const throw ()
 Maximum container size. More...
 
bool empty () const throw ()
 Empty container check. More...
 

Protected Attributes

Type * m_array
 Underlying allocated array.
 
size_t m_size
 Length of the array.
 

Detailed Description

template<typename Type>
class libcoyotl::array< Type >

This class defines a simple array with elements stored in contiguous allocated memory. The Standard C++ valarray is focused on numerical applications and largely incompatible with the STL. The std::vector includes dyanmic array features that simply aren't necessary for many applications.

Constructor & Destructor Documentation

template<typename Type >
libcoyotl::array< Type >::array ( size_t  a_length)

Constructs an array with a_length uninitialized elements. /param a_length number of elements in the array

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

template<typename Type >
libcoyotl::array< Type >::array ( size_t  a_length,
const Type &  a_init_value 
)

Constructs an array with specific number of elements initialized to given value. /param a_length number of elements in the array /param a_init_value initial value of all array elements

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

template<typename Type >
libcoyotl::array< Type >::array ( const array< Type > &  a_source)

Creates a new array identical to an existing one.

Parameters
a_source- The a_source object

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

template<typename Type >
libcoyotl::array< Type >::array ( size_t  a_length,
const Type *  a_carray 
)

Constructs a new array by copying the elements of the specified C-style array. /param a_length number of elements in the array /param a_carray pointer to an array of with a_length elements

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

template<typename Type >
libcoyotl::array< Type >::~array ( )
throw (
)
virtual

A virtual destructor. By default, it does nothing; this is a placeholder that identifies this class as a potential base, ensuring that objects of a derived class will have their destructors called if they are destroyed through a base-class pointer.

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

Member Function Documentation

template<typename Type >
void libcoyotl::array< Type >::append ( const array< Type > &  a_array)

Appends the a_other array to the target, extending the length of the target by the length of a_other.

Parameters
a_array- Array to be appended to the target

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

template<typename Type >
array< Type >::iterator libcoyotl::array< Type >::begin ( )
throw (
)
inline

Returns an iterator to the first elements of the array.

Returns
An iterator pointing to the first element in the array

References libcoyotl::array< Type >::m_array.

Referenced by libcoyotl::array< Type >::operator<(), libcoyotl::array< Type >::operator==(), and libcoyotl::array< Type >::rend().

template<typename Type >
array< Type >::const_iterator libcoyotl::array< Type >::begin ( ) const
throw (
)
inline

Returns a const iterator to the first element of the array.

Returns
A const iterator pointing to the first element in the array

References libcoyotl::array< Type >::m_array.

template<typename Type >
const Type * libcoyotl::array< Type >::c_array ( ) const
throw (
)
inline

Returns a pointer to the internal C-style array encapsulated by this array. The returned pointer is constant, so no elements can be change via this function.

Returns
A const pointer to the underlying C-style array

References libcoyotl::array< Type >::m_array.

template<typename Type >
bool libcoyotl::array< Type >::empty ( ) const
throw (
)
inline

Always false, as an array is never "empty". Required by Standard C++ algorithms and container definitions.

Returns
Always false
template<typename Type >
array< Type >::iterator libcoyotl::array< Type >::end ( )
throw (
)
inline

Returns an iterator to the first element beyond the end of the array.

Returns
An iterator pointing to the first element beyond the end of the array

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

Referenced by libcoyotl::array< Type >::operator<(), libcoyotl::array< Type >::operator==(), and libcoyotl::array< Type >::rbegin().

template<typename Type >
array< Type >::const_iterator libcoyotl::array< Type >::end ( ) const
throw (
)
inline

Returns a const iterator to the first element beyond the end of the array.

Returns
A const iterator pointing to the first element beyond the end of the array

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.

template<typename Type >
size_t libcoyotl::array< Type >::max_size ( ) const
throw (
)
inline

Returns the maximum size of the container, which is the same as the size(). Required by Standard C++ algorithms and container definitions.

Returns
Number of elements in the target array

References libcoyotl::array< Type >::m_size.

template<typename Type >
bool libcoyotl::array< Type >::operator!= ( const array< Type > &  a_comparand) const
throw (
)
inline

Compares corresponding elements of the target array to the argument array, checking for inequality.

Parameters
a_comparand- Comparand array
Returns
true if any elements of the target are not equal to corresponding elements in the comparand; false otherwise.
template<typename Type >
bool libcoyotl::array< Type >::operator< ( const array< Type > &  a_comparand) const
throw (
)
inline

Compares corresponding elements of the target array and the comparand array, checking that all target elements are less than comparand elements.

Parameters
a_comparand- Comparand array
Returns
true if all elements of the target are less than corresponding elements in the comparand; false otherwise.

References libcoyotl::array< Type >::begin(), and libcoyotl::array< Type >::end().

template<typename Type >
bool libcoyotl::array< Type >::operator<= ( const array< Type > &  a_comparand) const
throw (
)
inline

Compares corresponding elements of the target array and the comparand array, checking that all target elements are less than or equal to comparand elements.

Parameters
a_comparand- Comparand array
Returns
true if all elements of the target are less than or equal to corresponding elements in the comparand; false otherwise.
template<typename Type >
array< Type > & libcoyotl::array< Type >::operator= ( const array< Type > &  a_source)
throw (
)

Assigns an existing object the state of another.

Parameters
a_source- The source object
template<typename Type >
array< Type > & libcoyotl::array< Type >::operator= ( const Type &  a_value)
throw (
)

Assigns a given value to all elements in an array.

Parameters
a_value- Value to be assigned
Returns
A reference to the target array
template<typename Type >
array< Type > & libcoyotl::array< Type >::operator= ( const Type *  a_carray)
throw (
)

Assign elements from a c-style array, assuming that c_array contains at least the number of elements in the target array.

Parameters
a_carray- A pointer to a C-style array
template<typename Type >
bool libcoyotl::array< Type >::operator== ( const array< Type > &  a_comparand) const
throw (
)
inline

Compares corresponding elements of the target array to the argument array, checking for equality.

Parameters
a_comparand- Comparand array
Returns
true all corresponding elements are equal, false otherwise.

References libcoyotl::array< Type >::begin(), and libcoyotl::array< Type >::end().

template<typename Type >
bool libcoyotl::array< Type >::operator> ( const array< Type > &  a_comparand) const
throw (
)
inline

Compares corresponding elements of the target array and the comparand array, checking that all target elements are greater than comparand elements.

Parameters
a_comparand- Comparand array
Returns
true if all elements of the target are greater than corresponding elements in the comparand; false otherwise.
template<typename Type >
bool libcoyotl::array< Type >::operator>= ( const array< Type > &  a_comparand) const
throw (
)
inline

Compares corresponding elements of the target array and the comparand array, checking that all target elements are greater than or equal to comparand elements.

Parameters
a_comparand- Comparand array
Returns
true if all elements of the target are greater than or equal to corresponding elements in the comparand; false otherwise.
template<typename Type >
Type & libcoyotl::array< Type >::operator[] ( size_t  n)
throw (LIBCOYOTL_ARRAY_EXCEPTIONS
)
inline

Returns a reference to a specific element in an array.

Parameters
n- Index of an element
Returns
A reference to the element at index n

References libcoyotl::array< Type >::m_array.

template<typename Type >
Type libcoyotl::array< Type >::operator[] ( size_t  n) const
throw (LIBCOYOTL_ARRAY_EXCEPTIONS
)
inline

Returns a specific element in an array.

Parameters
n- Index of an element
Returns
A copy of the element at index n

References libcoyotl::array< Type >::m_array.

template<typename Type >
array< Type >::reverse_iterator libcoyotl::array< Type >::rbegin ( )
throw (
)
inline

Returns a reverse iterator to the first element beyond the end of the array.

Returns
An iterator pointing to the first element beyond the end of the array

References libcoyotl::array< Type >::end().

template<typename Type >
array< Type >::const_reverse_iterator libcoyotl::array< Type >::rbegin ( ) const
throw (
)
inline

Returns a reverse iterator to the first element beyond the end of the array.

Returns
An iterator pointing to the first element beyond the end of the array

References libcoyotl::array< Type >::end().

template<typename Type >
array< Type >::reverse_iterator libcoyotl::array< Type >::rend ( )
throw (
)
inline

Returns a reverse iterator to the first element of the array.

Returns
A const reverse iterator pointing to the first element in the array

References libcoyotl::array< Type >::begin().

template<typename Type >
array< Type >::const_reverse_iterator libcoyotl::array< Type >::rend ( ) const
throw (
)
inline

Returns a const reverse iterator to the first element of the array.

Returns
A const reverse iterator pointing to the first element in the array

References libcoyotl::array< Type >::begin().

template<typename Type >
size_t libcoyotl::array< Type >::size ( ) const
throw (
)
inline

Returns the number of elements in an array. Required by Standard C++ algorithms and container definitions.

Returns
Number of elements in target array

References libcoyotl::array< Type >::m_size.

template<typename Type >
void libcoyotl::array< Type >::swap ( array< Type > &  a_source)
throw (
)

Exchanges the corresponding elements of two arrays; used by various Standard C++ algorithms.

Parameters
a_source- Another array

References libcoyotl::array< Type >::m_array, and libcoyotl::array< Type >::m_size.


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

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.