Click here to Skip to main content
15,893,190 members
Articles / Desktop Programming / MFC

Small C++ class to transform any static control into a hyperlink control

Rate me:
Please Sign up or sign in to vote.
4.31/5 (23 votes)
6 Feb 200611 min read 100.4K   1.3K   41  
This class is small, efficient and is compatible with Win32 API programs and MFC programs as well.
/*
 * Module ID: debug.h
 * Title    : Header file for debugging services.
 * Purpose  : Provide debugging macros
 *
 * Author   : Olivier Langlois <olanglois@sympatico.ca>
 * Date     : June, 25 1996
 *
 * Revision :
 *
 * 001        22-Nov-1997 - Olivier Langlois
 *            Add macros using assert()
 *
 * 002        12-Mar-1998 - Olivier Langlois
 *            Add <iostream.h>. It is very frequent to need iostreams
 *            when debugging.
 *
 * 003        26-Sep-1998 - Olivier Langlois
 *            Modify ASSERT() macro name for uASSERT() to avoid conflict
 *            a MFC macro having the same name.
 *
 * 004        13-Jan-2006 - Olivier Langlois
 *            Change <iostream.h> to <iostream> as <iostream.h> is not
 *            supported anymore in newer MS compilers.
 */

#ifndef _DEBUG_H_
#define _DEBUG_H_

#ifdef  DEBUG
#ifdef  __GNUG__
//#       include <std/typeinfo.h>
#endif
#       include <iostream>
#       include <assert.h>
#       define D(x)  x

		  /* Check pre- and post-conditions */
#       define uPRECONDITION(a)    assert( (a) != 0 )
#       define POSTCONDITION(a)    assert( (a) != 0 )
#       define PRECONDITION2(a,b)  assert((b, (a) !=0))
#       define POSTCONDITION2(a,b) assert((b, (a) !=0))
#       define uASSERT(a)          assert( (a) != 0 )

/*
 * DEBUGTAG can be used with an object from the ostream class in C++
 * or with the printf() function in C.
 *
 * Examples:
 * With C++  : cerr << DEBUGTAG;
 * With C    : printf( "%s:%d", DEBUGTAG );
 */
#       ifdef  __cplusplus
#       define DEBUGTAG  __FILE__ << ":" << __LINE__ << " "
#       else
#       define DEBUGTAG  __FILE__, __LINE__
#       endif

#else
#       define D(x)
#       define uPRECONDITION(a)
#       define POSTCONDITION(a)
#       define PRECONDITION2(a,b)
#       define POSTCONDITION2(a,b)
#       define uASSERT(a)
#       ifdef  __cplusplus
#       define DEBUGTAG ""
#       else

/*
 * There is no way to make DEBUGTAG disapear completely in C without
 * causing problems.
 * The ideal usage of DEBUGTAG in C is to use it only inside the D()
 * macro.
 */
#       define DEBUGTAG "", 0
#       endif
#endif

/*
 * Old 16 bits stuff...
 *
 * SEG(p)	Evaluate the address segment
 * OFF(p)   Evaluate the address offset
 * PHYS(p)	Return the physical address in an unsigned long
 *          type variable.
 */

#define SEG(p)	 ( ((unsigned *)&(p))[1] )
#define OFF(p)  ( ((unsigned *)&(p))[0] )
#define PHYS(p) (((unsigned long)OFF(p)) + ((unsigned long)SEG(p) << 4))

/* NUMELE(array)	  Evaluate the number of elements in a list
 * LASTELE(array)     Evaluate the pointer of the last element of a list
 * INBOUNDS(array,p)  Evaluate true is p is inside array
 * RANGE(a,b,c)       Evaluate true if a <= b <= c
 *
 * NBITS(type)        Return the number of bits in the variable type t
 *
 * MAXINT             Evaluate the maximum value that can reach a signed int
 *                    variable.
 */

#define NUMELE(a)     (sizeof(a)/sizeof(*(a)))
#define LASTELE(a)    ((a) + (NUMELE(a)-1))
#define TOOHIGH(a,p)  ((p) - (a) > (NUMELE(a) - 1))
#define TOOLOW(a,p)   ((p) - (a) < 0 )
#define INBOUNDS(a,p) ( ! (TOOHIGH(a,p) || TOOLOW(a,p)) )

#define _IS(t,x)  (((t)1 << (x))!=0) /* Evaluate true if the variable type */
									 /* t length is < x.                   */

#define NBITS(t)     (4 * (1 + _IS(t,4)  + _IS(t,8)  + _IS(t,12) + _IS(t,16) \
					  + _IS(t,20) + _IS(t,24) + _IS(t,28) + _IS(t,32)) )

#define MAXINT    (((unsigned)~0) >> 1)

#endif  /* _DEBUG_H_ */

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
I'm located in Montreal,Canada and I graduated in electrical engineering at E.T.S.

Highly experienced C++ developer. I have been working 3 years at Nortel Networks on their Next-gen OC-768 products firmware. I then worked for the FAA 3 years on their next-gen Oceanic Air Traffic Control system. Followed by a short period in the video game industry at Quazal, the online multiplayer middleware provider and now I am in the Internet audio/video streaming business at StreamTheWorld.

To contact me, visit my website

Comments and Discussions