1 | // $Id: tvector.cc,v 1.1.1.1 2000-03-02 16:48:24 ansari Exp $
|
---|
2 | // C.Magneville 04/99
|
---|
3 | #include "machdefs.h"
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <iostream.h>
|
---|
7 | #include <complex>
|
---|
8 | #include "pexceptions.h"
|
---|
9 | #include "tvector.h"
|
---|
10 | #include "objfio.h"
|
---|
11 |
|
---|
12 | template <class T>
|
---|
13 | TVector<T>::TVector(uint_4 n)
|
---|
14 | // Constructeur d'un vecteur de "n" elements
|
---|
15 | : TMatrix<T>(n,1)
|
---|
16 | {
|
---|
17 | }
|
---|
18 |
|
---|
19 | template <class T>
|
---|
20 | TVector<T>::TVector(uint_4 n, T* values,Bridge* br)
|
---|
21 | // Construit un vecteur de n elements. On fournit
|
---|
22 | // le tableau des valeurs et eventuellement un Bridge.
|
---|
23 | : TMatrix<T>(n,1,values,br)
|
---|
24 | {
|
---|
25 | }
|
---|
26 |
|
---|
27 | template <class T>
|
---|
28 | TVector<T>::TVector(const TVector<T>& v)
|
---|
29 | // Constructeur par copie (partage si "v" temporaire).
|
---|
30 | : TMatrix<T>(v)
|
---|
31 | {
|
---|
32 | }
|
---|
33 |
|
---|
34 | template <class T>
|
---|
35 | TVector<T>::TVector(const TVector<T>& v,bool share)
|
---|
36 | // Constructeur par copie avec possibilite de forcer le partage ou non.
|
---|
37 | : TMatrix<T>(v,share)
|
---|
38 | {
|
---|
39 | }
|
---|
40 |
|
---|
41 | template <class T>
|
---|
42 | TVector<T>::TVector(const TMatrix<T>& a)
|
---|
43 | // Constructeur a partir d'une matrice "a" de dimension (n,1)
|
---|
44 | : TMatrix<T>(a)
|
---|
45 | {
|
---|
46 | if(a.NCols() != 1)
|
---|
47 | throw(SzMismatchError("TVector(const TMatrix<T>& a) size mismatch, ncol!=1"));
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | ///////////////////////////////////////////////////////////
|
---|
52 | // --------------------------------------------------------
|
---|
53 | // Les objets delegues pour la gestion de persistance
|
---|
54 | // --------------------------------------------------------
|
---|
55 | ///////////////////////////////////////////////////////////
|
---|
56 |
|
---|
57 | template <class T>
|
---|
58 | FIO_TVector<T>::FIO_TVector()
|
---|
59 | {
|
---|
60 | dobj=new TVector<T>;
|
---|
61 | ownobj=true;
|
---|
62 | }
|
---|
63 |
|
---|
64 | template <class T>
|
---|
65 | FIO_TVector<T>::FIO_TVector(string const & filename)
|
---|
66 | {
|
---|
67 | dobj=new TVector<T>;
|
---|
68 | ownobj=true;
|
---|
69 | Read(filename);
|
---|
70 | }
|
---|
71 |
|
---|
72 | template <class T>
|
---|
73 | FIO_TVector<T>::FIO_TVector(const TVector<T> & obj)
|
---|
74 | {
|
---|
75 | dobj = new TVector<T>(obj);
|
---|
76 | ownobj=true;
|
---|
77 | }
|
---|
78 |
|
---|
79 | template <class T>
|
---|
80 | FIO_TVector<T>::FIO_TVector(TVector<T> * obj)
|
---|
81 | {
|
---|
82 | dobj = obj;
|
---|
83 | ownobj=false;
|
---|
84 | }
|
---|
85 |
|
---|
86 | template <class T>
|
---|
87 | FIO_TVector<T>::~FIO_TVector()
|
---|
88 | {
|
---|
89 | if (ownobj && dobj) delete dobj;
|
---|
90 | }
|
---|
91 |
|
---|
92 | template <class T>
|
---|
93 | AnyDataObj* FIO_TVector<T>::DataObj()
|
---|
94 | {
|
---|
95 | return(dobj);
|
---|
96 | }
|
---|
97 |
|
---|
98 | template <class T>
|
---|
99 | void FIO_TVector<T>::SetDataObj(AnyDataObj & o)
|
---|
100 | {
|
---|
101 | TVector<T> * po = dynamic_cast< TVector<T> * >(&o);
|
---|
102 | if (po == NULL) return;
|
---|
103 | if (ownobj && dobj) delete dobj;
|
---|
104 | dobj = po; ownobj = false;
|
---|
105 | }
|
---|
106 |
|
---|
107 | template <class T>
|
---|
108 | void FIO_TVector<T>::ReadSelf(PInPersist& is)
|
---|
109 | {
|
---|
110 | // On lit les 3 premiers uint_4
|
---|
111 | // 0: Numero de version, 1 : NRows=NElts, 2 : NCol=1
|
---|
112 | uint_4 itab[3];
|
---|
113 | is.Get(itab,3);
|
---|
114 | if (dobj == NULL) dobj = new TVector<T>(itab[1]);
|
---|
115 | else dobj->ReSize(itab[1]);
|
---|
116 | // On lit le NDataBlock
|
---|
117 | FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
|
---|
118 | fio_nd.Read(is);
|
---|
119 | }
|
---|
120 |
|
---|
121 | template <class T>
|
---|
122 | void FIO_TVector<T>::WriteSelf(POutPersist& os) const
|
---|
123 | {
|
---|
124 | if (dobj == NULL) return;
|
---|
125 | // On ecrit 3 uint_4 ....
|
---|
126 | // 0: Numero de version, 1 : NRows=NElts, 2 : NCol=1
|
---|
127 | uint_4 itab[3];
|
---|
128 | itab[0] = 1; // Numero de version a 1
|
---|
129 | itab[1] = dobj->NElts();
|
---|
130 | itab[2] = 1;
|
---|
131 | os.Put(itab,3);
|
---|
132 | // On ecrit le NDataBlock
|
---|
133 | FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
|
---|
134 | fio_nd.Write(os);
|
---|
135 | }
|
---|
136 |
|
---|
137 | ///////////////////////////////////////////////////////////////
|
---|
138 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
139 | #pragma define_template TVector<uint_1>
|
---|
140 | #pragma define_template TVector<uint_2>
|
---|
141 | #pragma define_template TVector<int_2>
|
---|
142 | #pragma define_template TVector<int_4>
|
---|
143 | #pragma define_template TVector<int_8>
|
---|
144 | #pragma define_template TVector<uint_4>
|
---|
145 | #pragma define_template TVector<uint_8>
|
---|
146 | #pragma define_template TVector<r_4>
|
---|
147 | #pragma define_template TVector<r_8>
|
---|
148 | #pragma define_template TVector< complex<r_4> >
|
---|
149 | #pragma define_template TVector< complex<r_8> >
|
---|
150 | // Instances des delegues FileIO (PPersist)
|
---|
151 | #pragma define_template FIO_TVector<uint_1>
|
---|
152 | #pragma define_template FIO_TVector<uint_2>
|
---|
153 | #pragma define_template FIO_TVector<int_2>
|
---|
154 | #pragma define_template FIO_TVector<int_4>
|
---|
155 | #pragma define_template FIO_TVector<int_8>
|
---|
156 | #pragma define_template FIO_TVector<uint_4>
|
---|
157 | #pragma define_template FIO_TVector<uint_8>
|
---|
158 | #pragma define_template FIO_TVector<r_8>
|
---|
159 | #pragma define_template FIO_TVector<r_4>
|
---|
160 | #pragma define_template FIO_TVector< complex<r_4> >
|
---|
161 | #pragma define_template FIO_TVector< complex<r_8> >
|
---|
162 | #endif
|
---|
163 |
|
---|
164 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
165 | template class TVector<uint_1>;
|
---|
166 | template class TVector<uint_2>;
|
---|
167 | template class TVector<int_2>;
|
---|
168 | template class TVector<int_4>;
|
---|
169 | template class TVector<int_8>;
|
---|
170 | template class TVector<uint_4>;
|
---|
171 | template class TVector<uint_8>;
|
---|
172 | template class TVector<r_4>;
|
---|
173 | template class TVector<r_8>;
|
---|
174 | template class TVector< complex<r_4> >;
|
---|
175 | template class TVector< complex<r_8> >;
|
---|
176 | // Instances des delegues FileIO (PPersist)
|
---|
177 | template class FIO_TVector<uint_1>;
|
---|
178 | template class FIO_TVector<uint_2>;
|
---|
179 | template class FIO_TVector<int_2>;
|
---|
180 | template class FIO_TVector<int_4>;
|
---|
181 | template class FIO_TVector<int_8>;
|
---|
182 | template class FIO_TVector<uint_4>;
|
---|
183 | template class FIO_TVector<uint_8>;
|
---|
184 | template class FIO_TVector<r_8>;
|
---|
185 | template class FIO_TVector<r_4>;
|
---|
186 | template class FIO_TVector< complex<r_4> >;
|
---|
187 | template class FIO_TVector< complex<r_8> >;
|
---|
188 | #endif
|
---|