Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/general/netgenout.hpp
3206 views
1
#ifndef NETGEN_OUT_STREAM_HPP__
2
#define NETGEN_OUT_STREAM_HPP__
3
4
// #include <ostream>
5
// #include <mystdlib.h>
6
// #include <meshing.hpp>
7
8
#ifdef PARALLEL
9
extern int id;
10
extern int ntasks;
11
#endif
12
extern int printmessage_importance;
13
14
15
16
class Imp
17
{
18
int importance;
19
public:
20
Imp () : importance(0) { ; }
21
22
Imp ( int aimportance ) : importance(aimportance) { ; }
23
24
int GetImp () const { return importance; }
25
};
26
27
28
class Proc
29
{
30
int proc;
31
public:
32
Proc () : proc(0) { ; }
33
34
Proc ( int aproc ) : proc(aproc) { ; }
35
36
int GetProc () const { return proc; }
37
};
38
39
class Procs
40
{
41
const netgen::FlatArray<int> procs;
42
43
public:
44
45
Procs ( const netgen::FlatArray<int> & aprocs ) : procs (aprocs) { ; }
46
47
const netgen::FlatArray<int> & GetProcs () const { return procs; }
48
};
49
50
51
52
class NetgenOutStream
53
{
54
ostream * out;
55
56
bool print;
57
bool printheader;
58
59
60
public:
61
NetgenOutStream() :
62
out(&std::cout),
63
print(1),
64
printheader(1)
65
{
66
;
67
}
68
69
NetgenOutStream(ostream * aout, Imp imp ) :
70
out(aout),
71
printheader(1)
72
{
73
if ( netgen::printmessage_importance >= imp.GetImp() )
74
print = true;
75
else
76
print = false;
77
}
78
79
NetgenOutStream(ostream * aout, Proc proc ) :
80
out(aout),
81
printheader(1)
82
{
83
#ifdef PARALLEL
84
if ( netgen::id == proc.GetProc() )
85
print = true;
86
else
87
print = false;
88
#else
89
if ( 0 == proc.GetProc() )
90
print = true;
91
else
92
print = false;
93
94
#endif
95
}
96
97
NetgenOutStream(ostream * aout, Procs & procs ) :
98
out(aout),
99
printheader(1)
100
{
101
#ifdef PARALLEL
102
if ( procs.GetProcs().Contains(netgen::id) )
103
print = true;
104
else
105
print = false;
106
#else
107
if ( procs.GetProcs().Contains(0) )
108
print = true;
109
else
110
print = false;
111
112
#endif
113
}
114
115
ostream & OStream ()
116
{
117
return *out;
118
}
119
120
template <typename T>
121
NetgenOutStream & operator<< (T & var)
122
{
123
if ( print )
124
{
125
#ifdef PARALLEL
126
if ( printheader )
127
{
128
*out << "proc " << netgen::id << ": ";
129
printheader = false;
130
}
131
#endif
132
*out << var;
133
}
134
return (*this);
135
}
136
137
NetgenOutStream& operator<< (ostream& ( *pf )(ostream&))
138
{
139
if ( print )
140
*out << (*pf) ;
141
142
return (*this);
143
}
144
145
NetgenOutStream& operator<< (ios& ( *pf )(ios&))
146
{
147
if ( print)
148
*out << (*pf) ;
149
150
printheader = 1;
151
152
return (*this);
153
}
154
155
NetgenOutStream& operator<< (ios_base& ( *pf )(ios_base&))
156
{
157
if (print )
158
*out << (*pf) ;
159
return (*this);
160
}
161
162
163
};
164
165
166
NetgenOutStream operator<< ( ostream & ost, Imp imp );
167
NetgenOutStream operator<< ( ostream & ost, Proc proc );
168
NetgenOutStream operator<< ( ostream & ost, Procs & procs );
169
// {
170
// return ( NetgenOutStream ( &ost, imp.GetImp() ) );
171
// }
172
173
// template <typename T>
174
// NetgenOutStream& operator<< (NetgenOutStream& out, T c )
175
// {
176
// out.OStream() << c << endl;
177
// return out;
178
// }
179
180
181
182
183
184
#endif
185
186