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. --- build.sh | 4 ++-- src/variable.cpp | 35 +++++++++++++++++++++++++---------- src/variable.h | 2 ++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/build.sh b/build.sh index 126e6f9..0120833 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/bash -BUSRC="stack.cpp string.cpp hash.cpp list.cpp trace.cpp stream.cpp formatter.cpp util.cpp sharedcore.cpp exceptionbase.cpp heap.cpp archivebase.cpp archive.cpp queue.cpp archival.cpp sio.cpp stdstream.cpp process.cpp plugger.cpp optparser.cpp signals.cpp array.cpp membuf.cpp file.cpp variant.cpp random.cpp randombasic.cpp randombase.cpp" -BUHDR="stack.h string.h hash.h list.h trace.h stream.h formatter.h util.h sharedcore.h exceptionbase.h heap.h archivebase.h archive.h queue.h archival.h sio.h stdstream.h process.h plugger.h singleton.h optparser.h array.h membuf.h file.h variant.h fmt.h extratypes.h random.h randombasic.h randombase.h" +BUSRC="stack.cpp string.cpp hash.cpp list.cpp trace.cpp stream.cpp formatter.cpp util.cpp sharedcore.cpp exceptionbase.cpp heap.cpp archivebase.cpp archive.cpp queue.cpp archival.cpp sio.cpp stdstream.cpp process.cpp plugger.cpp optparser.cpp signals.cpp array.cpp membuf.cpp file.cpp variant.cpp random.cpp randombasic.cpp randombase.cpp streamstack.cpp" +BUHDR="stack.h string.h hash.h list.h trace.h stream.h formatter.h util.h sharedcore.h exceptionbase.h heap.h archivebase.h archive.h queue.h archival.h sio.h stdstream.h process.h plugger.h singleton.h optparser.h array.h membuf.h file.h variant.h fmt.h extratypes.h random.h randombasic.h randombase.h streamstack.h" BUEXPSRC="regex.cpp" BUEXPHDR="regex.h" BUCOMPAT="config.h compat/linux.h compat/win32.h compat/osx.h" 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