-
Notifications
You must be signed in to change notification settings - Fork 5
/
vector.h
106 lines (93 loc) · 3.81 KB
/
vector.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
This is vector.h
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#ifndef VECTOR_H /* guarantee unique inclusion */
#define VECTOR_H
#include "globals.h"
#include "io.h"
#include "list.h"
#include "memory.h"
namespace vector {
using namespace coxeter;
using namespace io;
using namespace list;
using namespace memory;
/* type declarations */
template <class T>
class Vector;
/********* implementation **************************************************/
template <class T>
class Vector
{
private:
List<T> d_list;
public:
/* constructors and destructors */
Vector(){};
Vector(Ulong n):d_list(n) {};
Vector(const Vector<T>& w):d_list(w.list()) {};
Vector(T* const& ptr, const Ulong& n):d_list(ptr,n) {};
Vector(T* const& ptr, const Ulong& n, bool b):d_list(ptr,n,b) {};
~Vector() {};
/* manipulators */
T& operator[] (const Ulong& j); /* inlined */
const Vector<T>& operator= (const Vector<T>& w); /* inlined */
Vector<T>& operator+= (const Vector<T>& w);
Vector<T>& operator-= (const Vector<T>& w);
Vector<T>& operator*= (const T& a);
Ulong& dim(); /* inlined */
T* ptr(); /* inlined */
void reduceDim();
void setDim(const Ulong& n); /* inlined */
void setDimValue(const Ulong& n); /* inlined */
void setVect(const T *source, const Ulong& first, const Ulong& r);
/* inlined */
void setVect(const T *source, const Ulong& r); /* inlined */
void setZero(const Ulong& first, const Ulong& r); /* inlined */
void setZero(const Ulong& r); /* inlined */
void setZero(); /* inlined */
/* accessors */
const T& operator[] (const Ulong& j) const; /* inlined */
const Ulong& dim() const; /* inlined */
const List<T>& list() const; /* inlined */
const T* ptr() const; /* inlined */
};
/* inline implementations */
template<class T> inline T& Vector<T>::operator[] (const Ulong& j)
{return d_list[j];}
template<class T>
inline const Vector<T>& Vector<T>::operator= (const Vector<T>& w)
{d_list.assign(w.list()); return *this;}
template<class T> Ulong& Vector<T>::dim() {return d_list.size();}
template<class T> inline T* Vector<T>::ptr() {return d_list.ptr();}
template<class T> inline void Vector<T>::setDim(const Ulong& n)
{Ulong d = dim(); d_list.setSize(n); if (n>d) setZero(d,n-d);}
template<class T> inline void Vector<T>::setDimValue(const Ulong& n)
{d_list.setSizeValue(n);}
template<class T>
inline void Vector<T>::setVect(const T *source, const Ulong& first,
const Ulong& r)
{d_list.setData(source,first,r);}
template<class T> inline void Vector<T>::setVect(const T *source,
const Ulong& r)
{setVect(source,0,r);}
template<class T> inline void Vector<T>::setZero(const Ulong& first,
const Ulong& r)
{d_list.setZero(first,r);}
template<class T>
inline void Vector<T>::setZero(const Ulong& r) {d_list.setZero(0,r);}
template<class T> inline void Vector<T>::setZero() {d_list.setZero();}
template<class T>
inline const T& Vector<T>::operator[] (const Ulong& j) const
{return d_list[j];}
template<class T>
inline const Ulong& Vector<T>::dim() const {return d_list.size();}
template<class T>
inline const List<T>& Vector<T>::list() const {return d_list;}
template<class T>
inline const T* Vector<T>::ptr() const {return d_list.ptr();}
}
#include "vector.hpp"
#endif