From 1331c762c05643d7a4fcd4abeb951ed814cea47d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 6 Nov 2012 08:16:41 +0000 Subject: Slightly optimized list operations, and added list subtraction. If you subtract any item from a list it will remove one matching item from the source list for each item in the subtracted list. --- src/variable.cpp | 35 +++++++++++++++++++++++++---------- src/variable.h | 2 ++ 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/variable.cpp b/src/variable.cpp index f638dc9..ffc41a6 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -327,7 +327,7 @@ Bu::String Variable::toString() const VarList Variable::toList() const { if( eType == typeList ) - return *this; + return *uVal.lVal; return VarList( *this ); } @@ -621,7 +621,7 @@ bool Variable::operator!=( const Variable &rhs ) const bool Variable::operator<( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -656,7 +656,7 @@ bool Variable::operator<( const Variable &rhs ) const bool Variable::operator>( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -691,7 +691,7 @@ bool Variable::operator>( const Variable &rhs ) const bool Variable::operator<=( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -726,7 +726,7 @@ bool Variable::operator<=( const Variable &rhs ) const bool Variable::operator>=( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -761,7 +761,7 @@ bool Variable::operator>=( const Variable &rhs ) const Variable Variable::operator+( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -796,7 +796,7 @@ Variable Variable::operator+( const Variable &rhs ) const Variable Variable::operator-( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -818,7 +818,7 @@ Variable Variable::operator-( const Variable &rhs ) const throw Bu::ExceptionBase("You cannot subtract string values."); case typeList: - throw Bu::ExceptionBase("You cannot subtract list values."); + return Variable( toList() - rhs.toList() ); case typeRef: throw Bu::ExceptionBase("You cannot subtract reference values."); @@ -831,7 +831,7 @@ Variable Variable::operator-( const Variable &rhs ) const Variable Variable::operator*( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -866,7 +866,7 @@ Variable Variable::operator*( const Variable &rhs ) const Variable Variable::operator/( const Variable &rhs ) const { - Type eTop = Bu::max( eType, rhs.eType ); + Type eTop = Bu::buMax( eType, rhs.eType ); switch( eTop ) { case typeNone: @@ -1038,3 +1038,18 @@ Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ) return ar; } +VarList operator-( const VarList &rBase, const VarList &rSub ) +{ + VarList lRet( rBase ); + + for( VarList::const_iterator i = rSub.begin(); i; i++ ) + { + VarList::const_iterator k; + for( k = lRet.begin(); k && *k != *i; k++ ) { } + if( k ) + lRet.erase( k ); + } + + return lRet; +} + diff --git a/src/variable.h b/src/variable.h index 241393e..890552a 100644 --- a/src/variable.h +++ b/src/variable.h @@ -123,4 +123,6 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ); Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); +VarList operator-( const VarList &rBase, const VarList &rSub ); + #endif -- cgit v1.2.3