Instance< c > Class Template Reference

Instance< c > Class Template Reference

#include <kernel.h>

Class Description

template<typename c>
class mudbox::Instance< c >

This is a helper class to manage class instances implemented in plugins, provided for convenience.

The following two are equal:

{
Image *pMyImage = CreateInstance<Image>();
pMyImage->DoSomething();
delete pMyImage;
}

and

{
Instance<Image> pMyImage;
pMyImage->DoSomething();
}

In the second case, the target object will be automatically deleted when the block ends. You can also use this class to define member variables in your classes. This way when the owner class is constructed, the instances of the needed classes will be created, and when the object destructed, those instances will be removed from the memory too. For example:

class MyClass
{
Instance<Image> m_pSourceImage, m_pDestinationImage;
public:
// member functions which work with the two images
}

You can also create an Instance with an existing object. For example:

Node* pNode = CreateInstance<Node>();
Instance<Node> cInstance(pNode);

Here, cInstance takes ownership of pNode, and will delete it when cInstance goes out of scope.

Definition at line 616 of file kernel.h.

Public Member Functions

 Instance (c *pObject)
 
 Instance (void)
 
 ~Instance (void)
 
coperator-> (void)
 
const coperator-> (void) const
 
 operator c * (void) const
 
cRelease ()
 Take ownership of m_pObject. More...
 

Constructor & Destructor Documentation

Instance ( c pObject)
inline

Definition at line 621 of file kernel.h.

621 : m_pObject( pObject ) {};
Instance ( void  )
inline

Definition at line 622 of file kernel.h.

622 { m_pObject = CreateInstance<c>(); };
~Instance ( void  )
inline

Definition at line 623 of file kernel.h.

623 { if( m_pObject ) delete m_pObject; };

Member Function Documentation

c* operator-> ( void  )
inline

Definition at line 624 of file kernel.h.

624 { return m_pObject; };
const c* operator-> ( void  ) const
inline

Definition at line 625 of file kernel.h.

625 { return m_pObject; };
operator c * ( void  ) const
inline

Definition at line 626 of file kernel.h.

626 { return m_pObject; };
c* Release ( )
inline

Take ownership of m_pObject.

After this call the Instance should not be used and the caller is responsible for deleting the returned object.

Definition at line 630 of file kernel.h.

630 { c* pTemp = m_pObject; m_pObject = 0; return pTemp; }
const GLubyte * c
Definition: GLee.h:5419

The documentation for this class was generated from the following file: