From 2cd1a89109651a19138aec9988d765208d7709e5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 1 Nov 2010 23:15:11 +0000 Subject: Minor changes to the float that may circumvent some stupidness in the mingwrt snprintf code. I really need to write my own number parser/writer. --- src/float.cpp | 19 +++++++++++++------ src/float.h | 3 +++ src/gatsstream.cpp | 20 ++++++++++---------- 3 files changed, 26 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/float.cpp b/src/float.cpp index 139df3e..e85dff8 100644 --- a/src/float.cpp +++ b/src/float.cpp @@ -19,21 +19,28 @@ Gats::Float::~Float() void Gats::Float::write( Bu::Stream &rOut ) const { - char buf[50]; - - int iSize = snprintf( buf, 50, "%la", fVal ); + if( sWriteCache.isEmpty() ) + { + char buf[50]; + int iSize = snprintf( buf, 50, "%la", fVal ); + sWriteCache.set( buf, iSize ); + } rOut.write("f", 1 ); - Gats::Integer::writePackedInt( rOut, iSize ); - rOut.write( buf, iSize ); + Gats::Integer::writePackedInt( rOut, sWriteCache.getSize() ); + rOut.write( sWriteCache.getStr(), sWriteCache.getSize() ); } +#include +using namespace Bu; + void Gats::Float::read( Bu::Stream &rIn, char cType ) { int iSize; Gats::Integer::readPackedInt( rIn, iSize ); char buf[50]; - rIn.read( buf, iSize ); + buf[rIn.read( buf, iSize )] = '\0'; + sio << "Reading float, iSize = " << iSize << ", str = " << buf << sio.nl; sscanf( buf, "%la", &fVal ); } diff --git a/src/float.h b/src/float.h index 27233ae..f7a3ed3 100644 --- a/src/float.h +++ b/src/float.h @@ -3,6 +3,8 @@ #include "gats/object.h" +#include + namespace Gats { class Float : public Gats::Object @@ -20,6 +22,7 @@ namespace Gats private: double fVal; + mutable Bu::FString sWriteCache; }; } diff --git a/src/gatsstream.cpp b/src/gatsstream.cpp index 3e9b211..71372db 100644 --- a/src/gatsstream.cpp +++ b/src/gatsstream.cpp @@ -7,9 +7,9 @@ #include #endif -// #include +#include #include -// using namespace Bu; +using namespace Bu; Gats::GatsStream::GatsStream( Bu::Stream &rStream ) : rStream( rStream ) @@ -40,40 +40,40 @@ Gats::Object *Gats::GatsStream::readObject() uint8_t uVer; qbRead.peek( &uVer, 1 ); - // sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; + sio << "Gats::GatsStream::readObject(): Packet version: " << (int)uVer << sio.nl; int32_t iSize; qbRead.peek( &iSize, 4, 1 ); iSize = ntohl( iSize ); - // sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; + sio << "Gats::GatsStream::readObject(): Header read, looking for " << iSize << "b, we have " << qbRead.getSize() << "b." << sio.nl; while( qbRead.getSize() < iSize ) { int32_t iRead = iSize - qbRead.getSize(); if( iRead > 1500 ) iRead = 1500; - // sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; + sio << "Gats::GatsStream::readObject(): Attempting to read " << iRead << "b." << sio.nl; int32_t iReal = rStream.read( buf, iRead ); - // sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; + sio << "Gats::GatsStream::readObject(): Read " << iReal << "b." << sio.nl; qbRead.write( buf, iReal ); if( iReal < iRead ) { - // sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; + sio << "Gats::GatsStream::readObject(): Insufficient data read in block, bailing on read." << sio.nl; return NULL; } } if( qbRead.getSize() < iSize ) { - // sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; + sio << "Gats::GatsStream::readObject(): Somehow, we still don't have enough data, bailing." << sio.nl; return NULL; } - // sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; + sio << "Gats::GatsStream::readObject(): We have " << qbRead.getSize() << "b of " << iSize << "b, time to read the object." << sio.nl; qbRead.seek( 5 ); Gats::Object *pObj = Gats::Object::read( qbRead ); - // sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; + sio << "Gats::GatsStream::readObject(): Read completed, there are " << qbRead.getSize() << "b left in the buffer." << sio.nl; return pObj; } -- cgit v1.2.3