1 : |
agomez |
1 |
#ifndef doublevector_h
|
2 : |
|
|
#define doublevector_h
|
3 : |
|
|
|
4 : |
|
|
#include "mathfunc.h" |
5 : |
|
|
#include "gadget.h" |
6 : |
|
|
|
7 : |
|
|
/**
|
8 : |
|
|
* \class DoubleVector
|
9 : |
|
|
* \brief This class implements a dynamic vector of double values
|
10 : |
|
|
*/
|
11 : |
|
|
class DoubleVector {
|
12 : |
|
|
public:
|
13 : |
|
|
/**
|
14 : |
|
|
* \brief This is the default DoubleVector constructor
|
15 : |
|
|
*/
|
16 : |
|
|
DoubleVector() { size = 0; v = 0; };
|
17 : |
|
|
/**
|
18 : |
|
|
* \brief This is the DoubleVector constructor for a specified size
|
19 : |
|
|
* \param sz is the size of the vector to be created
|
20 : |
|
|
* \note The elements of the vector will all be created, and set to zero
|
21 : |
|
|
*/
|
22 : |
|
|
DoubleVector(int sz);
|
23 : |
|
|
/**
|
24 : |
|
|
* \brief This is the DoubleVector constructor for a specified size with an initial value
|
25 : |
|
|
* \param sz is the size of the vector to be created
|
26 : |
|
|
* \param initial is the initial value for all the entries of the vector
|
27 : |
|
|
*/
|
28 : |
|
|
DoubleVector(int sz, double initial);
|
29 : |
|
|
/**
|
30 : |
|
|
* \brief This is the DoubleVector constructor that creates a copy of an existing DoubleVector
|
31 : |
|
|
* \param initial is the DoubleVector to copy
|
32 : |
|
|
*/
|
33 : |
|
|
DoubleVector(const DoubleVector& initial);
|
34 : |
|
|
/**
|
35 : |
|
|
* \brief This is the DoubleVector destructor
|
36 : |
|
|
* \note This will free all the memory allocated to all the elements of the vector
|
37 : |
|
|
*/
|
38 : |
|
|
~DoubleVector();
|
39 : |
ulcessvp |
12 |
/**
|
40 : |
|
|
* \brief This is method initialize the DoubleVector for a specified size with an initial value
|
41 : |
|
|
* \param sz is the size of the vector to be created
|
42 : |
|
|
* \param initial is the initial value for all the entries of the vector
|
43 : |
|
|
*/
|
44 : |
ulcessvp |
11 |
void Initialize(int sz, double initial);
|
45 : |
agomez |
1 |
/**
|
46 : |
|
|
* \brief This will add new entries to the vector
|
47 : |
|
|
* \param addsize is the number of new entries to the vector
|
48 : |
|
|
* \param value is the value that will be entered for the new entries
|
49 : |
|
|
*/
|
50 : |
|
|
void resize(int addsize, double value);
|
51 : |
|
|
/**
|
52 : |
|
|
* \brief This will delete an entry from the vector
|
53 : |
|
|
* \param pos is the element of the vector to be deleted
|
54 : |
|
|
* \note This will free the memory allocated to the deleted element of the vector
|
55 : |
|
|
*/
|
56 : |
|
|
void Delete(int pos);
|
57 : |
|
|
/**
|
58 : |
|
|
* \brief This will return the size of the vector
|
59 : |
|
|
* \return the size of the vector
|
60 : |
|
|
*/
|
61 : |
|
|
int Size() const { return size; };
|
62 : |
|
|
/**
|
63 : |
|
|
* \brief This will return the value of an element of the vector
|
64 : |
|
|
* \param pos is the element of the vector to be returned
|
65 : |
|
|
* \return the value of the specified element
|
66 : |
|
|
*/
|
67 : |
|
|
double& operator [] (int pos) { return v[pos]; };
|
68 : |
|
|
/**
|
69 : |
|
|
* \brief This will return the value of an element of the vector
|
70 : |
|
|
* \param pos is the element of the vector to be returned
|
71 : |
|
|
* \return the value of the specified element
|
72 : |
|
|
*/
|
73 : |
|
|
const double& operator [] (int pos) const { return v[pos]; };
|
74 : |
|
|
/**
|
75 : |
|
|
* \brief This will reset the vector
|
76 : |
|
|
* \note This will delete every entry from the vector and set the size to zero
|
77 : |
|
|
*/
|
78 : |
|
|
void Reset();
|
79 : |
|
|
/**
|
80 : |
|
|
* \brief This function will set all of the entries of the vector to zero
|
81 : |
|
|
*/
|
82 : |
|
|
void setToZero();
|
83 : |
|
|
/**
|
84 : |
|
|
* \brief This operator will calculate the dot product of the vector and an existing DoubleVector
|
85 : |
|
|
* \param d is the DoubleVector to copy
|
86 : |
|
|
* \return the dot product of the two vectors
|
87 : |
|
|
*/
|
88 : |
|
|
double operator * (const DoubleVector& d) const;
|
89 : |
|
|
/**
|
90 : |
|
|
* \brief This operator will set the vector equal to an existing DoubleVector
|
91 : |
|
|
* \param d is the DoubleVector to copy
|
92 : |
|
|
*/
|
93 : |
|
|
DoubleVector& operator = (const DoubleVector& d);
|
94 : |
|
|
protected:
|
95 : |
|
|
/**
|
96 : |
|
|
* \brief This is the vector of double values
|
97 : |
|
|
*/
|
98 : |
|
|
double* v;
|
99 : |
|
|
/**
|
100 : |
|
|
* \brief This is the size of the vector
|
101 : |
|
|
*/
|
102 : |
|
|
int size;
|
103 : |
|
|
};
|
104 : |
|
|
|
105 : |
|
|
#endif
|