mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
Core: Improved Create for InArray, One, Any, ArrayMap, FixedArrayMap, SortedArrayMap
git-svn-id: svn://ultimatepp.org/upp/trunk@11558 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
2989a43743
commit
2ea7c50caa
9 changed files with 29 additions and 27 deletions
|
|
@ -104,7 +104,7 @@ public:
|
|||
T& Add(const K& k) { return B::Add(k); }
|
||||
T& Add(const K& k, T *newt) { B::key.Add(k); return B::value.Add(newt); }
|
||||
template <class TT, class... Args>
|
||||
TT& Create(const K& k, Args... args) { TT *q = new TT(args...); B::key.Add(k); return static_cast<TT&>(B::value.Add(q)); }
|
||||
TT& Create(const K& k, Args&&... args) { TT *q = new TT(std::forward<Args>(args)...); B::key.Add(k); return static_cast<TT&>(B::value.Add(q)); }
|
||||
|
||||
FixedArrayMap(const FixedArrayMap& s, int) : FixedAMap<K, T, Array<T>, Less>(s, 1) {}
|
||||
FixedArrayMap(Vector<K>&& ndx, Array<T>&& val) : FixedAMap<K, T, Array<T>, Less>(pick(ndx), pick(val)) {}
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ public:
|
|||
T& Insert(int i) { return Insert(i, new T); }
|
||||
T& Insert(int i, const T& x) { return Insert(i, new T(x)); }
|
||||
template<class TT, class... Args>
|
||||
TT& InsertCreate(int i, Args... args) { TT *q = new TT(args...); Insert(i, q); return *q; }
|
||||
TT& InsertCreate(int i, Args&&... args) { TT *q = new TT(std::forward<Args>(args)...); Insert(i, q); return *q; }
|
||||
|
||||
void InsertN(int i, int count);
|
||||
template <class Range>
|
||||
|
|
@ -319,7 +319,7 @@ public:
|
|||
void AddN(int n) { InsertN(GetCount(), n); }
|
||||
T& Add(T *newt) { Insert(GetCount(), newt); return *newt; }
|
||||
template<class TT, class... Args>
|
||||
TT& Create(Args... args) { TT *q = new TT(args...); Add(q); return *q; }
|
||||
TT& Create(Args&&... args) { TT *q = new TT(std::forward<Args>(args)...); Add(q); return *q; }
|
||||
|
||||
int GetCount() const { return iv.GetCount(); }
|
||||
bool IsEmpty() const { return GetCount() == 0; }
|
||||
|
|
@ -727,7 +727,7 @@ public:
|
|||
T& Add(const K& k) { B::value.res = NULL; B::key.Add(k); return *(T*)B::value.res; }
|
||||
T& Add(const K& k, T *newt) { B::value.res = newt; B::key.Add(k); return *newt; }
|
||||
template <class TT, class... Args>
|
||||
TT& Create(const K& k, Args... args) { TT *q = new TT(args...); B::value.res = q; B::key.Add(k); return *q; }
|
||||
TT& Create(const K& k, Args&&... args) { TT *q = new TT(std::forward<Args>(args)...); B::value.res = q; B::key.Add(k); return *q; }
|
||||
|
||||
int FindAdd(const K& k) { B::value.res = NULL; return B::key.FindAdd(k); }
|
||||
int FindAdd(const K& k, const T& init);
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ public:
|
|||
T& Insert(int i, const K& k, T *newt) { B::key.Insert(i, k); return B::value.Insert(i, newt); }
|
||||
using B::Insert;
|
||||
template <class TT, class... Args>
|
||||
TT& Create(const K& k, Args... args) { TT *q = new TT(args...); B::key.Add(k); return static_cast<TT&>(B::value.Add(q)); }
|
||||
TT& Create(const K& k, Args&&... args) { TT *q = new TT(std::forward<Args>(args)...); B::key.Add(k); return static_cast<TT&>(B::value.Add(q)); }
|
||||
|
||||
T& Set(int i, T *ptr) { return B::value.Set(i, ptr); }
|
||||
T *PopDetach() { B::key.Drop(); return B::value.PopDetach(); }
|
||||
|
|
|
|||
|
|
@ -46,11 +46,11 @@ public:
|
|||
T& operator*() { ASSERT(ptr); return *ptr; }
|
||||
|
||||
template <class TT, class... Args>
|
||||
TT& Create(Args... args) { TT *q = new TT(args...); Attach(q); return *q; }
|
||||
TT& Create(Args&&... args) { TT *q = new TT(std::forward<Args>(args)...); Attach(q); return *q; }
|
||||
template <class TT> // with C++ conforming compiler, this would not be needed - GCC bug workaround
|
||||
TT& Create() { TT *q = new TT; Attach(q); return *q; }
|
||||
template <class... Args>
|
||||
T& Create(Args... args) { T *q = new T(args...); Attach(q); return *q; }
|
||||
T& Create(Args&&... args) { T *q = new T(std::forward<Args>(args)...); Attach(q); return *q; }
|
||||
T& Create() { T *q = new T; Attach(q); return *q; }
|
||||
|
||||
template <class TT>
|
||||
|
|
@ -90,7 +90,7 @@ class Any : Moveable<Any> {
|
|||
T data;
|
||||
|
||||
template <class... Args>
|
||||
Data(Args... args) : data(args...) { typeno = StaticTypeNo<T>(); }
|
||||
Data(Args&&... args) : data(std::forward<Args>(args)...) { typeno = StaticTypeNo<T>(); }
|
||||
};
|
||||
|
||||
BaseData *ptr;
|
||||
|
|
@ -99,7 +99,7 @@ class Any : Moveable<Any> {
|
|||
void Pick(Any&& s) { ptr = s.ptr; const_cast<Any&>(s).ptr = NULL; }
|
||||
|
||||
public:
|
||||
template <class T, class... Args> T& Create(Args... args) { Clear(); Data<T> *x = new Data<T>(args...); ptr = x; return x->data; }
|
||||
template <class T, class... Args> T& Create(Args&&... args) { Clear(); Data<T> *x = new Data<T>(std::forward<Args>(args)...); ptr = x; return x->data; }
|
||||
template <class T> bool Is() const { return ptr && ptr->typeno == StaticTypeNo<T>(); }
|
||||
template <class T> T& Get() { ASSERT(Is<T>()); Chk(); return ((Data<T>*)ptr)->data; }
|
||||
template <class T> const T& Get() const { ASSERT(Is<T>()); Chk(); return ((Data<T>*)ptr)->data; }
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ while destroying its content by picking..&]
|
|||
[s0; &]
|
||||
[ {{10000F(128)G(128)@1 [s0; [* Public Method List]]}}&]
|
||||
[s3;%- &]
|
||||
[s5;:Upp`:`:Any`:`:Create`(Args`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) class]_
|
||||
[*@4 T], [@(0.0.255) class...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) .
|
||||
..]_args)&]
|
||||
[s5;:Upp`:`:Any`:`:Create`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) cla
|
||||
ss]_[*@4 T], [@(0.0.255) class...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) `&
|
||||
`&...]_args)&]
|
||||
[s2; Creates content of type T inside Any. Additional parameters
|
||||
to constructor can be specified.&]
|
||||
[s3;%- &]
|
||||
|
|
|
|||
|
|
@ -137,9 +137,10 @@ from T as well. No constructor is applied.&]
|
|||
[s7; [%-*@3 newt]-|Value.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:ArrayMap`:`:Create`(const K`&`,Args`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c
|
||||
lass]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Create]([@(0.0.255) c
|
||||
onst]_[*@4 K][@(0.0.255) `&]_[*@3 k], [*@4 Args][@(0.0.255) ...]_args)&]
|
||||
[s5;:Upp`:`:ArrayMap`:`:Create`(const K`&`,Args`&`&`.`.`.args`):%- [@(0.0.255) template
|
||||
]_<[@(0.0.255) class]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Cr
|
||||
eate]([@(0.0.255) const]_[*@4 K][@(0.0.255) `&]_[*@3 k], [*@4 Args][@(0.0.255) `&`&...]_args)
|
||||
&]
|
||||
[s2;%- [%% Adds a new key ][*@3 k][%% with value element of type ][*@4 TT][%%
|
||||
(must be derived from ][*@4 T]). Value is constructd in`-place,
|
||||
with args as constructor parameters.&]
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ iterators.&]
|
|||
[s2; Inserts a copy of [%-*@3 x] at [%-*@3 i]. Invalidates iterators.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:InArray`:`:InsertCreate`(int`,Args`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c
|
||||
lass]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* InsertCreate]([@(0.0.255) i
|
||||
nt]_[*@3 i], [*@4 Args][@(0.0.255) ...]_args)&]
|
||||
[s5;:Upp`:`:InArray`:`:InsertCreate`(int`,Args`&`&`.`.`.args`):%- [@(0.0.255) template]_
|
||||
<[@(0.0.255) class]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Inse
|
||||
rtCreate]([@(0.0.255) int]_[*@3 i], [*@4 Args][@(0.0.255) `&`&...]_args)&]
|
||||
[s2; Creates a in`-place constructed element (with args as constructor
|
||||
parameters) of type [%-*@4 TT] and inserts it at [%-*@3 i]. Invalidates
|
||||
iterators.&]
|
||||
|
|
@ -91,9 +91,9 @@ t]_[*@3 i])&]
|
|||
[s2; Same as Insert(GetCount(), [%-*@3 newt]). Invalidates iterators.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:InArray`:`:Create`(Args`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) cla
|
||||
ss]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) .
|
||||
..]_args)&]
|
||||
[s5;:Upp`:`:InArray`:`:Create`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c
|
||||
lass]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) `&
|
||||
`&...]_args)&]
|
||||
[s2; Same as InsertCreate<[%-*@4 TT]>(GetCount(), args...). Invalidates
|
||||
iterators.&]
|
||||
[s3; &]
|
||||
|
|
|
|||
|
|
@ -125,9 +125,9 @@ content. Returns constant reference to content.&]
|
|||
Returns reference to content.&]
|
||||
[s3; &]
|
||||
[s4; &]
|
||||
[s5;:Upp`:`:One`:`:Create`(Args`.`.`.args`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T
|
||||
T], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) .
|
||||
..]_args)&]
|
||||
[s5;:Upp`:`:One`:`:Create`(Args`&`&`.`.`.args`): [@(0.0.255) template]_<[@(0.0.255) class
|
||||
]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* Create]([*@4 Args][@(0.0.255) `&
|
||||
`&...]_args)&]
|
||||
[s2;%% Creates [%-*@4 TT] content in One. If there is content in One
|
||||
while calling this function, it is destroyed. Additional arguments
|
||||
can be specified for [%-*@4 TT ]constructor.&]
|
||||
|
|
|
|||
|
|
@ -46,9 +46,10 @@ nst]_[*@4 K][@(0.0.255) `&]_[*@3 k], [*@4 T]_`*[*@3 newt])&]
|
|||
[%-*@3 newt] `- SortedArrayMap takes ownership. Returns [%- `*][%-*@3 newt].&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:SortedArrayMap`:`:Create`(const K`&`,Args`.`.`.args`):%- [@(0.0.255) templa
|
||||
te]_<[@(0.0.255) class]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&]_[* C
|
||||
reate]([@(0.0.255) const]_[*@4 K][@(0.0.255) `&]_[*@3 k], [*@4 Args][@(0.0.255) ...]_args)&]
|
||||
[s5;:Upp`:`:SortedArrayMap`:`:Create`(const K`&`,Args`&`&`.`.`.args`):%- [@(0.0.255) te
|
||||
mplate]_<[@(0.0.255) class]_[*@4 TT], [@(0.0.255) class...]_[*@4 Args]>_[*@4 TT][@(0.0.255) `&
|
||||
]_[* Create]([@(0.0.255) const]_[*@4 K][@(0.0.255) `&]_[*@3 k], [*@4 Args][@(0.0.255) `&`&...]_
|
||||
args)&]
|
||||
[s2; Inserts the key at upper bound key position and creates a new
|
||||
value of type [%-*@4 TT] using args as constructor parameters.
|
||||
[%-*@4 TT] has to be derived from [%-*@4 T]. Returns a reference
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue