classe 'Vector' : fin de l'implementation des operateurs et methodes 'at()'.
[ProjetInfo.git] / vector.h
blob096badf403e046f272789a490251fd45379dfbe4
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 (std::vector<double> components);
19 /*Can throw logic_error exceptions
20 /!\ Be aware that the index 'i' is understood as a mathematical index, not a general C++ index /!\*/
21 Vector (const unsigned int dimension, STANDARD_BASIS aVector, const unsigned int i);
22 Vector (const Vector &otherVector);
24 //Accessors and modifiers
25 const std::vector<double>& components () const {return m_components;}
26 void setComponents (const std::vector<double> &newVector) {m_components = newVector;}
27 unsigned int dimension () const;
30 //Operators
31 void operator = (const Vector &otherVector);
33 //All operators can throw logic_error exceptions
35 Vector operator + (const Vector &otherVector) const;
36 Vector& operator += (const Vector &otherVector);
38 Vector operator - (const Vector &otherVector) const;
39 Vector& operator -= (const Vector &otherVector);
41 Vector operator * (const double scalar) const;
42 Vector& operator *= (const double scalar);
43 double operator * (const Vector &otherVector) const; //Dot product of two vectors
45 //Can throw domain_error exceptions
46 Vector operator / (const double scalar) const;
47 Vector& operator /= (const double scalar);
49 Vector operator ^ (const Vector &otherVector) const;
51 Vector operator == (const Vector &otherVector) const;
52 Vector operator != (const Vector &otherVector) const;
54 /*Can throw out_of_range exceptions
55 /!\ index is understood as a mathematical index, not as a general C++ index /!\
56 See method 'at()' for the C++ like getter*/
57 double operator [] (const double index) const;
58 double& operator [] (const double index);
60 /*Can throw out_of_range exception
61 C++ like getter*/
62 double at (const unsigned int index) const;
63 double& at (const unsigned int index);
65 double dotProduct (const Vector &otherVector) const; //Calculate Euclidea standard product
67 //Other methods
68 void addComponent (double value);
69 double magnitude () const;
70 double magnitude2 () const;
71 void show () const;
74 private:
75 std::vector<double> m_components;
78 #endif // VECTOR_H