summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-09-18 15:10:54 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-09-23 17:27:47 +0200
commit23e1fc277d5651babce17bb74408ef6505f101d2 (patch)
treeedf64a973766400f870095f4ecd25784bfea6ba5 /include
parent7f895dfbf5fb084d747e52db678d75e3273cd825 (diff)
loplugin: cstylecast, update PTR_CAST macro to use static_cast
I introduce a template method into the PTR_CAST machinery to maintain constness. There is now a FIXME in sd/../docshell.cxx because I needed to use a dynamic_cast there to work around the games it appears to be playing with OLE in-place activation. Signed-off-by: Stephan Bergmann <sbergman@redhat.com>, dropping the GCC-extension, unnecessary use of typeof from tools/rtti.hxx Change-Id: Iba5ace1aa27e02b34fcc91af1e658c43371afd03
Diffstat (limited to 'include')
-rw-r--r--include/tools/debug.hxx2
-rw-r--r--include/tools/inetstrm.hxx4
-rw-r--r--include/tools/link.hxx2
-rw-r--r--include/tools/rtti.hxx13
4 files changed, 15 insertions, 6 deletions
diff --git a/include/tools/debug.hxx b/include/tools/debug.hxx
index b80d0f08c9ca..050dc3428298 100644
--- a/include/tools/debug.hxx
+++ b/include/tools/debug.hxx
@@ -98,7 +98,7 @@ inline sal_uIntPtr DbgIsBoldAppFont()
inline void DbgSetTestSolarMutex( DbgTestSolarMutexProc pProc )
{
- DbgFunc( DBG_FUNC_SETTESTSOLARMUTEX, (void*)(long)pProc );
+ DbgFunc( DBG_FUNC_SETTESTSOLARMUTEX, reinterpret_cast<void*>(reinterpret_cast<long>(pProc)) );
}
#define DBG_ASSERTWARNING( sCon, aWarning ) \
diff --git a/include/tools/inetstrm.hxx b/include/tools/inetstrm.hxx
index 89c715fc2ab3..e2dfc729de72 100644
--- a/include/tools/inetstrm.hxx
+++ b/include/tools/inetstrm.hxx
@@ -203,7 +203,7 @@ public:
}
INetMIMEMessage *GetSourceMessage (void) const
{
- return ((INetMIMEMessage *)INetMessageIStream::GetSourceMessage());
+ return static_cast<INetMIMEMessage *>(INetMessageIStream::GetSourceMessage());
}
using INetMessageOStream::SetTargetMessage;
@@ -213,7 +213,7 @@ public:
}
INetMIMEMessage *GetTargetMessage (void) const
{
- return ((INetMIMEMessage *)INetMessageOStream::GetTargetMessage());
+ return static_cast<INetMIMEMessage *>(INetMessageOStream::GetTargetMessage());
}
};
diff --git a/include/tools/link.hxx b/include/tools/link.hxx
index c603c0ea707e..9b7e7fe6d302 100644
--- a/include/tools/link.hxx
+++ b/include/tools/link.hxx
@@ -119,7 +119,7 @@ public:
bool operator!=( const Link& rLink ) const
{ return !(Link::operator==( rLink )); }
bool operator<( const Link& rLink ) const
- { return ((sal_uIntPtr)rLink.pFunc < (sal_uIntPtr)pFunc); }
+ { return reinterpret_cast<sal_uIntPtr>(rLink.pFunc) < reinterpret_cast<sal_uIntPtr>(pFunc); }
};
inline Link::Link()
diff --git a/include/tools/rtti.hxx b/include/tools/rtti.hxx
index 0a5696b1dd46..92555a26c326 100644
--- a/include/tools/rtti.hxx
+++ b/include/tools/rtti.hxx
@@ -122,8 +122,17 @@ typedef void* (*TypeId)();
T: Target type to cast into
p: Pointer to be cast into T
*/
-#define PTR_CAST( T, pObj ) \
- ( pObj && (pObj)->IsA( TYPE(T) ) ? (T*)(pObj) : 0 )
+#define PTR_CAST( T, pObj ) rttiCast<T>(pObj, TYPE(T))
+
+template<class T1, class T2>
+inline T1* rttiCast(T2* pObj, const TypeId& rTypeId) {
+ return (pObj && pObj->IsA( rTypeId )) ? static_cast<T1*>(pObj) : 0;
+};
+
+template<class T1, class T2>
+inline const T1* rttiCast(const T2* pObj, const TypeId& rTypeId) {
+ return (pObj && pObj->IsA( rTypeId )) ? static_cast<const T1*>(pObj) : 0;
+};
/** Check whether object pObj has a Base Class T
(or if pObj is an instance of T) */