diff options
author | Mike Buland <mike@xagasoft.com> | 2024-08-28 11:45:51 -0700 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2024-08-28 11:45:51 -0700 |
commit | 0886ad4f53deb8e148f87f77b9e7ff690c02b069 (patch) | |
tree | c40ccf830b944d8172566b6e3c5d4e4ca0fc7712 /src/stable/myriadstream.cpp | |
parent | f1e3f25d9b7a12cdedb99e4cb0bfa66157a1a972 (diff) | |
download | libbu++-0886ad4f53deb8e148f87f77b9e7ff690c02b069.tar.gz libbu++-0886ad4f53deb8e148f87f77b9e7ff690c02b069.tar.bz2 libbu++-0886ad4f53deb8e148f87f77b9e7ff690c02b069.tar.xz libbu++-0886ad4f53deb8e148f87f77b9e7ff690c02b069.zip |
Most of the new myriad api is in.
Still to go: bootstrapping reading the initial header, saving the
header, growing streams as we write?
Diffstat (limited to 'src/stable/myriadstream.cpp')
-rw-r--r-- | src/stable/myriadstream.cpp | 72 |
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 | ||
20 | Bu::MyriadStream::~MyriadStream() | 35 | Bu::MyriadStream::~MyriadStream() |
@@ -34,93 +49,120 @@ void Bu::MyriadStream::close() | |||
34 | 49 | ||
35 | Bu::size Bu::MyriadStream::read( void *pBuf, size iBytes ) | 50 | Bu::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 ); | |
39 | Bu::String Bu::MyriadStream::readLine() | 54 | iPos += iRead; |
40 | { | 55 | return iRead; |
41 | } | ||
42 | |||
43 | Bu::String Bu::MyriadStream::readAll() | ||
44 | { | ||
45 | } | 56 | } |
46 | 57 | ||
47 | Bu::size Bu::MyriadStream::write( const void *pBuf, size iBytes ) | 58 | Bu::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 ); | |
51 | Bu::size Bu::MyriadStream::write( const Bu::String &sBuf ) | 62 | iPos += iWrite; |
52 | { | 63 | return iWrite; |
53 | } | 64 | } |
54 | 65 | ||
55 | Bu::size Bu::MyriadStream::tell() | 66 | Bu::size Bu::MyriadStream::tell() |
56 | { | 67 | { |
68 | Bu::MutexLocker l( mAccess ); | ||
69 | return iPos; | ||
57 | } | 70 | } |
58 | 71 | ||
59 | void Bu::MyriadStream::seek( size offset ) | 72 | void Bu::MyriadStream::seek( size offset ) |
60 | { | 73 | { |
74 | Bu::MutexLocker l( mAccess ); | ||
75 | iPos += offset; | ||
61 | } | 76 | } |
62 | 77 | ||
63 | void Bu::MyriadStream::setPos( size pos ) | 78 | void Bu::MyriadStream::setPos( size pos ) |
64 | { | 79 | { |
80 | Bu::MutexLocker l( mAccess ); | ||
81 | iPos = pos; | ||
65 | } | 82 | } |
66 | 83 | ||
67 | void Bu::MyriadStream::setPosEnd( size pos ) | 84 | void Bu::MyriadStream::setPosEnd( size pos ) |
68 | { | 85 | { |
86 | Bu::MutexLocker l( mAccess ); | ||
87 | iPos = pStream->getSize()-pos; | ||
69 | } | 88 | } |
70 | 89 | ||
71 | bool Bu::MyriadStream::isEos() | 90 | bool Bu::MyriadStream::isEos() |
72 | { | 91 | { |
92 | Bu::MutexLocker l( mAccess ); | ||
93 | return iPos == pStream->getSize(); | ||
73 | } | 94 | } |
74 | 95 | ||
75 | bool Bu::MyriadStream::isOpen() | 96 | bool Bu::MyriadStream::isOpen() |
76 | { | 97 | { |
98 | return true; | ||
77 | } | 99 | } |
78 | 100 | ||
79 | void Bu::MyriadStream::flush() | 101 | void Bu::MyriadStream::flush() |
80 | { | 102 | { |
103 | // Does this make sense? | ||
81 | } | 104 | } |
82 | 105 | ||
83 | bool Bu::MyriadStream::canRead() | 106 | bool Bu::MyriadStream::canRead() |
84 | { | 107 | { |
108 | return true; | ||
85 | } | 109 | } |
86 | 110 | ||
87 | bool Bu::MyriadStream::canWrite() | 111 | bool Bu::MyriadStream::canWrite() |
88 | { | 112 | { |
113 | return true; | ||
89 | } | 114 | } |
90 | 115 | ||
91 | bool Bu::MyriadStream::isReadable() | 116 | bool Bu::MyriadStream::isReadable() |
92 | { | 117 | { |
118 | Bu::MutexLocker l( mAccess ); | ||
119 | return (eMode&Bu::Myriad::Read) != 0; | ||
93 | } | 120 | } |
94 | 121 | ||
95 | bool Bu::MyriadStream::isWritable() | 122 | bool Bu::MyriadStream::isWritable() |
96 | { | 123 | { |
124 | Bu::MutexLocker l( mAccess ); | ||
125 | return (eMode&Bu::Myriad::Write) != 0; | ||
97 | } | 126 | } |
98 | 127 | ||
99 | bool Bu::MyriadStream::isSeekable() | 128 | bool Bu::MyriadStream::isSeekable() |
100 | { | 129 | { |
130 | return true; | ||
101 | } | 131 | } |
102 | 132 | ||
103 | bool Bu::MyriadStream::isBlocking() | 133 | bool Bu::MyriadStream::isBlocking() |
104 | { | 134 | { |
135 | return true; | ||
105 | } | 136 | } |
106 | 137 | ||
107 | void Bu::MyriadStream::setBlocking( bool bBlocking ) | 138 | void Bu::MyriadStream::setBlocking( bool /*bBlocking*/ ) |
108 | { | 139 | { |
140 | // Dunno what this would even mean here. | ||
109 | } | 141 | } |
110 | 142 | ||
111 | void Bu::MyriadStream::setSize( size iSize ) | 143 | void 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 | ||
115 | Bu::size Bu::MyriadStream::getSize() const | 151 | Bu::size Bu::MyriadStream::getSize() const |
116 | { | 152 | { |
153 | Bu::MutexLocker l( mAccess ); | ||
154 | return pStream->getSize(); | ||
117 | } | 155 | } |
118 | 156 | ||
119 | Bu::size Bu::MyriadStream::getBlockSize() const | 157 | Bu::size Bu::MyriadStream::getBlockSize() const |
120 | { | 158 | { |
159 | Bu::MutexLocker l( mAccess ); | ||
160 | return pStream->getBlockSize(); | ||
121 | } | 161 | } |
122 | 162 | ||
123 | Bu::String getLocation() const | 163 | Bu::String Bu::MyriadStream::getLocation() const |
124 | { | 164 | { |
165 | Bu::MutexLocker l( mAccess ); | ||
166 | return pStream->getLocation(); | ||
125 | } | 167 | } |
126 | 168 | ||