From ceac394c2133d44e81db2eb633ff54a9ad6ce7c5 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 10 Nov 2005 05:52:11 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r3865, which included commits to RCS files with non-trunk default branches. svn path=/trunk/extensions/gripd/; revision=3866 --- src/midiio/include/Array.cpp | 378 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100644 src/midiio/include/Array.cpp (limited to 'src/midiio/include/Array.cpp') diff --git a/src/midiio/include/Array.cpp b/src/midiio/include/Array.cpp new file mode 100644 index 0000000..044ed2d --- /dev/null +++ b/src/midiio/include/Array.cpp @@ -0,0 +1,378 @@ +// +// Copyright 1997-1999 by Craig Stuart Sapp, All Rights Reserved. +// Programmer: Craig Stuart Sapp +// Creation Date: Wed Feb 5 19:42:53 PST 1997 +// Last Modified: Sun May 11 20:41:28 GMT-0800 1997 +// Last Modified: Wed Jul 7 11:44:50 PDT 1999 (added setAll() function) +// Filename: ...sig/maint/code/base/Array/Array.cpp +// Web Address: http://sig.sapp.org/src/sigBase/Array.cpp +// Syntax: C++ +// +// Description: An array which can grow dynamically. Array is derived from +// the Collection class and adds various mathematical operators +// to the Collection class. The Array template class is used for +// storing numbers of any type which can be added, multiplied +// and divided into one another. +// + +#ifndef _ARRAY_CPP_INCLUDED +#define _ARRAY_CPP_INCLUDED + +#include "Array.h" +#include +#include + + +////////////////////////////// +// +// Array::Array +// + +template +Array::Array(void) : Collection(4) { } + +template +Array::Array(int arraySize) : Collection(arraySize) { } + +template +Array::Array(Array& anArray) : Collection(anArray) { } + +template +Array::Array(int arraySize, type *anArray) : + Collection(arraySize, anArray) { } + + + + +////////////////////////////// +// +// Array::~Array +// + +template +Array::~Array() { } + + + +////////////////////////////// +// +// Array::setAll -- sets the contents of each element to the +// specified value +// + +template +void Array::setAll(type aValue) { + for (int i=0; i +type Array::sum(void) { + type theSum = 0; + for (int i=0; i +type Array::sum(int loIndex, int hiIndex) { + type theSum = 0; + for (int i=loIndex; i<=hiIndex; i++) { + theSum += array[i]; + } + return theSum; +} + + + +////////////////////////////// +// +// Array::zero(-1, -1) +// + +template +void Array::zero(int minIndex, int maxIndex) { + if (size == 0) return; + if (minIndex == -1) minIndex = 0; + if (maxIndex == -1) maxIndex = size-1; + + if (minIndex < 0 || maxIndex < 0 || minIndex > maxIndex || + maxIndex >= size) { + cerr << "Error in zero function: min = " << minIndex + << " max = " << maxIndex << " size = " << size << endl; + exit(1); + } + + for (int i=minIndex; i<=maxIndex; i++) { + array[i] = 0; + } +} + + +//////////////////////////////////////////////////////////////////////////// +// +// operators +// + + +template +int Array::operator==(const Array& aArray) { + if (getSize() != aArray.getSize()) { + return 0; + } + Array& t = *this; + int i; + for (i=0; i +Array& Array::operator=(const Array& anArray) { + if (allocSize < anArray.size) { + if (allocSize != 0) { + delete [] array; + } + allocSize = anArray.size; + size = anArray.size; + array = new type[size]; + allowGrowthQ = anArray.allowGrowthQ; + growthAmount = anArray.growthAmount; + maxSize = anArray.maxSize; + } + size = anArray.size; + for (int i=0; i +Array& Array::operator+=(const Array& anArray) { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + for (int i=0; i +Array Array::operator+(const Array& anArray) const { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + Array bArray(*this); + bArray += anArray; + return bArray; +} + + +template +Array Array::operator+(type aNumber) const { + Array anArray(*this); + for (int i=0; i +Array& Array::operator-=(const Array& anArray) { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + for (int i=0; i +Array Array::operator-(const Array& anArray) const { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + Array bArray(*this); + bArray -= anArray; + return bArray; +} + + +template +Array Array::operator-(void) const { + Array anArray(*this); + for (int i=0; i +Array Array::operator-(type aNumber) const { + Array anArray(*this); + for (int i=0; i +Array& Array::operator*=(const Array& anArray) { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + for (int i=0; i +Array Array::operator*(const Array& anArray) const { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + Array bArray(*this); + bArray *= anArray; + return bArray; +} + + +template +Array Array::operator*(type aNumber) const { + Array anArray(*this); + for (int i=0; i +Array& Array::operator/=(const Array& anArray) { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + for (int i=0; i +Array Array::operator/(const Array& anArray) const { + if (size != anArray.size) { + cerr << "Error: different size arrays " << size << " and " + << anArray.size << endl; + exit(1); + } + + Array bArray(*this); + bArray /= anArray; + return bArray; +} + + +#endif /* _ARRAY_CPP_INCLUDED */ + + + +// md5sum: 8f52a167c93f51702ce316204fd6e722 - Array.cpp =css= 20030102 -- cgit v1.2.1