-
Notifications
You must be signed in to change notification settings - Fork 0
/
NegVector.h
84 lines (72 loc) · 1.46 KB
/
NegVector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef NEGVECTOR_H_
#define NEGVECTOR_H_
#include <vector>
#include <iostream>
template <typename T>
class NegVector : public std::vector<T>
{
/**
* @class NegVector
* @brief A Vector class that allows negative indices for Alm values.
*/
private:
int mBegin; // Largest value that can be indexed.
public:
NegVector();
virtual ~NegVector();
T &operator[](int index);
T &operator[](int index) const;
void resize(int n);
int size();
int size(int n) {
resize(n);
return size();
}
void clear();
};
// Constructor, set empty vector.
template <typename T>
NegVector<T>::NegVector()
:
mBegin(-1)
{
}
// Destructor
template <typename T>
NegVector<T>::~NegVector()
{
}
// Resize so vector goes from -n,..,0,..,n
template <typename T>
void NegVector<T>::resize(int n)
{
mBegin = n;
std::vector<T>::resize(2*mBegin+1);
}
// Return the size (not the real one though)
// returns -1 if vector is not initialised
template <typename T>
int NegVector<T>::size()
{
return mBegin;
}
// clear everything
template <typename T>
void NegVector<T>::clear()
{
mBegin = -1;
std::vector<T>::clear();
}
// Return the element
template <typename T>
T &NegVector<T>::operator [](int index)
{
return std::vector<T>::operator[](index+mBegin);
}
// Return the element
template <typename T>
T &NegVector<T>::operator [](int index) const
{
return std::vector<T>::operator[](index+mBegin);
}
#endif /*NEGVECTOR_H_*/