cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmnMultiplexerStreambufProxy.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ofri Sadowsky
7  Created on: 2002-05-20
8 
9  (C) Copyright 2002-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 
26 #pragma once
27 
28 #ifndef _cmnMultiplexerStreambufProxy_h
29 #define _cmnMultiplexerStreambufProxy_h
30 
33 
34 #include <list>
35 #include <algorithm>
36 
86 template<class _element, class _trait>
87 class cmnMultiplexerStreambufProxy : public std::basic_streambuf<_element, _trait>
88 {
89 private:
93 
94  public:
95 
97  typedef typename std::basic_streambuf<_element, _trait>::int_type int_type;
98 
101  : OutputChannel(output), LogLevel(level)
102  {}
103 
105  cmnLogLevel GetLOD(void) const {
106  return LogLevel;
107  }
108 
110  void SetLOD(cmnLogLevel level) {
111  LogLevel = level;
112  }
113 
115  ChannelType * GetOutput(void) const {
116  return OutputChannel;
117  }
118 
119  // Here we override the basic_streambuf methods for multiplexing.
120  // This part is declared 'protected' following the declarations of
121  // basic_streambuf. See basic_streambuf documentation for more
122  // details.
123  protected:
124 
126  virtual std::streamsize xsputn(const _element * s, std::streamsize n);
127 
129  virtual int sync(void);
130 
135  virtual int_type overflow(int_type c = _trait::eof());
136 
137 
138  private:
139  ChannelType * OutputChannel;
140  cmnLogLevel LogLevel;
141 
142 };
143 
144 
145 //********************************
146 // Template method implementation
147 //********************************
148 
149 
151 template <class _element, class _trait>
152 std::streamsize cmnMultiplexerStreambufProxy<_element, _trait>::xsputn(const _element *s, std::streamsize n)
153 {
154  return OutputChannel->xsputn(s, n, LogLevel);
155 }
156 
157 
159 template <class _element, class _trait>
161 {
162  return OutputChannel->sync();
163 }
164 
165 
170 template<class _element, class _trait>
173 {
174  return OutputChannel->overflow(c, LogLevel);
175 }
176 
177 
178 #endif // _cmnMultiplexerStreambufProxy_h
Portability across compilers and operating systems tools.
virtual std::streamsize xsputn(const _element *s, std::streamsize n)
Definition: cmnMultiplexerStreambufProxy.h:152
virtual int sync(void)
Definition: cmnMultiplexerStreambufProxy.h:160
short cmnLogLevel
Definition: cmnLogLoD.h:55
Types for dynamic control of output messages.
Definition: cmnForwardDeclarations.h:40
cmnMultiplexerStreambufProxy(ChannelType *output, cmnLogLevel level)
Definition: cmnMultiplexerStreambufProxy.h:100
std::basic_streambuf< _element, _trait >::int_type int_type
Definition: cmnMultiplexerStreambufProxy.h:97
Type Definitions for dynamic control of output messages.
cmnLODMultiplexerStreambuf< _element, _trait > ChannelType
Definition: cmnMultiplexerStreambufProxy.h:96
void SetLOD(cmnLogLevel level)
Definition: cmnMultiplexerStreambufProxy.h:110
ChannelType * GetOutput(void) const
Definition: cmnMultiplexerStreambufProxy.h:115
cmnLogLevel GetLOD(void) const
Definition: cmnMultiplexerStreambufProxy.h:105
A Streambuffer class that allows output to multiple streambuf objects for Level of Detail information...
Definition: cmnLODMultiplexerStreambuf.h:108
virtual int_type overflow(int_type c=_trait::eof())
Definition: cmnMultiplexerStreambufProxy.h:172