| [ce3d2b] | 1 | /* | 
|---|
|  | 2 | * VectorContent.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Jul 2, 2010 | 
|---|
|  | 5 | *      Author: crueger | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef VECTORCONTENT_HPP_ | 
|---|
|  | 9 | #define VECTORCONTENT_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | /** | 
|---|
|  | 12 | * !file | 
|---|
|  | 13 | * The way GSL works does not allow for forward definitions of the structures. | 
|---|
|  | 14 | * Because of this the pointer to the gsl_vector struct is wrapped inside another | 
|---|
| [9d5ddf] | 15 | * (dumb) object that allows for forward definitions. | 
|---|
| [bc8a41] | 16 | * | 
|---|
|  | 17 | * DO NOT USE OUTSIDE OF VECTOR UNLESS YOU ABSOLUTELY HAVE TO AND KNOW WHAT YOU ARE DOING. | 
|---|
| [ce3d2b] | 18 | */ | 
|---|
|  | 19 |  | 
|---|
| [bbf1bd] | 20 | #include <iosfwd> | 
|---|
|  | 21 |  | 
|---|
| [ce3d2b] | 22 | #include <gsl/gsl_vector.h> | 
|---|
|  | 23 |  | 
|---|
| [bbf1bd] | 24 | class Vector; | 
|---|
|  | 25 |  | 
|---|
|  | 26 | /** Dummy structure to create a unique signature. | 
|---|
|  | 27 | * | 
|---|
|  | 28 | */ | 
|---|
| [8e9ce1] | 29 | struct VectorBaseCase{}; | 
|---|
| [8e17d6] | 30 |  | 
|---|
| [bbf1bd] | 31 | class VectorContent{ | 
|---|
|  | 32 | friend std::ostream & operator<< (std::ostream& ost, const VectorContent &m); | 
|---|
|  | 33 | friend VectorContent const operator*(const VectorContent& a, const double m); | 
|---|
|  | 34 | friend VectorContent const operator*(const double m, const VectorContent& a); | 
|---|
|  | 35 | friend VectorContent const operator+(const VectorContent& a, const VectorContent& b); | 
|---|
|  | 36 | friend VectorContent const operator-(const VectorContent& a, const VectorContent& b); | 
|---|
| [8e17d6] | 37 |  | 
|---|
| [bbf1bd] | 38 | public: | 
|---|
|  | 39 | explicit VectorContent(size_t _dim); | 
|---|
| [8e9ce1] | 40 | VectorContent(VectorBaseCase); | 
|---|
| [bbf1bd] | 41 | VectorContent(const VectorContent * const src); | 
|---|
|  | 42 | VectorContent(const VectorContent & src); | 
|---|
|  | 43 | virtual ~VectorContent(); | 
|---|
|  | 44 |  | 
|---|
|  | 45 | // Accessing | 
|---|
|  | 46 | double &at(size_t m); | 
|---|
|  | 47 | const double at(size_t m) const; | 
|---|
|  | 48 | double & operator[](size_t i); | 
|---|
|  | 49 | const double operator[](size_t i) const; | 
|---|
|  | 50 | double *Pointer(size_t m) const; | 
|---|
|  | 51 | const double *const_Pointer(size_t m) const; | 
|---|
|  | 52 |  | 
|---|
|  | 53 | // Assignment operator | 
|---|
|  | 54 | VectorContent &operator=(const VectorContent& src); | 
|---|
|  | 55 |  | 
|---|
|  | 56 | // Initializing | 
|---|
|  | 57 | void setFromDoubleArray(double * x); | 
|---|
|  | 58 | void setFromVector(Vector &v); | 
|---|
|  | 59 | void setValue(double x); | 
|---|
|  | 60 | void setZero(); | 
|---|
|  | 61 | int setBasis(size_t m); | 
|---|
|  | 62 |  | 
|---|
|  | 63 | // Exchanging elements | 
|---|
|  | 64 | int SwapElements(size_t i, size_t j); | 
|---|
|  | 65 | int Reverse(); | 
|---|
|  | 66 |  | 
|---|
|  | 67 | // checking state | 
|---|
|  | 68 | bool IsZero() const; | 
|---|
|  | 69 | bool IsOne() const; | 
|---|
|  | 70 |  | 
|---|
|  | 71 | // properties | 
|---|
|  | 72 | bool IsNormalTo(const Vector &normal) const; | 
|---|
|  | 73 | bool IsEqualTo(const Vector &a) const; | 
|---|
|  | 74 |  | 
|---|
|  | 75 | // properties relative to another VectorContent | 
|---|
|  | 76 | double DistanceSquared(const VectorContent &y) const; | 
|---|
|  | 77 | double ScalarProduct(const VectorContent &y) const; | 
|---|
|  | 78 | double Angle(const VectorContent &y) const; | 
|---|
|  | 79 |  | 
|---|
|  | 80 | // operators | 
|---|
|  | 81 | bool operator==(const VectorContent& b) const; | 
|---|
|  | 82 | const VectorContent& operator+=(const VectorContent& b); | 
|---|
|  | 83 | const VectorContent& operator-=(const VectorContent& b); | 
|---|
|  | 84 | const VectorContent& operator*=(const double m); | 
|---|
|  | 85 |  | 
|---|
|  | 86 | size_t dimension; | 
|---|
| [ce3d2b] | 87 | gsl_vector *content; | 
|---|
| [bbf1bd] | 88 | private: | 
|---|
| [ce3d2b] | 89 | }; | 
|---|
|  | 90 |  | 
|---|
| [bbf1bd] | 91 | std::ostream & operator << (std::ostream& ost, const VectorContent &m); | 
|---|
|  | 92 | VectorContent const operator*(const VectorContent& a, const double m); | 
|---|
|  | 93 | VectorContent const operator*(const double m, const VectorContent& a); | 
|---|
|  | 94 | VectorContent const operator+(const VectorContent& a, const VectorContent& b); | 
|---|
|  | 95 | VectorContent const operator-(const VectorContent& a, const VectorContent& b); | 
|---|
|  | 96 |  | 
|---|
|  | 97 | /** Vector view. | 
|---|
|  | 98 | * Extension of VectorContent to contain not a gsl_vector but only a view on a | 
|---|
|  | 99 | * gsl_vector (or row/column in a gsl_matrix). | 
|---|
|  | 100 | * | 
|---|
| [8e9ce1] | 101 | * We need the above VectorBaseCase here: | 
|---|
| [bbf1bd] | 102 | * content, i.e. the gsl_vector, must not be allocated, as it is just a view | 
|---|
| [8e9ce1] | 103 | * with an internal gsl_vector_view. Hence, VectorBaseCase is just dummy class | 
|---|
|  | 104 | * to give the constructor a unique signature. | 
|---|
| [bbf1bd] | 105 | */ | 
|---|
|  | 106 | struct VectorViewContent : public VectorContent | 
|---|
|  | 107 | { | 
|---|
| [8e17d6] | 108 | VectorViewContent(gsl_vector_view _view) : | 
|---|
| [8e9ce1] | 109 | VectorContent(VectorBaseCase()), | 
|---|
| [8e17d6] | 110 | view(_view) | 
|---|
|  | 111 | { | 
|---|
| [bbf1bd] | 112 | dimension = _view.vector.size; | 
|---|
| [8e17d6] | 113 | content=&view.vector; | 
|---|
|  | 114 | } | 
|---|
| [bbf1bd] | 115 | ~VectorViewContent(){ | 
|---|
| [3dbb9d] | 116 | content=0; | 
|---|
|  | 117 | } | 
|---|
| [8e17d6] | 118 | gsl_vector_view view; | 
|---|
|  | 119 | }; | 
|---|
|  | 120 |  | 
|---|
| [ce3d2b] | 121 | #endif /* VECTORCONTENT_HPP_ */ | 
|---|