Ardour  8.12
transmitter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2016 Paul Davis <paul@linuxaudiosystems.com>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __libmisc_transmitter_h__
20 #define __libmisc_transmitter_h__
21 
22 #include <sstream>
23 #include <iostream>
24 
25 #include <pbd/signals.h>
26 
27 #include "pbd/libpbd_visibility.h"
28 
29 class LIBPBD_API Transmitter : public std::stringstream
30 
31 {
32  public:
33  enum Channel {
39  Throw
40  };
41 
43 
44  PBD::Signal2<void,Channel, const char *> &sender() {
45  return *send;
46  }
47 
48  bool does_not_return ();
49 
50  protected:
51  virtual void deliver ();
52  friend std::ostream& endmsg (std::ostream &);
53 
54  private:
56  PBD::Signal2<void, Channel, const char *> *send;
57 
58  PBD::Signal2<void, Channel, const char *> debug;
59  PBD::Signal2<void, Channel, const char *> info;
60  PBD::Signal2<void, Channel, const char *> warning;
61  PBD::Signal2<void, Channel, const char *> error;
62  PBD::Signal2<void, Channel, const char *> fatal;
63 };
64 
65 /* for EGCS 2.91.66, if this function is not compiled within the same
66  compilation unit as the one where a ThrownError is thrown, then
67  nothing will catch the error. This is a pretty small function, so
68  inlining it here seems like a reasonable workaround.
69 */
70 
71 inline std::ostream &
72 endmsg (std::ostream &ostr)
73 
74 {
75  Transmitter *t;
76 
77  /* There is a serious bug in the Cygnus/GCC libstdc++ library:
78  cout is not actually an ostream, but a trick was played
79  to make the compiler think that it is. This will cause
80  the dynamic_cast<> to fail with SEGV. So, first check to
81  see if ostr == cout, and handle it specially.
82  */
83 
84  if (&ostr == &std::cout) {
85  std::cout << std::endl;
86  return ostr;
87  } else if (&ostr == &std::cerr) {
88  std::cerr << std::endl;
89  return ostr;
90  }
91 
92  if ((t = dynamic_cast<Transmitter *> (&ostr)) != 0) {
93  t->deliver ();
94  } else {
95  /* hmm. not a Transmitter, so just put a newline on
96  it and assume that that will be enough.
97  */
98 
99  ostr << std::endl;
100  }
101 
102  return ostr;
103 }
104 
105 
106 extern "C" { LIBPBD_API void pbd_c_error (const char *); }
107 
108 #endif // __libmisc_transmitter_h__
PBD::Signal2< void, Channel, const char * > fatal
Definition: transmitter.h:62
PBD::Signal2< void, Channel, const char * > debug
Definition: transmitter.h:58
Transmitter(Channel)
bool does_not_return()
PBD::Signal2< void, Channel, const char * > info
Definition: transmitter.h:59
PBD::Signal2< void, Channel, const char * > warning
Definition: transmitter.h:60
Channel channel
Definition: transmitter.h:55
PBD::Signal2< void, Channel, const char * > & sender()
Definition: transmitter.h:44
virtual void deliver()
PBD::Signal2< void, Channel, const char * > * send
Definition: transmitter.h:56
PBD::Signal2< void, Channel, const char * > error
Definition: transmitter.h:61
#define LIBPBD_API
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:72
void pbd_c_error(const char *)