XUnoTunnel->dynamic_cast in CNode

Change-Id: Ifcedcb6fc4e20da6351e4ccf035a3fe06d607961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145507
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2023-01-13 09:32:47 +02:00
parent bf432958c1
commit d04c197b43
4 changed files with 13 additions and 35 deletions

View File

@@ -32,7 +32,6 @@
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/xml/dom/XNode.hpp>
#include <com/sun/star/xml/dom/XNodeList.hpp>
#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
@@ -89,7 +88,8 @@ namespace DOM
class CDocument;
class CNode : public cppu::WeakImplHelper< css::xml::dom::XNode, css::lang::XUnoTunnel, css::xml::dom::events::XEventTarget >
class SAL_LOPLUGIN_ANNOTATE("crosscast") CNode
: public cppu::WeakImplHelper< css::xml::dom::XNode, css::xml::dom::events::XEventTarget >
{
friend class CDocument;
friend class CElement;
@@ -123,8 +123,6 @@ namespace DOM
virtual ~CNode() override;
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId() noexcept;
xmlNodePtr GetNodePtr() { return m_aNodePtr; }
virtual CDocument & GetOwnerDocument();
@@ -290,10 +288,6 @@ namespace DOM
sal_Bool useCapture) override;
virtual sal_Bool SAL_CALL dispatchEvent(const css::uno::Reference< css::xml::dom::events::XEvent >& evt) override;
// --- XUnoTunnel
virtual ::sal_Int64 SAL_CALL
getSomething(css::uno::Sequence< ::sal_Int8 > const& rId) override;
};
/// eliminate redundant namespace declarations

View File

@@ -470,7 +470,7 @@ namespace DOM
}
::rtl::Reference<CNode> const pCNode(
comphelper::getFromUnoTunnel<CNode>(Reference<XNode>(oldAttr)));
dynamic_cast<CNode*>(oldAttr.get()));
if (!pCNode.is()) { throw RuntimeException(); }
xmlNodePtr const pNode = pCNode->GetNodePtr();
@@ -529,8 +529,7 @@ namespace DOM
}
// get the implementation
CAttr *const pCAttr = dynamic_cast<CAttr*>(
comphelper::getFromUnoTunnel<CNode>(xNewAttr));
CAttr *const pCAttr = dynamic_cast<CAttr*>(xNewAttr.get());
if (!pCAttr) { throw RuntimeException(); }
xmlAttrPtr const pAttr =
reinterpret_cast<xmlAttrPtr>(pCAttr->GetNodePtr());

View File

@@ -161,12 +161,6 @@ namespace DOM
}
}
const css::uno::Sequence< sal_Int8 > & CNode::getUnoTunnelId() noexcept
{
static const comphelper::UnoIdInit theCNodeUnoTunnelId;
return theCNodeUnoTunnelId.getSeq();
}
CDocument & CNode::GetOwnerDocument()
{
OSL_ASSERT(m_xDocument.is());
@@ -300,7 +294,7 @@ namespace DOM
if (nullptr == m_aNodePtr) { return nullptr; }
CNode *const pNewChild(comphelper::getFromUnoTunnel<CNode>(xNewChild));
CNode *const pNewChild(dynamic_cast<CNode*>(xNewChild.get()));
if (!pNewChild) { throw RuntimeException(); }
xmlNodePtr const cur = pNewChild->GetNodePtr();
if (!cur) { throw RuntimeException(); }
@@ -639,8 +633,8 @@ namespace DOM
::osl::ClearableMutexGuard guard(m_rMutex);
CNode *const pNewNode(comphelper::getFromUnoTunnel<CNode>(newChild));
CNode *const pRefNode(comphelper::getFromUnoTunnel<CNode>(refChild));
CNode *const pNewNode(dynamic_cast<CNode*>(newChild.get()));
CNode *const pRefNode(dynamic_cast<CNode*>(refChild.get()));
if (!pNewNode || !pRefNode) { throw RuntimeException(); }
xmlNodePtr const pNewChild(pNewNode->GetNodePtr());
xmlNodePtr const pRefChild(pRefNode->GetNodePtr());
@@ -740,7 +734,7 @@ namespace DOM
Reference<XNode> xReturn( xOldChild );
::rtl::Reference<CNode> const pOld(comphelper::getFromUnoTunnel<CNode>(xOldChild));
::rtl::Reference<CNode> const pOld(dynamic_cast<CNode*>(xOldChild.get()));
if (!pOld.is()) { throw RuntimeException(); }
xmlNodePtr const old = pOld->GetNodePtr();
if (!old) { throw RuntimeException(); }
@@ -808,10 +802,8 @@ namespace DOM
::osl::ClearableMutexGuard guard(m_rMutex);
::rtl::Reference<CNode> const pOldNode(
comphelper::getFromUnoTunnel<CNode>(xOldChild));
::rtl::Reference<CNode> const pNewNode(
comphelper::getFromUnoTunnel<CNode>(xNewChild));
::rtl::Reference<CNode> const pOldNode(dynamic_cast<CNode*>(xOldChild.get()));
::rtl::Reference<CNode> const pNewNode(dynamic_cast<CNode*>(xNewChild.get()));
if (!pOldNode.is() || !pNewNode.is()) { throw RuntimeException(); }
xmlNodePtr const pOld = pOldNode->GetNodePtr();
xmlNodePtr const pNew = pNewNode->GetNodePtr();
@@ -976,12 +968,6 @@ namespace DOM
pDispatcher->dispatchEvent(*pDocument, m_rMutex, pNode, this, evt);
return true;
}
::sal_Int64 SAL_CALL
CNode::getSomething(Sequence< ::sal_Int8 > const& rId)
{
return comphelper::getSomethingImpl(rId, this);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -109,7 +109,7 @@ namespace XPath
static void lcl_collectNamespaces(
nsmap_t & rNamespaces, Reference< XNode > const& xNamespaceNode)
{
DOM::CNode *const pCNode(comphelper::getFromUnoTunnel<DOM::CNode>(xNamespaceNode));
DOM::CNode *const pCNode(dynamic_cast<DOM::CNode*>(xNamespaceNode.get()));
if (!pCNode) { throw RuntimeException(); }
::osl::MutexGuard const g(pCNode->GetOwnerDocument().GetMutex());
@@ -291,11 +291,10 @@ namespace XPath
// get the node and document
::rtl::Reference<DOM::CDocument> const pCDoc(
dynamic_cast<DOM::CDocument*>( comphelper::getFromUnoTunnel<DOM::CNode>(
xContextNode->getOwnerDocument())));
dynamic_cast<DOM::CDocument*>(xContextNode->getOwnerDocument().get()));
if (!pCDoc.is()) { throw RuntimeException(); }
DOM::CNode *const pCNode = comphelper::getFromUnoTunnel<DOM::CNode>(xContextNode);
DOM::CNode *const pCNode = dynamic_cast<DOM::CNode*>(xContextNode.get());
if (!pCNode) { throw RuntimeException(); }
::osl::MutexGuard const g(pCDoc->GetMutex()); // lock the document!