This example demonstrates the counting of references for static and dynamic
instances created by either an empty or standard implementation of the reference
counter. The example uses the console application project in the following implementation:
#include "conio.h"
#include "OdaCommon.h"
#include "OdToolKit.h"
#include "..\..\Kernel\Extensions\ExServices\ExHostAppServices.h"
#include "..\..\Kernel\Extensions\ExServices\ExSystemServices.h"
class MyApp : public ExSystemServices
{
protected:
ODRX_USING_HEAP_OPERATORS(ExSystemServices);
public:
MyApp() {};
};
void TestStaticInstance();
void TestDynamicInstance();
int main()
{
OdStaticRxObject<MyApp> svcs;
odInitialize(&svcs);
odPrintConsoleString(L"\nCreating the static instance");
TestStaticInstance();
odPrintConsoleString(L"\nReturn from Test");
getch();
odPrintConsoleString(L"\n\n");
odPrintConsoleString(L"\nCreating the dynamic instance");
TestDynamicInstance();
odPrintConsoleString(L"\nReturn from Test");
getch();
odUninitialize();
return 0;
}
The example defines the TestStaticInstance() function for testing instances created
statically and the TestDynamicInstance() function for testing instances created
dynamically. Both functions call the RefCountTest() function, which gets the raw
pointer to the instance of the user-defined class (MyObj) derived from the OdRxObject,
and both functions create new smart pointers to them, assign the address of
the instance (or NULL) to them, and print the reference counter after assignment
operators. The RefCountTest() function has the following implementation:
The implementation of the TestStaticInstance() and TestDynamicInstance() functions
depends on the definition of the user-defined class (MyObj) that can be derived
either from the empty implementation
using the OdStaticRxObject class or the standard
implementation using the OdRxObjectImpl class.