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 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'src/variable.cpp') 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; +} + -- cgit v1.2.3