[PATCH] Add support for bool for the operator << and >> of SvStream
In order to use the type bool when appropriate
-- instead of an unsigned char to mimic it --
SvStream need to be extended to support the serialization of
bool elements.
 tools/inc/tools/stream.hxx     |    2 ++
 tools/source/stream/stream.cxx |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/tools/inc/tools/stream.hxx b/tools/inc/tools/stream.hxx
index 0ce15bc..ad1d27a 100644
--- a/tools/inc/tools/stream.hxx
+++ b/tools/inc/tools/stream.hxx
@@ -361,6 +361,7 @@ public:
     SvStream&          operator>>( signed char& rChar );
     SvStream&          operator>>( char& rChar );
     SvStream&          operator>>( unsigned char& rChar );
+    SvStream&          operator>>( bool& rBool );
     SvStream&          operator>>( float& rFloat );
     SvStream&          operator>>( double& rDouble );
 #ifdef ENABLE_BYTESTRING_STREAM_OPERATORS
@@ -379,6 +380,7 @@ public:
     SvStream&          operator<<( signed char nChar );
     SvStream&          operator<<( char nChar );
     SvStream&          operator<<( unsigned char nChar );
+    SvStream&          operator<<( bool nBool );
     SvStream&          operator<<( float nFloat );
     SvStream&          operator<<( const double& rDouble );
     SvStream&          operator<<( const char* pBuf );
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index e4395cf..5ff0d8e 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1271,6 +1271,21 @@ SvStream& SvStream::operator>>( unsigned char& r )
     return *this;
 }
+SvStream& SvStream::operator>>( bool& r )
+{
+    if( (eIOMode == STREAM_IO_READ || !bIsConsistent) &&
+        sizeof(char) <= nBufFree )
+    {
+        r = *pBufPos ? true : false;
+        nBufActualPos += sizeof(bool);
+        pBufPos += sizeof(bool);
+        nBufFree -= sizeof(bool);
+    }
+    else
+        Read( (char*)&r, sizeof(bool) );
+    return *this;
+}
+
 SvStream& SvStream::operator>>( float& r )
 {
     // Read( (char*)&r, sizeof(float) );
@@ -1422,6 +1437,25 @@ SvStream& SvStream::operator<<  ( unsigned char v )
     return *this;
 }
+SvStream& SvStream::operator<<  ( bool v )
+{
+    int tmp = eIOMode;
+
+    if(tmp == STREAM_IO_WRITE && sizeof(char) <= nBufFree )
+    {
+        *(unsigned char*)pBufPos = (unsigned char)v;
+        pBufPos++; // = sizeof(bool);
+        nBufActualPos++; // = sizeof(bool);
+        if( nBufActualPos > nBufActualLen )  // Append ?
+            nBufActualLen = nBufActualPos;
+        nBufFree--;
+        bIsDirty = TRUE;
+    }
+    else
+        Write( (char*)&v, sizeof(bool) );
+    return *this;
+}
+
 SvStream& SvStream::operator<< ( float v )
 {
 #ifdef UNX
-- 
1.7.1
Context
- [Libreoffice] [PATCH] Add support for bool for the operator << and	>> of SvStream · Norbert Thiebaud
 
   
 
  Privacy Policy |
  
Impressum (Legal Info) |
  
Copyright information: Unless otherwise specified, all text and images
  on this website are licensed under the
  
Creative Commons Attribution-Share Alike 3.0 License.
  This does not include the source code of LibreOffice, which is
  licensed under the Mozilla Public License (
MPLv2).
  "LibreOffice" and "The Document Foundation" are
  registered trademarks of their corresponding registered owners or are
  in actual use as trademarks in one or more countries. Their respective
  logos and icons are also subject to international copyright laws. Use
  thereof is explained in our 
trademark policy.