Home » U++ Library support » U++ Core » Ptr improve
Re: Ptr improve [message #32406 is a reply to message #32404] |
Mon, 16 May 2011 16:06   |
|
mirek wrote on Mon, 16 May 2011 16:05 |
Quote: | Any comments are welcome!
|
No. This is going against U++ principles.
Mirek
|
Mirek,
As an alternative solution can you add a new virtual method OnPrecDelete() in class PteBase:
class PteBase {
protected:
struct Prec {
PteBase *ptr;
Atomic n;
};
virtual void OnPrecDelete() {};
volatile Prec *prec;
Prec *PtrAdd();
static void PtrRelease(Prec *prec);
static Prec *PtrAdd(const Uuid& uuid);
PteBase();
~PteBase();
friend class PtrBase;
};
and change in cpp file the method:
void PteBase::PtrRelease(Prec *prec){
CriticalSection::Lock __(sPteLock);
if(prec && --prec->n == 0){
if(prec->ptr){
prec->ptr->prec = NULL;
prec->ptr->OnPrecDelete();
}
delete prec;
prec = NULL;
}
}
In this case I can use for my specialized class this functionality by:
#include <Core/Core.h>
using namespace Upp;
struct Foo : public Pte<Foo> {
String text;
~Foo();
protected:
virtual void OnPrecDelete(){delete (Foo*)this;}
};
Foo::~Foo(){
Cout() << "deleted " << (void*)(this) << "\n";
}
Foo* factory(){
return new Foo;
}
CONSOLE_APP_MAIN
{
Ptr<Foo> ptr;
{
Ptr<Foo> ptr1 = new Foo;
ptr1->text = "Text";
ptr = ptr1;
Cout() << (void*)~ptr << " -> " << ptr->text << "\n";
}
Cout() << "-------------\n";
Cout() << (void*)~ptr << "\n";
ptr = factory();
ptr = factory();
}
|
|
|
 |
|
Ptr improve
By: tojocky on Mon, 16 May 2011 14:07
|
 |
|
Re: Ptr improve
By: mirek on Mon, 16 May 2011 15:05
|
 |
|
Re: Ptr improve
By: tojocky on Mon, 16 May 2011 15:31
|
 |
|
Re: Ptr improve
By: tojocky on Mon, 16 May 2011 16:06
|
 |
|
Re: Ptr improve
By: mirek on Mon, 16 May 2011 23:13
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
By: tojocky on Wed, 18 May 2011 13:12
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
By: tojocky on Fri, 20 May 2011 08:32
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
By: mirek on Fri, 20 May 2011 13:19
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
By: mirek on Mon, 23 May 2011 22:37
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
By: mirek on Tue, 24 May 2011 17:46
|
 |
|
Re: Ptr improve
By: mr_ped on Tue, 24 May 2011 18:28
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
By: mirek on Sat, 28 May 2011 20:57
|
 |
|
Re: Ptr improve
By: mr_ped on Wed, 25 May 2011 09:34
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
|
 |
|
Re: Ptr improve
By: mirek on Sat, 28 May 2011 21:10
|
Goto Forum:
Current Time: Wed Apr 30 03:20:15 CEST 2025
Total time taken to generate the page: 0.04751 seconds
|