From 5a44fdd2d551a7de14c10cf24dccdfc5ddbcc98f Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 16 Apr 2011 18:24:01 +0000 Subject: [PATCH] Core: Array/Vector Set, Insert, InsertPick now return a reference to the element git-svn-id: svn://ultimatepp.org/upp/trunk@3344 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Vcont.h | 18 +++++++++++------- uppsrc/Core/Vcont.hpp | 6 ++++-- uppsrc/Core/src.tpp/Array$en-us.tpp | 22 +++++++++++++++++----- uppsrc/Core/src.tpp/Vector$en-us.tpp | 22 +++++++++++++++++----- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/uppsrc/Core/Vcont.h b/uppsrc/Core/Vcont.h index 3bf29b502..217cce719 100644 --- a/uppsrc/Core/Vcont.h +++ b/uppsrc/Core/Vcont.h @@ -63,14 +63,16 @@ public: void Reserve(int n); int GetAlloc() const { return alloc; } - void Set(int i, const T& x, int count = 1); + void Set(int i, const T& x, int count); + T& Set(int i, const T& x) { Set(i, x, 1); return Get(i); } void Remove(int i, int count = 1); void Remove(const int *sorted_list, int n); void Remove(const Vector& sorted_list); void InsertN(int i, int count = 1); - T& Insert(int i) { InsertN(i); return Get(i); } - void Insert(int i, const T& x, int count = 1); - void InsertPick(int i, pick_ T& x); + T& Insert(int i) { InsertN(i); return Get(i); } + void Insert(int i, const T& x, int count); + T& Insert(int i, const T& x) { Insert(i, x, 1); return Get(i); } + T& InsertPick(int i, pick_ T& x); void Insert(int i, const Vector& x); void Insert(int i, const Vector& x, int offset, int count); void InsertPick(int i, pick_ Vector& x); @@ -185,14 +187,16 @@ public: void Reserve(int xtra) { vector.Reserve(xtra); } int GetAlloc() const { return vector.GetAlloc(); } - void Set(int i, const T& x, int count = 1); + void Set(int i, const T& x, int count); + T& Set(int i, const T& x) { Set(i, x, 1); return Get(i); } void Remove(int i, int count = 1); void Remove(const int *sorted_list, int n); void Remove(const Vector& sorted_list); void InsertN(int i, int count = 1); T& Insert(int i) { InsertN(i); return Get(i); } - void Insert(int i, const T& x, int count = 1); - void InsertPick(int i, pick_ T& x); + void Insert(int i, const T& x, int count); + T& Insert(int i, const T& x) { Insert(i, x, 1); return Get(i); } + T& InsertPick(int i, pick_ T& x); void Insert(int i, const Array& x); void Insert(int i, const Array& x, int offset, int count); void Append(const Array& x) { Insert(GetCount(), x); } diff --git a/uppsrc/Core/Vcont.hpp b/uppsrc/Core/Vcont.hpp index 933230a79..dbbd71b0a 100644 --- a/uppsrc/Core/Vcont.hpp +++ b/uppsrc/Core/Vcont.hpp @@ -273,11 +273,12 @@ void Vector::Insert(int q, const T& x, int count) { } template -void Vector::InsertPick(int q, pick_ T& x) +T& Vector::InsertPick(int q, pick_ T& x) { ASSERT(&x < vector || &x > vector + items); RawInsert(q, 1); ::new(vector[q]) T(x); + return Get(q); } template @@ -448,10 +449,11 @@ void Array::Insert(int i, const T& x, int count) { } template -void Array::InsertPick(int i, pick_ T& x) +T& Array::InsertPick(int i, pick_ T& x) { vector.InsertN(i, 1); vector[i] = new T(x); + return Get(i); } template diff --git a/uppsrc/Core/src.tpp/Array$en-us.tpp b/uppsrc/Core/src.tpp/Array$en-us.tpp index 0e86b8e0a..00ae170bc 100644 --- a/uppsrc/Core/src.tpp/Array$en-us.tpp +++ b/uppsrc/Core/src.tpp/Array$en-us.tpp @@ -267,7 +267,7 @@ current capacity, capacity is increased to the required value.&] [s3;%- &] [s4;%- &] [s5;:Array`:`:Set`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) int]_[*@3 i -], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_[@3 1])&] +], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&] [s2; Sets the requested number of elements starting at the position [* i] to the specified value. If the required number of elements exceeds existing elements of the Array then elements are added @@ -279,6 +279,12 @@ to the Array.&] [s7; [*C@3 count]-|Number of elements.&] [s3;%- &] [s4;%- &] +[s5;:Array`:`:Set`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Set]([@(0.0.255) int]_[*@3 i], + [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] +[s2; Sets the element at [%-*@3 i] to [%-*@3 x] and returns a reference +to this element.&] +[s3; &] +[s4;%- &] [s5;:Array`:`:Remove`(int`,int`):%- [@(0.0.255) void]_[* Remove]([@(0.0.255) int]_[*@3 i], [@(0.0.255) int]_[*@3 count]_`=_[@3 1])&] [s2; Removes requested number of elements.&] @@ -323,8 +329,7 @@ the specified position.&] [s3;%- &] [s4;%- &] [s5;:Array`:`:Insert`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Insert]([@(0.0.255) int -]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_[@3 1 -])&] +]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&] [s2; Inserts a specified number of elements, setting them to a specified value.&] [s6;~~~.992; Requires T to have deep copy constructor.&] @@ -334,9 +339,16 @@ value.&] [s7; [*C@3 count]-|Number of elements to insert.&] [s3;%- &] [s4;%- &] -[s5;:Array`:`:InsertPick`(int`,pick`_ T`&`):%- [@(0.0.255) void]_[* InsertPick]([@(0.0.255) i +[s5;:Array`:`:Insert`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Insert]([@(0.0.255) int]_ +[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] +[s2; Inserts an element at [%-*@3 i] setting it to [%-*@3 x] and returns +a reference to it.&] +[s3; &] +[s4;%- &] +[s5;:Array`:`:InsertPick`(int`,pick`_ T`&`):%- [*@4 T][@(0.0.255) `&]_[* InsertPick]([@(0.0.255) i nt]_[*@3 i], [@(0.128.128) pick`_]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] -[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x].&] +[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x] +and returns a reference to it.&] [s6;~~~.992; Requires T to have pick constructor.&] [s6;~~~.992; Invalidates iterators to the Array.&] [s3; &] diff --git a/uppsrc/Core/src.tpp/Vector$en-us.tpp b/uppsrc/Core/src.tpp/Vector$en-us.tpp index 35f7fd4ba..bfd9da4d6 100644 --- a/uppsrc/Core/src.tpp/Vector$en-us.tpp +++ b/uppsrc/Core/src.tpp/Vector$en-us.tpp @@ -237,7 +237,7 @@ capacity, capacity is increased to the required value.&] [s3;%- &] [s4;%- &] [s5;:Vector`:`:Set`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) int]_[*@3 i -], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_[@3 1])&] +], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&] [s2; Sets requested number of elements starting at the position [* i] to the specified value. If required number of elements exceeds existing elements of Vector then elements are added to Vector.&] @@ -248,6 +248,12 @@ existing elements of Vector then elements are added to Vector.&] [s7; [*C@3 count]-|Number of elements.&] [s3;%- &] [s4;%- &] +[s5;:Vector`:`:Set`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Set]([@(0.0.255) int]_[*@3 i], + [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] +[s2; Sets element at [%-*@3 i] to [%-*@3 x].and returns a reference to +the element.&] +[s3; &] +[s4;%- &] [s5;:Vector`:`:Remove`(int`,int`):%- [@(0.0.255) void]_[* Remove]([@(0.0.255) int]_[*@3 i], [@(0.0.255) int]_[*@3 count]_`=_[@3 1])&] [s2; Removes requested number of elements.&] @@ -292,8 +298,7 @@ a specified position.&] [s3;%- &] [s4;%- &] [s5;:Vector`:`:Insert`(int`,const T`&`,int`):%- [@(0.0.255) void]_[* Insert]([@(0.0.255) in -t]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count]_`=_ -[@3 1])&] +t]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) int]_[*@3 count])&] [s2; Inserts a specified number of elements, setting them to a specified value.&] [s6;~~~.992; Requires T to have deep copy constructor.&] @@ -303,9 +308,16 @@ value.&] [s7; [*C@3 count]-|Number of elements to insert.&] [s3;%- &] [s4;%- &] -[s5;:Vector`:`:InsertPick`(int`,pick`_ T`&`):%- [@(0.0.255) void]_[* InsertPick]([@(0.0.255) i +[s5;:Vector`:`:Insert`(int`,const T`&`):%- [*@4 T][@(0.0.255) `&]_[* Insert]([@(0.0.255) int]_ +[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] +[s2; Inserts element at position [%-*@3 i] setting its value to [%-*@3 x] +and returns a reference to it.&] +[s3; &] +[s4;%- &] +[s5;:Vector`:`:InsertPick`(int`,pick`_ T`&`):%- [*@4 T][@(0.0.255) `&]_[* InsertPick]([@(0.0.255) i nt]_[*@3 i], [@(0.128.128) pick`_]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] -[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x].&] +[s2; Inserts an element at [%-*@3 i] picking the content of [%-*@3 x] +and returns a reference to this new element.&] [s6;~~~.992; Requires T to have pick constructor.&] [s6;~~~.992; Invalidates iterators and references to Vector.&] [s3; &]