// XTPMacros.h : common macros
//
// This file is a part of the XTREME TOOLKIT PRO MFC class library.
// (c)1998-2012 Codejock Software, All Rights Reserved.
//
// THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
// RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
// CONSENT OF CODEJOCK SOFTWARE.
//
// THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
// IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
// YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
// SINGLE COMPUTER.
//
// CONTACT INFORMATION:
// support@codejock.com
// http://www.codejock.com
//
/////////////////////////////////////////////////////////////////////////////
//{{AFX_CODEJOCK_PRIVATE
#if !defined(__XTPMACROS_H__)
#define __XTPMACROS_H__
//}}AFX_CODEJOCK_PRIVATE
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
//-----------------------------------------------------------------------------
// Summary:
// Frees dynamically allocated memory.
// Parameters:
// ptr - Points to the memory to free.
// Remarks:
// This macro will first check to see if the block of memory specified by
// ptr is NULL. If ptr is not NULL, SAFE_DELETE will deallocate
// the block of memory and set its value to NULL. The pointer argument
// must refer to a block of memory previously allocated for an object
// created with the new operator.
// Example:
//
// CName* pName = new CName; // Allocate memory for the object
// pName->SetName("Firstname", "Lastname");
// SAFE_DELETE(pName); // Deallocate memory for the object
// ASSERT(pName == NULL);
//
//-----------------------------------------------------------------------------
#ifndef SAFE_DELETE
#define SAFE_DELETE(ptr)
#endif
//{{AFX_CODEJOCK_PRIVATE
#undef SAFE_DELETE
#define SAFE_DELETE(ptr) \
if (ptr) { delete ptr; ptr = NULL; }
//}}AFX_CODEJOCK_PRIVATE
//-----------------------------------------------------------------------------
// Summary:
// Frees dynamically allocated memory for an array.
// Parameters:
// ptr - Points to the memory array to free.
// Remarks:
// This macro will first check to see if the block of memory specified by
// ptr is NULL. If ptr is not NULL, SAFE_DELETE_AR will deallocate
// the block of memory and set its value to NULL. The pointer argument
// must refer to a block of memory previously allocated for an object
// created with the new operator.
// Example:
//
// char* pCharArray = new char[256]; // Allocate memory for the array
// strcpy(pCharArray, "Array of characters");
// SAFE_DELETE_AR(pCharArray); // Deallocate memory for the array
// ASSERT(pCharArray == NULL);
//
//-----------------------------------------------------------------------------
#ifndef SAFE_DELETE_AR
#define SAFE_DELETE_AR(ptr)
#endif
//{{AFX_CODEJOCK_PRIVATE
#undef SAFE_DELETE_AR
#define SAFE_DELETE_AR(ptr) \
if (ptr) { delete [] ptr; ptr = NULL; }
//}}AFX_CODEJOCK_PRIVATE
//-----------------------------------------------------------------------------
// Summary:
// Decrements the reference count for the specified object.
// Parameters:
// comPointer - Points to the COM object to release.
// Remarks:
// This macro will first check to see if the COM object specified by comPointer
// is NULL. If the object is not NULL, the macro calls IUnknown::Release
// COM object specified by comPointer and set its value to NULL.
// See Also:
// IUnknown::Release
//-----------------------------------------------------------------------------
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(comPointer)
#endif
//{{AFX_CODEJOCK_PRIVATE
#undef SAFE_RELEASE
#define SAFE_RELEASE(comPointer) \
if (comPointer) { (comPointer)->Release(); (comPointer)=NULL; }
//}}AFX_CODEJOCK_PRIVATE
//-----------------------------------------------------------------------------
// Summary:
// Checks object pointer and if not NULL calls a specified function.
// Parameters:
// classPointer - Pointer to the class that contains the function to call.
// functionName - Name of the function to call.
// Remarks:
// This macro will first check to see if the class specified by classPointer
// is NULL. If the class is not NULL, the macro calls the function specified
// by functionName.
// Example:
//
// SAFE_CALLPTR(m_pItem, OnConstraintsChanged());
//
//-----------------------------------------------------------------------------
#define SAFE_CALLPTR(classPointer, functionName)
//{{AFX_CODEJOCK_PRIVATE
#undef SAFE_CALLPTR
#define SAFE_CALLPTR(classPointer, functionName) \
if (classPointer) classPointer->functionName
//}}AFX_CODEJOCK_PRIVATE
//-----------------------------------------------------------------------------
// Summary:
// Destroys an icon and frees any memory the icon occupied.
// Parameters:
// hIcon - Handle to the icon to free.
// Remarks:
// This macro will first check to see if the icon handle specified by
// hIcon is NULL. If hIcon is not NULL, SAFE_DELETE_HICON will
// destroy the icon handle and set its value to NULL.
// Example:
//
// HICON hIcon = XTPResourceManager()->LoadIcon(
// MAKEINTRESOURCE(dwID), item.size);
// ::DrawIconEx(pDC->GetSafeHdc(), point.x, point.y, hIcon,
// size.cx, size.cy, 0, NULL, DI_NORMAL);
// SAFE_DELETE_HICON(hIcon);
// ASSERT(hIcon == NULL);
//
//-----------------------------------------------------------------------------
#define SAFE_DELETE_HICON(hIcon)
//{{AFX_CODEJOCK_PRIVATE
#undef SAFE_DELETE_HICON
#define SAFE_DELETE_HICON(hIcon) \
if (hIcon) {::DestroyIcon(hIcon); hIcon = NULL;}
//}}AFX_CODEJOCK_PRIVATE
//-----------------------------------------------------------------------------
// Summary:
// Destroys a GDI object and frees the handle.
// Parameters:
// obj - Handle to the GDI object free.
// Remarks:
// This macro will first check to see if the GDI object specified by
// obj is NULL. If obj is not NULL, SAFE_DELETE_OBJ will
// delete the GDI object and set its value to NULL.
// Example:
//
// extern CFont m_font;
// extern LOGFONT lf;
// SAFE_DELETE_OBJ(m_font);
// m_font.CreateFontIndirect(&lf);
//
//-----------------------------------------------------------------------------
#define SAFE_DELETE_OBJ(obj)
//{{AFX_CODEJOCK_PRIVATE
#undef SAFE_DELETE_OBJ
#define SAFE_DELETE_OBJ(obj) \
if (obj.GetSafeHandle()) {obj.DeleteObject();}
//}}AFX_CODEJOCK_PRIVATE
//-----------------------------------------------------------------------------
// Summary:
// XT_ASSERT_MSG is similar to ASSERT, except that it allows a custom
// message to be specified.
// Parameters:
// exp - Specifies an expression (including pointer values)
// that evaluates to nonzero or 0.
// msg - Specifies a NULL terminated user defined string of
// the message to display to the user.
// Remarks:
// Evaluates its argument. If the result is 0, the macro prints a
// diagnostic message and aborts the program. If the condition is
// nonzero, it does nothing.
// // example for XT_ASSERT_MSG
// CAge* pAge = new CAge(21); // CAge is derived from CObject.
//
// // Terminates program only if pAge is NOT a CAge*.
// XT_ASSERT_MSG(pAge!= NULL, _T("Failed to allocate memory."));
// XT_ASSERT_MSG(pAge->IsKindOf(RUNTIME_CLASS(CAge)), _T("This is not a CAge object."));
//
// See Also:
// ASSERT, VERIFY
//-----------------------------------------------------------------------------
#define XT_ASSERT_MSG(exp, msg)
//{{AFX_CODEJOCK_PRIVATE
#undef XT_ASSERT_MSG
#ifdef _DEBUG
#ifndef _AFX_NO_DEBUG_CRT
#define XT_ASSERT_MSG(exp, msg) \
{ \
if (!(exp) && (_CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, "\n-----------------------\n" msg "\n-----------------------"))) \
AfxDebugBreak(); \
} \
#else
#define XT_ASSERT_MSG(exp, msg) (void)((exp) || (_assert("\n-----------------------\n" msg "\n-----------------------", __FILE__, __LINE__), 0))
#endif//_AFX_NO_DEBUG_CRT
#else
#define XT_ASSERT_MSG(exp, msg) ((void)0)
#endif//_DEBUG
//}}AFX_CODEJOCK_PRIVATE
//{{AFX_CODEJOCK_PRIVATE
#ifdef _DEBUG
#ifndef _AFX_NO_DEBUG_CRT
#define XTP_ERROR_MSG(msg) \
{ \
if ((_CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, "\n-----------------------\n" msg "\n-----------------------"))) \
AfxDebugBreak(); \
} \
#else
#define XTP_ERROR_MSG(msg) (void)((_assert("\n-----------------------\n" msg "\n-----------------------", __FILE__, __LINE__), 0))
#endif//_AFX_NO_DEBUG_CRT
#else
#define XTP_ERROR_MSG(msg) ((void)0)
#endif//_DEBUG
#if _MSC_VER >= 1400
#define _XTP_DEPRECATE(_Message) __declspec(deprecated(_Message))
#elif _MSC_VER >= 1300
#define _XTP_DEPRECATE(_Message) __declspec(deprecated)
#else
#define _XTP_DEPRECATE(_Message)
#endif
#ifdef _UNICODE
#ifndef UNICODE
#define UNICODE
#endif
#endif
#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define __LOC__ __FILE__ "("__STR1__(__LINE__)"): "
// usage: #pragma message(__LOC__"Need to do 3D collision testing")
#ifdef _AFXDLL
#define SAFE_MANAGE_STATE(s) AFX_MANAGE_STATE(s)
#else
#define SAFE_MANAGE_STATE(s)
#endif
#ifndef AFX_INLINE
#define AFX_INLINE inline
#endif
#ifndef CBRS_GRIPPER
#define CBRS_GRIPPER 0x00400000L
#endif
#ifndef WS_EX_LAYOUTRTL
#define WS_EX_LAYOUTRTL 0x00400000L
#endif
#ifndef DT_WORD_ELLIPSIS
#define DT_WORD_ELLIPSIS 0x00040000L
#endif
#ifndef _countof
#define _countof(array) (sizeof(array)/sizeof(array[0]))
#endif
#if (_MSC_VER >= 1300)
template<> AFX_INLINE UINT AFXAPI HashKey