Main Page | Namespace List | Alphabetical List | Class List | File List | Class Members | File Members

MVector.h

Go to the documentation of this file.
00001 //=======================================================================
00002 // Basic C++: a simple mathematical vector class
00003 //      Specification
00004 //-----------------------------------------------------------------------
00005 // Jean-Paul Rigault --- Copyright 2004
00006 // $Id: MVector.h,v 1.2 2004/11/28 16:50:16 jpr Exp $
00007 //=======================================================================
00008 
00009 #ifndef _MVECTOR_H_
00010 #define _MVECTOR_H_
00011 
00012 #include <iostream>
00013 #include <vector>
00014 using namespace std;
00015 
00023 class MVector
00024 {
00025 private:
00026 
00027     int _ncomps;                
00028     vector<double> _components; 
00029    
00030 public:
00031 
00033     class Out_Of_Bounds {};
00034 
00036     class Bad_Dimensions {};
00037 
00046 
00047     MVector(int n = 0, double x = 0.0);
00048 
00058     MVector& operator+=(const MVector& mv) {return *this = *this + mv;}
00059     MVector& operator-=(const MVector& mv) {return *this = *this - mv;}
00060 
00067 
00068     int ncomps() const {return _ncomps;}
00070     int size() const {return ncomps();}
00071 
00073     double norm() const;
00074 
00081 
00082     friend MVector operator+(const MVector& mv1, const MVector& mv2);
00084     friend MVector operator-(const MVector& mv1, const MVector& mv2);
00086     friend double operator*(const MVector& mv1, const MVector& mv2);
00088     friend double dot(const MVector& mv1, const MVector& mv2)
00089     {
00090         return mv1 * mv2; 
00091     }    
00092 
00099 
00100     friend bool operator==(const MVector& mv1, const MVector& mv2);
00102     friend bool operator!=(const MVector& mv1, const MVector& mv2)
00103     {
00104         return ! (mv1 == mv2);
00105     }
00106 
00113 
00114     double& operator[](int i);
00116     double operator[](int i) const;
00117 
00120 
00121     friend ostream& operator<<(ostream& os, const MVector& mv);
00122 };
00123 
00124 #endif

Generated on Mon Dec 12 18:25:42 2005 for Vectors_and_Matrices by  doxygen 1.4.3