Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Vector.h

Go to the documentation of this file.
00001 #ifndef Vector_H
00002 #define Vector_H
00003 
00004 #include "defines.h"
00005 #include <vector>
00006 //#include <iostream>
00007 #include <iosfwd>
00008 
00009 namespace annie
00010 {
00012 /* note: we should NOT use all of the std::vector functions. This opens us a way to define Vector as real[fixed] or dynamically resizable array of reals
00013  * TODO: hide them in the vector's descendant, then..!
00014  * TODO: it's inconvenient to set the size... but we cannot slow down [] ...
00015  * with all respect and understanding, I'd rename Vector to Vector
00016  * 
00017 The time-critical function is [].
00018 * OPT: employ STL's valarray ?
00019 */
00020 //typedef std::vector<real> Vector;
00021 typedef std::vector<real> VFather;
00022 class Vector : protected  VFather   {
00023     public:
00024     #define BLUB_TYPE(t) typedef VFather::t t
00025     BLUB_TYPE(size_type);
00026 
00027     //TODO: purge dependency on iterators.... we can make iterated sucessor if needed. Or can we do it. without overhead ???
00028     BLUB_TYPE(iterator);
00029     BLUB_TYPE(const_iterator);
00031     #undef BLUB_TYPE
00032     Vector()    {}
00034     Vector(uint items, real values) : VFather(items, values) {}
00035     Vector(const Vector &src) : VFather(src)    {}
00036     Vector(size_type size) : VFather(size) {}
00037     Vector &operator = (const Vector &v)    { VFather::operator=(v); return *this; }
00038 
00039     friend  bool operator==(const Vector &o1, const Vector &o2);
00040 
00041     static Vector fromInts(std::vector<int> iv);
00042     static Vector fromInts(uint size, int *data);
00043     
00044     size_type size() const  { return VFather::size(); }
00045     void reserve(size_type s) { VFather::reserve(s); }
00046     void resize(size_type s) { VFather::resize(s); }
00047     iterator begin() { return VFather::begin(); }
00048     const_iterator begin() const    { return VFather::begin(); }
00049     const_iterator end() const  { return VFather::end(); }
00050     real &operator[](uint i)    { return VFather::operator[](i); }
00051     const real &operator[](uint i)  const { return VFather::operator[](i); }
00052     //unwanted?
00053     void clear() { VFather::clear(); }
00054     void push_back(const real & x)  { VFather::push_back(x); }
00055 
00057     real magnitude()    const;
00058     void normalize();
00059     Vector operator- (const Vector &v) const;
00060     Vector operator+ (const Vector &v) const;
00061     Vector &operator+= (const Vector &v);
00062 
00063     Vector subset(uint start=0) const { return subset(start, size() - start); }
00064     Vector subset(uint start, uint size=0) const;
00065 
00067     void setAll(real val);
00068     
00070     void null() { setAll(0.); }
00071 
00076     Vector &append(const Vector &v);    
00077     
00081     void setMore(const Vector &v, uint startIndex=0);
00082 
00084     void clamp(real min, real max);
00085     
00087     Vector &operator*= (const real r);
00088     Vector operator* (const real r) const;
00089     Vector operator+ (const real r) const;
00090     Vector &operator+= (const real r);
00091     
00092     real distance(const Vector &to) const;
00093     const static Vector ZOID;   //0-dimensional constant
00094     
00096     operator std::string() const;
00097 
00098     void toStream(std::ostream &s) const;
00099   protected:
00100     template<class InputIterator>
00101     Vector(InputIterator f,  InputIterator t) : VFather(f, t) {}
00102 };
00103 std::ostream &operator<<(std::ostream &os, const annie::Vector &v);
00104 bool operator==(const Vector &o1, const Vector &o2);
00105 }
00106 #endif //_H

Generated on Fri Jun 18 13:18:11 2004 for Annie by doxygen 1.3.5