mirror of
https://github.com/boostorg/build.git
synced 2026-02-17 01:32:12 +00:00
Updated the vector class defined in Boost Build's containers.jam module. vector.empty() rule no longer returns true for a non empty container containing only empty strings. Removed vector.indices() rule that had a defective implementation causing vector.equal() to compare only the first and last vector element (reported by Rick Yang). Corrected the vector.equal() rule. Added new vector class related tests. Minor stylistic changes.
[SVN r46225]
This commit is contained in:
@@ -6,9 +6,6 @@
|
||||
|
||||
# Various container classes.
|
||||
|
||||
import "class" : * ;
|
||||
|
||||
|
||||
# Base for container objects. This lets us construct recursive structures. That
|
||||
# is containers with containers in them, specifically so we can tell literal
|
||||
# values from node values.
|
||||
@@ -45,12 +42,12 @@ class node
|
||||
#
|
||||
class vector : node
|
||||
{
|
||||
import numbers : range ;
|
||||
import numbers ;
|
||||
import utility ;
|
||||
import sequence ;
|
||||
|
||||
rule __init__ (
|
||||
values * # Initial contents of vector.
|
||||
values * # Initial contents of vector.
|
||||
)
|
||||
{
|
||||
node.__init__ ;
|
||||
@@ -80,7 +77,7 @@ class vector : node
|
||||
rule at (
|
||||
index # The element index, one based.
|
||||
: * # Additional indices to access recursively.
|
||||
)
|
||||
)
|
||||
{
|
||||
local r = $(self.value[$(index)]) ;
|
||||
if $(2)
|
||||
@@ -97,7 +94,7 @@ class vector : node
|
||||
rule get-at (
|
||||
index # The element index, one based.
|
||||
: * # Additional indices to access recursively.
|
||||
)
|
||||
)
|
||||
{
|
||||
local r = $(self.value[$(index)]) ;
|
||||
if $(2)
|
||||
@@ -112,7 +109,7 @@ class vector : node
|
||||
#
|
||||
rule push-front (
|
||||
value # Value to become first element.
|
||||
)
|
||||
)
|
||||
{
|
||||
self.value = $(value) $(self.value) ;
|
||||
}
|
||||
@@ -128,8 +125,8 @@ class vector : node
|
||||
# Add the given value at the end of the vector.
|
||||
#
|
||||
rule push-back (
|
||||
value # Value to become back element.
|
||||
)
|
||||
value # Value to become back element.
|
||||
)
|
||||
{
|
||||
self.value += $(value) ;
|
||||
}
|
||||
@@ -150,7 +147,7 @@ class vector : node
|
||||
rule insert (
|
||||
index # The index to insert at, one based.
|
||||
: value # The value to insert.
|
||||
)
|
||||
)
|
||||
{
|
||||
local left = $(self.value[1-$(index)]) ;
|
||||
local right = $(self.value[$(index)-]) ;
|
||||
@@ -165,9 +162,9 @@ class vector : node
|
||||
# not specifying an end is equivalent to the [start, start] range.
|
||||
#
|
||||
rule erase (
|
||||
start # Index of first element ro remove.
|
||||
start # Index of first element to remove.
|
||||
end ? # Optional, index of last element to remove.
|
||||
)
|
||||
)
|
||||
{
|
||||
end ?= $(start) ;
|
||||
local left = $(self.value[1-$(start)]) ;
|
||||
@@ -195,23 +192,12 @@ class vector : node
|
||||
#
|
||||
rule empty ( )
|
||||
{
|
||||
if ! $(self.value)
|
||||
if ! $(self.value)-is-defined
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
# Returns the list of all valid indices for this vector.
|
||||
#
|
||||
rule indices ( )
|
||||
{
|
||||
if ! [ empty ]
|
||||
{
|
||||
local size = [ size ] ;
|
||||
return [ range 1 : $(size) ] $(size) ;
|
||||
}
|
||||
}
|
||||
|
||||
# Returns the textual representation of content.
|
||||
#
|
||||
rule str ( )
|
||||
@@ -220,7 +206,6 @@ class vector : node
|
||||
}
|
||||
|
||||
# Sorts the vector inplace, calling 'utility.less' for comparisons.
|
||||
# NOTE: this rule is unused at the moment.
|
||||
#
|
||||
rule sort ( )
|
||||
{
|
||||
@@ -233,9 +218,10 @@ class vector : node
|
||||
rule equal ( another )
|
||||
{
|
||||
local mismatch ;
|
||||
if [ size ] = [ $(another).size ]
|
||||
local size = [ size ] ;
|
||||
if $(size) = [ $(another).size ]
|
||||
{
|
||||
for local i in [ indices ]
|
||||
for local i in [ numbers.range 1 $(size) ]
|
||||
{
|
||||
if ! [ utility.equal [ at $(i) ] [ $(another).at $(i) ] ]
|
||||
{
|
||||
@@ -262,12 +248,11 @@ local rule __test__ ( )
|
||||
import "class" : new ;
|
||||
|
||||
local v1 = [ new vector ] ;
|
||||
assert.true $(v1).empty ;
|
||||
assert.result 0 : $(v1).size ;
|
||||
assert.result : $(v1).indices ;
|
||||
assert.result "[" "]" : $(v1).str ;
|
||||
$(v1).push-back b ;
|
||||
$(v1).push-front a ;
|
||||
assert.result 1 2 : $(v1).indices ;
|
||||
assert.result "[" a b "]" : $(v1).str ;
|
||||
assert.result a : $(v1).front ;
|
||||
assert.result b : $(v1).back ;
|
||||
@@ -321,13 +306,16 @@ local rule __test__ ( )
|
||||
assert.true $(v6).equal [ new vector [ new vector 1 2 3 ] ] ;
|
||||
|
||||
local v7 = [ new vector 111 222 333 ] ;
|
||||
assert.true $(v7).equal $(v7) ;
|
||||
$(v7).insert 4 : 444 ;
|
||||
assert.result 111 222 333 444 : $(v7).get ;
|
||||
$(v7).insert 999 : xxx ;
|
||||
assert.result 111 222 333 444 xxx : $(v7).get ;
|
||||
|
||||
local v8 = [ new vector "" "" "" ] ;
|
||||
assert.true $(v7).equal $(v7) ;
|
||||
assert.result 3 : $(v8).size ;
|
||||
assert.false $(v8).empty ;
|
||||
$(v8).insert 2 : 222 ;
|
||||
assert.result 4 : $(v8).size ;
|
||||
assert.result "" 222 "" "" : $(v8).get ;
|
||||
@@ -337,4 +325,10 @@ local rule __test__ ( )
|
||||
$(v8).insert 999 : xxx ;
|
||||
assert.result 6 : $(v8).size ;
|
||||
assert.result "" 222 "" "" "" xxx : $(v8).get ;
|
||||
|
||||
# Regression test for a bug causing vector.equal to compare only the first
|
||||
# and the last element in the given vectors.
|
||||
local v9 = [ new vector 111 xxx 222 ] ;
|
||||
local v10 = [ new vector 111 yyy 222 ] ;
|
||||
assert.false $(v9).equal $(v10) ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user