diff options
author | Mike Buland <eichlan@xagasoft.com> | 2013-03-03 22:16:18 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2013-03-03 22:16:18 +0000 |
commit | 21f5d80dade777675f10fd393f0a953b36268f9d (patch) | |
tree | 1eb3870849c072ad44ff48ea10a654e9d85eb08d | |
parent | 6638b698662442709103522c5268a3b597d27329 (diff) | |
download | libbu++-21f5d80dade777675f10fd393f0a953b36268f9d.tar.gz libbu++-21f5d80dade777675f10fd393f0a953b36268f9d.tar.bz2 libbu++-21f5d80dade777675f10fd393f0a953b36268f9d.tar.xz libbu++-21f5d80dade777675f10fd393f0a953b36268f9d.zip |
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.
-rw-r--r-- | src/unstable/dualfilter.cpp | 8 | ||||
-rw-r--r-- | src/unstable/dualfilter.h | 67 |
2 files changed, 75 insertions, 0 deletions
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 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2013 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #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 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2013 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #ifndef BU_DUAL_FILTER_H | ||
9 | #define BU_DUAL_FILTER_H | ||
10 | |||
11 | #include "bu/filter.h" | ||
12 | |||
13 | namespace Bu | ||
14 | { | ||
15 | template<typename Flt> | ||
16 | class DualFilter : public Bu::Filter | ||
17 | { | ||
18 | public: | ||
19 | DualFilter( Bu::Stream &rNext ) : | ||
20 | Bu::Filter( rNext ), | ||
21 | fRead( rNext ), | ||
22 | fWrite( rNext ) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | virtual ~DualFilter() | ||
27 | { | ||
28 | } | ||
29 | |||
30 | virtual void start() | ||
31 | { | ||
32 | fRead.start(); | ||
33 | fWrite.start(); | ||
34 | } | ||
35 | |||
36 | virtual Bu::size stop() | ||
37 | { | ||
38 | return fRead.stop() + fWrite.stop(); | ||
39 | } | ||
40 | |||
41 | virtual void close() | ||
42 | { | ||
43 | Bu::Filter::close(); | ||
44 | fRead.close(); | ||
45 | fWrite.close(); | ||
46 | } | ||
47 | |||
48 | virtual Bu::size read( void *pBuf, Bu::size iBytes ) | ||
49 | { | ||
50 | return fRead.read( pBuf, iBytes ); | ||
51 | } | ||
52 | |||
53 | virtual Bu::size write( void *pBuf, Bu::size iBytes ) | ||
54 | { | ||
55 | return fWrite.write( pBuf, iBytes ); | ||
56 | } | ||
57 | |||
58 | Flt &getReadFilter() { return fRead; } | ||
59 | Flt &getWriteFilter() { return fWrite; } | ||
60 | |||
61 | private: | ||
62 | Flt fRead; | ||
63 | Flt fWrite; | ||
64 | }; | ||
65 | }; | ||
66 | |||
67 | #endif | ||