diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 18:09:04 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2011-01-20 18:09:04 +0000 |
| commit | 393f1b414746a7f1977971dd7659dd2b47092b11 (patch) | |
| tree | 81d0ca1ee70ab86a7d79c1991abe5c387b655fb2 /src/membuf.cpp | |
| parent | c259f95bd0e58b247940a339bb9b4b401b4e9438 (diff) | |
| parent | 7e25a863325dc3e9762397e700030969e093b087 (diff) | |
| download | libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.gz libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.bz2 libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.xz libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.zip | |
Wow! Merged the branch, streams are updated, and there's no more FString, run
the fixstrings.sh script in the support directory to (hopefully) automatically
update your projects.
Diffstat (limited to 'src/membuf.cpp')
| -rw-r--r-- | src/membuf.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/membuf.cpp b/src/membuf.cpp index b822641..14d0d58 100644 --- a/src/membuf.cpp +++ b/src/membuf.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2007-2010 Xagasoft, All rights reserved. | 2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. |
| 3 | * | 3 | * |
| 4 | * This file is part of the libbu++ library and is released under the | 4 | * This file is part of the libbu++ library and is released under the |
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
| @@ -14,7 +14,7 @@ Bu::MemBuf::MemBuf() : | |||
| 14 | { | 14 | { |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | Bu::MemBuf::MemBuf( const Bu::FString &str ) : | 17 | Bu::MemBuf::MemBuf( const Bu::String &str ) : |
| 18 | sBuf( str ), | 18 | sBuf( str ), |
| 19 | nPos( 0 ) | 19 | nPos( 0 ) |
| 20 | { | 20 | { |
| @@ -28,9 +28,9 @@ void Bu::MemBuf::close() | |||
| 28 | { | 28 | { |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) | 31 | size Bu::MemBuf::read( void *pBuf, size nBytes ) |
| 32 | { | 32 | { |
| 33 | if( (size_t)sBuf.getSize()-(size_t)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 ); |
| @@ -39,7 +39,7 @@ size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) | |||
| 39 | return nBytes; | 39 | return nBytes; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | size_t Bu::MemBuf::write( const void *pBuf, size_t 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 | { |
| @@ -52,7 +52,7 @@ size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) | |||
| 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_t 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 ); |
| @@ -66,26 +66,26 @@ size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) | |||
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | long 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( long 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( long 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( long 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; |
| @@ -140,7 +140,7 @@ void Bu::MemBuf::setBlocking( bool ) | |||
| 140 | { | 140 | { |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | void Bu::MemBuf::setSize( long iSize ) | 143 | void Bu::MemBuf::setSize( size iSize ) |
| 144 | { | 144 | { |
| 145 | if( iSize < 0 ) | 145 | if( iSize < 0 ) |
| 146 | iSize = 0; | 146 | iSize = 0; |
| @@ -149,12 +149,27 @@ void Bu::MemBuf::setSize( long iSize ) | |||
| 149 | nPos = iSize; | 149 | nPos = iSize; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | Bu::FString &Bu::MemBuf::getString() | 152 | Bu::size Bu::MemBuf::getSize() const |
| 153 | { | ||
| 154 | return sBuf.getSize(); | ||
| 155 | } | ||
| 156 | |||
| 157 | Bu::size Bu::MemBuf::getBlockSize() const | ||
| 158 | { | ||
| 159 | return sBuf.getSize(); | ||
| 160 | } | ||
| 161 | |||
| 162 | Bu::String Bu::MemBuf::getLocation() const | ||
| 163 | { | ||
| 164 | return ""; | ||
| 165 | } | ||
| 166 | |||
| 167 | Bu::String &Bu::MemBuf::getString() | ||
| 153 | { | 168 | { |
| 154 | return sBuf; | 169 | return sBuf; |
| 155 | } | 170 | } |
| 156 | 171 | ||
| 157 | void Bu::MemBuf::setString( const Bu::FString &sNewData ) | 172 | void Bu::MemBuf::setString( const Bu::String &sNewData ) |
| 158 | { | 173 | { |
| 159 | sBuf = sNewData; | 174 | sBuf = sNewData; |
| 160 | nPos = 0; | 175 | nPos = 0; |
