From 21f5d80dade777675f10fd393f0a953b36268f9d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 3 Mar 2013 22:16:18 +0000 Subject: Adding the Bu::DualFilter which could work out really well, it's going in for testing now. The idea is that it makes it easy to use a bi-directional stream like a tcpstream that requires a seperate filter instance for each read and write side. --- src/unstable/dualfilter.cpp | 8 ++++++ src/unstable/dualfilter.h | 67 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/unstable/dualfilter.cpp create mode 100644 src/unstable/dualfilter.h (limited to 'src') diff --git a/src/unstable/dualfilter.cpp b/src/unstable/dualfilter.cpp new file mode 100644 index 0000000..8d019de --- /dev/null +++ b/src/unstable/dualfilter.cpp @@ -0,0 +1,8 @@ +/* + * Copyright (C) 2007-2013 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "dualfilter.h" diff --git a/src/unstable/dualfilter.h b/src/unstable/dualfilter.h new file mode 100644 index 0000000..ce6a13a --- /dev/null +++ b/src/unstable/dualfilter.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007-2013 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_DUAL_FILTER_H +#define BU_DUAL_FILTER_H + +#include "bu/filter.h" + +namespace Bu +{ + template + class DualFilter : public Bu::Filter + { + public: + DualFilter( Bu::Stream &rNext ) : + Bu::Filter( rNext ), + fRead( rNext ), + fWrite( rNext ) + { + } + + virtual ~DualFilter() + { + } + + virtual void start() + { + fRead.start(); + fWrite.start(); + } + + virtual Bu::size stop() + { + return fRead.stop() + fWrite.stop(); + } + + virtual void close() + { + Bu::Filter::close(); + fRead.close(); + fWrite.close(); + } + + virtual Bu::size read( void *pBuf, Bu::size iBytes ) + { + return fRead.read( pBuf, iBytes ); + } + + virtual Bu::size write( void *pBuf, Bu::size iBytes ) + { + return fWrite.write( pBuf, iBytes ); + } + + Flt &getReadFilter() { return fRead; } + Flt &getWriteFilter() { return fWrite; } + + private: + Flt fRead; + Flt fWrite; + }; +}; + +#endif -- cgit v1.2.3