source: Sophya/trunk/SophyaLib/TArray/tvector.h@ 2745

Last change on this file since 2745 was 2719, checked in by cmv, 20 years ago

remplissage STL vector / TVector cmv 13/05/05

File size: 4.5 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// C.Magneville 05/99
3#ifndef TVector_SEEN
4#define TVector_SEEN
5
6#include "tmatrix.h"
7
8namespace SOPHYA {
9
10//! Class of vector (line or column)
11template <class T>
12class TVector : public TMatrix<T> {
13public:
14 // Creation / destruction
15 TVector();
16 TVector(sa_size_t n, short lcv=AutoVectorType, short mm=AutoMemoryMapping, bool fzero=true);
17 TVector(const TVector<T>& v);
18 TVector(const TVector<T>& v, bool share);
19 TVector(const TArray<T>& a);
20 TVector(const TArray<T>& a, bool share, short lcv=AutoVectorType, short mm=AutoMemoryMapping);
21 TVector(const BaseArray& a);
22 TVector(const vector<T>& v, short lcv=AutoVectorType);
23
24 virtual ~TVector();
25
26 //! Operator =
27 /*! \warning Datas are copied (cloned) from \b a.
28 \sa NDataBlock::operator=(const NDataBlock<T>&) */
29 inline TVector<T>& operator = (const TVector<T>& a)
30 { Set(a); return(*this); }
31 //! Operator = between a vector and a matrix
32 inline TVector<T>& operator = (const TMatrix<T>& a)
33 { Set(a); return(*this); }
34 //! Operator = between a vector and an array
35 inline TVector<T>& operator = (const TArray<T>& a)
36 { Set(a); return(*this); }
37 //! Operator = between Vectors with different types
38 inline TVector<T>& operator = (const BaseArray& a)
39 { SetBA(a); return(*this); }
40
41 // Gestion taille/Remplissage
42 void ReSize(sa_size_t n, short lcv=SameVectorType, bool fzero=true);
43 //! a synonym (alias) for method ReSize(sa_size_t, short)
44 inline void SetSize(sa_size_t n, short lcv=SameVectorType, bool fzero=true)
45 { ReSize(n, lcv, fzero); }
46 void Realloc(sa_size_t n, short lcv=SameVectorType, bool force=false);
47
48 // Remplissage from/to a STL vector
49 sa_size_t FillFr(const vector<T>& v,bool noresize=false);
50 sa_size_t FillTo(vector<T>& v,bool addtoend=false);
51
52 // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
53 TVector<T> SubVector(Range relt) const ;
54 //! Extract a vector define by Range \b relt
55 inline TVector<T> operator () (Range relt) const
56 { return SubVector(relt); }
57
58 // Informations pointeur/data
59 //! return the number of elements
60 inline sa_size_t NElts() const {return Size(); }
61
62 // Inline element acces methods
63 inline T const& operator()(sa_size_t n) const;
64 inline T& operator()(sa_size_t n);
65
66 // Operateur d'affectation
67 //! Fill the vector with Sequence \b seq
68 inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
69
70 // Operations diverses avec une constante
71 //! Set vector elements to constant value \b x
72 inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
73 //! Add constant value \b x to vector elements
74 inline TVector<T>& operator += (T x) { AddCst(x,*this); return(*this); }
75 //! Substract constant value \b x to vector elements
76 inline TVector<T>& operator -= (T x) { SubCst(x,*this); return(*this); }
77 //! Multiply vector elements by constant value \b x
78 inline TVector<T>& operator *= (T x) { MulCst(x,*this); return(*this); }
79 //! Divide vector elements by constant value \b x
80 inline TVector<T>& operator /= (T x) { DivCst(x,*this); return(*this); }
81
82 // operations avec matrices
83 //! += : add a vector in place
84 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a,*this); return(*this); }
85 //! += : substract a vector in place
86 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a,*this); return(*this); }
87
88 virtual string InfoString() const;
89
90};
91
92// ---- inline acces methods ------
93
94//! Return the value of element \b n
95template <class T>
96inline T const& TVector<T>::operator()(sa_size_t n) const
97{
98#ifdef SO_BOUNDCHECKING
99 if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
100 else CheckBound(0, n, 0, 0, 0, 4);
101#endif
102 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
103}
104
105//! Return the value of element \b n
106template <class T>
107inline T & TVector<T>::operator()(sa_size_t n)
108{
109#ifdef SO_BOUNDCHECKING
110 if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
111 else CheckBound(0, n, 0, 0, 0, 4);
112#endif
113 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
114}
115
116// Typedef pour simplifier et compatibilite Peida
117/*! \ingroup TArray
118 \typedef Vector
119 \brief To simplified TVector<r_8> writing
120*/
121typedef TVector<r_8> Vector;
122
123} // Fin du namespace
124
125#endif
Note: See TracBrowser for help on using the repository browser.