summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-04-22 14:30:48 +0200
committerNoel Grandin <noel@peralex.com>2016-04-25 09:13:35 +0200
commit668e3d422c6f87a534911a7884bd22fac47c4262 (patch)
tree632a093f52042f275043b1c7189c81cbe6f98201
parenta82805f8f97eeb6acadd7806cdb7120bed45a376 (diff)
use std::vector<> instead of embedding next pointers for ErrorHandler data
Change-Id: I759fc0d2bbc113873e2dda8edc8eb2eaf8036626
-rw-r--r--include/tools/errinf.hxx14
-rw-r--r--tools/source/ref/errinf.cxx121
2 files changed, 59 insertions, 76 deletions
diff --git a/include/tools/errinf.hxx b/include/tools/errinf.hxx
index 1f9946bce920..571561eccdc0 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 5d7af962575e..07e59f0fd773 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;