Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C++

Extended Debug Macros

Rate me:
Please Sign up or sign in to vote.
2.00/5 (5 votes)
13 Jun 20011 min read 54.6K   723   11  
A set of debug macros for checking expressions that work in
// LJSDebug.h file --- 2001/03/16 +++������(Jungsul Lee), South Korea

// compile mode�� ������� ����뿡 ����ϱ� ���� ��ũ�� ���� ����
// This is a debug macro definition file and is available regardless of compile mode

//-----------------------------------------------------------//
// macro, return false and exit function when expression is false
// ���ǽ��� ������ ���, ������ �����ϰ� �Լ� �ߴ� ��ũ��
// CHECKEXPR(bExpression, ERRORMSG, RETURNVALUE) 
// CHECKVOIDEXPR(bExpression, ERRORMSG) 
// CHECKFUNC(bExpression, ERRORMSG, RETURNVALUE) 
// CHECKVOIDFUNC(bExpression, ERRORMSG) 
//
// macro, make sure whether exit program or not when expression is false
// ���ǽ��� ������ ���, ���α׷� ���� ���θ� Ȯ�� 
// EXITCHECKEXPR(bExpression, ERRORMSG, RETURNVALUE) 
// EXITCHECKVOIDEXPR(bExpression, ERRORMSG) 
// EXITCHECKFUNC(bExpression, ERRORMSG, RETURNVALUE) 
// EXITCHECKVOIDFUNC(bExpression, ERRORMSG) 

// ~EXPR ��ũ�δ� ���� �˻翡, ~FUNC ��ũ�δ� �Լ��� �˻翡 ����Ѵ�.
// ~EXPR macro is used to check expression, ~FUNC macro is used to check function

// ~VOID~ ��ũ�δ� �� ��ũ�θ� ȣ���ϴ� �Լ��� �������� void�� �Լ��� ����.
// ~VOID~ macro is used when return value type of the function calling this macro
// is void
 
// bExpression : �˻��� ���ǽ�( specifies expression to be evaluated)
// ERRORMSG    : ���ǽ��� ������ ��� ������ �޼���( message to be shown when expression is false)
// RETURNVALUE : ���ǽ��� ������ ��� ��ȯ�� ��( return value when expression is false)

// �� ������ ����� ���θ� �����ϰ�, ���� ������ ���� ����� �ɼ��� �� ��쿣, ����Ǵ� ���Ͽ���
// �ѹ��� �����ָ� �ȴ�. ���� stdafx.h���� ���ָ�, �ѹ��� ���� ������  ���� ���Ͽ��� �� �� �ִ�.
// �� ���ϸ��� ������� ���ΰ� Ʋ���ٸ�, *.cpp���Ͽ��� include�����ִ� ���� ����. �׷��� �ϸ� ����
// �� ���ϸ��� ����� �ɼ��� �ٸ��� �� �� �ִ�.
// If you would like to define debug option just one time and use this debug option at other files, 
// you have better define this option at file is included by other files, commonly stdafx.h file.
// If you would like to define debug option differently to each file, it is good to include LJSDebug.h
// file in *.cpp file. If so, you can define debug option seperately from any other files.

//-----------------------------------------------------------//

#ifndef __LJS__DEBUG__//(start if) // ��ü �ڵ��� �ߺ� ���Ǹ� ���ϱ� ���� �� to avoid whole file redifinition

#define __LJS__DEBUG__  

// LJSDebug.h ������ ���� ���ؼ�, #include "LJSDebug.h" �� ���� ����, debug�� �� 
// ������ ���� �������� ������ __LJS__DEBUG__YES__ , __LJS__DEBUG__NO__��
// ��� �Ѵ�.
// if you would like to use LJSDebug.h file, you must define __LJS__DEBUG__YES__ 
// macro if you will debug, __LJS__DEBUG__NO__ if won't debug before
// #include "LJSDebug.h" phrase!!
#ifndef __LJS__DEBUG__YES__ 
#ifndef __LJS__DEBUG__NO__
  #error You must define __LJS__DEBUG__YES__ or __LJS__DEBUG__NO__ macro before #include "LJSDebug.h" phrase if you use LJSDebug.h file!!
#endif
#endif

//---������ ��ũ�ΰ� �̹� ����Ǿ� ���� ���,  ��ó�� �ߴ�!!
//---stop pre-processing when any macro will be defined is alread defined!!
#ifdef CHECKVOIDFUNC
   #error CHECKVOIDFUNC macro is alread defined !!
#elif defined(CHECKFUNC)
   #error CHECKFUNC macro is alread defined !!
#elif defined(CHECKVOIDEXPR)
   #error CHECKVOIDEXPR macro is alread defined !!
#elif defined(CHECKEXPR)
   #error CHECKEXPR macro is alread defined !!
#elif defined(EXITCHECKEXPR)
   #error EXITCHECKEXPR macro is alread defined !!
#elif defined(EXITCHECKVOIDEXPR)
   #error EXITCHECKVOIDEXPR macro is alread defined !!
#elif defined(EXITCHECKVOIDFUNC)
   #error EXITCHECKVOIDFUNC macro is alread defined !!
#elif defined(EXITCHECKFUNC)
   #error EXITCHECKFUNC macro is alread defined !!
#endif

#ifdef  __LJS__DEBUG__YES__//(start debug yes if)debugging�� �� ���
 
#define CHECKVOIDFUNC(bEXPRESSION, ERRORMSG)\
                                              if(!(bEXPRESSION)) {\
											    AfxMessageBox(ERRORMSG);\
												return;};\

#define CHECKFUNC(bEXPRESSION, ERRORMSG, RETURNVALUE)\
                                              if(!(bEXPRESSION)) {\
                                                 AfxMessageBox(ERRORMSG);\
                                                 return RETURNVALUE ;};\

#define CHECKVOIDEXPR(bEXPRESSION, ERRORMSG)\
        CHECKVOIDFUNC(bEXPRESSION, ERRORMSG)\

#define CHECKEXPR(bEXPRESSION, ERRORMSG, RETURNVALUE)\
        CHECKFUNC(bEXPRESSION, ERRORMSG, RETURNVALUE)\

#define EXITCHECKEXPR(bEXPRESSION,ERRORMSG, RETURNVALUE)\
	if(!(bEXPRESSION)){\
	  if(AfxMessageBox(CString(ERRORMSG)+CString(_T("\n\nDo you exit program now?")),\
	                   MB_YESNO) == IDYES)\
	    exit(-1);\
	  else return RETURNVALUE;};\
				  
#define EXITCHECKVOIDEXPR(bEXPRESSION,ERRORMSG)\
	if(!(bEXPRESSION)){\
      if(AfxMessageBox(CString(ERRORMSG)+CString(_T("\n\nDo you exit program now?")),\
	                   MB_YESNO) == IDYES)\
  	    exit(-1);\
	  else return ;};\

#define EXITCHECKVOIDFUNC(bEXPRESSION,ERRORMSG)\
        EXITCHECKVOIDEXPR(bEXPRESSION,ERRORMSG)\

#define EXITCHECKFUNC(bEXPRESSION,ERRORMSG, RETURNVALUE)\
        EXITCHECKEXPR(bEXPRESSION,ERRORMSG, RETURNVALUE)\

#endif//(end debug yes if)

#ifdef __LJS__DEBUG__NO__//(start debug no if)debugging�� ���� ���

#define CHECKEXPR(bExpression, ERRORMSG, RETURNVALUE) 
#define CHECKVOIDEXPR(bExpression, ERRORMSG) 
#define CHECKFUNC(bExpression, ERRORMSG, RETURNVALUE)         bExpression
#define CHECKVOIDFUNC(bExpression, ERRORMSG)                  bExpression
#define EXITCHECKEXPR(bExpression, ERRORMSG, RETURNVALUE) 
#define EXITCHECKVOIDEXPR(bExpression, ERRORMSG) 
#define EXITCHECKFUNC(bExpression, ERRORMSG, RETURNVALUE)     bExpression
#define EXITCHECKVOIDFUNC(bExpression, ERRORMSG)              bExpression

#endif//(end bebug no if)

#endif //(end if)
 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions