#ifndef _SCTL_VECTOR_HPP_ #define _SCTL_VECTOR_HPP_ #include SCTL_INCLUDE(mem_mgr.hpp) #include SCTL_INCLUDE(common.hpp) #include #include #include // TODO: Implement dynamic-vector which can be created with variable size from a stack memory pool namespace SCTL_NAMESPACE { template class ConstVector { public: typedef ValueType value_type; typedef ValueType& reference; typedef const ValueType& const_reference; typedef Iterator iterator; typedef ConstIterator const_iterator; typedef Long difference_type; typedef Long size_type; ConstVector(); ConstVector(Long dim_, ConstIterator data_ = NullIterator(), bool own_data_ = true); ConstVector(const ConstVector& V, bool own_data_ = true); ConstVector(const std::vector& V, bool own_data_ = true); ~ConstVector(); void Swap(ConstVector& v1); void ReInit(Long dim_, ConstIterator data_ = NullIterator(), bool own_data_ = true); void Write(const char* fname) const; Long Dim() const; ConstIterator begin() const; ConstIterator end() const; // Element access const ValueType& operator[](Long j) const; // ConstVector-ConstVector operations Vector operator+(const ConstVector& V) const; Vector operator-(const ConstVector& V) const; Vector operator*(const ConstVector& V) const; Vector operator/(const ConstVector& V) const; // ConstVector-Scalar operations Vector operator+(ValueType s) const; Vector operator-(ValueType s) const; Vector operator*(ValueType s) const; Vector operator/(ValueType s) const; protected: void Init(Long dim_, Iterator data_ = NullIterator(), bool own_data_ = true); Long dim; Long capacity; Iterator data_ptr; bool own_data; }; template class Vector : public ConstVector { public: typedef ValueType value_type; typedef ValueType& reference; typedef const ValueType& const_reference; typedef Iterator iterator; typedef ConstIterator const_iterator; typedef Long difference_type; typedef Long size_type; Vector(); Vector(Long dim_, Iterator data_ = NullIterator(), bool own_data_ = true); Vector(const Vector& V); Vector(const std::vector& V); //~Vector(); void Swap(Vector& v1); void ReInit(Long dim_, Iterator data_ = NullIterator(), bool own_data_ = true); void Read(const char* fname); void SetZero(); ConstIterator begin() const { return ConstVector::begin(); } Iterator begin(); ConstIterator end() const { return ConstVector::end(); } Iterator end(); void PushBack(const ValueType& x); // Element access const ValueType& operator[](Long j) const { return this->ConstVector::operator[](j); } ValueType& operator[](Long j); // Vector-Vector operations Vector& operator=(const std::vector& V); Vector& operator=(const Vector& V); Vector& operator+=(const Vector& V); Vector& operator-=(const Vector& V); Vector& operator*=(const Vector& V); Vector& operator/=(const Vector& V); // Vector-Scalar operations Vector& operator=(ValueType s); Vector& operator+=(ValueType s); Vector& operator-=(ValueType s); Vector& operator*=(ValueType s); Vector& operator/=(ValueType s); }; template ConstVector operator+(ValueType s, const ConstVector& V); template ConstVector operator-(ValueType s, const ConstVector& V); template ConstVector operator*(ValueType s, const ConstVector& V); template ConstVector operator/(ValueType s, const ConstVector& V); template std::ostream& operator<<(std::ostream& output, const ConstVector& V); } // end namespace #include SCTL_INCLUDE(vector.txx) #endif //_SCTL_VECTOR_HPP_