classe 'Vector' : ajout de deux constructeurs et surcharge de l'operateur 'ostream...
[ProjetInfo.git] / vector.h
blob9f54470b8f70003659fe3f88de173abb6f422da6
1 #ifndef VECTOR_H
2 #define VECTOR_H
4 #include <iostream>
5 #include <stdexcept>
6 #include <exception>
7 #include <vector>
8 #include <cmath>
10 class Vector
12 public:
13 enum STANDARD_BASIS {ei}; //Allows instantiation of particular vectors of Rn
15 //Constructors and destructors
16 Vector ();
17 Vector (const unsigned int dimension);
18 Vector (const double cmp1, const double cmp2, const double cmp3);
19 Vector (double components[], const unsigned int size);
20 Vector (std::vector<double> components);
21 /*Can throw logic_error exceptions
22 /!\ Be aware that the index 'i' is understood as a mathematical index, not a general C++ index /!\*/
23 Vector (const unsigned int dimension, STANDARD_BASIS aVector, const unsigned int i);
24 Vector (const Vector &otherVector);
26 //Accessors and modifiers
27 const std::vector<double>& components () const {return m_components;}
28 void setComponents (const std::vector<double> &newVector) {m_components = newVector;}
29 unsigned int dimension () const;
32 //Operators
33 void operator = (const Vector &otherVector);
35 //All operators can throw logic_error exceptions
37 Vector operator + (const Vector &otherVector) const;
38 Vector& operator += (const Vector &otherVector);
40 Vector operator - (const Vector &otherVector) const;
41 Vector& operator -= (const Vector &otherVector);
43 Vector operator * (const double scalar) const;
44 Vector& operator *= (const double scalar);
45 double operator * (const Vector &otherVector) const; //Dot product of two vectors
47 //Can throw domain_error exceptions
48 Vector operator / (const double scalar) const;
49 Vector& operator /= (const double scalar);
51 Vector operator ^ (const Vector &otherVector) const;
53 bool operator == (const Vector &otherVector) const;
54 bool operator != (const Vector &otherVector) const;
56 /*Can throw out_of_range exceptions
57 /!\ index is understood as a mathematical index, not as a general C++ index /!\
58 See method 'at()' for the C++ like getter*/
59 double operator [] (const double index) const;
60 double& operator [] (const double index);
62 /*Can throw out_of_range exception
63 C++ like getter*/
64 double at (const unsigned int index) const;
65 double& at (const unsigned int index);
67 friend std::ostream& operator << (std::ostream& os, const Vector& aVector);
69 double dotProduct (const Vector &otherVector) const; //Calculate Euclidea standard product
71 //Other methods
72 void addComponent (double value = 0);
73 double magnitude () const;
74 double magnitude2 () const;
75 void show () const;
78 private:
79 std::vector<double> m_components;
82 #endif // VECTOR_H