Merge branch 'mat-devel'
[ProjetInfo.git] / math / inc / vector.h
blob173ade15a000411c08afab19a4fd350b87703f8a
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 All operators can throw logic_error exceptions*/
34 void operator = (const Vector &otherVector);
36 Vector operator + (const Vector &otherVector) const;
37 Vector& operator += (const Vector &otherVector);
39 Vector operator - (const Vector &otherVector) const;
40 Vector& operator -= (const Vector &otherVector);
42 Vector operator * (const double scalar) const;
43 Vector& operator *= (const double scalar);
44 double operator * (const Vector &otherVector) const; //Dot product of two vectors
46 //Can throw domain_error exceptions
47 Vector operator / (const double scalar) const;
48 Vector& operator /= (const double scalar);
50 Vector operator ^ (const Vector &otherVector) const;
52 bool operator == (const Vector &otherVector) const;
53 bool operator != (const Vector &otherVector) const;
55 /*Can throw out_of_range exceptions
56 /!\ index is understood as a mathematical index, not as a general C++ index /!\
57 See method 'at()' for the C++ like getter/setter*/
58 double operator [] (const double index) const;
59 double& operator [] (const double index);
61 /*Can throw out_of_range exception
62 C++ like getter/setter*/
63 double at (const unsigned int index) const;
64 double& at (const unsigned int index);
66 friend std::ostream& operator << (std::ostream& os, const Vector& aVector);
68 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