aboutsummaryrefslogtreecommitdiff
path: root/src/stable/streamstack.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
committerMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
commit469bbcf0701e1eb8a6670c23145b0da87357e178 (patch)
treeb5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/streamstack.h
parentee1b79396076edc4e30aefb285fada03bb45e80d (diff)
downloadlibbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/streamstack.h')
-rw-r--r--src/stable/streamstack.h144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/stable/streamstack.h b/src/stable/streamstack.h
new file mode 100644
index 0000000..846935b
--- /dev/null
+++ b/src/stable/streamstack.h
@@ -0,0 +1,144 @@
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#ifndef BU_STREAM_STACK_H
9#define BU_STREAM_STACK_H
10
11#include "bu/stream.h"
12
13#include <typeinfo>
14
15namespace Bu
16{
17 class StreamStack : public Bu::Stream
18 {
19 private:
20 typedef Bu::List<Bu::Stream *> FilterList;
21
22 public:
23 StreamStack();
24 StreamStack( Bu::Stream *pStream );
25 virtual ~StreamStack();
26
27 bool isEmpty();
28 bool hasStream();
29 void setStream( Bu::Stream *pStream );
30
31 void clear();
32 void popFilter();
33 Bu::Stream *getTop();
34
35 Bu::Stream *getStream();
36
37 template<typename filter>
38 Bu::Stream *findFilter()
39 {
40 for( FilterList::iterator i = lFilts.begin(); i; i++ )
41 {
42 if( typeid(**i) == typeid( filter ) )
43 {
44 return *i;
45 }
46 }
47
48 throw Bu::ExceptionBase("Filter not found.");
49 }
50
51 template<typename filter>
52 void pushFilter()
53 {
54 checkStack();
55
56 filter *pFlt = new filter( *lFilts.first() );
57 lFilts.prepend( pFlt );
58 }
59
60 template<typename filter, typename p1t>
61 void pushFilter( p1t p1 )
62 {
63 checkStack();
64
65 filter *pFlt = new filter( *lFilts.first(), p1 );
66 lFilts.prepend( pFlt );
67 }
68
69 template<typename filter, typename p1t, typename p2t>
70 void pushFilter( p1t p1, p2t p2 )
71 {
72 checkStack();
73
74 filter *pFlt = new filter( *lFilts.first(), p1, p2 );
75 lFilts.prepend( pFlt );
76 }
77
78 template<typename filter, typename p1t, typename p2t, typename p3t>
79 void pushFilter( p1t p1, p2t p2, p3t p3 )
80 {
81 checkStack();
82
83 filter *pFlt = new filter( *lFilts.first(), p1, p2, p3 );
84 lFilts.prepend( pFlt );
85 }
86
87 template<typename filter, typename p1t, typename p2t, typename p3t,
88 typename p4t>
89 void pushFilter( p1t p1, p2t p2, p3t p3, p4t p4 )
90 {
91 checkStack();
92
93 filter *pFlt = new filter( *lFilts.first(), p1, p2, p3, p4 );
94 lFilts.prepend( pFlt );
95 }
96
97 template<typename filter, typename p1t, typename p2t, typename p3t,
98 typename p4t, typename p5t>
99 void pushFilter( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )
100 {
101 checkStack();
102
103 filter *pFlt = new filter( *lFilts.first(), p1, p2, p3, p4, p5 );
104 lFilts.prepend( pFlt );
105 }
106
107 //
108 // Everything below here merely passes on the call to the top of the
109 // stream stack.
110 //
111
112 virtual void close();
113 virtual Bu::size read( void *pBuf, Bu::size nBytes );
114 virtual Bu::size write( const void *pBuf, Bu::size nBytes );
115
116 virtual Bu::size write( const Bu::String &sBuf );
117 virtual Bu::size tell();
118 virtual void seek( Bu::size offset );
119 virtual void setPos( Bu::size pos );
120 virtual void setPosEnd( Bu::size pos );
121 virtual bool isEos();
122 virtual bool isOpen();
123 virtual void flush();
124 virtual bool canRead();
125 virtual bool canWrite();
126 virtual bool isReadable();
127 virtual bool isWritable();
128 virtual bool isSeekable();
129 virtual bool isBlocking();
130 virtual void setBlocking( bool bBlocking=true );
131 virtual void setSize( Bu::size iSize );
132 virtual size getSize() const;
133 virtual size getBlockSize() const;
134 virtual Bu::String getLocation() const;
135
136 private:
137 void checkStack() const;
138
139 private:
140 FilterList lFilts;
141 };
142};
143
144#endif