Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

Array Class Reference

#include <ArrayInt.h>

List of all members.

Public Methods

 Array (int=10)
 Array (const Array &)
 ~Array ()
int getSize () const
const Array & operator= (const Array &)
bool operator== (const Array &) const
bool operator!= (const Array &right) const
intoperator[] (int)
const intoperator[] (int) const

Static Public Methods

int getArrayCount ()

Private Attributes

int size
intptr

Static Private Attributes

int arrayCount = 0

Friends

ostream & operator<< (ostream &, const Array &)
istream & operator>> (istream &, Array &)


Constructor & Destructor Documentation

Array::Array int    arraySize = 10
 

Definition at line 12 of file ArrayInt.cpp.

00013 {
00014    size = ( arraySize > 0 ? arraySize : 10 ); 
00015    ptr = new int[ size ]; // create space for array
00016    assert( ptr != 0 );    // terminate if memory not allocated
00017    ++arrayCount;          // count one more object
00018 
00019    for ( int i = 0; i < size; i++ )
00020       ptr[ i ] = 0;          // initialize array
00021 }

Array::Array const Array &    init
 

Definition at line 25 of file ArrayInt.cpp.

00025                                 : size( init.size )
00026 {
00027    ptr = new int[ size ]; // create space for array
00028    assert( ptr != 0 );    // terminate if memory not allocated
00029    ++arrayCount;          // count one more object
00030 
00031    for ( int i = 0; i < size; i++ )
00032       ptr[ i ] = init.ptr[ i ];  // copy init into object
00033 }

Array::~Array  
 

Definition at line 36 of file ArrayInt.cpp.

00037 {
00038    delete [] ptr;            // reclaim space for array
00039    --arrayCount;             // one fewer objects
00040 }


Member Function Documentation

int Array::getArrayCount   [static]
 

Definition at line 103 of file ArrayInt.cpp.

Referenced by main().

00103 { return arrayCount; }

int Array::getSize   const
 

Definition at line 43 of file ArrayInt.cpp.

Referenced by main().

00043 { return size; }

bool Array::operator!= const Array &    right const [inline]
 

Definition at line 23 of file ArrayInt.h.

00024       { return ! ( *this == right ); }

const Array & Array::operator= const Array &    right
 

Definition at line 47 of file ArrayInt.cpp.

00048 {
00049    if ( &right != this ) {  // check for self-assignment
00050       
00051       // for arrays of different sizes, deallocate original
00052       // left side array, then allocate new left side array.
00053       if ( size != right.size ) {
00054          delete [] ptr;         // reclaim space
00055          size = right.size;     // resize this object
00056          ptr = new int[ size ]; // create space for array copy
00057          assert( ptr != 0 );    // terminate if not allocated
00058       }
00059 
00060       for ( int i = 0; i < size; i++ )
00061          ptr[ i ] = right.ptr[ i ];  // copy array into object
00062    }
00063 
00064    return *this;   // enables x = y = z;
00065 }

bool Array::operator== const Array &    right const
 

Definition at line 69 of file ArrayInt.cpp.

00070 {
00071    if ( size != right.size )
00072       return false;    // arrays of different sizes
00073 
00074    for ( int i = 0; i < size; i++ )
00075       if ( ptr[ i ] != right.ptr[ i ] )
00076          return false; // arrays are not equal
00077 
00078    return true;        // arrays are equal
00079 }

const int & Array::operator[] int    subscript const
 

Definition at line 93 of file ArrayInt.cpp.

00094 {
00095    // check for subscript out of range error
00096    assert( 0 <= subscript && subscript < size );
00097 
00098    return ptr[ subscript ]; // const reference return
00099 }

int & Array::operator[] int    subscript
 

Definition at line 83 of file ArrayInt.cpp.

00084 {
00085    // check for subscript out of range error
00086    assert( 0 <= subscript && subscript < size );
00087 
00088    return ptr[ subscript ]; // reference return
00089 }


Friends And Related Function Documentation

ostream& operator<< ostream &    output,
const Array &    a
[friend]
 

Definition at line 116 of file ArrayInt.cpp.

00117 {
00118    int i;
00119 
00120    for ( i = 0; i < a.size; i++ ) {
00121       output << setw( 12 ) << a.ptr[ i ];
00122 
00123       if ( ( i + 1 ) % 4 == 0 ) // 4 numbers per row of output
00124          output << endl;
00125    }
00126 
00127    if ( i % 4 != 0 )
00128       output << endl;
00129 
00130    return output;   // enables cout << x << y;
00131 }

istream& operator>> istream &    input,
Array &    a
[friend]
 

Definition at line 107 of file ArrayInt.cpp.

00108 {
00109    for ( int i = 0; i < a.size; i++ )
00110       input >> a.ptr[ i ];
00111 
00112    return input;   // enables cin >> x >> y;
00113 }


Member Data Documentation

int Array::arrayCount = 0 [static, private]
 

Definition at line 9 of file ArrayInt.cpp.

int* Array::ptr [private]
 

Definition at line 32 of file ArrayInt.h.

Referenced by operator<<(), operator=(), operator==(), and operator>>().

int Array::size [private]
 

Definition at line 31 of file ArrayInt.h.

Referenced by operator<<(), operator=(), operator==(), and operator>>().


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:48:23 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001