Instance< c > Class Template Reference


Detailed 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 821 of file kernel.h.

#include <kernel.h>

List of all members.

Public Member Functions

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

Constructor & Destructor Documentation

Instance ( c *  pObject ) [inline]

Definition at line 826 of file kernel.h.

: m_pObject( pObject ) {};
Instance ( void  ) [inline]

Definition at line 827 of file kernel.h.

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

Definition at line 828 of file kernel.h.

{ if( m_pObject ) delete m_pObject; };

Member Function Documentation

c* operator-> ( void  ) [inline]

Definition at line 829 of file kernel.h.

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

Definition at line 830 of file kernel.h.

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

Definition at line 831 of file kernel.h.

{ 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 835 of file kernel.h.

{ c* pTemp = m_pObject; m_pObject = 0; return pTemp; }

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