Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
iorheobase.h
Go to the documentation of this file.
1# ifndef _IORHEOBASE_H
2# define _IORHEOBASE_H
23
24#include "rheolef/compiler.h"
25namespace rheolef {
26
27// --------------------------------------------------------------
28// header macro definitions, for code reduction purpose
29// --------------------------------------------------------------
30
31#define iorheobase_def_boolean_accessor_macro(ioclass,stream,name) \
32 static bool get##name (stream& s) \
33 { \
34 return ioclass::flags(s) [name]; \
35 }
36#define iorheobase_manip_boolean_accessor_macro(ioclass,stream,name) \
37 inline stream& name (stream& s) \
38 { \
39 ioclass::setf (s, ioclass::name); \
40 return s; \
41 } \
42 inline stream& no##name (stream& s) \
43 { \
44 ioclass::unsetf (s, ioclass::name); \
45 return s; \
46 }
47 // ------------------------------------------------------
48#define iorheobase_def_member_macro(ioclass,stream,name,groupe) \
49 iorheobase_def_boolean_accessor_macro(ioclass,stream,name)
50
51#define iorheobase_manip_member_macro(ioclass,stream,name,groupe) \
52 inline stream& name (stream& s) \
53 { \
54 ioclass::setf(s, ioclass::name, ioclass::groupe##_field); \
55 return s; \
56 }
57 // ------------------------------------------------------
58#define iorheobase_def_scalar_macro(ioclass,t, a) \
59 protected: \
60 t a ## _; \
61 const t& a () const; \
62 void a (const t& x); \
63 public: \
64 static const t& get##a (std::ios& s); \
65 static std::ios& set##a (std::ios& s, const t& x);
66
67#define iorheobase_manip_scalar_macro(ioclass,t, a, io) \
68 inline io##rheomanip1<t> set##a (const t& x) \
69 { \
70 return io##rheomanip1<t>(&(ioclass::set##a), x); \
71 }
72
73// --------------------------------------------------------------
74// body macro definitions, for code reduction purpose
75// --------------------------------------------------------------
76# define iorheobase_io_scalar_body_macro(ioclass,t,a) \
77const t& \
78ioclass::a () const \
79{ \
80 return a##_; \
81} \
82void \
83ioclass::a (const t& x) \
84{ \
85 a##_ = x; \
86} \
87const t& \
88ioclass::get##a (std::ios& s) \
89{ \
90 return (ioclass::get_pointer(s) -> a()); \
91} \
92std::ios& \
93ioclass::set##a (std::ios& s, const t& x) \
94{ \
95 (ioclass::get_pointer(s) -> a(x)); \
96 return s; \
97}
98// --------------------------------------------------------------
99// io manipulators
100// --------------------------------------------------------------
101template <class T>
103 irheomanip1 (std::ios& (*ff)(std::ios&, const T&), const T& ii)
104 : f(ff), i(ii) {}
105// data:
106 std::ios& (*f) (std::ios&, const T&);
108};
109template <class T>
110inline
111std::istream&
112operator>> (std::istream& is, const irheomanip1<T>& m)
113{
114 m.f (is, m.i);
115 return is;
116}
117template <class T>
119 orheomanip1 (std::ios& (*ff)(std::ios&, const T&), const T& ii)
120 : f(ff), i(ii) {}
121// data:
122 std::ios& (*f) (std::ios&, const T&);
124};
125template <class T>
126inline
127std::ostream&
128operator<< (std::ostream& os, const orheomanip1<T>& m)
129{
130 m.f (os, m.i);
131 return os;
132}
133template <class T>
135 iorheomanip1 (std::ios& (*ff)(std::ios&, const T&), const T& ii)
136 : f(ff), i(ii) {}
137// data:
138 std::ios& (*f) (std::ios&, const T&);
140};
141template <class T>
142inline
143std::istream&
144operator>> (std::istream& is, const iorheomanip1<T>& m)
145{
146 m.f (is, m.i);
147 return is;
148}
149template <class T>
150inline
151std::ostream&
152operator<< (std::ostream& os, const iorheomanip1<T>& m)
153{
154 m.f (os, m.i);
155 return os;
156}
157// ---------------------------------------------------------------------
158// iofem trivial memory handler
159// TODO: a global destructor that delete the list
160// when global cstor/dstor works...
161// ---------------------------------------------------------------------
162
163
164template <class T>
166public:
167 static std::list<T*> *pointer_list;
168 static inline T* iorheobase_alloc () {
169 static bool init = false;
170 if (!init) {
171 pointer_list = new_macro(std::list<T*>);
172 init = true;
173 }
174 T *p = new_macro(T);
175 (*pointer_list).push_back(p);
176 return p;
177 }
178 //
179 // io-manips / memory interface
180 //
181 static inline T* get_pointer (std::ios& io) {
182 static int iobaseidx = 0;
183 static bool iobaseidx_initialized = false;
184 if (!iobaseidx_initialized) {
185 iobaseidx = std::ios::xalloc();
186 iobaseidx_initialized = true;
187 }
188 T* p = (T*)io.pword(iobaseidx);
189
190#ifdef _RHEOLEF_HAVE_IOS_BITALLOC
191 // io.pword(iobaseidx) n'est pas forcement nul la premiere fois
192 // e.g. CRAY C++ ne l'initialise pas
193 // => peut valoir une valeur arbitraire...
194 // pas moyen de savoir quand il faut l'initialiser
195 // std::ios::bitalloc: un bit va permettre de dire
196 // si on a deja initialise'
197 // bitalloc = pas standard (e.g. pas avec KAI C++)
198 // mais permet de contourner le bug du
199 // compilateur cray c++
200 // le script configure teste si bitalloc() existe
201 static long iobase_bitidx;
202 static bool iobase_bitidx_initialized = false;
203 long bit;
204 if (!iobase_bitidx_initialized) {
205 iobase_bitidx = std::ios::bitalloc();
206 iobase_bitidx_initialized = true;
207 }
208 long bit_init;
209 if (iobase_bitidx == 0) {
210 // no bits are still available in std::ios...
211 bit_init = (p != 0);
212 } else {
213 // get iobase_bitidx flag in io.flags:
214 long io_flags = io.flags();
215 bit_init = io_flags & iobase_bitidx;
216 // set iobase_bitidx flag to true in io.flags:
217 io.flags(io_flags | iobase_bitidx);
218 }
219#else // ! _RHEOLEF_HAVE_IOS_BITALLOC
220 long bit_init = (p != 0);
221#endif // _RHEOLEF_HAVE_IOS_BITALLOC
222
223 if (bit_init == 0) {
224 if (p != 0) {
225 warning_macro ("ios::pwords(int) return value not initialized (fixed)");
226 }
227 io.pword(iobaseidx) = p = iorheobase_alloc();
228 } else {
229 if (p == 0) {
230 fatal_macro ("ios::pwords(int) return null value: memory corrupted");
231 }
232 }
233 return p;
234 }
235};
236}// namespace rheolef
237# endif /* _IORHEOBASE_H */
static std::list< T * > * pointer_list
Definition iorheobase.h:167
static T * get_pointer(std::ios &io)
Definition iorheobase.h:181
#define fatal_macro(message)
Definition dis_macros.h:33
#define warning_macro(message)
Definition dis_macros.h:53
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition catchmark.h:99
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition catchmark.h:88
Definition cavity_dg.h:29
Definition sphere.icc:25
iorheomanip1(std::ios &(*ff)(std::ios &, const T &), const T &ii)
Definition iorheobase.h:135
irheomanip1(std::ios &(*ff)(std::ios &, const T &), const T &ii)
Definition iorheobase.h:103
orheomanip1(std::ios &(*ff)(std::ios &, const T &), const T &ii)
Definition iorheobase.h:119