vector.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef _SCTL_VECTOR_HPP_
  2. #define _SCTL_VECTOR_HPP_
  3. #include SCTL_INCLUDE(common.hpp)
  4. #include <vector>
  5. #include <cstdlib>
  6. #include <cstdint>
  7. namespace SCTL_NAMESPACE {
  8. template <class ValueType> class Vector {
  9. public:
  10. Vector();
  11. Vector(Long dim_, Iterator<ValueType> data_ = Iterator<ValueType>(NULL), bool own_data_ = true);
  12. Vector(const Vector& V);
  13. Vector(const std::vector<ValueType>& V);
  14. ~Vector();
  15. void Swap(Vector<ValueType>& v1);
  16. void ReInit(Long dim_, Iterator<ValueType> data_ = NULL, bool own_data_ = true);
  17. void Write(const char* fname) const;
  18. void Read(const char* fname);
  19. Long Dim() const;
  20. Long Capacity() const;
  21. void SetZero();
  22. Iterator<ValueType> begin();
  23. ConstIterator<ValueType> begin() const;
  24. Iterator<ValueType> end();
  25. ConstIterator<ValueType> end() const;
  26. void PushBack(const ValueType& x);
  27. // Element access
  28. ValueType& operator[](Long j);
  29. const ValueType& operator[](Long j) const;
  30. // Vector-Vector operations
  31. Vector& operator=(const std::vector<ValueType>& V);
  32. Vector& operator=(const Vector& V);
  33. Vector& operator+=(const Vector& V);
  34. Vector& operator-=(const Vector& V);
  35. Vector& operator*=(const Vector& V);
  36. Vector& operator/=(const Vector& V);
  37. Vector operator+(const Vector& V) const;
  38. Vector operator-(const Vector& V) const;
  39. Vector operator*(const Vector& V) const;
  40. Vector operator/(const Vector& V) const;
  41. // Vector-Scalar operations
  42. Vector& operator=(ValueType s);
  43. Vector& operator+=(ValueType s);
  44. Vector& operator-=(ValueType s);
  45. Vector& operator*=(ValueType s);
  46. Vector& operator/=(ValueType s);
  47. Vector operator+(ValueType s) const;
  48. Vector operator-(ValueType s) const;
  49. Vector operator*(ValueType s) const;
  50. Vector operator/(ValueType s) const;
  51. private:
  52. Long dim;
  53. Long capacity;
  54. Iterator<ValueType> data_ptr;
  55. bool own_data;
  56. };
  57. template <class ValueType> Vector<ValueType> operator+(ValueType s, const Vector<ValueType>& V);
  58. template <class ValueType> Vector<ValueType> operator-(ValueType s, const Vector<ValueType>& V);
  59. template <class ValueType> Vector<ValueType> operator*(ValueType s, const Vector<ValueType>& V);
  60. template <class ValueType> Vector<ValueType> operator/(ValueType s, const Vector<ValueType>& V);
  61. template <class ValueType> std::ostream& operator<<(std::ostream& output, const Vector<ValueType>& V);
  62. } // end namespace
  63. #include SCTL_INCLUDE(vector.txx)
  64. #endif //_SCTL_VECTOR_HPP_