initial
[prop.git] / include / AD / numeric / vector.h
blob1fe5b4484a675fdabbb6759b59c05e3286eec653
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
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
9 // your programs.
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
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef vector_h
26 #define vector_h
28 #include <iostream.h>
29 #include <AD/generic/generic.h>
31 template <class T>
32 class Vector {
34 int len; // length of the vector
35 T * V; // the vector array
37 public:
39 // Constructors and destructor
42 Vector() : len(0), V(0) {}
43 Vector(int arity) : len(arity), V(new T [arity]) {}
44 Vector(T&);
45 Vector(T&, T&);
46 Vector(T&, T&, T&);
47 Vector(const T [], int arity);
48 Vector(const Vector&);
49 ~Vector() { delete [] V; }
52 // Assignment
55 Vector& operator = (const Vector&);
58 // Selectors
60 int length() const { return len; }
61 T& operator [] (int i) const { return V[i]; }
62 T abs() const;
65 // In place vector operations
67 Vector operator - ();
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
92 // Comparisons
95 friend Bool operator == (const Vector&, const Vector&);
96 friend Bool operator != (const Vector& a, const Vector& b)
97 { return ! (a == b); }
100 // Input and output
102 friend ostream& operator << (ostream&, const Vector&);
103 friend istream& operator >> (istream&, Vector&);
106 #endif