Public Member Functions | Friends

List< Type > Class Template Reference

The List class template is used to construct lists of all types, Integer, Real, Complex, Pitch, Rhythm, etc. More...

#include <List.h>

List of all members.

Public Member Functions

 List ()
 Default List constructor.
 List (List Const &L)
 List copy constructor.
 List (Type i_)
 List constructor for a list of length 1.
 List (Type i1_, Type i2_)
 List constructor for a list of length 2.
 List (Type i1_, Type i2_, Type i3_)
 List constructor for a list of length 3.
 List (Type i1_, Type i2_, Type i3_, Type i4_)
 List constructor for a list of length 4.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_)
 List constructor for a list of length 5.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_)
 List constructor for a list of length 6.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_)
 List constructor for a list of length 7.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_)
 List constructor for a list of length 8.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_)
 List constructor for a list of length 9.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_)
 List constructor for a list of length 10.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_)
 List constructor for a list of length 11.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_)
 List constructor for a list of length 12.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_)
 List constructor for a list of length 13.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_, Type i14_)
 List constructor for a list of length 14.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_, Type i14_, Type i15_)
 List constructor for a list of length 15.
 List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_, Type i14_, Type i15_, Type i16_, Type i17_, Type i18_, Type i19_, Type i20_, Type i21_, Type i22_)
 List constructor for a list of length 16.
 ~List ()
 Default List destructor.
Bool operator== (Const List &L)
 List equality operator.
Bool operator!= (Const List &L)
 List inequality operator.
Listoperator+= (Const List &L)
 List concatenation/copy operator, joins lists together.
List operator+ (Const List &L)
 List concatenation operator, joins lists together.
Listoperator= (Const List &L)
 List assignment operator.
Type & operator[] (Integer elem)
 List indexing operator.
Listoperator+= (Const Type x)
 List increment operator, adds Integer to value of all elements of list.
Listoperator-= (Const Type x)
 List decrement operator, subtracts Integer to value from all elements of list.
Listoperator+ (Const Type x)
 List addition operator, adds Integer to value of all elements of list.
Listoperator- (Const Type x)
 List subtraction operator, subtracts Integer to value from all elements of list.
Listoperator* (Const Type x)
 List multiplication operator, multiplies Integer by value of all elements of list.
Listoperator/ (Const Type x)
 List division operator, multiplies Integer by value of all elements of list.
Void print (String s=0)
 List print method.
Void SetListSize (Integer n)
 Preset list to a particular size.
Void checkSize (Integer len)
 List range checking method.
Integer length ()
 List length method.
Type max ()
 List max method.
Integer maxPos ()
 List maxPos method.
Type min ()
 List min method.
Integer minPos ()
 List minPos method.
Void rotate (Integer n, Integer i=0)
 Rotate list by n elements from position i.
Void transpose (Type t, Type lim)
 Offset values of list elements by t modulo lim.
Void invert (Type lim)
 Invert values of list elements at limit.
Void retrograde ()
 Retrograde values of list elements.

Friends

ostream & operator<< (ostream &os, Const List &r)
 Print list to output stream.
Void adjustSize (Integer len, List &r)
 Lists are auto-ranging in size.
istream & operator>> (istream &is, List &r)
 Read a list from the input stream.

Detailed Description

template<class Type>
class List< Type >

The List class template is used to construct lists of all types, Integer, Real, Complex, Pitch, Rhythm, etc.

List automatically adjusts its length to accommodate whatever index is provided, therefore, no initial bounds must be provided when the list is created. Simply indexing an element of the list causes it to come into being, initialized to 0 (for reference), or to the value being assigned.

Definition at line 31 of file List.h.


Constructor & Destructor Documentation

template<class Type >
List< Type >::List (  ) [inline]

Default List constructor.

See also:
~List

Definition at line 84 of file List.h.

Referenced by List< Type >::operator*(), and List< Type >::operator+().

: m_val(0), m_len(0) { }
template<class Type >
List< Type >::List ( List< Type > Const &  L ) [inline]

List copy constructor.

Parameters:
LList to copy
See also:
~List
Returns:
The copied list

Definition at line 90 of file List.h.

                              {
                m_val = new Type [ m_len = L.m_len ];
                memcpy(m_val, L.m_val, sizeof(Type) * m_len);
        }
template<class Type >
List< Type >::List ( Type  i_ ) [inline]

List constructor for a list of length 1.

Parameters:
i_First value
See also:
~List
Returns:
the created list containing one element i_

Definition at line 99 of file List.h.

                      { 
                m_val = new Type [ m_len = 1 ];
                m_val[0] = i_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_ 
) [inline]

List constructor for a list of length 2.

Parameters:
i1_First value
i2_Second value
See also:
~List
Returns:
the created list containing 2 elements

Definition at line 109 of file List.h.

                                  { 
                m_val = new Type [ m_len = 2 ];
                m_val[0] = i1_; 
                m_val[1] = i2_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_ 
) [inline]

List constructor for a list of length 3.

Definition at line 116 of file List.h.

                                            {
                m_val = new Type [ m_len = 3 ];
                m_val[0] = i1_; 
                m_val[1] = i2_; 
                m_val[2] = i3_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_ 
) [inline]

List constructor for a list of length 4.

Definition at line 124 of file List.h.

                                                      {
                m_val = new Type [ m_len = 4 ];
                m_val[0] = i1_; 
                m_val[1] = i2_; 
                m_val[2] = i3_; 
                m_val[3] = i4_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_ 
) [inline]

List constructor for a list of length 5.

Definition at line 133 of file List.h.

                                                                {
                m_val = new Type [ m_len = 5 ];
                m_val[0] = i1_; 
                m_val[1] = i2_; 
                m_val[2] = i3_; 
                m_val[3] = i4_; 
                m_val[4] = i5_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_ 
) [inline]

List constructor for a list of length 6.

Definition at line 143 of file List.h.

                                                                          {
                m_val = new Type [ m_len = 6 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_ 
) [inline]

List constructor for a list of length 7.

Definition at line 149 of file List.h.

                                                                                    {
                m_val = new Type [ m_len = 7 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_ 
) [inline]

List constructor for a list of length 8.

Definition at line 155 of file List.h.

                                                                                              {
                m_val = new Type [ m_len = 8 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_ 
) [inline]

List constructor for a list of length 9.

Definition at line 161 of file List.h.

                                                                                                        {
                m_val = new Type [ m_len = 9 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_;
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_,
Type  i10_ 
) [inline]

List constructor for a list of length 10.

Definition at line 168 of file List.h.

                                                                                                                   {
                m_val = new Type [ m_len = 10 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_; m_val[9] = i10_;
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_,
Type  i10_,
Type  i11_ 
) [inline]

List constructor for a list of length 11.

Definition at line 175 of file List.h.

                                                                                                                              {
                m_val = new Type [ m_len = 11 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_;
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_,
Type  i10_,
Type  i11_,
Type  i12_ 
) [inline]

List constructor for a list of length 12.

Definition at line 182 of file List.h.

                                                                                                                                         {
                m_val = new Type [ m_len = 12 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_;
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_,
Type  i10_,
Type  i11_,
Type  i12_,
Type  i13_ 
) [inline]

List constructor for a list of length 13.

Definition at line 189 of file List.h.

                                                                                                                                                    {
                m_val = new Type [ m_len = 13 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_;
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_,
Type  i10_,
Type  i11_,
Type  i12_,
Type  i13_,
Type  i14_ 
) [inline]

List constructor for a list of length 14.

Definition at line 196 of file List.h.

                                                                                                                                                                {
                m_val = new Type [ m_len = 14 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_; m_val[13] = i14_;
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_,
Type  i10_,
Type  i11_,
Type  i12_,
Type  i13_,
Type  i14_,
Type  i15_ 
) [inline]

List constructor for a list of length 15.

Definition at line 203 of file List.h.

                                                                                                                                                                           {
                m_val = new Type [ m_len = 15 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_; m_val[13] = i14_; m_val[14] = i15_;
        }
template<class Type >
List< Type >::List ( Type  i1_,
Type  i2_,
Type  i3_,
Type  i4_,
Type  i5_,
Type  i6_,
Type  i7_,
Type  i8_,
Type  i9_,
Type  i10_,
Type  i11_,
Type  i12_,
Type  i13_,
Type  i14_,
Type  i15_,
Type  i16_,
Type  i17_,
Type  i18_,
Type  i19_,
Type  i20_,
Type  i21_,
Type  i22_ 
) [inline]

List constructor for a list of length 16.

Definition at line 210 of file List.h.

                                                                                               {
                m_val = new Type [ m_len = 22 ];
                m_val[0] = i1_; m_val[1] = i2_;  m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_;  m_val[6] = i7_;  m_val[7] = i8_; 
                m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_; m_val[13] = i14_; m_val[14] = i15_;
                m_val[15] = i16_; m_val[16] = i17_; m_val[17] = i18_; m_val[18] = i19_; m_val[19] = i20_; m_val[20] = i21_; m_val[21] = i22_;
        }
template<class Type >
List< Type >::~List (  ) [inline]

Default List destructor.

Definition at line 219 of file List.h.

References If.

                { 
                If ( m_val )
                        delete [] m_val; 
                m_val = 0;
                m_len = 0;
        }

Member Function Documentation

template<class Type >
Void List< Type >::checkSize ( Integer  len ) [inline]

List range checking method.

If the list is empty, the list is created. If the list exists, and it is less than length len, then it is reallocated to contain len elements.

Parameters:
lenSize to reallocate list, if necessary.
Returns:
Modified list

Definition at line 447 of file List.h.

References Else, and If.

Referenced by List< Type >::operator[]().

                                    {
                If (m_val == 0)
                        m_val = new Type [ m_len = len+1 ];
                Else If (m_len <= len) {
                        m_len = len+1;
                        m_val = (Type*) realloc( m_val, m_len * sizeof(Type));
                }
        }
template<class Type >
Void List< Type >::invert ( Type  lim ) [inline]

Invert values of list elements at limit.

Parameters:
limLimit for inversion

Definition at line 540 of file List.h.

References For, and List< Type >::length().

Referenced by Invert().

                                {
                For ( Integer i = 0; i < length(); i = i + 1 ) {
                        m_val[ i ] = ( lim - m_val[ i ] ) % lim;
                }
        }
template<class Type >
Integer List< Type >::length (  ) [inline]

List length method.

Returns:
Length of the list

Definition at line 458 of file List.h.

References Return.

Referenced by Invert(), List< Type >::invert(), List< Type >::operator!=(), List< Type >::operator==(), List< Type >::retrograde(), List< Type >::rotate(), Transpose(), and List< Type >::transpose().

                         { 
                Return m_len; 
        }
template<class Type >
Type List< Type >::max (  ) [inline]

List max method.

Returns:
Maximum element of the list

Definition at line 464 of file List.h.

References For, and Return.

Referenced by Max(), and List< Type >::maxPos().

                   {
                assert(m_len > 0);
                Type max = m_val[0];
                For ( Integer i = 1; i < m_len; i++ )
                        max = m_val[i] < max ? max : m_val[i];
                Return max;
        }
template<class Type >
Integer List< Type >::maxPos (  ) [inline]

List maxPos method.

Returns:
index of Maximum element of the list. If multiple elements have the same max. value, this returns the first one.

Definition at line 475 of file List.h.

References For, If, List< Type >::max(), and Return.

                         {
                assert(m_len > 0);
                Type max = m_val[0];
                Integer mp = 0;
                For ( Integer i = 1; i < m_len; i++ ) {
                        If ( m_val[i] > max ) {
                                max = m_val[i];
                                mp = i;
                        }
                }
                Return mp;
        }
template<class Type >
Type List< Type >::min (  ) [inline]

List min method.

Returns:
Minimum element of the list

Definition at line 490 of file List.h.

References For, and Return.

Referenced by Min(), and List< Type >::minPos().

                   {
                assert(m_len > 0);
                Type min = m_val[0];
                For ( Integer i = 1; i < m_len; i++ )
                        min = m_val[i] < min ? m_val[i] : min;
                Return min;
        }
template<class Type >
Integer List< Type >::minPos (  ) [inline]

List minPos method.

Returns:
Minimum element of the list If multiple elements have the same max. value, this returns the first one.

Definition at line 501 of file List.h.

References For, If, List< Type >::min(), and Return.

                         {
                assert(m_len > 0);
                Type min = m_val[0];
                Integer mp = 0;
                For ( Integer i = 1; i < m_len; i++ ) {
                        If ( m_val[i] < min ) {
                                min = m_val[i];
                                mp = i;
                        }
                }
                Return mp;
        }
template<class Type >
Bool List< Type >::operator!= ( Const List< Type > &  L ) [inline]

List inequality operator.

Definition at line 239 of file List.h.

References For, If, List< Type >::length(), Return, and True.

                                         {
                If ( L.m_len != m_len )
                        Return(True);
                Integer cnt = 0;
                For( Integer i = 0; i < length(); i++ ) {
                        If ( L.m_val[i] == m_val[i] )
                                cnt++;
                }
                Return( cnt != m_len );
        }
template<class Type >
List& List< Type >::operator* ( Const Type  x ) [inline]

List multiplication operator, multiplies Integer by value of all elements of list.

Parameters:
xInteger value to multiply by all elements of list
Returns:
Modified list

Definition at line 335 of file List.h.

References For, List< Type >::List(), and Return.

                                        {
                List* t = new List (*this);
                *t = *this; // copy this
                For ( Integer i = 0; i < m_len; i++ )
                        t->m_val[i] *= x;
                Return( *t );
        }
template<class Type >
List& List< Type >::operator+ ( Const Type  x ) [inline]

List addition operator, adds Integer to value of all elements of list.

Parameters:
xInteger value to add to all elements of list
Returns:
Modified list

Definition at line 313 of file List.h.

References For, List< Type >::List(), and Return.

                                        {
                List* t = new List (*this);
                *t = *this; // copy this
                For ( Integer i = 0; i < m_len; i++ )
                        t->m_val[i] += x;
                Return( *t );
        }
template<class Type >
List List< Type >::operator+ ( Const List< Type > &  L ) [inline]

List concatenation operator, joins lists together.

Parameters:
LList to concatenate to this
Returns:
Concatenated lists

Definition at line 263 of file List.h.

References Return.

                                        {
                List r = *this;
                r += L;
                Return r;
        }
template<class Type >
List& List< Type >::operator+= ( Const List< Type > &  L ) [inline]

List concatenation/copy operator, joins lists together.

Parameters:
LList to concatenate to this
Returns:
Concatenated lists

Definition at line 253 of file List.h.

References Return.

                                          {
                m_val = (Type*) realloc( m_val, (m_len + L.m_len) * sizeof(Type));
                memcpy(&m_val[m_len], L.m_val, sizeof(Type) * L.m_len);
                m_len += L.m_len;
                Return( *this );
        }
template<class Type >
List& List< Type >::operator+= ( Const Type  x ) [inline]

List increment operator, adds Integer to value of all elements of list.

Parameters:
xInteger value to add to all elements of list
Returns:
Modified list

Definition at line 295 of file List.h.

References For, and Return.

                                         {
                For ( Integer i = 0; i < m_len; i++ )
                        m_val[i] += x;
                Return( *this );
        }
template<class Type >
List& List< Type >::operator- ( Const Type  x ) [inline]

List subtraction operator, subtracts Integer to value from all elements of list.

Parameters:
xInteger value to subtract from all elements of list
Returns:
Modified list

Definition at line 324 of file List.h.

References For, and Return.

                                        {
                List* t = new List [ m_len ];
                *t = *this; // copy this
                For ( Integer i = 0; i < m_len; i++ )
                        t->m_val[i] -= x;
                Return( *t );
        }
template<class Type >
List& List< Type >::operator-= ( Const Type  x ) [inline]

List decrement operator, subtracts Integer to value from all elements of list.

Parameters:
xInteger value to subtract from all elements of list
Returns:
Modified list

Definition at line 304 of file List.h.

References For, and Return.

                                         {
                For ( Integer i = 0; i < m_len; i++ )
                        m_val[i] -= x;
                Return( *this );
        }
template<class Type >
List& List< Type >::operator/ ( Const Type  x ) [inline]

List division operator, multiplies Integer by value of all elements of list.

Parameters:
xInteger value to divide by all elements of list
Returns:
Modified list

Definition at line 346 of file List.h.

References For, and Return.

                                        {
                List* t = new List [ m_len ];
                *t = *this; // copy this
                For ( Integer i = 0; i < m_len; i++ )
                        t->m_val[i] /= x;
                Return( *t );
        }
template<class Type >
List& List< Type >::operator= ( Const List< Type > &  L ) [inline]

List assignment operator.

Parameters:
LList to assign to this
Returns:
Assigned list

Definition at line 272 of file List.h.

References If, and Return.

                                         {
                If (this == &L)
                        Return *this;
                If (m_val != 0)
                        delete [] m_val;
                m_val = new Type [ m_len = L.m_len ];
                memcpy(m_val, L.m_val, sizeof(Type) * m_len);
                Return( *this );
        }
template<class Type >
Bool List< Type >::operator== ( Const List< Type > &  L ) [inline]

List equality operator.

Two lists are equal if they have the same length and all elements in corresponding positions are identical.

Definition at line 228 of file List.h.

References False, For, If, List< Type >::length(), Return, and True.

                                         {
                If ( L.m_len != m_len )
                        Return(False);
                For( Integer i = 0; i < length(); i++ ) {
                        If ( L.m_val[i] != m_val[i] )
                                Return( False );
                }
                Return( True );
        }
template<class Type >
Type& List< Type >::operator[] ( Integer  elem ) [inline]

List indexing operator.

Performs range checking.

Parameters:
elemInteger index of list element to return
Returns:
Indexed list element

Definition at line 286 of file List.h.

References List< Type >::checkSize(), and Return.

                                         {
                assert( elem >= 0);
                checkSize(elem);
                Return m_val[elem];
        }
template<class Type >
Void List< Type >::print ( String  s = 0 ) [inline]

List print method.

Parameters:
sString value to print at head of list.

Definition at line 418 of file List.h.

References For, and If.

                                 {
                If (s)
                        cout << s;
                cout << "{ ";
                cout.precision(2);
                For (Integer i = 0; i < m_len-1; i++)
                        cout << m_val[i] << ", ";
                cout << m_val[m_len-1];
                cout << " }" << endl;
        }
template<class Type >
Void List< Type >::retrograde (  ) [inline]

Retrograde values of list elements.

Definition at line 547 of file List.h.

References For, and List< Type >::length().

                           {
                Integer n = length( );
                Type* t = new Type [ m_len ];
                memcpy(t, m_val, sizeof(Type) * m_len);
                For ( Integer i = 0; i < n; i = i + 1 )
                        m_val[ i ] = t[ n - i - 1 ];
        }
template<class Type >
Void List< Type >::rotate ( Integer  n,
Integer  i = 0 
) [inline]

Rotate list by n elements from position i.

Parameters:
iStarting position, usually set to 0.
nNumber of elements to rotate. Positive n rotates counterclockwise; negative n rotates clockwise.

Definition at line 517 of file List.h.

References If, List< Type >::length(), Mod(), and PosMod().

                                                {
                n = Mod( n, length() );                 // constrain rotation to length of list
                Type x = m_val[ i ];                    // store f[ i ] for use after recursion
                If ( i < length() - 1 )                 // reached the end?
                        rotate( n, i+1 );                       // no, set up next element via recursion
                // We continue from here when the recursion unwinds
                Integer pos = PosMod( i+n, length() );  // index list modulo its length
                m_val[ pos ] = x;                               // assign value of x saved above
        }
template<class Type >
Void List< Type >::SetListSize ( Integer  n ) [inline]

Preset list to a particular size.

Definition at line 430 of file List.h.

References Else, and If.

                                    {
        If(m_val)
                        delete[] m_val;
        If (n > 0) {
            m_val = new Type[n];
            memset( m_val, 0, sizeof(Type) * n / sizeof(char) );
        }
        Else 
                        m_val = NULL;
        m_len = n;
    }
template<class Type >
Void List< Type >::transpose ( Type  t,
Type  lim 
) [inline]

Offset values of list elements by t modulo lim.

Note: uses PosMod() to preserve elements within the interval 0..lim.

Parameters:
tTransposition value
limTransposition limit

Definition at line 531 of file List.h.

References For, List< Type >::length(), and PosMod().

                                           {
                For ( Integer i = 0; i < length(); i = i + 1 ) {
                        Type x = m_val[ i ] + t;
                        m_val[ i ] = PosMod(x, lim);
                }
        }

Friends And Related Function Documentation

template<class Type >
Void adjustSize ( Integer  len,
List< Type > &  r 
) [friend]

Lists are auto-ranging in size.

This function reallocates the memory for a list to match its length requirements.

Definition at line 52 of file List.h.

                                                      {
                If (r.m_val == 0) {
                        r.m_val = new Type [ r.m_len = len+1 ];
                } Else If (r.m_len <= len) {
                        r.m_len = len+1;
                        r.m_val = (Type*) realloc( r.m_val, r.m_len * sizeof(Type));
                }
         }
template<class Type >
ostream& operator<< ( ostream &  os,
Const List< Type > &  r 
) [friend]

Print list to output stream.

List is printed as '{' <elem0> ',' <elem1> ',' ... '}'

Definition at line 35 of file List.h.

                                                              {
                If (r.m_len > 0)
                        os << "(";
                for (Integer i = 0; i < r.m_len; i++) {
                        os << r.m_val[i];
                        If (i != r.m_len-1)
                                os << ", ";
                        Else
                                os << ")";
                }
                os << endl;
                Return os;
         }
template<class Type >
istream& operator>> ( istream &  is,
List< Type > &  r 
) [friend]

Read a list from the input stream.

List is read as '(' <elem0> ',' <elem1> ',' ... ')'

Definition at line 63 of file List.h.

                                                          {
                 char ch;
                 Type t;
                 Integer len = 0;
                 is >> ch;
                 If (ch != '{' And ch != '(')
                         Return is;
                 While (is >> t >> ch And ch == ',') {
                        adjustSize(len, r);
                        r.m_val[len++] = t;
                 }
                adjustSize(len, r);
                r.m_val[len++] = t;
                assert( ch == '}' || ch == ')');
                Return is;
         }

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