Merge branch 'master' of https://github.com/Limvot/kraken
This commit is contained in:
@@ -128,4 +128,67 @@ fun safe_recursive_clone<T>(first: *T, cloningFunc: fun(*T, fun(*T):*T, fun(*T):
|
|||||||
return rec_it(first)
|
return rec_it(first)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj shared_ptr<T> (Object){
|
||||||
|
var data: *T;
|
||||||
|
var refCount: int;
|
||||||
|
|
||||||
|
fun construct(): *shared_ptr<T> {
|
||||||
|
data = 0;
|
||||||
|
refCount = 1;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun construct(newPtr: *T): *shared_ptr<T> {
|
||||||
|
data = newPtr;
|
||||||
|
refCount = 1;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun construct(newPtr: ref shared_ptr<T>): *shared_ptr<T> {
|
||||||
|
data = newPtr.data;
|
||||||
|
refCount = newPtr.refCount;
|
||||||
|
refCount++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun destruct(): void {
|
||||||
|
if(refCount == 1){
|
||||||
|
delete(data,1);
|
||||||
|
refCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun operator*(): ref T {
|
||||||
|
return *data;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun operator->(): *T {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun operator=(newPtr: ref shared_ptr<T>): ref shared_ptr<T> {
|
||||||
|
if(this != &newPtr){
|
||||||
|
if(refCount == 1){
|
||||||
|
delete(data,1);
|
||||||
|
refCount--;
|
||||||
|
}
|
||||||
|
//use copy constructor here???
|
||||||
|
data = newPtr.data;
|
||||||
|
refCount = newPtr.refCount;
|
||||||
|
refCount++;
|
||||||
|
}//end self-assignment check
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun operator=(newPtr: ref *T): ref shared_ptr<T> {
|
||||||
|
data = newPtr;
|
||||||
|
refCount = 1;
|
||||||
|
delete(newPtr,1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}; //end shared_ptr class
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user