ThreadStream.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2007 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Util/genutil/ThreadStream.h
10 
11 #ifndef __ThreadStream_h
12 #define __ThreadStream_h
13 
14 #ifdef HAVE_CONFIG_H
15 #include <config.h>
16 #endif
17 
18 #ifdef HAVE_PTHREAD
19 #include <pthread.h>
20 #endif
21 
22 #include "Warning.h"
23 
26 {
27 public:
28 
30  ThreadStream ();
31 
33  ~ThreadStream ();
34 
36  std::ostream& get ();
37 
39  void * get_raw ();
40 
42  void set (std::ostream*);
43 
45  void set (void *);
46 
47 private:
48 
49 #ifdef HAVE_PTHREAD
50  pthread_key_t key;
51 #else
52  std::ostream* stream;
53 #endif
54 
55 };
56 
57 template<class T>
58 ThreadStream& operator<< (ThreadStream& ts, const T& t)
59 {
60  ts.get() << t;
61  return ts;
62 }
63 
65 inline ThreadStream& operator<< (ThreadStream& ts, manipulator m)
66 {
67  ts.get() << m;
68  return ts;
69 }
70 
71 #endif
std::ostream & get()
Interface to ostream.
Definition: ThreadStream.C:41
A convenient exception handling class.
Definition: Error.h:54
Manages a unique std::ostream for each thread.
Definition: ThreadStream.h:25
~ThreadStream()
Destructor.
Definition: ThreadStream.C:32
ThreadStream()
Default constructor.
Definition: ThreadStream.C:23
void * get_raw()
Interface to raw void*.
void set(std::ostream *)
Set the ostream for the current thread.
Definition: ThreadStream.C:54

Generated using doxygen 1.8.17