diff options
author | Armin Le Grand (Collabora) <Armin.Le.Grand@me.com> | 2025-01-09 11:51:33 +0100 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2025-01-10 19:38:37 +0100 |
commit | 9304f13db61dc101ff1c121277c344a472c2951a (patch) | |
tree | 837bf672c5e529964a7e29ea97cbce7a142ea405 /svx/inc/sxlogitm.hxx | |
parent | 77e536c61a20cbf77207dbf599a88bd21e8ecc27 (diff) |
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 <Armin.Le.Grand@me.com>
Diffstat (limited to 'svx/inc/sxlogitm.hxx')
-rw-r--r-- | svx/inc/sxlogitm.hxx | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/svx/inc/sxlogitm.hxx b/svx/inc/sxlogitm.hxx index 5fe217b77c62..140cb12965b5 100644 --- a/svx/inc/sxlogitm.hxx +++ b/svx/inc/sxlogitm.hxx @@ -24,7 +24,8 @@ class SdrLogicSizeWidthItem final : public SdrMetricItem { public: - SdrLogicSizeWidthItem(tools::Long nWdt=0): SdrMetricItem(SDRATTR_LOGICSIZEWIDTH, nWdt, SfxItemType::SdrLogicSizeWidthItemType) {} + DECLARE_ITEM_TYPE_FUNCTION(SdrLogicSizeWidthItem) + SdrLogicSizeWidthItem(tools::Long nWdt=0): SdrMetricItem(SDRATTR_LOGICSIZEWIDTH, nWdt) {} virtual SdrLogicSizeWidthItem* Clone(SfxItemPool*) const override { return new SdrLogicSizeWidthItem(*this); @@ -33,7 +34,8 @@ public: class SdrLogicSizeHeightItem final : public SdrMetricItem { public: - SdrLogicSizeHeightItem(tools::Long nHgt=0): SdrMetricItem(SDRATTR_LOGICSIZEHEIGHT, nHgt, SfxItemType::SdrLogicSizeHeightItemType) {} + DECLARE_ITEM_TYPE_FUNCTION(SdrLogicSizeHeightItem) + SdrLogicSizeHeightItem(tools::Long nHgt=0): SdrMetricItem(SDRATTR_LOGICSIZEHEIGHT, nHgt) {} virtual SdrLogicSizeHeightItem* Clone(SfxItemPool*) const override { return new SdrLogicSizeHeightItem(*this); |