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