Go to the documentation of this file.00001
00002
00003
00004 #ifndef subvector_hh
00005 #define subvector_hh
00006
00007 #include "vector.hh"
00008 #include "space/spaceSet.hh"
00009 #include "toolbox/set.hh"
00010
00011 namespace concepts {
00012
00013
00014
00025 template<class F>
00026 class SubVector : public Function<F> {
00027 public:
00029 SubVector(Vector<F>& f, const Set<IndexRange>& indices);
00030 SubVector(const Vector<F>& f, const Set<IndexRange>& indices);
00031
00032 virtual ~SubVector() {}
00033
00034 virtual Function<F>& operator=(const Function<F>& fnc);
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 template<class H>
00045 Function<F>& operator=(const Function<H>& fnc);
00046
00048 SubVector<F>& operator=(F c);
00049
00050 virtual F& operator()(uint i) {
00051 conceptsAssert3(i < this->dim_, Assertion(), "i = " << i << ", n = " << this->dim_);
00052 conceptsAssert(v_, Assertion());
00053 return (*v_)(indices_[i]); }
00054 virtual F operator()(uint i) const {
00055 conceptsAssert3(i < this->dim_, Assertion(), "i = " << i << ", n = " << this->dim_);
00056 if (v_)
00057 return (*v_)(indices_[i]);
00058 return (*vc_)(indices_[i]);
00059 }
00060
00062 virtual Function<F>& operator+=(const Function<F>& fnc);
00063 virtual Function<F>& operator+=(F c);
00064
00066 virtual Function<F>& operator-=(const Function<F>& fnc);
00067 virtual Function<F>& operator-=(F c);
00068
00069 virtual Function<F>& operator*=(F sc);
00070
00071 virtual Function<F>& add(const Function<F>& fnc, F sc);
00072
00074 uint n() const { return this->dim_; }
00075 protected:
00076 virtual std::ostream& info(std::ostream& os) const;
00077 private:
00079 Vector<F>* v_;
00081 const Vector<F>* vc_;
00083 const Set<IndexRange> indices_;
00084 };
00085
00086 template<class F>
00087 template<class H>
00088 Function<F>& SubVector<F>::operator=(const Function<H>& fnc) {
00089 conceptsAssert(v_, Assertion());
00090 uint j = 0;
00091 for (Set<IndexRange>::index_iterator i = indices_.index_begin();
00092 i != indices_.index_end(); )
00093 (*v_)(i++) = fnc(j++);
00094 return *this;
00095 }
00096
00097 }
00098
00099 #endif // subvector_hh