From 7ebfdb3e7b71fdd315032adb0854e28f0073e1f7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 27 Sep 2021 08:04:28 -0700 Subject: Added explicit assignment/comparison operators. Added = and == to all primitive types, not to the container types (yet?). --- c++-libbu++/src/boolean.cpp | 24 ++++++++++++++++++++++++ c++-libbu++/src/boolean.h | 5 +++++ c++-libbu++/src/float.cpp | 22 ++++++++++++++++++++++ c++-libbu++/src/float.h | 5 +++++ c++-libbu++/src/integer.cpp | 22 ++++++++++++++++++++++ c++-libbu++/src/integer.h | 5 +++++ c++-libbu++/src/string.cpp | 33 +++++++++++++++++++++++++++++++++ c++-libbu++/src/string.h | 7 +++++++ 8 files changed, 123 insertions(+) diff --git a/c++-libbu++/src/boolean.cpp b/c++-libbu++/src/boolean.cpp index e442c2c..d4702a5 100644 --- a/c++-libbu++/src/boolean.cpp +++ b/c++-libbu++/src/boolean.cpp @@ -54,6 +54,30 @@ void Gats::Boolean::read( Bu::Stream &rIn, char cType ) } } +Gats::Boolean &Gats::Boolean::operator=( const Gats::Boolean &rhs ) +{ + bVal = rhs.bVal; + + return *this; +} + +Gats::Boolean &Gats::Boolean::operator=( bool rhs ) +{ + bVal = rhs; + + return *this; +} + +bool Gats::Boolean::operator==( const Gats::Boolean &rhs ) const +{ + return bVal == rhs.bVal; +} + +bool Gats::Boolean::operator==( bool rhs ) const +{ + return bVal == rhs; +} + Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Boolean &b ) { return f << "(bool) " << b.getValue(); diff --git a/c++-libbu++/src/boolean.h b/c++-libbu++/src/boolean.h index 2fed713..ac01762 100644 --- a/c++-libbu++/src/boolean.h +++ b/c++-libbu++/src/boolean.h @@ -27,6 +27,11 @@ namespace Gats virtual void write( Bu::Stream &rOut ) const; virtual void read( Bu::Stream &rIn, char cType ); + Gats::Boolean &operator=( const Gats::Boolean &rhs ); + Gats::Boolean &operator=( bool rhs ); + bool operator==( const Gats::Boolean &rhs ) const; + bool operator==( bool rhs ) const; + private: bool bVal; }; diff --git a/c++-libbu++/src/float.cpp b/c++-libbu++/src/float.cpp index c011794..409efd7 100644 --- a/c++-libbu++/src/float.cpp +++ b/c++-libbu++/src/float.cpp @@ -130,6 +130,28 @@ void Gats::Float::read( Bu::Stream &rIn, char cType ) } } +Gats::Float &Gats::Float::operator=( const Gats::Float &rhs ) +{ + fVal = rhs.fVal; + return *this; +} + +Gats::Float &Gats::Float::operator=( float &rhs ) +{ + fVal = rhs; + return *this; +} + +bool Gats::Float::operator==( const Gats::Float &rhs ) const +{ + return fVal == rhs.fVal; +} + +bool Gats::Float::operator==( float rhs ) const +{ + return fVal == rhs; +} + Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Float &flt ) { return f << "(float) " << flt.getValue(); diff --git a/c++-libbu++/src/float.h b/c++-libbu++/src/float.h index 9aab0a5..0e42f76 100644 --- a/c++-libbu++/src/float.h +++ b/c++-libbu++/src/float.h @@ -29,6 +29,11 @@ namespace Gats virtual void write( Bu::Stream &rOut ) const; virtual void read( Bu::Stream &rIn, char cType ); + Gats::Float &operator=( const Gats::Float &rhs ); + Gats::Float &operator=( float &rhs ); + bool operator==( const Gats::Float &rhs ) const; + bool operator==( float rhs ) const; + private: double fVal; mutable Bu::String sWriteCache; diff --git a/c++-libbu++/src/integer.cpp b/c++-libbu++/src/integer.cpp index f63dd37..1f10279 100644 --- a/c++-libbu++/src/integer.cpp +++ b/c++-libbu++/src/integer.cpp @@ -39,6 +39,28 @@ void Gats::Integer::read( Bu::Stream &rIn, char cType ) readPackedInt( rIn, iVal ); } +Gats::Integer &Gats::Integer::operator=( const Gats::Integer &rhs ) +{ + iVal = rhs.iVal; + return *this; +} + +Gats::Integer &Gats::Integer::operator=( int64_t rhs ) +{ + iVal = rhs; + return *this; +} + +bool Gats::Integer::operator==( const Gats::Integer &rhs ) +{ + return iVal == rhs.iVal; +} + +bool Gats::Integer::operator==( int64_t rhs ) +{ + return iVal == rhs; +} + Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Integer &i ) { return f << "(int) " << i.getValue(); diff --git a/c++-libbu++/src/integer.h b/c++-libbu++/src/integer.h index d1ef3aa..e0a8d26 100644 --- a/c++-libbu++/src/integer.h +++ b/c++-libbu++/src/integer.h @@ -31,6 +31,11 @@ namespace Gats virtual void write( Bu::Stream &rOut ) const; virtual void read( Bu::Stream &rIn, char cType ); + Gats::Integer &operator=( const Gats::Integer &rhs ); + Gats::Integer &operator=( int64_t rhs ); + bool operator==( const Gats::Integer &rhs ); + bool operator==( int64_t rhs ); + template static void readPackedInt( Bu::Stream &rStream, itype &rOut ) { diff --git a/c++-libbu++/src/string.cpp b/c++-libbu++/src/string.cpp index f329f41..32018b8 100644 --- a/c++-libbu++/src/string.cpp +++ b/c++-libbu++/src/string.cpp @@ -65,6 +65,39 @@ void Gats::String::read( Bu::Stream &rIn, char cType ) rIn.read( getStr(), iSize ); } +Gats::String &Gats::String::operator=( const char *s ) +{ + Bu::String::operator=( s ); + return *this; +} + +Gats::String &Gats::String::operator=( const Gats::String &s ) +{ + Bu::String::operator=( s ); + return *this; +} + +Gats::String &Gats::String::operator=( const Bu::String &s ) +{ + Bu::String::operator=( s ); + return *this; +} + +bool Gats::String::operator==( const char *s ) const +{ + return Bu::String::operator==( s ); +} + +bool Gats::String::operator==( const Gats::String &s ) const +{ + return Bu::String::operator==( s ); +} + +bool Gats::String::operator==( const Bu::String &s ) const +{ + return Bu::String::operator==( s ); +} + Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) { for( Gats::String::const_iterator i = s.begin(); i; i++ ) diff --git a/c++-libbu++/src/string.h b/c++-libbu++/src/string.h index b37137e..eae60e3 100644 --- a/c++-libbu++/src/string.h +++ b/c++-libbu++/src/string.h @@ -30,6 +30,13 @@ namespace Gats virtual void write( Bu::Stream &rOut ) const; virtual void read( Bu::Stream &rIn, char cType ); + Gats::String &operator=( const char *s ); + Gats::String &operator=( const Gats::String &s ); + Gats::String &operator=( const Bu::String &s ); + bool operator==( const char *s ) const; + bool operator==( const Gats::String &s ) const; + bool operator==( const Bu::String &s ) const; + private: }; }; -- cgit v1.2.3