SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Vector.hh
1 #ifndef VECTOR_HH
2 #define VECTOR_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <cmath>
7 #include <vector>
8 
9 // Other includes
10 #include "Assert.hh"
11 
17 template<typename T> class Vector {
18  public:
20  Vector();
21 
23  Vector(const size_t& n);
24 
26  Vector(const std::vector<T>& vec);
27 
29  Vector(const T* vec, const size_t& n);
30 
32  Vector(const size_t& n, const T& value);
33 
35  Vector(const Vector& vec);
36 
38  ~Vector();
39 
41  Vector& operator=(const Vector& vec);
42 
44  Vector operator-() const;
45 
47  Vector operator+(const Vector& vec) const;
48 
50  void operator+=(const Vector& vec);
51 
53  Vector operator-(const Vector& vec) const;
54 
56  void operator-=(const Vector& vec);
57 
59  T operator*(const Vector& vec) const;
60 
62  Vector operator*(const T& factor) const;
63 
65  void operator*=(const T& factor);
66 
68  Vector operator/(const T& factor) const;
69 
71  void operator/=(const T& factor);
72 
74  const T& operator[](const size_t i) const;
75 
77  T& operator[](const size_t i);
78 
80  const T& back() const;
81 
83  const T& front() const;
84 
86  T mag() const;
87 
89  T mag2() const;
90 
92  T norm() const;
93 
95  T norm2() const;
96 
98  T dot(const Vector& vec) const;
99 
101  Vector cross(const Vector& vec) const;
102 
104  void push_back(const T& element);
105 
107  void push_front(const T& element);
108 
110  void resize(const size_t n);
111 
113  const size_t size() const;
114 
116  const std::vector<T>& std() const;
117 
118  private:
119 
120  std::vector<T> _vec;
121 };
122 
123 #include "Vector-inl.hh"
124 
125 #endif
T mag2() const
Returns the square of the magnitude of the vector.
Definition: Vector-inl.hh:197
T dot(const Vector &vec) const
Returns the dot product with another vecror.
Definition: Vector-inl.hh:207
Vector operator/(const T &factor) const
Overload the vector ratio with a scalar.
Definition: Vector-inl.hh:134
Object that can host any type of data in a vector arrangement.
Definition: Vector.hh:17
T mag() const
Returns the magnitude of the vector.
Definition: Vector-inl.hh:192
const T & front() const
Returns the first element of the vector.
Definition: Vector-inl.hh:242
~Vector()
Destructor.
Definition: Vector-inl.hh:31
void operator+=(const Vector &vec)
Overload the vector sum.
Definition: Vector-inl.hh:65
void push_front(const T &element)
Adds element at the back.
Definition: Vector-inl.hh:262
const T & operator[](const size_t i) const
Overload the subscript operator, return a value.
Definition: Vector-inl.hh:170
std::vector< T > _vec
Underlying std::vector.
Definition: Vector.hh:120
const T & back() const
Returns the last element of the vector.
Definition: Vector-inl.hh:238
const size_t size() const
Returns dimension of the vector.
Definition: Vector-inl.hh:266
Vector cross(const Vector &vec) const
Returns the cross product with another vecror.
Definition: Vector-inl.hh:221
const std::vector< T > & std() const
Returns the vector as an std::vector.
Definition: Vector-inl.hh:270
void resize(const size_t n)
Resizes the vector to chosen dimension.
Definition: Vector-inl.hh:254
Vector operator+(const Vector &vec) const
Overload the vector sum.
Definition: Vector-inl.hh:51
void operator-=(const Vector &vec)
Overload the v substraction.
Definition: Vector-inl.hh:90
Vector()
Default constructor, initilizes an empty vector of dimension 0.
Definition: Vector-inl.hh:1
Vector & operator=(const Vector &vec)
Equality operator.
Definition: Vector-inl.hh:33
T operator*(const Vector &vec) const
Overload the vector product (dot product)
Definition: Vector-inl.hh:101
T norm() const
Returns the norm of the vector.
Definition: Vector-inl.hh:246
Vector operator-() const
Overload the unary minus for vector algebra.
Definition: Vector-inl.hh:41
void operator/=(const T &factor)
Overload the vector ratio with a scalar.
Definition: Vector-inl.hh:148
T norm2() const
Returns the square of the norm of the vector.
Definition: Vector-inl.hh:250
void push_back(const T &element)
Adds element at the back.
Definition: Vector-inl.hh:258
void operator*=(const T &factor)
Overload the vector product with a scalar.
Definition: Vector-inl.hh:126