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 #include "mpi_interface.hpp"
8 
9 namespace netgen
10 {
11 
12   //DLL_HEADER extern int printmessage_importance;
13 DLL_HEADER extern int printdots;
14 
15 
16 
17 class Imp
18 {
19   int importance;
20 public:
Imp()21   Imp () : importance(0) { ; }
22 
Imp(int aimportance)23   Imp ( int aimportance ) : importance(aimportance) { ; }
24 
GetImp() const25   int GetImp () const { return importance; }
26 };
27 
28 
29 class Proc
30 {
31   int proc;
32 public:
Proc()33   Proc () : proc(0) { ; }
34 
Proc(int aproc)35   Proc ( int aproc ) : proc(aproc) { ; }
36 
GetProc() const37   int GetProc () const { return proc; }
38 };
39 
40 class Procs
41 {
42   const netgen::NgFlatArray<int> procs;
43 
44 public:
45 
Procs(const netgen::NgFlatArray<int> & aprocs)46   Procs ( const netgen::NgFlatArray<int> & aprocs ) : procs (aprocs) { ; }
47 
GetProcs() const48   const netgen::NgFlatArray<int> & GetProcs () const { return procs; }
49 };
50 
51 
52 
53 class NetgenOutStream
54 {
55   ostream * out;
56 
57   bool print;
58   bool printheader;
59 
60 
61 public:
NetgenOutStream()62   NetgenOutStream() :
63     out(&std::cout),
64     print(1),
65     printheader(1)
66   {
67     ;
68   }
69 
NetgenOutStream(ostream * aout,Imp imp)70   NetgenOutStream(ostream * aout, Imp imp ) :
71     out(aout),
72     printheader(1)
73   {
74     if ( netgen::printmessage_importance >= imp.GetImp() )
75       print = true;
76     else
77       print = false;
78   }
79 
NetgenOutStream(ostream * aout,Proc proc)80   NetgenOutStream(ostream * aout, Proc proc ) :
81     out(aout),
82     printheader(1)
83   {
84 #ifdef PARALLEL
85     if ( netgen::id == proc.GetProc() )
86       print = true;
87     else
88       print = false;
89 #else
90     if ( 0 == proc.GetProc() )
91       print = true;
92     else
93       print = false;
94 
95 #endif
96   }
97 
NetgenOutStream(ostream * aout,Procs & procs)98   NetgenOutStream(ostream * aout, Procs & procs ) :
99     out(aout),
100     printheader(1)
101   {
102 #ifdef PARALLEL
103     if ( procs.GetProcs().Contains(netgen::id) )
104       print = true;
105     else
106       print = false;
107 #else
108     if ( procs.GetProcs().Contains(0) )
109       print = true;
110     else
111       print = false;
112 
113 #endif
114   }
115 
OStream()116   ostream & OStream ()
117   {
118     return *out;
119   }
120 
121   template <typename T>
operator <<(T & var)122   NetgenOutStream & operator<< (T & var)
123   {
124     if ( print )
125       {
126 #ifdef PARALLEL
127 	if ( printheader )
128 	  {
129 	    *out << "proc " << netgen::id << ": ";
130 	    printheader = false;
131 	  }
132 #endif
133 	*out << var;
134       }
135     return (*this);
136   }
137 
operator <<(ostream & (* pf)(ostream &))138   NetgenOutStream& operator<< (ostream& ( *pf )(ostream&))
139   {
140     if ( print )
141       *out << (*pf) ;
142 
143     return (*this);
144   }
145 
operator <<(ios & (* pf)(ios &))146   NetgenOutStream& operator<< (ios& ( *pf )(ios&))
147   {
148     if ( print)
149       *out << (*pf) ;
150 
151     printheader = 1;
152 
153     return (*this);
154   }
155 
operator <<(ios_base & (* pf)(ios_base &))156   NetgenOutStream& operator<< (ios_base& ( *pf )(ios_base&))
157   {
158     if (print )
159       *out << (*pf) ;
160     return (*this);
161   }
162 
163 
164 };
165 
166 /*
167 NetgenOutStream operator<< ( ostream & ost, Imp  imp );
168 NetgenOutStream operator<< ( ostream & ost, Proc proc );
169 NetgenOutStream operator<< ( ostream & ost, Procs & procs );
170 */
171 
operator <<(ostream & ost,Imp imp)172 inline NetgenOutStream operator<< ( ostream & ost, Imp  imp )
173   {
174     return ( NetgenOutStream ( &ost, imp ) );
175   }
176 
operator <<(ostream & ost,Proc proc)177 inline   NetgenOutStream operator<< ( ostream & ost, Proc proc )
178   {
179     return ( NetgenOutStream ( &ost, proc ) );
180   }
181 
182 
operator <<(ostream & ost,Procs & procs)183 inline   NetgenOutStream operator<< ( ostream & ost, Procs & procs )
184   {
185     return ( NetgenOutStream ( &ost, procs ) );
186   }
187 
188 
189 
190 // {
191 //   return ( NetgenOutStream ( &ost, imp.GetImp() ) );
192 // }
193 
194 // template <typename T>
195 // NetgenOutStream& operator<< (NetgenOutStream& out, T c )
196 // {
197 //   out.OStream() << c << endl;
198 //   return out;
199 // }
200 
201 
202 }
203 
204 
205 #endif
206