diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-08-22 05:34:12 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-08-22 05:34:12 +0000 |
commit | 611f1c821f9d882f935ac62b0c566d4988f26d1c (patch) | |
tree | 91e69a124cbff0862a8b2f4899d253455a40eaa3 /src/streamstack.cpp | |
parent | 7f17eeb7fccd52b7049f9f598121130dfd1b55ae (diff) | |
download | libbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.tar.gz libbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.tar.bz2 libbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.tar.xz libbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.zip |
Bu::StreamStack works, it's tested, reasonably, it will be used first in the
gats project in Gats::ProtocolGats.
Diffstat (limited to '')
-rw-r--r-- | src/streamstack.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/streamstack.cpp b/src/streamstack.cpp index 9e45cc4..c7f8af5 100644 --- a/src/streamstack.cpp +++ b/src/streamstack.cpp | |||
@@ -4,83 +4,203 @@ Bu::StreamStack::StreamStack() | |||
4 | { | 4 | { |
5 | } | 5 | } |
6 | 6 | ||
7 | Bu::StreamStack::StreamStack( Bu::Stream *pStream ) | ||
8 | { | ||
9 | lFilts.prepend( pStream ); | ||
10 | } | ||
11 | |||
7 | Bu::StreamStack::~StreamStack() | 12 | Bu::StreamStack::~StreamStack() |
8 | { | 13 | { |
14 | clearStack(); | ||
15 | } | ||
16 | |||
17 | bool Bu::StreamStack::isEmpty() | ||
18 | { | ||
19 | return lFilts.isEmpty(); | ||
20 | } | ||
21 | |||
22 | bool Bu::StreamStack::hasStream() | ||
23 | { | ||
24 | return !lFilts.isEmpty(); | ||
25 | } | ||
26 | |||
27 | void Bu::StreamStack::setStream( Bu::Stream *pStream ) | ||
28 | { | ||
29 | if( !lFilts.isEmpty() ) | ||
30 | throw Bu::ExceptionBase("There is already a stream set."); | ||
31 | |||
32 | lFilts.prepend( pStream ); | ||
33 | } | ||
34 | |||
35 | void Bu::StreamStack::clearStack() | ||
36 | { | ||
37 | for( FilterList::iterator i = lFilts.begin(); i; i++ ) | ||
38 | { | ||
39 | delete *i; | ||
40 | } | ||
41 | |||
42 | lFilts.clear(); | ||
43 | } | ||
44 | |||
45 | void Bu::StreamStack::popFilter() | ||
46 | { | ||
47 | if( lFilts.isEmpty() ) | ||
48 | return; | ||
49 | |||
50 | delete lFilts.first(); | ||
51 | lFilts.erase( lFilts.begin() ); | ||
52 | } | ||
53 | |||
54 | Bu::Stream *Bu::StreamStack::getTop() | ||
55 | { | ||
56 | checkStack(); | ||
57 | |||
58 | return lFilts.first(); | ||
59 | } | ||
60 | |||
61 | Bu::Stream *Bu::StreamStack::getStream() | ||
62 | { | ||
63 | checkStack(); | ||
64 | |||
65 | return lFilts.last(); | ||
9 | } | 66 | } |
10 | 67 | ||
11 | void Bu::StreamStack::close() | 68 | void Bu::StreamStack::close() |
12 | { | 69 | { |
70 | checkStack(); | ||
71 | |||
72 | lFilts.first()->close(); | ||
13 | } | 73 | } |
14 | 74 | ||
15 | size_t Bu::StreamStack::read( void *pBuf, size_t nBytes ) | 75 | size_t Bu::StreamStack::read( void *pBuf, size_t nBytes ) |
16 | { | 76 | { |
77 | checkStack(); | ||
78 | |||
79 | return lFilts.first()->read( pBuf, nBytes ); | ||
17 | } | 80 | } |
18 | 81 | ||
19 | size_t Bu::StreamStack::write( const void *pBuf, size_t nBytes ) | 82 | size_t Bu::StreamStack::write( const void *pBuf, size_t nBytes ) |
20 | { | 83 | { |
84 | checkStack(); | ||
85 | |||
86 | return lFilts.first()->write( pBuf, nBytes ); | ||
21 | } | 87 | } |
22 | 88 | ||
23 | size_t Bu::StreamStack::write( const Bu::FString &sBuf ) | 89 | size_t Bu::StreamStack::write( const Bu::FString &sBuf ) |
24 | { | 90 | { |
91 | checkStack(); | ||
92 | |||
93 | return lFilts.first()->write( sBuf ); | ||
25 | } | 94 | } |
26 | 95 | ||
27 | long Bu::StreamStack::tell() | 96 | long Bu::StreamStack::tell() |
28 | { | 97 | { |
98 | checkStack(); | ||
99 | |||
100 | return lFilts.first()->tell(); | ||
29 | } | 101 | } |
30 | 102 | ||
31 | void Bu::StreamStack::seek( long offset ) | 103 | void Bu::StreamStack::seek( long offset ) |
32 | { | 104 | { |
105 | checkStack(); | ||
106 | |||
107 | lFilts.first()->seek( offset ); | ||
33 | } | 108 | } |
34 | 109 | ||
35 | void Bu::StreamStack::setPos( long pos ) | 110 | void Bu::StreamStack::setPos( long pos ) |
36 | { | 111 | { |
112 | checkStack(); | ||
113 | |||
114 | lFilts.first()->setPos( pos ); | ||
37 | } | 115 | } |
38 | 116 | ||
39 | void Bu::StreamStack::setPosEnd( long pos ) | 117 | void Bu::StreamStack::setPosEnd( long pos ) |
40 | { | 118 | { |
119 | checkStack(); | ||
120 | |||
121 | lFilts.first()->setPosEnd( pos ); | ||
41 | } | 122 | } |
42 | 123 | ||
43 | bool Bu::StreamStack::isEos() | 124 | bool Bu::StreamStack::isEos() |
44 | { | 125 | { |
126 | checkStack(); | ||
127 | |||
128 | return lFilts.first()->isEos(); | ||
45 | } | 129 | } |
46 | 130 | ||
47 | bool Bu::StreamStack::isOpen() | 131 | bool Bu::StreamStack::isOpen() |
48 | { | 132 | { |
133 | checkStack(); | ||
134 | |||
135 | return lFilts.first()->isOpen(); | ||
49 | } | 136 | } |
50 | 137 | ||
51 | void Bu::StreamStack::flush() | 138 | void Bu::StreamStack::flush() |
52 | { | 139 | { |
140 | checkStack(); | ||
141 | |||
142 | lFilts.first()->flush(); | ||
53 | } | 143 | } |
54 | 144 | ||
55 | bool Bu::StreamStack::canRead() | 145 | bool Bu::StreamStack::canRead() |
56 | { | 146 | { |
147 | checkStack(); | ||
148 | |||
149 | return lFilts.first()->canRead(); | ||
57 | } | 150 | } |
58 | 151 | ||
59 | bool Bu::StreamStack::canWrite() | 152 | bool Bu::StreamStack::canWrite() |
60 | { | 153 | { |
154 | checkStack(); | ||
155 | |||
156 | return lFilts.first()->canWrite(); | ||
61 | } | 157 | } |
62 | 158 | ||
63 | bool Bu::StreamStack::isReadable() | 159 | bool Bu::StreamStack::isReadable() |
64 | { | 160 | { |
161 | checkStack(); | ||
162 | |||
163 | return lFilts.first()->isReadable(); | ||
65 | } | 164 | } |
66 | 165 | ||
67 | bool Bu::StreamStack::isWritable() | 166 | bool Bu::StreamStack::isWritable() |
68 | { | 167 | { |
168 | checkStack(); | ||
169 | |||
170 | return lFilts.first()->isWritable(); | ||
69 | } | 171 | } |
70 | 172 | ||
71 | bool Bu::StreamStack::isSeekable() | 173 | bool Bu::StreamStack::isSeekable() |
72 | { | 174 | { |
175 | checkStack(); | ||
176 | |||
177 | return lFilts.first()->isSeekable(); | ||
73 | } | 178 | } |
74 | 179 | ||
75 | bool Bu::StreamStack::isBlocking() | 180 | bool Bu::StreamStack::isBlocking() |
76 | { | 181 | { |
182 | checkStack(); | ||
183 | |||
184 | return lFilts.first()->isBlocking(); | ||
77 | } | 185 | } |
78 | 186 | ||
79 | void Bu::StreamStack::setBlocking( bool bBlocking ) | 187 | void Bu::StreamStack::setBlocking( bool bBlocking ) |
80 | { | 188 | { |
189 | checkStack(); | ||
190 | |||
191 | lFilts.first()->setBlocking( bBlocking ); | ||
81 | } | 192 | } |
82 | 193 | ||
83 | void Bu::StreamStack::setSize( long iSize ) | 194 | void Bu::StreamStack::setSize( long iSize ) |
84 | { | 195 | { |
196 | checkStack(); | ||
197 | |||
198 | lFilts.first()->setSize( iSize ); | ||
199 | } | ||
200 | |||
201 | inline void Bu::StreamStack::checkStack() | ||
202 | { | ||
203 | if( lFilts.isEmpty() ) | ||
204 | throw Bu::ExceptionBase("StreamStack is empty."); | ||
85 | } | 205 | } |
86 | 206 | ||