MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TeeByteSink.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  TeeByteSink.h ByteSink that duplicates output onto two ByteSinks
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
28 #ifndef TEEBYTESINK_H
29 #define TEEBYTESINK_H
30 
31 #include "ByteSink.h"
32 #include "Util.h" /* For MIN */
33 
34 namespace MFM
35 {
36 
41  class TeeByteSink : public ByteSink
42  {
43  public:
44 
54  m_sink1(0),
55  m_sink2(0)
56  { }
57 
69  TeeByteSink(ByteSink & sink1, ByteSink & sink2) :
70  m_sink1(&sink1),
71  m_sink2(&sink2)
72  { }
73 
81  ByteSink * GetSink1() const
82  {
83  return m_sink1;
84  }
85 
93  ByteSink * GetSink2() const
94  {
95  return m_sink2;
96  }
97 
109  {
110  ByteSink * ret = m_sink1;
111  m_sink1 = sink;
112  return ret;
113  }
114 
126  {
127  ByteSink * ret = m_sink2;
128  m_sink2 = sink;
129  return ret;
130  }
131 
143  virtual void WriteBytes(const u8 * data, const u32 len)
144  {
145  if (m_sink1)
146  {
147  m_sink1->WriteBytes(data, len);
148  }
149 
150  if (m_sink2)
151  {
152  m_sink2->WriteBytes(data, len);
153  }
154  }
155 
163  virtual s32 CanWrite()
164  {
165  return MIN<s32>(m_sink1 ? m_sink1->CanWrite() : S32_MAX,
166  m_sink2 ? m_sink2->CanWrite() : S32_MAX);
167  }
168 
169  private:
170  ByteSink * m_sink1;
171  ByteSink * m_sink2;
172  };
173 }
174 
175 #endif /* TEEBYTESINK_H */
ByteSink * GetSink2() const
Definition: TeeByteSink.h:93
virtual void WriteBytes(const u8 *data, const u32 len)
Definition: TeeByteSink.h:143
TeeByteSink(ByteSink &sink1, ByteSink &sink2)
Definition: TeeByteSink.h:69
virtual s32 CanWrite()
Definition: TeeByteSink.h:163
Definition: TeeByteSink.h:41
ByteSink * GetSink1() const
Definition: TeeByteSink.h:81
Definition: ByteSink.h:47
ByteSink * SetSink1(ByteSink *sink)
Definition: TeeByteSink.h:108
#define S32_MAX
Definition: itype.h:86
ByteSink * SetSink2(ByteSink *sink)
Definition: TeeByteSink.h:125
virtual void WriteBytes(const u8 *data, const u32 len)=0
virtual s32 CanWrite()=0
TeeByteSink()
Definition: TeeByteSink.h:53