diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-11-06 08:16:41 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-06 08:16:41 +0000 |
| commit | 1331c762c05643d7a4fcd4abeb951ed814cea47d (patch) | |
| tree | 5d15e3c9b47517f86b472a3d93c025b0ff1a84b6 | |
| parent | 9d507ea353a92ca51e7a9d7ae5c82d3aa35c04d1 (diff) | |
| download | build-1331c762c05643d7a4fcd4abeb951ed814cea47d.tar.gz build-1331c762c05643d7a4fcd4abeb951ed814cea47d.tar.bz2 build-1331c762c05643d7a4fcd4abeb951ed814cea47d.tar.xz build-1331c762c05643d7a4fcd4abeb951ed814cea47d.zip | |
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.
| -rwxr-xr-x | build.sh | 4 | ||||
| -rw-r--r-- | src/variable.cpp | 35 | ||||
| -rw-r--r-- | src/variable.h | 2 |
3 files changed, 29 insertions, 12 deletions
| @@ -1,7 +1,7 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | 2 | ||
| 3 | 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" | 3 | 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" |
| 4 | 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" | 4 | 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" |
| 5 | BUEXPSRC="regex.cpp" | 5 | BUEXPSRC="regex.cpp" |
| 6 | BUEXPHDR="regex.h" | 6 | BUEXPHDR="regex.h" |
| 7 | BUCOMPAT="config.h compat/linux.h compat/win32.h compat/osx.h" | 7 | 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 | |||
| 327 | VarList Variable::toList() const | 327 | VarList Variable::toList() const |
| 328 | { | 328 | { |
| 329 | if( eType == typeList ) | 329 | if( eType == typeList ) |
| 330 | return *this; | 330 | return *uVal.lVal; |
| 331 | return VarList( *this ); | 331 | return VarList( *this ); |
| 332 | } | 332 | } |
| 333 | 333 | ||
| @@ -621,7 +621,7 @@ bool Variable::operator!=( const Variable &rhs ) const | |||
| 621 | 621 | ||
| 622 | bool Variable::operator<( const Variable &rhs ) const | 622 | bool Variable::operator<( const Variable &rhs ) const |
| 623 | { | 623 | { |
| 624 | Type eTop = Bu::max( eType, rhs.eType ); | 624 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 625 | switch( eTop ) | 625 | switch( eTop ) |
| 626 | { | 626 | { |
| 627 | case typeNone: | 627 | case typeNone: |
| @@ -656,7 +656,7 @@ bool Variable::operator<( const Variable &rhs ) const | |||
| 656 | 656 | ||
| 657 | bool Variable::operator>( const Variable &rhs ) const | 657 | bool Variable::operator>( const Variable &rhs ) const |
| 658 | { | 658 | { |
| 659 | Type eTop = Bu::max( eType, rhs.eType ); | 659 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 660 | switch( eTop ) | 660 | switch( eTop ) |
| 661 | { | 661 | { |
| 662 | case typeNone: | 662 | case typeNone: |
| @@ -691,7 +691,7 @@ bool Variable::operator>( const Variable &rhs ) const | |||
| 691 | 691 | ||
| 692 | bool Variable::operator<=( const Variable &rhs ) const | 692 | bool Variable::operator<=( const Variable &rhs ) const |
| 693 | { | 693 | { |
| 694 | Type eTop = Bu::max( eType, rhs.eType ); | 694 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 695 | switch( eTop ) | 695 | switch( eTop ) |
| 696 | { | 696 | { |
| 697 | case typeNone: | 697 | case typeNone: |
| @@ -726,7 +726,7 @@ bool Variable::operator<=( const Variable &rhs ) const | |||
| 726 | 726 | ||
| 727 | bool Variable::operator>=( const Variable &rhs ) const | 727 | bool Variable::operator>=( const Variable &rhs ) const |
| 728 | { | 728 | { |
| 729 | Type eTop = Bu::max( eType, rhs.eType ); | 729 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 730 | switch( eTop ) | 730 | switch( eTop ) |
| 731 | { | 731 | { |
| 732 | case typeNone: | 732 | case typeNone: |
| @@ -761,7 +761,7 @@ bool Variable::operator>=( const Variable &rhs ) const | |||
| 761 | 761 | ||
| 762 | Variable Variable::operator+( const Variable &rhs ) const | 762 | Variable Variable::operator+( const Variable &rhs ) const |
| 763 | { | 763 | { |
| 764 | Type eTop = Bu::max( eType, rhs.eType ); | 764 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 765 | switch( eTop ) | 765 | switch( eTop ) |
| 766 | { | 766 | { |
| 767 | case typeNone: | 767 | case typeNone: |
| @@ -796,7 +796,7 @@ Variable Variable::operator+( const Variable &rhs ) const | |||
| 796 | 796 | ||
| 797 | Variable Variable::operator-( const Variable &rhs ) const | 797 | Variable Variable::operator-( const Variable &rhs ) const |
| 798 | { | 798 | { |
| 799 | Type eTop = Bu::max( eType, rhs.eType ); | 799 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 800 | switch( eTop ) | 800 | switch( eTop ) |
| 801 | { | 801 | { |
| 802 | case typeNone: | 802 | case typeNone: |
| @@ -818,7 +818,7 @@ Variable Variable::operator-( const Variable &rhs ) const | |||
| 818 | throw Bu::ExceptionBase("You cannot subtract string values."); | 818 | throw Bu::ExceptionBase("You cannot subtract string values."); |
| 819 | 819 | ||
| 820 | case typeList: | 820 | case typeList: |
| 821 | throw Bu::ExceptionBase("You cannot subtract list values."); | 821 | return Variable( toList() - rhs.toList() ); |
| 822 | 822 | ||
| 823 | case typeRef: | 823 | case typeRef: |
| 824 | throw Bu::ExceptionBase("You cannot subtract reference values."); | 824 | throw Bu::ExceptionBase("You cannot subtract reference values."); |
| @@ -831,7 +831,7 @@ Variable Variable::operator-( const Variable &rhs ) const | |||
| 831 | 831 | ||
| 832 | Variable Variable::operator*( const Variable &rhs ) const | 832 | Variable Variable::operator*( const Variable &rhs ) const |
| 833 | { | 833 | { |
| 834 | Type eTop = Bu::max( eType, rhs.eType ); | 834 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 835 | switch( eTop ) | 835 | switch( eTop ) |
| 836 | { | 836 | { |
| 837 | case typeNone: | 837 | case typeNone: |
| @@ -866,7 +866,7 @@ Variable Variable::operator*( const Variable &rhs ) const | |||
| 866 | 866 | ||
| 867 | Variable Variable::operator/( const Variable &rhs ) const | 867 | Variable Variable::operator/( const Variable &rhs ) const |
| 868 | { | 868 | { |
| 869 | Type eTop = Bu::max( eType, rhs.eType ); | 869 | Type eTop = Bu::buMax( eType, rhs.eType ); |
| 870 | switch( eTop ) | 870 | switch( eTop ) |
| 871 | { | 871 | { |
| 872 | case typeNone: | 872 | case typeNone: |
| @@ -1038,3 +1038,18 @@ Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ) | |||
| 1038 | return ar; | 1038 | return ar; |
| 1039 | } | 1039 | } |
| 1040 | 1040 | ||
| 1041 | VarList operator-( const VarList &rBase, const VarList &rSub ) | ||
| 1042 | { | ||
| 1043 | VarList lRet( rBase ); | ||
| 1044 | |||
| 1045 | for( VarList::const_iterator i = rSub.begin(); i; i++ ) | ||
| 1046 | { | ||
| 1047 | VarList::const_iterator k; | ||
| 1048 | for( k = lRet.begin(); k && *k != *i; k++ ) { } | ||
| 1049 | if( k ) | ||
| 1050 | lRet.erase( k ); | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | return lRet; | ||
| 1054 | } | ||
| 1055 | |||
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 ); | |||
| 123 | Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); | 123 | Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); |
| 124 | Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); | 124 | Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); |
| 125 | 125 | ||
| 126 | VarList operator-( const VarList &rBase, const VarList &rSub ); | ||
| 127 | |||
| 126 | #endif | 128 | #endif |
