diff options
Diffstat (limited to 'src/stable/streamstack.cpp')
-rw-r--r-- | src/stable/streamstack.cpp | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/src/stable/streamstack.cpp b/src/stable/streamstack.cpp new file mode 100644 index 0000000..d45306d --- /dev/null +++ b/src/stable/streamstack.cpp | |||
@@ -0,0 +1,234 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 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 "bu/streamstack.h" | ||
9 | |||
10 | Bu::StreamStack::StreamStack() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | Bu::StreamStack::StreamStack( Bu::Stream *pStream ) | ||
15 | { | ||
16 | lFilts.prepend( pStream ); | ||
17 | } | ||
18 | |||
19 | Bu::StreamStack::~StreamStack() | ||
20 | { | ||
21 | clear(); | ||
22 | } | ||
23 | |||
24 | bool Bu::StreamStack::isEmpty() | ||
25 | { | ||
26 | return lFilts.isEmpty(); | ||
27 | } | ||
28 | |||
29 | bool Bu::StreamStack::hasStream() | ||
30 | { | ||
31 | return !lFilts.isEmpty(); | ||
32 | } | ||
33 | |||
34 | void Bu::StreamStack::setStream( Bu::Stream *pStream ) | ||
35 | { | ||
36 | if( !lFilts.isEmpty() ) | ||
37 | throw Bu::ExceptionBase("There is already a stream set."); | ||
38 | |||
39 | lFilts.prepend( pStream ); | ||
40 | } | ||
41 | |||
42 | void Bu::StreamStack::clear() | ||
43 | { | ||
44 | for( FilterList::iterator i = lFilts.begin(); i; i++ ) | ||
45 | { | ||
46 | delete *i; | ||
47 | } | ||
48 | |||
49 | lFilts.clear(); | ||
50 | } | ||
51 | |||
52 | void Bu::StreamStack::popFilter() | ||
53 | { | ||
54 | if( lFilts.isEmpty() ) | ||
55 | return; | ||
56 | |||
57 | delete lFilts.first(); | ||
58 | lFilts.erase( lFilts.begin() ); | ||
59 | } | ||
60 | |||
61 | Bu::Stream *Bu::StreamStack::getTop() | ||
62 | { | ||
63 | checkStack(); | ||
64 | |||
65 | return lFilts.first(); | ||
66 | } | ||
67 | |||
68 | Bu::Stream *Bu::StreamStack::getStream() | ||
69 | { | ||
70 | checkStack(); | ||
71 | |||
72 | return lFilts.last(); | ||
73 | } | ||
74 | |||
75 | void Bu::StreamStack::close() | ||
76 | { | ||
77 | checkStack(); | ||
78 | |||
79 | lFilts.first()->close(); | ||
80 | } | ||
81 | |||
82 | Bu::size Bu::StreamStack::read( void *pBuf, Bu::size nBytes ) | ||
83 | { | ||
84 | checkStack(); | ||
85 | |||
86 | return lFilts.first()->read( pBuf, nBytes ); | ||
87 | } | ||
88 | |||
89 | Bu::size Bu::StreamStack::write( const void *pBuf, Bu::size nBytes ) | ||
90 | { | ||
91 | checkStack(); | ||
92 | |||
93 | return lFilts.first()->write( pBuf, nBytes ); | ||
94 | } | ||
95 | |||
96 | Bu::size Bu::StreamStack::write( const Bu::String &sBuf ) | ||
97 | { | ||
98 | checkStack(); | ||
99 | |||
100 | return lFilts.first()->write( sBuf ); | ||
101 | } | ||
102 | |||
103 | Bu::size Bu::StreamStack::tell() | ||
104 | { | ||
105 | checkStack(); | ||
106 | |||
107 | return lFilts.first()->tell(); | ||
108 | } | ||
109 | |||
110 | void Bu::StreamStack::seek( Bu::size offset ) | ||
111 | { | ||
112 | checkStack(); | ||
113 | |||
114 | lFilts.first()->seek( offset ); | ||
115 | } | ||
116 | |||
117 | void Bu::StreamStack::setPos( Bu::size pos ) | ||
118 | { | ||
119 | checkStack(); | ||
120 | |||
121 | lFilts.first()->setPos( pos ); | ||
122 | } | ||
123 | |||
124 | void Bu::StreamStack::setPosEnd( Bu::size pos ) | ||
125 | { | ||
126 | checkStack(); | ||
127 | |||
128 | lFilts.first()->setPosEnd( pos ); | ||
129 | } | ||
130 | |||
131 | bool Bu::StreamStack::isEos() | ||
132 | { | ||
133 | checkStack(); | ||
134 | |||
135 | return lFilts.first()->isEos(); | ||
136 | } | ||
137 | |||
138 | bool Bu::StreamStack::isOpen() | ||
139 | { | ||
140 | checkStack(); | ||
141 | |||
142 | return lFilts.first()->isOpen(); | ||
143 | } | ||
144 | |||
145 | void Bu::StreamStack::flush() | ||
146 | { | ||
147 | checkStack(); | ||
148 | |||
149 | lFilts.first()->flush(); | ||
150 | } | ||
151 | |||
152 | bool Bu::StreamStack::canRead() | ||
153 | { | ||
154 | checkStack(); | ||
155 | |||
156 | return lFilts.first()->canRead(); | ||
157 | } | ||
158 | |||
159 | bool Bu::StreamStack::canWrite() | ||
160 | { | ||
161 | checkStack(); | ||
162 | |||
163 | return lFilts.first()->canWrite(); | ||
164 | } | ||
165 | |||
166 | bool Bu::StreamStack::isReadable() | ||
167 | { | ||
168 | checkStack(); | ||
169 | |||
170 | return lFilts.first()->isReadable(); | ||
171 | } | ||
172 | |||
173 | bool Bu::StreamStack::isWritable() | ||
174 | { | ||
175 | checkStack(); | ||
176 | |||
177 | return lFilts.first()->isWritable(); | ||
178 | } | ||
179 | |||
180 | bool Bu::StreamStack::isSeekable() | ||
181 | { | ||
182 | checkStack(); | ||
183 | |||
184 | return lFilts.first()->isSeekable(); | ||
185 | } | ||
186 | |||
187 | bool Bu::StreamStack::isBlocking() | ||
188 | { | ||
189 | checkStack(); | ||
190 | |||
191 | return lFilts.first()->isBlocking(); | ||
192 | } | ||
193 | |||
194 | void Bu::StreamStack::setBlocking( bool bBlocking ) | ||
195 | { | ||
196 | checkStack(); | ||
197 | |||
198 | lFilts.first()->setBlocking( bBlocking ); | ||
199 | } | ||
200 | |||
201 | void Bu::StreamStack::setSize( Bu::size iSize ) | ||
202 | { | ||
203 | checkStack(); | ||
204 | |||
205 | lFilts.first()->setSize( iSize ); | ||
206 | } | ||
207 | |||
208 | Bu::size Bu::StreamStack::getSize() const | ||
209 | { | ||
210 | checkStack(); | ||
211 | |||
212 | return lFilts.first()->getSize(); | ||
213 | } | ||
214 | |||
215 | Bu::size Bu::StreamStack::getBlockSize() const | ||
216 | { | ||
217 | checkStack(); | ||
218 | |||
219 | return lFilts.first()->getBlockSize(); | ||
220 | } | ||
221 | |||
222 | Bu::String Bu::StreamStack::getLocation() const | ||
223 | { | ||
224 | checkStack(); | ||
225 | |||
226 | return lFilts.first()->getLocation(); | ||
227 | } | ||
228 | |||
229 | inline void Bu::StreamStack::checkStack() const | ||
230 | { | ||
231 | if( lFilts.isEmpty() ) | ||
232 | throw Bu::ExceptionBase("StreamStack is empty."); | ||
233 | } | ||
234 | |||