aboutsummaryrefslogtreecommitdiff
path: root/src/stable/myriadstream.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/stable/myriadstream.cpp72
1 files changed, 57 insertions, 15 deletions
diff --git a/src/stable/myriadstream.cpp b/src/stable/myriadstream.cpp
index cbbd4fe..9ea2e17 100644
--- a/src/stable/myriadstream.cpp
+++ b/src/stable/myriadstream.cpp
@@ -6,7 +6,8 @@ Bu::MyriadStream::MyriadStream( Bu::Myriad &rMyriad,
6 Bu::Myriad::Stream *pStream, Bu::Myriad::Mode eMode ) : 6 Bu::Myriad::Stream *pStream, Bu::Myriad::Mode eMode ) :
7 rMyriad( rMyriad ), 7 rMyriad( rMyriad ),
8 pStream( pStream ), 8 pStream( pStream ),
9 eMode( eMode ) 9 eMode( eMode ),
10 iPos( 0 )
10{ 11{
11 if( (eMode&Bu::Myriad::ReadWrite) == 0 ) 12 if( (eMode&Bu::Myriad::ReadWrite) == 0 )
12 { 13 {
@@ -15,6 +16,20 @@ Bu::MyriadStream::MyriadStream( Bu::Myriad &rMyriad,
15 } 16 }
16 Bu::MutexLocker l( mAccess ); 17 Bu::MutexLocker l( mAccess );
17 pStream->open(); 18 pStream->open();
19
20 if( (eMode&Bu::Myriad::Write) != 0 )
21 {
22 // Writing mode, what other options do we deal with?
23 if( (eMode&Bu::Myriad::Truncate) != 0 )
24 {
25 // Truncate, set size to zero before starting.
26 pStream->setSize( 0 );
27 }
28 else if( (eMode&Bu::Myriad::Append) != 0 )
29 {
30 iPos = pStream->getSize();
31 }
32 }
18} 33}
19 34
20Bu::MyriadStream::~MyriadStream() 35Bu::MyriadStream::~MyriadStream()
@@ -34,93 +49,120 @@ void Bu::MyriadStream::close()
34 49
35Bu::size Bu::MyriadStream::read( void *pBuf, size iBytes ) 50Bu::size Bu::MyriadStream::read( void *pBuf, size iBytes )
36{ 51{
37} 52 Bu::MutexLocker l( mAccess );
38 53 int32_t iRead = pStream->read( iPos, pBuf, iBytes );
39Bu::String Bu::MyriadStream::readLine() 54 iPos += iRead;
40{ 55 return iRead;
41}
42
43Bu::String Bu::MyriadStream::readAll()
44{
45} 56}
46 57
47Bu::size Bu::MyriadStream::write( const void *pBuf, size iBytes ) 58Bu::size Bu::MyriadStream::write( const void *pBuf, size iBytes )
48{ 59{
49} 60 Bu::MutexLocker l( mAccess );
50 61 int32_t iWrite = pStream->write( iPos, pBuf, iBytes );
51Bu::size Bu::MyriadStream::write( const Bu::String &sBuf ) 62 iPos += iWrite;
52{ 63 return iWrite;
53} 64}
54 65
55Bu::size Bu::MyriadStream::tell() 66Bu::size Bu::MyriadStream::tell()
56{ 67{
68 Bu::MutexLocker l( mAccess );
69 return iPos;
57} 70}
58 71
59void Bu::MyriadStream::seek( size offset ) 72void Bu::MyriadStream::seek( size offset )
60{ 73{
74 Bu::MutexLocker l( mAccess );
75 iPos += offset;
61} 76}
62 77
63void Bu::MyriadStream::setPos( size pos ) 78void Bu::MyriadStream::setPos( size pos )
64{ 79{
80 Bu::MutexLocker l( mAccess );
81 iPos = pos;
65} 82}
66 83
67void Bu::MyriadStream::setPosEnd( size pos ) 84void Bu::MyriadStream::setPosEnd( size pos )
68{ 85{
86 Bu::MutexLocker l( mAccess );
87 iPos = pStream->getSize()-pos;
69} 88}
70 89
71bool Bu::MyriadStream::isEos() 90bool Bu::MyriadStream::isEos()
72{ 91{
92 Bu::MutexLocker l( mAccess );
93 return iPos == pStream->getSize();
73} 94}
74 95
75bool Bu::MyriadStream::isOpen() 96bool Bu::MyriadStream::isOpen()
76{ 97{
98 return true;
77} 99}
78 100
79void Bu::MyriadStream::flush() 101void Bu::MyriadStream::flush()
80{ 102{
103 // Does this make sense?
81} 104}
82 105
83bool Bu::MyriadStream::canRead() 106bool Bu::MyriadStream::canRead()
84{ 107{
108 return true;
85} 109}
86 110
87bool Bu::MyriadStream::canWrite() 111bool Bu::MyriadStream::canWrite()
88{ 112{
113 return true;
89} 114}
90 115
91bool Bu::MyriadStream::isReadable() 116bool Bu::MyriadStream::isReadable()
92{ 117{
118 Bu::MutexLocker l( mAccess );
119 return (eMode&Bu::Myriad::Read) != 0;
93} 120}
94 121
95bool Bu::MyriadStream::isWritable() 122bool Bu::MyriadStream::isWritable()
96{ 123{
124 Bu::MutexLocker l( mAccess );
125 return (eMode&Bu::Myriad::Write) != 0;
97} 126}
98 127
99bool Bu::MyriadStream::isSeekable() 128bool Bu::MyriadStream::isSeekable()
100{ 129{
130 return true;
101} 131}
102 132
103bool Bu::MyriadStream::isBlocking() 133bool Bu::MyriadStream::isBlocking()
104{ 134{
135 return true;
105} 136}
106 137
107void Bu::MyriadStream::setBlocking( bool bBlocking ) 138void Bu::MyriadStream::setBlocking( bool /*bBlocking*/ )
108{ 139{
140 // Dunno what this would even mean here.
109} 141}
110 142
111void Bu::MyriadStream::setSize( size iSize ) 143void Bu::MyriadStream::setSize( size iSize )
112{ 144{
145 Bu::MutexLocker l( mAccess );
146 pStream->setSize( iSize );
147 if( iPos > iSize )
148 iPos = iSize;
113} 149}
114 150
115Bu::size Bu::MyriadStream::getSize() const 151Bu::size Bu::MyriadStream::getSize() const
116{ 152{
153 Bu::MutexLocker l( mAccess );
154 return pStream->getSize();
117} 155}
118 156
119Bu::size Bu::MyriadStream::getBlockSize() const 157Bu::size Bu::MyriadStream::getBlockSize() const
120{ 158{
159 Bu::MutexLocker l( mAccess );
160 return pStream->getBlockSize();
121} 161}
122 162
123Bu::String getLocation() const 163Bu::String Bu::MyriadStream::getLocation() const
124{ 164{
165 Bu::MutexLocker l( mAccess );
166 return pStream->getLocation();
125} 167}
126 168