From f29fe16932ede752589ef9ed34a757342387932f Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Fri, 16 Apr 2004 10:30:07 +0000
Subject: [PATCH] added and documented wx_const/static_cast<>

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26831 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/function.tex | 35 +++++++++++++++++++++++++++++++++++
 include/wx/defs.h          | 33 +++++++++++++++++++++------------
 include/wx/event.h         |  6 +-----
 include/wx/object.h        |  2 +-
 4 files changed, 58 insertions(+), 18 deletions(-)

diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index 545b103690..c5c7746ff5 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -235,6 +235,8 @@ the corresponding topic.
 \helpref{wxWakeUpIdle}{wxwakeupidle}\\
 \helpref{wxWriteResource}{wxwriteresource}\\
 \helpref{wxYield}{wxyield}\\
+\helpref{wx\_const\_cast}{wxconstcastraw}\\
+\helpref{wx\_static\_cast}{wxstaticcastraw}\\
 \helpref{\_}{underscore}\\
 \helpref{\_T}{underscoret}
 
@@ -3289,6 +3291,7 @@ supports {\it const\_cast} or into an old, C-style cast, otherwise.
 
 \wxheading{See also}
 
+\helpref{wx\_const\_cast}{wxconstcastraw}\\
 \helpref{wxDynamicCast}{wxdynamiccast}\\
 \helpref{wxStaticCast}{wxstaticcast}
 
@@ -3376,10 +3379,42 @@ This macro checks that the cast is valid in debug mode (an assert failure will
 result if {\tt wxDynamicCast(ptr, classname) == NULL}) and then returns the
 result of executing an equivalent of {\tt static\_cast<classname *>(ptr)}.
 
+\wxheading{See also}
+
+\helpref{wx\_static\_cast}{wxstaticcastraw}\\
 \helpref{wxDynamicCast}{wxdynamiccast}\\
 \helpref{wxConstCast}{wxconstcast}
 
 
+\membersection{wx\_const\_cast}\label{wxconstcastraw}
+
+\func{T}{wx\_const\_cast}{T, x}
+
+Same as \texttt{const\_cast<T>(x)} if the compiler supports const cast or 
+\texttt{(T)x} for old compilers. Unlike \helpref{wxConstCast}{wxconstcast},
+the cast it to the type \arg{T} and not to \texttt{T *} and also the order of
+arguments is the same as for the standard cast.
+
+\wxheading{See also}
+
+\helpref{wx\_static\_cast}{wxstaticcastraw}\\
+
+
+\membersection{wx\_static\_cast}\label{wxstaticcastraw}
+
+\func{T}{wx\_static\_cast}{T, x}
+
+Same as \texttt{static\_cast<T>(x)} if the compiler supports static cast or 
+\texttt{(T)x} for old compilers. Unlike \helpref{wxStaticCast}{wxstaticcast},
+there are no checks being done and the meaning of the macro arguments is exactly
+the same as for the standard static cast, i.e. \arg{T} is the full type name and
+star is not appended to it.
+
+\wxheading{See also}
+
+\helpref{wx\_const\_cast}{wxconstcastraw}\\
+
+
 
 \section{Log functions}\label{logfunctions}
 
diff --git a/include/wx/defs.h b/include/wx/defs.h
index 1216bce79c..99fb5fa250 100644
--- a/include/wx/defs.h
+++ b/include/wx/defs.h
@@ -1,12 +1,12 @@
 /**
-*  Name:        defs.h 
-*  Purpose:     Declarations/definitions common to all wx source files 
-*  Author:      Julian Smart and others 
+*  Name:        defs.h
+*  Purpose:     Declarations/definitions common to all wx source files
+*  Author:      Julian Smart and others
 *  Modified by: Ryan Norton (Converted to C)
-*  Created:     01/02/97 
-*  RCS-ID:      $Id$ 
-*  Copyright:   (c) 
-*  Licence:     wxWindows licence 
+*  Created:     01/02/97
+*  RCS-ID:      $Id$
+*  Copyright:   (c)
+*  Licence:     wxWindows licence
 */
 
 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
@@ -24,7 +24,7 @@
 
 #include "wx/platform.h"
 
-/*  RN - only double-check the environment when building in C++ 
+/*  RN - only double-check the environment when building in C++
     Shouldn't configure pass the environment to all sub-libs too? */
 #ifdef __cplusplus
 /*  Make sure the environment is set correctly */
@@ -283,12 +283,21 @@ typedef int wxWindowID;
     #endif
 #endif /*  HAVE_CXX_CASTS */
 
+#ifdef HAVE_STATIC_CAST
+    #define wx_static_cast(t, x) static_cast<t>(x)
+#else
+    #define wx_static_cast(t, x) ((t)(x))
+#endif
+
 #ifdef HAVE_CONST_CAST
-    #define wxConstCast(obj, className) const_cast<className *>(obj)
+    #define wx_const_cast(t, x) const_cast<t>(x)
 #else
-    #define wxConstCast(obj, className) ((className *)(obj))
+    #define wx_const_cast(t, x) ((t)(x))
 #endif
 
+/* for consistency with wxStatic/DynamicCast defined in wx/object.h */
+#define wxConstCast(obj, className) wx_const_cast(className *, obj)
+
 #ifndef HAVE_STD_WSTRING
     #if defined(__VISUALC__) && (__VISUALC__ >= 1100)
         /*  VC++ 6.0 and 5.0 have std::wstring (what about earlier versions?) */
@@ -744,7 +753,7 @@ typedef wxUint32 wxDword;
     #define wxLongLongSuffix l
     #define wxLongLongFmtSpec _T("l")
     #define wxLongLongIsLong
-#elif (defined(__VISUALC__) && defined(__WIN32__)) 
+#elif (defined(__VISUALC__) && defined(__WIN32__))
     #define wxLongLong_t __int64
     #define wxLongLongSuffix i64
     #define wxLongLongFmtSpec _T("I64")
@@ -756,7 +765,7 @@ typedef wxUint32 wxDword;
       #define wxLongLong_t __int64
       #define wxLongLongSuffix i64
       #define wxLongLongFmtSpec _T("Ld")
-#elif defined(__DIGITALMARS__) 
+#elif defined(__DIGITALMARS__)
       #define wxLongLong_t __int64
       #define wxLongLongSuffix LL
       #define wxLongLongFmtSpec _T("ll")
diff --git a/include/wx/event.h b/include/wx/event.h
index 64146b5b14..4c915163a3 100644
--- a/include/wx/event.h
+++ b/include/wx/event.h
@@ -57,11 +57,7 @@ typedef int wxEventType;
 
 // this is used to make the event table entry type safe, so that for an event
 // handler only a function with proper parameter list can be given.
-#ifdef HAVE_STATIC_CAST
-    #define wxStaticCastEvent(type, val) static_cast<type>(val)
-#else
-    #define wxStaticCastEvent(type, val) ((type)(val))
-#endif
+#define wxStaticCastEvent(type, val) wx_static_cast(type, val)
 
 // in previous versions of wxWindows the event types used to be constants
 // which created difficulties with custom/user event types definition
diff --git a/include/wx/object.h b/include/wx/object.h
index acf4956d16..f42eaa5eb3 100644
--- a/include/wx/object.h
+++ b/include/wx/object.h
@@ -544,7 +544,7 @@ public:
     // get the runtime identity of this object
     wxClassInfo *GetClassInfo() const
     {
-		return const_cast<wxClassInfo*>((const wxClassInfo*)m_classInfo);
+		return wx_const_cast(wxClassInfo *, m_classInfo);
     }
 
     wxObject* GetSuperClassInstance() const
-- 
2.50.0

