User:Ccw: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Replacing page with '__NOTOC__ {{MTA Developer}} message deleted')
No edit summary
Line 2: Line 2:
{{MTA Developer}}
{{MTA Developer}}


message deleted
 
=Some class constructors and destructors are too complex=
===Proposed solution to [issue http://bugs.mtasa.com/view.php?id=4377]===
==Example of solution when applied to CClientEntity and CClientColModel:==
 
Current base and concrete class declaration:
<syntaxhighlight lang="lua">
class CClientEntity
{
public:
                                    CClientEntity          ( ElementID ID );
    virtual                        ~CClientEntity          ( void );
...
 
 
class CClientColModel: public CClientEntity
{
public:
                                    CClientColModel        ( class CClientManager* pManager, ElementID ID );
                                    ~CClientColModel        ( void );
...
</syntaxhighlight>
 
 
Proposed base class declaration and definition:
<syntaxhighlight lang="lua">
class CClientEntity
{
protected:
                                    CClientEntity          ( ElementID ID );
    virtual                        ~CClientEntity          ( void );
    virtual void                    PostConstruct          ( void );
    virtual void                    PreDestroy              ( void );
public:
    void                            Delete                  ( void );
...
 
 
void CClientEntity::PostConstruct ()
{
    // Code from CClientEntity constructor moved here
}
 
void CClientEntity::PreDestroy ()
{
    // Code from CClientEntity destructor moved here
}
 
void CClientEntity::Delete ( void )
{
    PreDestroy ();
    delete this;
}
</syntaxhighlight>
 
 
 
 
Proposed concrete class declaration and definition:
<syntaxhighlight lang="lua">
class CClientColModel: public CClientEntity
{
public:
                                    CClientColModel        ( class CClientManager* pManager, ElementID ID );
                                    ~CClientColModel        ( void );
    virtual void                    PostConstruct          ( void );
    virtual void                    PreDestroy              ( void );
public:
    static CClientColModel*        NewCClientColModel      ( CClientStreamer * pStreamer, ElementID ID );
...
 
 
void CClientColModel::PostConstruct ()
{
    __super::PostConstruct ();
    // Code from CClientColModel constructor moved here
}
 
void CClientColModel::PreDestroy ()
{
    // Code from CClientColModel destructor moved here
    __super::PreDestroy ();
}
 
CClientColModel* CClientColModel::NewCClientColModel ( CClientStreamer * pStreamer, ElementID ID )
{
    CClientColModel* pElement = new CClientColModel ( pStreamer, ID );
    pElement->PostConstruct ()
    return pElement;
}
</syntaxhighlight>
 
 
 
===Other changes required===
Any occurrence of
<syntaxhighlight lang="lua">
new CClientColModel ( pStreamer, ID );
delete pElement;
</syntaxhighlight>
is replaced with
<syntaxhighlight lang="lua">
CClientColModel::NewCClientColModel ( pStreamer, ID );
pElement->Delete ();
</syntaxhighlight>

Revision as of 02:41, 1 June 2009

Coder.gif This user is an MTA developer


Some class constructors and destructors are too complex

Proposed solution to [issue http://bugs.mtasa.com/view.php?id=4377]

Example of solution when applied to CClientEntity and CClientColModel:

Current base and concrete class declaration:

class CClientEntity
{
public:
                                    CClientEntity           ( ElementID ID );
    virtual                         ~CClientEntity          ( void );
...


class CClientColModel: public CClientEntity
{
public:
                                    CClientColModel         ( class CClientManager* pManager, ElementID ID );
                                    ~CClientColModel        ( void );
...


Proposed base class declaration and definition:

class CClientEntity
{
protected:
                                    CClientEntity           ( ElementID ID );
    virtual                         ~CClientEntity          ( void );
    virtual void                    PostConstruct           ( void );
    virtual void                    PreDestroy              ( void );
public:
    void                            Delete                  ( void );
...


void CClientEntity::PostConstruct ()
{
    // Code from CClientEntity constructor moved here
}

void CClientEntity::PreDestroy ()
{
    // Code from CClientEntity destructor moved here
}

void CClientEntity::Delete ( void )
{
    PreDestroy ();
    delete this;
}



Proposed concrete class declaration and definition:

class CClientColModel: public CClientEntity
{
public:
                                    CClientColModel         ( class CClientManager* pManager, ElementID ID );
                                    ~CClientColModel        ( void );
    virtual void                    PostConstruct           ( void );
    virtual void                    PreDestroy              ( void );
public:
    static CClientColModel*         NewCClientColModel      ( CClientStreamer * pStreamer, ElementID ID );
...


void CClientColModel::PostConstruct ()
{
    __super::PostConstruct ();
    // Code from CClientColModel constructor moved here
}

void CClientColModel::PreDestroy ()
{
    // Code from CClientColModel destructor moved here
    __super::PreDestroy ();
}

CClientColModel* CClientColModel::NewCClientColModel ( CClientStreamer * pStreamer, ElementID ID )
{
    CClientColModel* pElement = new CClientColModel ( pStreamer, ID );
    pElement->PostConstruct ()
    return pElement;
}


Other changes required

Any occurrence of

new CClientColModel ( pStreamer, ID );
delete pElement;

is replaced with

CClientColModel::NewCClientColModel ( pStreamer, ID );
pElement->Delete ();