The List class template is used to construct lists of all types, Integer, Real, Complex, Pitch, Rhythm, etc. More...
#include <List.h>
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. | |
List & | operator+= (Const List &L) |
List concatenation/copy operator, joins lists together. | |
List | operator+ (Const List &L) |
List concatenation operator, joins lists together. | |
List & | operator= (Const List &L) |
List assignment operator. | |
Type & | operator[] (Integer elem) |
List indexing operator. | |
List & | operator+= (Const Type x) |
List increment operator, adds Integer to value of all elements of list. | |
List & | operator-= (Const Type x) |
List decrement operator, subtracts Integer to value from all elements of list. | |
List & | operator+ (Const Type x) |
List addition operator, adds Integer to value of all elements of list. | |
List & | operator- (Const Type x) |
List subtraction operator, subtracts Integer to value from all elements of list. | |
List & | operator* (Const Type x) |
List multiplication operator, multiplies Integer by value of all elements of list. | |
List & | operator/ (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. |
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.
Default List constructor.
Definition at line 84 of file List.h.
Referenced by List< Type >::operator*(), and List< Type >::operator+().
: m_val(0), m_len(0) { }
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_;
}
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_;
}
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_;
}
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_;
}
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_;
}
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.
len | Size to reallocate list, if necessary. |
Definition at line 447 of file List.h.
Referenced by List< Type >::operator[]().
Void List< Type >::invert | ( | Type | lim ) | [inline] |
List length method.
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; }
Type List< Type >::max | ( | ) | [inline] |
List max method.
Definition at line 464 of file List.h.
Referenced by Max(), and List< Type >::maxPos().
Type List< Type >::min | ( | ) | [inline] |
List min method.
Definition at line 490 of file List.h.
Referenced by Min(), and List< Type >::minPos().
List concatenation/copy operator, joins lists together.
L | List to concatenate to this |
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 ); }
Void List< Type >::retrograde | ( | ) | [inline] |
Rotate list by n elements from position i.
i | Starting position, usually set to 0. |
n | Number 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 }
Void List< Type >::transpose | ( | Type | t, |
Type | lim | ||
) | [inline] |
Lists are auto-ranging in size.
This function reallocates the memory for a list to match its length requirements.
ostream& operator<< | ( | ostream & | os, |
Const List< Type > & | r | ||
) | [friend] |
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; }