diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/membuf.cpp | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/membuf.cpp')
-rw-r--r-- | src/stable/membuf.cpp | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/src/stable/membuf.cpp b/src/stable/membuf.cpp index dea9a0e..4d6e8e6 100644 --- a/src/stable/membuf.cpp +++ b/src/stable/membuf.cpp | |||
@@ -10,13 +10,13 @@ | |||
10 | using namespace Bu; | 10 | using namespace Bu; |
11 | 11 | ||
12 | Bu::MemBuf::MemBuf() : | 12 | Bu::MemBuf::MemBuf() : |
13 | nPos( 0 ) | 13 | nPos( 0 ) |
14 | { | 14 | { |
15 | } | 15 | } |
16 | 16 | ||
17 | Bu::MemBuf::MemBuf( const Bu::String &str ) : | 17 | Bu::MemBuf::MemBuf( const Bu::String &str ) : |
18 | sBuf( str ), | 18 | sBuf( str ), |
19 | nPos( 0 ) | 19 | nPos( 0 ) |
20 | { | 20 | { |
21 | } | 21 | } |
22 | 22 | ||
@@ -30,76 +30,76 @@ void Bu::MemBuf::close() | |||
30 | 30 | ||
31 | size Bu::MemBuf::read( void *pBuf, size nBytes ) | 31 | size Bu::MemBuf::read( void *pBuf, size nBytes ) |
32 | { | 32 | { |
33 | if( (size)sBuf.getSize()-(size)nPos < nBytes ) | 33 | if( (size)sBuf.getSize()-(size)nPos < nBytes ) |
34 | nBytes = sBuf.getSize()-nPos; | 34 | nBytes = sBuf.getSize()-nPos; |
35 | 35 | ||
36 | memcpy( pBuf, sBuf.getStr()+nPos, nBytes ); | 36 | memcpy( pBuf, sBuf.getStr()+nPos, nBytes ); |
37 | nPos += nBytes; | 37 | nPos += nBytes; |
38 | 38 | ||
39 | return nBytes; | 39 | return nBytes; |
40 | } | 40 | } |
41 | 41 | ||
42 | size Bu::MemBuf::write( const void *pBuf, size nBytes ) | 42 | size Bu::MemBuf::write( const void *pBuf, size nBytes ) |
43 | { | 43 | { |
44 | if( nPos == sBuf.getSize() ) | 44 | if( nPos == sBuf.getSize() ) |
45 | { | 45 | { |
46 | // Easiest, just append the data. | 46 | // Easiest, just append the data. |
47 | sBuf.append( (const char *)pBuf, nBytes ); | 47 | sBuf.append( (const char *)pBuf, nBytes ); |
48 | nPos += nBytes; | 48 | nPos += nBytes; |
49 | return nBytes; | 49 | return nBytes; |
50 | } | 50 | } |
51 | else | 51 | else |
52 | { | 52 | { |
53 | // Trickier, we must do this in two parts, overwrite, then append | 53 | // Trickier, we must do this in two parts, overwrite, then append |
54 | // Frist, overwrite. | 54 | // Frist, overwrite. |
55 | size iOver = sBuf.getSize() - nPos; | 55 | size iOver = sBuf.getSize() - nPos; |
56 | if( iOver > nBytes ) | 56 | if( iOver > nBytes ) |
57 | iOver = nBytes; | 57 | iOver = nBytes; |
58 | memcpy( sBuf.getStr()+nPos, pBuf, iOver ); | 58 | memcpy( sBuf.getStr()+nPos, pBuf, iOver ); |
59 | // Then append | 59 | // Then append |
60 | if( iOver < nBytes ) | 60 | if( iOver < nBytes ) |
61 | { | 61 | { |
62 | sBuf.append( ((const char *)pBuf)+iOver, nBytes-iOver ); | 62 | sBuf.append( ((const char *)pBuf)+iOver, nBytes-iOver ); |
63 | } | 63 | } |
64 | nPos += nBytes; | 64 | nPos += nBytes; |
65 | return nBytes; | 65 | return nBytes; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | size Bu::MemBuf::tell() | 69 | size Bu::MemBuf::tell() |
70 | { | 70 | { |
71 | return nPos; | 71 | return nPos; |
72 | } | 72 | } |
73 | 73 | ||
74 | void Bu::MemBuf::seek( size offset ) | 74 | void Bu::MemBuf::seek( size offset ) |
75 | { | 75 | { |
76 | nPos += offset; | 76 | nPos += offset; |
77 | if( nPos < 0 ) nPos = 0; | 77 | if( nPos < 0 ) nPos = 0; |
78 | else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); | 78 | else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); |
79 | } | 79 | } |
80 | 80 | ||
81 | void Bu::MemBuf::setPos( size pos ) | 81 | void Bu::MemBuf::setPos( size pos ) |
82 | { | 82 | { |
83 | nPos = pos; | 83 | nPos = pos; |
84 | if( nPos < 0 ) nPos = 0; | 84 | if( nPos < 0 ) nPos = 0; |
85 | else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); | 85 | else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); |
86 | } | 86 | } |
87 | 87 | ||
88 | void Bu::MemBuf::setPosEnd( size pos ) | 88 | void Bu::MemBuf::setPosEnd( size pos ) |
89 | { | 89 | { |
90 | nPos = sBuf.getSize()-pos; | 90 | nPos = sBuf.getSize()-pos; |
91 | if( nPos < 0 ) nPos = 0; | 91 | if( nPos < 0 ) nPos = 0; |
92 | else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); | 92 | else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); |
93 | } | 93 | } |
94 | 94 | ||
95 | bool Bu::MemBuf::isEos() | 95 | bool Bu::MemBuf::isEos() |
96 | { | 96 | { |
97 | return (nPos == sBuf.getSize()); | 97 | return (nPos == sBuf.getSize()); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool Bu::MemBuf::isOpen() | 100 | bool Bu::MemBuf::isOpen() |
101 | { | 101 | { |
102 | return true; | 102 | return true; |
103 | } | 103 | } |
104 | 104 | ||
105 | void Bu::MemBuf::flush() | 105 | void Bu::MemBuf::flush() |
@@ -108,32 +108,32 @@ void Bu::MemBuf::flush() | |||
108 | 108 | ||
109 | bool Bu::MemBuf::canRead() | 109 | bool Bu::MemBuf::canRead() |
110 | { | 110 | { |
111 | return !isEos(); | 111 | return !isEos(); |
112 | } | 112 | } |
113 | 113 | ||
114 | bool Bu::MemBuf::canWrite() | 114 | bool Bu::MemBuf::canWrite() |
115 | { | 115 | { |
116 | return true; | 116 | return true; |
117 | } | 117 | } |
118 | 118 | ||
119 | bool Bu::MemBuf::isReadable() | 119 | bool Bu::MemBuf::isReadable() |
120 | { | 120 | { |
121 | return true; | 121 | return true; |
122 | } | 122 | } |
123 | 123 | ||
124 | bool Bu::MemBuf::isWritable() | 124 | bool Bu::MemBuf::isWritable() |
125 | { | 125 | { |
126 | return true; | 126 | return true; |
127 | } | 127 | } |
128 | 128 | ||
129 | bool Bu::MemBuf::isSeekable() | 129 | bool Bu::MemBuf::isSeekable() |
130 | { | 130 | { |
131 | return true; | 131 | return true; |
132 | } | 132 | } |
133 | 133 | ||
134 | bool Bu::MemBuf::isBlocking() | 134 | bool Bu::MemBuf::isBlocking() |
135 | { | 135 | { |
136 | return true; | 136 | return true; |
137 | } | 137 | } |
138 | 138 | ||
139 | void Bu::MemBuf::setBlocking( bool ) | 139 | void Bu::MemBuf::setBlocking( bool ) |
@@ -142,36 +142,36 @@ void Bu::MemBuf::setBlocking( bool ) | |||
142 | 142 | ||
143 | void Bu::MemBuf::setSize( size iSize ) | 143 | void Bu::MemBuf::setSize( size iSize ) |
144 | { | 144 | { |
145 | if( iSize < 0 ) | 145 | if( iSize < 0 ) |
146 | iSize = 0; | 146 | iSize = 0; |
147 | sBuf.setSize( iSize ); | 147 | sBuf.setSize( iSize ); |
148 | if( nPos > iSize ) | 148 | if( nPos > iSize ) |
149 | nPos = iSize; | 149 | nPos = iSize; |
150 | } | 150 | } |
151 | 151 | ||
152 | Bu::size Bu::MemBuf::getSize() const | 152 | Bu::size Bu::MemBuf::getSize() const |
153 | { | 153 | { |
154 | return sBuf.getSize(); | 154 | return sBuf.getSize(); |
155 | } | 155 | } |
156 | 156 | ||
157 | Bu::size Bu::MemBuf::getBlockSize() const | 157 | Bu::size Bu::MemBuf::getBlockSize() const |
158 | { | 158 | { |
159 | return sBuf.getSize(); | 159 | return sBuf.getSize(); |
160 | } | 160 | } |
161 | 161 | ||
162 | Bu::String Bu::MemBuf::getLocation() const | 162 | Bu::String Bu::MemBuf::getLocation() const |
163 | { | 163 | { |
164 | return ""; | 164 | return ""; |
165 | } | 165 | } |
166 | 166 | ||
167 | Bu::String &Bu::MemBuf::getString() | 167 | Bu::String &Bu::MemBuf::getString() |
168 | { | 168 | { |
169 | return sBuf; | 169 | return sBuf; |
170 | } | 170 | } |
171 | 171 | ||
172 | void Bu::MemBuf::setString( const Bu::String &sNewData ) | 172 | void Bu::MemBuf::setString( const Bu::String &sNewData ) |
173 | { | 173 | { |
174 | sBuf = sNewData; | 174 | sBuf = sNewData; |
175 | nPos = 0; | 175 | nPos = 0; |
176 | } | 176 | } |
177 | 177 | ||