1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
29 #include <AD/generic/generic.h>
34 int len
; // length of the vector
35 T
* V
; // the vector array
39 // Constructors and destructor
42 Vector() : len(0), V(0) {}
43 Vector(int arity
) : len(arity
), V(new T
[arity
]) {}
47 Vector(const T
[], int arity
);
48 Vector(const Vector
&);
49 ~Vector() { delete [] V
; }
55 Vector
& operator = (const Vector
&);
60 int length() const { return len
; }
61 T
& operator [] (int i
) const { return V
[i
]; }
65 // In place vector operations
68 Vector
& operator += (const T
&);
69 Vector
& operator -= (const T
&);
70 Vector
& operator *= (const T
&);
71 Vector
& operator /= (const T
&);
72 Vector
& operator += (const Vector
&);
73 Vector
& operator -= (const Vector
&);
76 // Arithmetic operators
79 friend Vector
operator + (const Vector
&, const Vector
&);
80 friend Vector
operator + (const Vector
&, const T
&);
81 friend Vector
operator + (const T
&, const Vector
&);
82 friend Vector
operator - (const Vector
&, const Vector
&);
83 friend Vector
operator - (const Vector
&, const T
&);
84 friend Vector
operator - (const T
&, const Vector
&);
85 friend T
operator * (const Vector
&, const Vector
&); // dot product
86 friend Vector
operator * (const Vector
&, const T
&);
87 friend Vector
operator * (const T
&, const Vector
&);
88 friend Vector
operator / (const Vector
&, const T
&);
89 Vector
cross(const Vector
&) const; // cross product
95 friend Bool
operator == (const Vector
&, const Vector
&);
96 friend Bool
operator != (const Vector
& a
, const Vector
& b
)
97 { return ! (a
== b
); }
102 friend ostream
& operator << (ostream
&, const Vector
&);
103 friend istream
& operator >> (istream
&, Vector
&);