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

Last change on this file since 2806 was 2752, checked in by ansari, 20 years ago

1/ Suppression du constructeur de copie avec specification d'organisation memoire (MemoryMapping) pour TMatrix<T> et TVector<T>
2/ Amelioration de l'impression des TArray/TMatrix avec la specification setw(largeur)
3/ Correction petit bug dans la lecture fichiers ASCII argument non transmis ds utilarr.cc

Reza 23 Mai 2005

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