aboutsummaryrefslogtreecommitdiff
path: root/src/membuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/membuf.cpp')
-rw-r--r--src/membuf.cpp41
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
17Bu::MemBuf::MemBuf( const Bu::FString &str ) : 17Bu::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
31size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) 31size 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
42size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) 42size 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
69long Bu::MemBuf::tell() 69size Bu::MemBuf::tell()
70{ 70{
71 return nPos; 71 return nPos;
72} 72}
73 73
74void Bu::MemBuf::seek( long offset ) 74void 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
81void Bu::MemBuf::setPos( long pos ) 81void 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
88void Bu::MemBuf::setPosEnd( long pos ) 88void 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
143void Bu::MemBuf::setSize( long iSize ) 143void 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
152Bu::FString &Bu::MemBuf::getString() 152Bu::size Bu::MemBuf::getSize() const
153{
154 return sBuf.getSize();
155}
156
157Bu::size Bu::MemBuf::getBlockSize() const
158{
159 return sBuf.getSize();
160}
161
162Bu::String Bu::MemBuf::getLocation() const
163{
164 return "";
165}
166
167Bu::String &Bu::MemBuf::getString()
153{ 168{
154 return sBuf; 169 return sBuf;
155} 170}
156 171
157void Bu::MemBuf::setString( const Bu::FString &sNewData ) 172void Bu::MemBuf::setString( const Bu::String &sNewData )
158{ 173{
159 sBuf = sNewData; 174 sBuf = sNewData;
160 nPos = 0; 175 nPos = 0;