tweak transport bar spacing
[ardour.git] / libs / pbd / pbd / transmitter.h
1 /*
2     Copyright (C) 1998-99 Paul Barton-Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __libmisc_transmitter_h__
21 #define __libmisc_transmitter_h__
22
23 #include <sstream>
24 #include <iostream>
25
26 #include <sigc++/sigc++.h>
27
28 class Transmitter : public std::stringstream
29
30 {
31   public:
32         enum Channel {
33                 Info,
34                 Error,
35                 Warning,
36                 Fatal,
37                 Throw
38         };
39
40         Transmitter (Channel);
41
42         sigc::signal<void,Channel, const char *> &sender() { 
43                 return *send;
44         }
45
46         bool does_not_return ();
47
48   protected:
49         virtual void deliver ();
50         friend std::ostream& endmsg (std::ostream &);
51
52   private:
53         Channel channel;
54         sigc::signal<void, Channel, const char *> *send;
55
56         sigc::signal<void, Channel, const char *> info;
57         sigc::signal<void, Channel, const char *> warning;
58         sigc::signal<void, Channel, const char *> error;
59         sigc::signal<void, Channel, const char *> fatal;
60 };
61
62 /* for EGCS 2.91.66, if this function is not compiled within the same
63    compilation unit as the one where a ThrownError is thrown, then 
64    nothing will catch the error. This is a pretty small function, so
65    inlining it here seems like a reasonable workaround.
66 */
67
68 inline std::ostream &
69 endmsg (std::ostream &ostr)
70
71 {
72         Transmitter *t;
73
74         /* There is a serious bug in the Cygnus/GCC libstdc++ library:
75            cout is not actually an ostream, but a trick was played
76            to make the compiler think that it is. This will cause
77            the dynamic_cast<> to fail with SEGV. So, first check to
78            see if ostr == cout, and handle it specially.
79         */
80
81         if (&ostr == &std::cout) {
82                 std::cout << std::endl;
83                 return ostr;
84         } else if (&ostr == &std::cerr) {
85                 std::cerr << std::endl;
86                 return ostr;
87         }
88
89         if ((t = dynamic_cast<Transmitter *> (&ostr)) != 0) {
90                 t->deliver ();
91         } else {
92                 /* hmm. not a Transmitter, so just put a newline on
93                    it and assume that that will be enough.
94                 */
95                 
96                 ostr << std::endl;
97         }
98
99         return ostr;
100 }
101
102
103 extern "C" { void pbd_c_error (const char *); }
104
105 #endif // __libmisc_transmitter_h__