Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Smart Object

juhgiyo edited this page · 6 revisions

Smart Object Usage

Linking

#include "epl.h"
using namespace epl;

Declaring Smart Class

class SomeClass : public SmartObject
{
public:
   SomeClass():SmartObject()
   {
      //Initialization
      ...
   }
   SomeClass(const SomeClass& b):SmartObject(b)
   {
      //Initialization by copying
      ...
   }
   virtual ~SomeClass();
   ...
};

Smart Class Usage Type1 (General Purpose)

SomeClass *someClass = new SomeClass(); // reference count = 1
...
delete someClass;                       // deletion (Only allowed when reference count is 1)

Smart Class Usage Type2 (Reference Management)

void SomeFunc(SomeClass *sClass)
{
   sClass->RetainObj();  // reference count =  2
   ...
   sClass->ReleaseObj(); // reference count =  1
}
... 
void SomeOtherFunc()
{
   SomeClass *someClass = new SomeClass(); // reference count = 1
   SomeFunc(someClass);
   someClass->ReleaseObj();                   // reference count = 0, and auto-released
}

Smart Class Usage Type3

SomeClass *someClass = new SomeClass(); // reference count = 1
someClass->RetainObj();                    // reference count = 2
...
someClass->ReleaseObj();                   // reference count = 1
delete someClass;                       // deletion (Only allowed when reference count is 1)

Smart Class Usage Type3

void SomeFunc(SomeClass *sClass)
{
   sClass->RetainObj();  // reference count = 3
   ...
   sClass->ReleaseObj(); // reference count = 2
}
...
SomeClass *someClass = new SomeClass(); // reference count = 1
someClass->RetainObj();                    // reference count = 2
SomeFunc(someClass);
someClass->ReleaseObj();                   // reference count = 1
someClass->ReleaseObj();                   // reference count = 0, and auto-release
Something went wrong with that request. Please try again.