//DataVector.cpp // //definitions of DataVector class functions #include #include "DataVector.h" using std::cerr; using std::endl; //no-arg constructor (need for declaring arrays) template DataVector::DataVector () {} //destructor template DataVector::~DataVector () { delete []vinput; delete []voutput; } //copy constructor template DataVector::DataVector (const DataVector &dv) { inputVectorLength = dv.inputVectorLength; outputVectorLength = dv.outputVectorLength; vinput = new userType[inputVectorLength]; voutput = new userType[outputVectorLength]; for (int counter = 0; counter < inputVectorLength; ++counter) { vinput[counter] = dv.vinput[counter]; } for (int counter = 0; counter < outputVectorLength; ++counter) { voutput[counter] = dv.voutput[counter]; } } //initializer template void DataVector::initialize (int inputLength, int outputLength) { inputVectorLength = inputLength; outputVectorLength = outputLength; vinput = new userType[inputVectorLength]; voutput = new userType[outputVectorLength]; } //equality operator template bool DataVector::operator== (const DataVector &dv) { if (this == &dv) return true; if (inputVectorLength != dv.inputVectorLength) return false; if (outputVectorLength != dv.outputVectorLength) return false; for (int counter = 0; counter < inputVectorLength; ++counter) { if (vinput[counter] != dv.vinput[counter]) return false; } for (int counter = 0; counter < outputVectorLength; ++counter) { if (voutput[counter] != dv.voutput[counter]) return false; } return true; } //assigment operator template DataVector& DataVector::operator= (const DataVector &dv) { if (this != &dv) { //input and output vectors must be same size in both if ( (inputVectorLength != dv.inputVectorLength) || (outputVectorLength != dv.outputVectorLength) ) { cerr << "Attempt to use assignment operator on vectors of different sizes" << endl; exit(0); } for (int counter = 0; counter < inputVectorLength; ++counter) { vinput[counter] = dv.vinput[counter]; } for (int counter = 0; counter < outputVectorLength; ++counter) { voutput[counter] = dv.voutput[counter]; } } return *this; } //readers and writers template inline int DataVector::readInputVectorLength () { return inputVectorLength; } template inline int DataVector::readOutputVectorLength () { return outputVectorLength; } template inline userType DataVector::readInputVector(int index){ return vinput[index]; } template inline void DataVector::writeInputVector (int index, userType value) { vinput[index] = value; } template inline userType DataVector::readOutputVector (int index) { return voutput[index]; } template inline void DataVector::writeOutputVector (int index, userType value) { voutput[index] = value; }