source: Sophya/trunk/SophyaLib/BaseTools/objfio.h@ 273

Last change on this file since 273 was 269, checked in by ansari, 26 years ago

Persist<NDataBlock> Reza 27/04/99

File size: 3.4 KB
RevLine 
[269]1// This may look like C code, but it is really -*- C++ -*-
2// Classe de gestion des I/O fichiers des objets
3// R.Ansari 04/99
4// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
5
6#ifndef OBJFILEIO_H_SEEN
7#define OBJFILEIO_H_SEEN
8
9#include "machdefs.h"
10#include "anydataobj.h"
11#include "ppersist.h"
12
13namespace PlanckDPC {
14
15 /*
16// Pour gerer les Persist I/O de tableaux numerique templates
17template <class T>
18void PIOSReadArray(PInPersist & is, T* arr, size_t n);
19template <class T>
20void PIOSWriteArray(POutPersist & os, T const * arr, size_t n);
21 */
22
23
24template <class T>
25class ObjFileIO : public PPersist {
26
27public :
28 ObjFileIO() { dobj=new T; }
29 ObjFileIO(string const & filename) { dobj=new T; Read(filename); }
30 ObjFileIO(const T & obj) { dobj = new T(obj); }
31 ObjFileIO(const T * obj) { dobj = new T(*obj); }
32 virtual ~ObjFileIO() { if (dobj) delete dobj; }
33
34 virtual AnyDataObj* DataObj() { return(dobj); }
35 inline operator T() { return(*dobj); }
36
37protected :
38 virtual void ReadSelf(PInPersist&);
39 virtual void WriteSelf(POutPersist&) const;
40
41 T * dobj;
42};
43
44// Fonctions d'ecriture de tableaux numeriques
45inline
46void PIOSReadArray(PInPersist & is, uint_1 * arr, size_t n)
47{
48is.GetBytes(arr, n);
49}
50
51inline
52void PIOSReadArray(PInPersist & is, uint_2 * arr, size_t n)
53{
54is.Get(arr, n);
55}
56
57inline
58void PIOSReadArray(PInPersist & is, int_2 * arr, size_t n)
59{
60is.Get(arr, n);
61}
62
63inline
64void PIOSReadArray(PInPersist & is, uint_4 * arr, size_t n)
65{
66is.Get(arr, n);
67}
68
69inline
70void PIOSReadArray(PInPersist & is, int_4 * arr, size_t n)
71{
72is.Get(arr, n);
73}
74
75inline
76void PIOSReadArray(PInPersist & is, uint_8 * arr, size_t n)
77{
78is.Get(arr, n);
79}
80
81inline
82void PIOSReadArray(PInPersist & is, int_8 * arr, size_t n)
83{
84is.Get(arr, n);
85}
86
87inline
88void PIOSReadArray(PInPersist & is, r_4 * arr, size_t n)
89{
90is.Get(arr, n);
91}
92
93inline
94void PIOSReadArray(PInPersist & is, r_8 * arr, size_t n)
95{
96is.Get(arr, n);
97}
98
99inline
100void PIOSReadArray(PInPersist & is, complex<float> * arr, size_t n)
101{
102r_4 * pr = (r_4 *)arr;
103is.Get(pr, n*2);
104}
105
106inline
107void PIOSReadArray(PInPersist & is, complex<double> * arr, size_t n)
108{
109r_8 * pr = (r_8 *)arr;
110is.Get(pr, n*2);
111}
112
113// Fonctions d ecriture de tableaux de nombre
114inline
115void PIOSWriteArray(POutPersist & os, uint_1 const * arr, size_t n)
116{
117os.PutBytes(arr, n);
118}
119
120inline
121void PIOSWriteArray(POutPersist & os, uint_2 const * arr, size_t n)
122{
123os.Put(arr, n);
124}
125
126inline
127void PIOSWriteArray(POutPersist & os, int_2 const * arr, size_t n)
128{
129os.Put(arr, n);
130}
131
132inline
133void PIOSWriteArray(POutPersist & os, uint_4 const * arr, size_t n)
134{
135os.Put(arr, n);
136}
137
138inline
139void PIOSWriteArray(POutPersist & os, int_4 const * arr, size_t n)
140{
141os.Put(arr, n);
142}
143
144inline
145void PIOSWriteArray(POutPersist & os, uint_8 const * arr, size_t n)
146{
147os.Put(arr, n);
148}
149
150inline
151void PIOSWriteArray(POutPersist & os, int_8 const * arr, size_t n)
152{
153os.Put(arr, n);
154}
155
156inline
157void PIOSWriteArray(POutPersist & os, r_4 const * arr, size_t n)
158{
159os.Put(arr, n);
160}
161
162inline
163void PIOSWriteArray(POutPersist & os, r_8 const * arr, size_t n)
164{
165os.Put(arr, n);
166}
167
168inline
169void PIOSWriteArray(POutPersist & os, complex<float> const * arr, size_t n)
170{
171r_4 const * pr = (r_4 const *)arr;
172os.Put(pr, n*2);
173}
174
175inline
176void PIOSWriteArray(POutPersist & os, complex<double> const * arr, size_t n)
177{
178r_8 const * pr = (r_8 const *)arr;
179os.Put(pr, n*2);
180}
181
182} // Fin namespace
183
184#endif
Note: See TracBrowser for help on using the repository browser.