aboutsummaryrefslogtreecommitdiff
path: root/src/stable/streamstack.cpp
blob: 47ae5c051f70e70d1ee27fcab192b74f01e9699e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 * Copyright (C) 2007-2012 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 "bu/streamstack.h"

Bu::StreamStack::StreamStack()
{
}

Bu::StreamStack::StreamStack( Bu::Stream *pStream )
{
	lFilts.prepend( pStream );
}

Bu::StreamStack::~StreamStack()
{
	clear();
}

bool Bu::StreamStack::isEmpty()
{
	return lFilts.isEmpty();
}

bool Bu::StreamStack::hasStream()
{
	return !lFilts.isEmpty();
}

void Bu::StreamStack::setStream( Bu::Stream *pStream )
{
	if( !lFilts.isEmpty() )
		throw Bu::ExceptionBase("There is already a stream set.");

	lFilts.prepend( pStream );
}

void Bu::StreamStack::clear()
{
	for( FilterList::iterator i = lFilts.begin(); i; i++ )
	{
		delete *i;
	}

	lFilts.clear();
}

void Bu::StreamStack::popFilter()
{
	if( lFilts.isEmpty() )
		return;

	delete lFilts.first();
	lFilts.erase( lFilts.begin() );
}

Bu::Stream *Bu::StreamStack::getTop()
{
	checkStack();

	return lFilts.first();
}

Bu::Stream *Bu::StreamStack::getStream()
{
	checkStack();

	return lFilts.last();
}

void Bu::StreamStack::close()
{
	checkStack();

	lFilts.first()->close();
}

Bu::size Bu::StreamStack::read( void *pBuf, Bu::size nBytes )
{
	checkStack();

	return lFilts.first()->read( pBuf, nBytes );
}

Bu::size Bu::StreamStack::write( const void *pBuf, Bu::size nBytes )
{
	checkStack();

	return lFilts.first()->write( pBuf, nBytes );
}

Bu::size Bu::StreamStack::write( const Bu::String &sBuf )
{
	checkStack();

	return lFilts.first()->write( sBuf );
}

Bu::size Bu::StreamStack::tell()
{
	checkStack();

	return lFilts.first()->tell();
}

void Bu::StreamStack::seek( Bu::size offset )
{
	checkStack();

	lFilts.first()->seek( offset );
}

void Bu::StreamStack::setPos( Bu::size pos )
{
	checkStack();

	lFilts.first()->setPos( pos );
}

void Bu::StreamStack::setPosEnd( Bu::size pos )
{
	checkStack();

	lFilts.first()->setPosEnd( pos );
}

bool Bu::StreamStack::isEos()
{
	checkStack();

	return lFilts.first()->isEos();
}

bool Bu::StreamStack::isOpen()
{
	checkStack();

	return lFilts.first()->isOpen();
}

void Bu::StreamStack::flush()
{
	checkStack();

	lFilts.first()->flush();
}

bool Bu::StreamStack::canRead()
{
	checkStack();

	return lFilts.first()->canRead();
}

bool Bu::StreamStack::canWrite()
{
	checkStack();

	return lFilts.first()->canWrite();
}

bool Bu::StreamStack::isReadable()
{
	checkStack();

	return lFilts.first()->isReadable();
}

bool Bu::StreamStack::isWritable()
{
	checkStack();

	return lFilts.first()->isWritable();
}

bool Bu::StreamStack::isSeekable()
{
	checkStack();

	return lFilts.first()->isSeekable();
}

bool Bu::StreamStack::isBlocking()
{
	checkStack();

	return lFilts.first()->isBlocking();
}

void Bu::StreamStack::setBlocking( bool bBlocking )
{
	checkStack();

	lFilts.first()->setBlocking( bBlocking );
}

void Bu::StreamStack::setSize( Bu::size iSize )
{
	checkStack();

	lFilts.first()->setSize( iSize );
}

Bu::size Bu::StreamStack::getSize() const
{
	checkStack();
	
	return lFilts.first()->getSize();
}

Bu::size Bu::StreamStack::getBlockSize() const
{
	checkStack();

	return lFilts.first()->getBlockSize();
}

Bu::String Bu::StreamStack::getLocation() const
{
	checkStack();

	return lFilts.first()->getLocation();
}

inline void Bu::StreamStack::checkStack() const
{
	if( lFilts.isEmpty() )
		throw Bu::ExceptionBase("StreamStack is empty.");
}