[Libreoffice-commits] core.git: include/tools tools/source

Noel Grandin noel at peralex.com
Mon Apr 25 07:15:24 UTC 2016


 include/tools/errinf.hxx    |   14 ++---
 tools/source/ref/errinf.cxx |  121 ++++++++++++++++++--------------------------
 2 files changed, 59 insertions(+), 76 deletions(-)

New commits:
commit 668e3d422c6f87a534911a7884bd22fac47c4262
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Apr 22 14:30:48 2016 +0200

    use std::vector<> instead of embedding next pointers for ErrorHandler data
    
    Change-Id: I759fc0d2bbc113873e2dda8edc8eb2eaf8036626

diff --git a/include/tools/errinf.hxx b/include/tools/errinf.hxx
index 1f9946b..571561e 100644
--- a/include/tools/errinf.hxx
+++ b/include/tools/errinf.hxx
@@ -75,7 +75,7 @@ public:
 
                             StringErrorInfo( sal_uIntPtr lUserId,
                                             const OUString& aStringP,
-                                            sal_uInt16 nFlags = 0);
+                                            sal_uInt16 nMask = 0);
     const OUString&         GetErrorString() const { return aString; }
 };
 
@@ -88,8 +88,8 @@ private:
 public:
 
     TwoStringErrorInfo(sal_uIntPtr nUserID, const OUString & rTheArg1,
-                       const OUString & rTheArg2, sal_uInt16 nFlags = 0):
-        DynamicErrorInfo(nUserID, nFlags), aArg1(rTheArg1), aArg2(rTheArg2) {}
+                       const OUString & rTheArg2, sal_uInt16 nMask = 0):
+        DynamicErrorInfo(nUserID, nMask), aArg1(rTheArg1), aArg2(rTheArg2) {}
 
     virtual ~TwoStringErrorInfo() {}
 
@@ -101,10 +101,10 @@ class TOOLS_DLLPUBLIC MessageInfo : public DynamicErrorInfo
 {
 public:
 
-    MessageInfo(sal_uIntPtr UserId, sal_uInt16 nFlags = 0) :
-        DynamicErrorInfo(UserId, nFlags) {}
-    MessageInfo(sal_uIntPtr UserId, const OUString &rArg, sal_uInt16 nFlags = 0 ) :
-        DynamicErrorInfo(UserId, nFlags), aArg(rArg) {}
+    MessageInfo(sal_uIntPtr UserId, sal_uInt16 nMask = 0) :
+        DynamicErrorInfo(UserId, nMask) {}
+    MessageInfo(sal_uIntPtr UserId, const OUString &rArg, sal_uInt16 nMask = 0 ) :
+        DynamicErrorInfo(UserId, nMask), aArg(rArg) {}
 
     const OUString&         GetMessageArg() const { return aArg; }
 
diff --git a/tools/source/ref/errinf.cxx b/tools/source/ref/errinf.cxx
index 5d7af96..07e59f0 100644
--- a/tools/source/ref/errinf.cxx
+++ b/tools/source/ref/errinf.cxx
@@ -18,25 +18,25 @@
  */
 
 #include <limits.h>
-#include <tools/debug.hxx>
 #include <tools/errinf.hxx>
 #include <rtl/strbuf.hxx>
 #include <osl/diagnose.h>
 #include <vcl/window.hxx>
+#include <vector>
 
 class ErrorHandler;
 
 namespace {
-typedef void (* DisplayFnPtr)();
+  typedef void (* DisplayFnPtr)();
 }
 
 struct EDcrData
 {
 public:
-    ErrorHandler               *pFirstHdl;
-    ErrorContext               *pFirstCtx;
-    DisplayFnPtr               pDsp;
-    bool                   bIsWindowDsp;
+    std::vector<ErrorHandler*>  errorHandlers;
+    std::vector<ErrorContext*>  contexts;
+    DisplayFnPtr                pDsp;
+    bool                        bIsWindowDsp;
 
     DynamicErrorInfo            *ppDcr[ERRCODE_DYNAMIC_COUNT];
     sal_uInt16                  nNextDcr;
@@ -59,9 +59,7 @@ friend class ErrorInfo;
 };
 
 EDcrData::EDcrData()
-    : pFirstHdl(nullptr)
-    , pFirstCtx(nullptr)
-    , pDsp(nullptr)
+    : pDsp(nullptr)
     , bIsWindowDsp(false)
     , nNextDcr(0)
 {
@@ -72,26 +70,23 @@ EDcrData::EDcrData()
 void DynamicErrorInfo_Impl::RegisterEDcr(DynamicErrorInfo *pDcr)
 {
     // Register dynamic identifier
-    EDcrData& pData=TheEDcrData::get();
-    lErrId= (((sal_uIntPtr)pData.nNextDcr + 1) << ERRCODE_DYNAMIC_SHIFT) +
-        pDcr->GetErrorCode();
-    DynamicErrorInfo **ppDcr=pData.ppDcr;
-    sal_uInt16 nNext=pData.nNextDcr;
+    EDcrData& pData = TheEDcrData::get();
+    lErrId = (((sal_uIntPtr)pData.nNextDcr + 1) << ERRCODE_DYNAMIC_SHIFT) +
+             pDcr->GetErrorCode();
 
-    if(ppDcr[nNext])
+    if(pData.ppDcr[pData.nNextDcr])
     {
-        delete ppDcr[nNext];
+        delete pData.ppDcr[pData.nNextDcr];
     }
-    ppDcr[nNext]=pDcr;
+    pData.ppDcr[pData.nNextDcr] = pDcr;
     if(++pData.nNextDcr>=ERRCODE_DYNAMIC_COUNT)
         pData.nNextDcr=0;
 }
 
 void DynamicErrorInfo_Impl::UnRegisterEDcr(DynamicErrorInfo *pDcr)
 {
-    DynamicErrorInfo **ppDcr=TheEDcrData::get().ppDcr;
-    sal_uIntPtr lIdx=(
-        ((sal_uIntPtr)(*pDcr) & ERRCODE_DYNAMIC_MASK)>>ERRCODE_DYNAMIC_SHIFT)-1;
+    DynamicErrorInfo **ppDcr = TheEDcrData::get().ppDcr;
+    sal_uIntPtr lIdx = (((sal_uIntPtr)(*pDcr) & ERRCODE_DYNAMIC_MASK) >> ERRCODE_DYNAMIC_SHIFT) - 1;
     DBG_ASSERT(ppDcr[lIdx]==pDcr,"ErrHdl: Error nicht gefunden");
     if(ppDcr[lIdx]==pDcr)
         ppDcr[lIdx]=nullptr;
@@ -130,8 +125,8 @@ DynamicErrorInfo::~DynamicErrorInfo()
 
 ErrorInfo* DynamicErrorInfo_Impl::GetDynamicErrorInfo(sal_uIntPtr lId)
 {
-    sal_uIntPtr lIdx=((lId & ERRCODE_DYNAMIC_MASK)>>ERRCODE_DYNAMIC_SHIFT)-1;
-    DynamicErrorInfo* pDcr=TheEDcrData::get().ppDcr[lIdx];
+    sal_uIntPtr lIdx = ((lId & ERRCODE_DYNAMIC_MASK)>>ERRCODE_DYNAMIC_SHIFT)-1;
+    DynamicErrorInfo* pDcr = TheEDcrData::get().ppDcr[lIdx];
     if(pDcr && (sal_uIntPtr)(*pDcr)==lId)
         return pDcr;
     else
@@ -144,17 +139,15 @@ sal_uInt16 DynamicErrorInfo::GetDialogMask() const
 }
 
 StringErrorInfo::StringErrorInfo(
-    sal_uIntPtr UserId, const OUString& aStringP,  sal_uInt16 nFlags)
-: DynamicErrorInfo(UserId, nFlags), aString(aStringP)
+    sal_uIntPtr UserId, const OUString& aStringP, sal_uInt16 nMask)
+: DynamicErrorInfo(UserId, nMask), aString(aStringP)
 {
 }
 
 class ErrorHandler_Impl
 {
 public:
-    ErrorHandler        *pNext;
-    static bool         CreateString(const ErrorHandler *pStart,
-                                     const ErrorInfo*, OUString&, sal_uInt16&);
+    static bool         CreateString(const ErrorInfo*, OUString&, sal_uInt16&);
 };
 
 static void aDspFunc(const OUString &rErr, const OUString &rAction)
@@ -169,51 +162,41 @@ static void aDspFunc(const OUString &rErr, const OUString &rAction)
 // FIXME: this is a horrible reverse dependency on VCL
 struct ErrorContextImpl
 {
-    ErrorContext *pNext;
     vcl::Window  *pWin; // should be VclPtr for strong lifecycle
 };
 
 ErrorContext::ErrorContext(vcl::Window *pWinP)
     : pImpl( new ErrorContextImpl )
 {
-    ErrorContext *&pHdl = TheEDcrData::get().pFirstCtx;
     pImpl->pWin = pWinP;
-    pImpl->pNext = pHdl;
-    pHdl = this;
+    TheEDcrData::get().contexts.insert(TheEDcrData::get().contexts.begin(), this);
 }
 
 ErrorContext::~ErrorContext()
 {
-    ErrorContext **ppCtx=&(TheEDcrData::get().pFirstCtx);
-    while(*ppCtx && *ppCtx!=this)
-        ppCtx=&((*ppCtx)->pImpl->pNext);
-    if(*ppCtx)
-        *ppCtx=(*ppCtx)->pImpl->pNext;
+    auto &rContexts = TheEDcrData::get().contexts;
+    rContexts.erase( ::std::remove(rContexts.begin(), rContexts.end(), this), rContexts.end());
 }
 
 ErrorContext *ErrorContext::GetContext()
 {
-    return TheEDcrData::get().pFirstCtx;
+    return TheEDcrData::get().contexts.empty() ? nullptr : TheEDcrData::get().contexts.front();
 }
 
+
 ErrorHandler::ErrorHandler()
     : pImpl(new ErrorHandler_Impl)
 {
-    EDcrData &pData=TheEDcrData::get();
-    ErrorHandler *&pHdl=pData.pFirstHdl;
-    pImpl->pNext=pHdl;
-    pHdl=this;
+    EDcrData &pData = TheEDcrData::get();
+    pData.errorHandlers.insert(pData.errorHandlers.begin(), this);
     if(!pData.pDsp)
         RegisterDisplay(&aDspFunc);
 }
 
 ErrorHandler::~ErrorHandler()
 {
-    ErrorHandler **ppHdl=&(TheEDcrData::get().pFirstHdl);
-    while(*ppHdl && *ppHdl!=this)
-        ppHdl=&((*ppHdl)->pImpl->pNext);
-    if(*ppHdl)
-        *ppHdl=(*ppHdl)->pImpl->pNext;
+    auto &rErrorHandlers = TheEDcrData::get().errorHandlers;
+    rErrorHandlers.erase( ::std::remove(rErrorHandlers.begin(), rErrorHandlers.end(), this), rErrorHandlers.end());
 }
 
 vcl::Window* ErrorContext::GetParent()
@@ -223,16 +206,16 @@ vcl::Window* ErrorContext::GetParent()
 
 void ErrorHandler::RegisterDisplay(WindowDisplayErrorFunc *aDsp)
 {
-    EDcrData &pData=TheEDcrData::get();
-    pData.bIsWindowDsp=true;
-    pData.pDsp = reinterpret_cast< DisplayFnPtr >(aDsp);
+    EDcrData &pData    = TheEDcrData::get();
+    pData.bIsWindowDsp = true;
+    pData.pDsp         = reinterpret_cast< DisplayFnPtr >(aDsp);
 }
 
 void ErrorHandler::RegisterDisplay(BasicDisplayErrorFunc *aDsp)
 {
-    EDcrData &pData=TheEDcrData::get();
-    pData.bIsWindowDsp=false;
-    pData.pDsp = reinterpret_cast< DisplayFnPtr >(aDsp);
+    EDcrData &pData    = TheEDcrData::get();
+    pData.bIsWindowDsp = false;
+    pData.pDsp         = reinterpret_cast< DisplayFnPtr >(aDsp);
 }
 
 /** Handles an error.
@@ -260,19 +243,20 @@ sal_uInt16 ErrorHandler::HandleError_Impl(
     OUString aAction;
     if(!lId || lId == ERRCODE_ABORT)
         return 0;
-    EDcrData &pData=TheEDcrData::get();
-    ErrorInfo *pInfo=ErrorInfo::GetErrorInfo(lId);
-    ErrorContext *pCtx=ErrorContext::GetContext();
-    if(pCtx)
-        pCtx->GetString(pInfo->GetErrorCode(), aAction);
-    vcl::Window *pParent=nullptr;
-    // Remove parent from context
-    for(;pCtx;pCtx=pCtx->pImpl->pNext)
-        if(pCtx->GetParent())
-        {
-            pParent=pCtx->GetParent();
-            break;
-        }
+    EDcrData &pData      = TheEDcrData::get();
+    vcl::Window *pParent = nullptr;
+    ErrorInfo *pInfo     = ErrorInfo::GetErrorInfo(lId);
+    if (!pData.contexts.empty())
+    {
+        pData.contexts.front()->GetString(pInfo->GetErrorCode(), aAction);
+        // Remove parent from context
+        for(ErrorContext *pCtx : pData.contexts)
+            if(pCtx->GetParent())
+            {
+                pParent=pCtx->GetParent();
+                break;
+            }
+    }
 
     bool bWarning = ((lId & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK);
     sal_uInt16 nErrFlags = ERRCODE_BUTTON_DEF_OK | ERRCODE_BUTTON_OK;
@@ -289,7 +273,7 @@ sal_uInt16 ErrorHandler::HandleError_Impl(
             nErrFlags = nDynFlags;
     }
 
-    if(ErrorHandler_Impl::CreateString(pData.pFirstHdl,pInfo,aErr,nErrFlags))
+    if(ErrorHandler_Impl::CreateString(pInfo,aErr,nErrFlags))
     {
         if (bJustCreateString)
         {
@@ -354,11 +338,10 @@ sal_uInt16 ErrorHandler::HandleError(sal_uIntPtr lId, sal_uInt16 nFlags)
     return HandleError_Impl( lId, nFlags, false, aDummy );
 }
 
-bool ErrorHandler_Impl::CreateString( const ErrorHandler *pStart,
-                                    const ErrorInfo* pInfo, OUString& pStr,
+bool ErrorHandler_Impl::CreateString( const ErrorInfo* pInfo, OUString& pStr,
                                     sal_uInt16 &rFlags)
 {
-    for(const ErrorHandler *pHdl=pStart;pHdl;pHdl=pHdl->pImpl->pNext)
+    for(const ErrorHandler *pHdl : TheEDcrData::get().errorHandlers)
     {
         if(pHdl->CreateString( pInfo, pStr, rFlags))
             return true;


More information about the Libreoffice-commits mailing list