From 162525457320b5dba9a4e736759f840757635231 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 18 Jul 2007 07:17:10 +0000 Subject: Incorporated a patch contributed by Brandon CS Sanders that allows libbu++ to compile under OSX. So far, no problems with anything else, it looks like build and nango both build without problems, libbu++ is truly becoming a full cross- platform toolkit. --- src/fstring.h | 41 ++++++++++++++++++++++++++++++----------- src/ito.cpp | 1 + src/server.cpp | 1 + src/serversocket.cpp | 11 ++++++++--- src/socket.cpp | 1 + src/tests/fstring.cpp | 4 ++++ src/unit/fstring.cpp | 9 +++++++++ 7 files changed, 54 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/fstring.h b/src/fstring.h index 72ac99d..4dee537 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -25,11 +25,11 @@ namespace Bu * generation in mind. Like the standard string class you can specify what * datatype to use for each character. Unlike the standard string class, * collection of appended and prepended terms is done lazily, making long - * operations that involve many appends very inexpensive. In addition internal - * ref-counting means that if you pass strings around between functions there's - * almost no overhead in time or memory since a reference is created and no - * data is actually copied. This also means that you never need to put any - * FBasicString into a ref-counting container class. + * operations that involve many appends very inexpensive. In addition + * internal ref-counting means that if you pass strings around between + * functions there's almost no overhead in time or memory since a reference + * is created and no data is actually copied. This also means that you + * never need to put any FBasicString into a ref-counting container class. * *@param chr (typename) Type of character (i.e. char) *@param nMinSize (int) Chunk size (default: 256) @@ -126,7 +126,7 @@ namespace Bu for( nLen = 0; pData[nLen] != (chr)0; nLen++ ); if( nLen == 0 ) return; - + Chunk *pNew = newChunk( nLen ); cpy( pNew->pData, pData, nLen ); @@ -156,7 +156,16 @@ namespace Bu */ void append( const chr &cData ) { - append( &cData, 1 ); + if( pLast && pLast->nLength < nMinSize ) + { + pLast->pData[pLast->nLength] = cData; + ++pLast->nLength; ++nLength; + // pLast->pData[pLast->nLength] = (chr)0; + } + else + { + append( &cData, 1 ); + } } /** @@ -323,11 +332,21 @@ namespace Bu * Plus equals operator for FString. *@param pData (const chr) The character to append to your FString. */ - MyType &operator +=( const chr pData ) + MyType &operator +=( const chr cData ) { - append( &pData, 1 ); + if( pLast && pLast->nLength < nMinSize ) + { + pLast->pData[pLast->nLength] = cData; + ++pLast->nLength; ++nLength; + // pLast->pData[pLast->nLength] = (chr)0; + } + else + { + append( &cData, 1 ); + } + //append( pData ); - return (*this); + //return (*this); } /** @@ -714,7 +733,7 @@ namespace Bu Chunk *pNew = aChunk.allocate( 1 ); pNew->pNext = NULL; pNew->nLength = nLen; - pNew->pData = aChr.allocate( nLen+1 ); + pNew->pData = aChr.allocate( (nLenpData[nLen] = (chr)0; return pNew; } diff --git a/src/ito.cpp b/src/ito.cpp index 001ca06..231e822 100644 --- a/src/ito.cpp +++ b/src/ito.cpp @@ -1,4 +1,5 @@ #include "ito.h" +#include "osx_compatibility.h" Bu::Ito::Ito() { diff --git a/src/server.cpp b/src/server.cpp index d07a597..53b4301 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3,6 +3,7 @@ #include "bu/serversocket.h" #include "bu/client.h" #include "bu/socket.h" +#include "osx_compatibility.h" Bu::Server::Server() : nTimeoutSec( 0 ), diff --git a/src/serversocket.cpp b/src/serversocket.cpp index 1424630..010c562 100644 --- a/src/serversocket.cpp +++ b/src/serversocket.cpp @@ -13,6 +13,7 @@ #include #include "serversocket.h" #include "exceptions.h" +#include "osx_compatibility.h" Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : nPort( nPort ) @@ -117,9 +118,13 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) nClient = ::accept( nServer, (struct sockaddr *)&clientname, (int *)&size ); -#else - nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); -#endif +#else /* not-cygwin */ +#ifdef __APPLE__ + nClient = ::accept( nServer, (struct sockaddr *)&clientname, (socklen_t*)&size ); +#else /* linux */ + nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); +#endif /* __APPLE__ */ +#endif /* __CYGWIN__ */ if( nClient < 0 ) { throw SocketException( diff --git a/src/socket.cpp b/src/socket.cpp index 50ed4e2..ce4ee82 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -13,6 +13,7 @@ #include #include "socket.h" #include "exceptions.h" +#include "osx_compatibility.h" #define RBS (1024*2) diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp index 48dfc5f..11f147d 100644 --- a/src/tests/fstring.cpp +++ b/src/tests/fstring.cpp @@ -110,6 +110,10 @@ void doTimings() #define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); int main( int argc, char *argv ) { + Bu::FString fs1; + for( int j = 0; j < 500000; j++ ) fs1 += (char)('a'+(j%26)); + return 0; + Bu::FString str("th"); str.prepend("Hello "); diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp index 2c6bf7a..462ce5e 100644 --- a/src/unit/fstring.cpp +++ b/src/unit/fstring.cpp @@ -9,6 +9,7 @@ public: setName("FString"); addTest( Unit::compare1 ); addTest( Unit::compare2 ); + addTest( Unit::appendSingle ); } virtual ~Unit() @@ -28,6 +29,14 @@ public: unitTest( !(b == "Bob") ); unitTest( b == "Bobo" ); } + + void appendSingle() + { + Bu::FString b; + for( char l = 'a'; l < 'g'; l++ ) + b += l; + unitTest( b == "abcdef" ); + } }; int main( int argc, char *argv[] ) -- cgit v1.2.3