home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cast.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.8 KB  |  139 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef __CAST_H
  20. #define __CAST_H
  21.  
  22. //    To handle casts between the various windows
  23. //        platforms.
  24. //    We use these macros/inline functions instead of just
  25. //        casting directly so that we can manipulate their
  26. //        behaviour on a broad scale, and very customized
  27. //        behaviour can be achieved if you need to range
  28. //        check values in debug mode, etc.
  29.  
  30. //    PAY ATTENTION, OR WE'RE ALL DEAD:
  31. //    The use of inline functions is to avoid the over evaluation
  32. //        problem (common to macros) when repeating parameters
  33. //        in doing a computation.
  34. //        i.e.
  35. //            #define EVAL(a) ((a) + (a))
  36. //
  37. //            EVAL(a *= a + a);
  38. //        However, by using inline function, it is not possible
  39. //        to provide every possible cast operation that macros
  40. //        do cover.  This is a known shortfall.  Templates were
  41. //        the solution, but it's not clear that we'll ever have
  42. //        a 16 bit compiler which supports templates.  You will
  43. //        have to implement each needed cast seperately.  You
  44. //        can mostly avoid the problem by using the largest possible
  45. //        data type.
  46.  
  47. //    To turn off all casting in the front end which
  48. //        utilizes these macros, define NO_CAST, and get
  49. //        ready for a boatload of warnings.
  50. //#define NO_CAST
  51.  
  52.  
  53. //    Now onto the show.
  54. //    GAB 09-13-95
  55.  
  56.  
  57. //    Native integer cast, good for use in WinAPI calls.
  58. //    In debug, we camp on you if we actually lose bits, as it
  59. //        is ambiguous if we should hold the top limit to MAXINT
  60. //        or if we should just take the lower sizeof(int) bytes
  61. //        and ignore the rest.
  62. #ifndef NO_CAST
  63. #ifndef _DEBUG
  64. #define CASTINT(a) ((int)(a))
  65. #else
  66. inline int CASTINT(long a)    {
  67.     int b = (int)a;
  68.  
  69.     ASSERT(a == (long)b);
  70.     return(b);
  71. }
  72. #endif
  73. #else
  74. #define CASTINT(a) (a)
  75. #endif
  76.  
  77. //    Native unsigned cast.
  78. //    In debug, we camp on you if we actually lose bits.
  79. #ifndef NO_CAST
  80. #ifndef _DEBUG
  81. #define CASTUINT(a) ((unsigned)(a))
  82. #else
  83. inline unsigned CASTUINT(long a)    {
  84.     unsigned b = (unsigned)a;
  85.  
  86.     ASSERT(a == (long)b);
  87.     return(b);
  88. }
  89. #endif
  90. #else
  91. #define CASTUINT(a) (a)
  92. #endif
  93.  
  94. #ifndef NO_CAST
  95. #ifndef _DEBUG
  96. #define CASTSIZE_T(a) ((size_t)(a))
  97. #else
  98. inline size_t CASTSIZE_T(long a)    {
  99.     size_t b = (size_t)a;
  100.  
  101.     ASSERT(a == (long)b);
  102.     return(b);
  103. }
  104. #endif
  105. #else
  106. #define CASTSIZE_T(a) (a)
  107. #endif
  108.  
  109. #ifndef NO_CAST
  110. #ifndef _DEBUG
  111. #define CASTDWORD(a) ((DWORD)(a))
  112. #else
  113. inline DWORD CASTDWORD(long a)    {
  114.     DWORD b = (DWORD)a;
  115.  
  116.     ASSERT(a == (long)b);
  117.     return(b);
  118. }
  119. #endif
  120. #else
  121. #define CASTDWORD(a) (a)
  122. #endif
  123.  
  124. //    NCAPI data from URL_Struct
  125. #define NCAPIDATA(pUrl) ((CNcapiUrlData *)(pUrl)->ncapi_data)
  126.  
  127. //  Context casts
  128. #define CX2VOID(pContext, CastFromClassCX) ((void *)((CAbstractCX *)((CastFromClassCX *)(pContext))))
  129. #define VOID2CX(pVoid, CastToClassCX) ((CastToClassCX *)((CAbstractCX *)((void *)(pVoid))))
  130.  
  131. #define ABSTRACTCX(pXPCX) ((pXPCX)->fe.cx)
  132. #define BOOKMARKCX(pXPCX) ((CNewBookmarkWnd *)((pXPCX)->fe.cx))
  133. #define WINCX(pXPCX) ((CWinCX *)((pXPCX)->fe.cx))
  134. #define CXDC(pXPCX) ((CDCCX *)((pXPCX)->fe.cx))
  135. #define PANECX(pXPCX) ((CPaneCX *)((pXPCX)->fe.cx))
  136.  
  137.  
  138. #endif // __CAST_H
  139.