GameErrors.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:2k
- /*******************************************************************
- * Advanced 3D Game Programming using DirectX 7.0
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Title: GameErrors.h
- * Desc: errors that game functions can have
- *
- * copyright (c) 1999 by Adrian Perez
- * See license.txt for modification and distribution information
- ******************************************************************/
- #ifndef _GAMEERRORS_H
- #define _GAMEERRORS_H
- #include <string>
- #include "GameGlobals.h"
- //==========--------------------------
- /**
- * This code is slow, using dynamic memory, but since we only use them
- * when something Really Bad happens, the user won't notice that their
- * application exits abmornally a few nanoseconds slower than usual
- */
- class cGameError
- {
- std::string m_errorText;
- public:
- cGameError( const char* errorText )
- {
- DP1("***n*** [ERROR] cGameError thrown! text: [%s]n***n", errorText );
- m_errorText = std::string( errorText );
- }
- const char* GetText()
- {
- return m_errorText.c_str();
- }
- };
- //==========--------------------------
- enum eResult
- {
- resAllGood = 0, // function passed with flying colors
- resFalse = 1, // function worked and returns value 'false'
- resFailed = -1, // function failed miserably
- resNotImpl = -2, // function has not been implemented
- resForceDWord = 0x7FFFFFFF
- };
- inline bool Succeeded( eResult in )
- {
- if( in >= 0 )
- return true;
- return false;
- }
- inline bool Failed( eResult in )
- {
- if( in < 0 )
- return true;
- return false;
- }
- /**
- * The Right Way to release our COM interfaces.
- * If they're still valid, release them, then
- * invalidate them.
- */
- template <class T>
- inline void SafeRelease( T& iface )
- {
- if( iface )
- {
- iface->Release();
- iface = NULL;
- }
- }
- /**
- * Make sure the release brings our refcount to 0.
- */
- template <class T>
- inline void ExtraSafeRelease( T& iface )
- {
- long refCount = 0;
- if( iface )
- {
- if( 0 < ( refCount = iface->Release() ) )
- {
- DP0("[ExtraSafeRelease]: ERROR: Interface was not released enough!");
- }
- iface = NULL;
- }
- }
- #endif //_GAMEERRORS_H