Hi all,

the attached is for removing some duplications in PdfVariant
with the help of const_cast. Please believe me that I had it
ready already on October 4, 2015, but didn't have enough courage
to send it in. Sorry that only build-tested it, I couldn't do tests
running code for security-policy reasons (my laptop is employer-sponsored).
So please run-test it if at all possible and if it works please commit (if
you have commit rights, of course). Also stay tuned for more patches tomorrow.

Best regards, mabri
Index: src/base/PdfVariant.h
===================================================================
--- src/base/PdfVariant.h	(revision 1680)
+++ src/base/PdfVariant.h	(working copy)
@@ -712,16 +712,8 @@
 
 PdfData & PdfVariant::GetRawData()
 {
-    DelayedLoad();
-
-    if( !IsRawData() )
-    {
-        PODOFO_RAISE_ERROR( ePdfError_InvalidDataType );
-    }
-    // Do not change this to an reinterpret_cast
-    // We need a c-style casts here to avoid crashes
-    // because a reinterpret_cast might point to a different position.
-    return *((PdfData*)m_Data.pData);
+    return const_cast<PdfData &>( // next line: selects the const overload
+        const_cast<const PdfVariant*>(this)->GetRawData() );
 }
 
 // -----------------------------------------------------
@@ -801,18 +793,8 @@
 // -----------------------------------------------------
 PdfArray & PdfVariant::GetArray_NoDL()
 {
-    // Test against eDataType directly not GetDataType() since
-    // we don't want to trigger a delayed load (and if required one has
-    // already been triggered).
-    if( m_eDataType != ePdfDataType_Array )
-    {
-        PODOFO_RAISE_ERROR( ePdfError_InvalidDataType );
-    }
-
-    // Do not change this to an reinterpret_cast
-    // We need a c-style casts here to avoid crashes
-    // because a reinterpret_cast might point to a different position.
-    return *((PdfArray*)m_Data.pData);
+    return const_cast<PdfArray &>( // next line: selects the const overload
+        const_cast<const PdfVariant*>(this)->GetArray_NoDL() );
 }
 
 // -----------------------------------------------------
@@ -857,18 +839,8 @@
 // -----------------------------------------------------
 PdfDictionary & PdfVariant::GetDictionary_NoDL()
 {
-    // Test against eDataType directly not GetDataType() since
-    // we don't want to trigger a delayed load (and if required one has
-    // already been triggered).
-    if( m_eDataType != ePdfDataType_Dictionary )
-    {
-        PODOFO_RAISE_ERROR( ePdfError_InvalidDataType );
-    }
-
-    // Do not change this to an reinterpret_cast
-    // We need a c-style casts here to avoid crashes
-    // because a reinterpret_cast might point to a different position.
-    return *((PdfDictionary*)m_Data.pData);
+    return const_cast<PdfDictionary &>( // next line const overload selected
+        const_cast<const PdfVariant*>(this)->GetDictionary_NoDL() );
 }
 
 // -----------------------------------------------------
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to