From 9304f13db61dc101ff1c121277c344a472c2951a Mon Sep 17 00:00:00 2001 From: "Armin Le Grand (Collabora)" Date: Thu, 9 Jan 2025 11:51:33 +0100 Subject: ITEM: Refactor ItemType ItemType is useful and faster than RTTI. Until now it was implemented by a 16-bit member in the base class, plus (potentially) all constructors having to hand a value in at item construction type (of type SfxItemType) to get that member set correctly. This works, but there is no reliable way to guarantee coverage, and there have already been cases with missing SfxItemType - these fallback to '0' and thus all Items with ItemType() == 0 are assumed equal and might be static_cast'ed to the wrong classes. Note that I identified *35* Items that had no correct ItemType set/implemented actually. It also uses 16-bit per incarnated Item at runtime. I thought and realized now a more systematic approach to do that with a pure virtual function at the Item itself. That can also be secured by a clang compiler plugin in the future to keep it working. It uses one virtual function per derived class, no longer space in incarnated Items. Also the constructors will get more simple again. But the main aspect is security - we cannot afford Items potentially being held as equal if they are not. Unfortunately C++ does not offer something like a 'strict pure virtual function' that would force to be overloaded in every derivation, but the used methotology and adding a clang test is reasonably safe. Have now done the cleanup of previous method. Change-Id: I04768285f1e9b73d64b0bb87df401944b5d35678 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180017 Tested-by: Jenkins Reviewed-by: Armin Le Grand --- include/svx/xflbmsxy.hxx | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/svx/xflbmsxy.hxx') diff --git a/include/svx/xflbmsxy.hxx b/include/svx/xflbmsxy.hxx index 76611d3bd56a..bb5375a42c5d 100644 --- a/include/svx/xflbmsxy.hxx +++ b/include/svx/xflbmsxy.hxx @@ -26,6 +26,7 @@ class SVXCORE_DLLPUBLIC XFillBmpSizeXItem final : public SfxMetricItem { public: + DECLARE_ITEM_TYPE_FUNCTION(XFillBmpSizeXItem) XFillBmpSizeXItem( tools::Long nSizeX = 0 ); SVX_DLLPRIVATE virtual XFillBmpSizeXItem* Clone( SfxItemPool* pPool = nullptr ) const override; @@ -42,6 +43,7 @@ public: class SVXCORE_DLLPUBLIC XFillBmpSizeYItem final : public SfxMetricItem { public: + DECLARE_ITEM_TYPE_FUNCTION(XFillBmpSizeYItem) XFillBmpSizeYItem( tools::Long nSizeY = 0 ); SVX_DLLPRIVATE virtual XFillBmpSizeYItem* Clone( SfxItemPool* pPool = nullptr ) const override; -- cgit