MathArray.h

Go to the documentation of this file.
00001 
00007 #ifndef MATHARRAY_H
00008 #define MATHARRAY_H
00009 
00010 #include "Array.h"
00011 
00012 template <class Elem, int Size> class MathArray : public Array<Elem,Size> {
00013 
00014   public:
00015     // constructor
00016     MathArray(void) : Array<Elem,Size>(0) { ; }
00017 
00018     // destructor
00019     ~MathArray(void) { ; }
00020 
00021     // copy constructor
00022     MathArray(const Array<Elem,Size> &a2) : Array<Elem,Size>(a2) { ; }
00023 
00024     // assignment operator
00025     MathArray<Elem,Size> & operator= (const Array<Elem,Size> &a2) {
00026       Array<Elem,Size>::operator=(a2);
00027       return (*this);
00028     }
00029 
00030     // set all elements to a given value (like 0)
00031     MathArray(const Elem &v) : Array<Elem,Size>(v) { ; }
00032     MathArray<Elem,Size> & operator= (const Elem &v) {
00033       Array<Elem,Size>::operator=(v);
00034       return (*this);
00035     }
00036 
00037     // bulk mathematical operations
00038     MathArray<Elem,Size> & operator+= (const Array<Elem,Size> &a2) {
00039       for ( int i = 0; i < Size; ++i ) { this->data[i] += a2.data[i]; }
00040       return (*this);
00041     }
00042     MathArray<Elem,Size> & operator+= (const Elem &v) {
00043       for ( int i = 0; i < Size; ++i ) { this->data[i] += v; }
00044       return (*this);
00045     }
00046     MathArray<Elem,Size> & operator-= (const Array<Elem,Size> &a2) {
00047       for ( int i = 0; i < Size; ++i ) { this->data[i] -= a2.data[i]; }
00048       return (*this);
00049     }
00050     MathArray<Elem,Size> & operator-= (const Elem &v) {
00051       for ( int i = 0; i < Size; ++i ) { this->data[i] -= v; }
00052       return (*this);
00053     }
00054     MathArray<Elem,Size> & operator*= (const Array<Elem,Size> &a2) {
00055       for ( int i = 0; i < Size; ++i ) { this->data[i] *= a2.data[i]; }
00056       return (*this);
00057     }
00058     MathArray<Elem,Size> & operator*= (const Elem &v) {
00059       for ( int i = 0; i < Size; ++i ) { this->data[i] *= v; }
00060       return (*this);
00061     }
00062     MathArray<Elem,Size> & operator/= (const Array<Elem,Size> &a2) {
00063       for ( int i = 0; i < Size; ++i ) { this->data[i] /= a2.data[i]; }
00064       return (*this);
00065     }
00066     MathArray<Elem,Size> & operator/= (const Elem &v) {
00067       for ( int i = 0; i < Size; ++i ) { this->data[i] /= v; }
00068       return (*this);
00069     }
00070     friend MathArray<Elem,Size> operator+ (
00071                 const Array<Elem,Size> &a1, const Array<Elem,Size> &a2 ) {
00072       return (MathArray<Elem,Size>(a1) += a2);
00073     }
00074     friend MathArray<Elem,Size> operator+ (
00075                 const Array<Elem,Size> &a1, const Elem &v2 ) {
00076       return (MathArray<Elem,Size>(a1) += v2);
00077     }
00078     friend MathArray<Elem,Size> operator+ (
00079                 const Elem & v1, const Array<Elem,Size> &a2 ) {
00080       return (MathArray<Elem,Size>(v1) += a2);
00081     }
00082     friend MathArray<Elem,Size> operator- (
00083                 const Array<Elem,Size> &a1, const Array<Elem,Size> &a2 ) {
00084       return (MathArray<Elem,Size>(a1) -= a2);
00085     }
00086     friend MathArray<Elem,Size> operator- (
00087                 const Array<Elem,Size> &a1, const Elem &v2 ) {
00088       return (MathArray<Elem,Size>(a1) -= v2);
00089     }
00090     friend MathArray<Elem,Size> operator- (
00091                 const Elem & v1, const Array<Elem,Size> &a2 ) {
00092       return (MathArray<Elem,Size>(v1) -= a2);
00093     }
00094     friend MathArray<Elem,Size> operator* (
00095                 const Array<Elem,Size> &a1, const Array<Elem,Size> &a2 ) {
00096       return (MathArray<Elem,Size>(a1) *= a2);
00097     }
00098     friend MathArray<Elem,Size> operator* (
00099                 const Array<Elem,Size> &a1, const Elem &v2 ) {
00100       return (MathArray<Elem,Size>(a1) *= v2);
00101     }
00102     friend MathArray<Elem,Size> operator* (
00103                 const Elem & v1, const Array<Elem,Size> &a2 ) {
00104       return (MathArray<Elem,Size>(v1) *= a2);
00105     }
00106     friend MathArray<Elem,Size> operator/ (
00107                 const Array<Elem,Size> &a1, const Array<Elem,Size> &a2 ) {
00108       return (MathArray<Elem,Size>(a1) /= a2);
00109     }
00110     friend MathArray<Elem,Size> operator/ (
00111                 const Array<Elem,Size> &a1, const Elem &v2 ) {
00112       return (MathArray<Elem,Size>(a1) /= v2);
00113     }
00114     friend MathArray<Elem,Size> operator/ (
00115                 const Elem & v1, const Array<Elem,Size> &a2 ) {
00116       return (MathArray<Elem,Size>(v1) /= a2);
00117     }
00118 
00119 };
00120 
00121 #endif
00122 

Generated on Thu Sep 21 01:17:12 2017 for NAMD by  doxygen 1.4.7