forked from amazingfate/loongoffice
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> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181252
45 lines
1.5 KiB
C++
45 lines
1.5 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <config_options.h>
|
|
#include <svl/eitem.hxx>
|
|
#include <svx/svxdllapi.h>
|
|
|
|
namespace model
|
|
{
|
|
enum class RectangleAlignment;
|
|
}
|
|
|
|
/** Item that holds a rectangle alignment value.
|
|
|
|
e.g. Top Left, Top, Top Right, Center.
|
|
@see model::RectangleAlignment
|
|
*/
|
|
class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) SvxRectangleAlignmentItem final
|
|
: public SfxEnumItem<model::RectangleAlignment>
|
|
{
|
|
public:
|
|
DECLARE_ITEM_TYPE_FUNCTION(SvxRectangleAlignmentItem)
|
|
SvxRectangleAlignmentItem(sal_uInt16 nWhich, model::RectangleAlignment nValue);
|
|
virtual ~SvxRectangleAlignmentItem() override;
|
|
|
|
SvxRectangleAlignmentItem(SvxRectangleAlignmentItem const&) = default;
|
|
SvxRectangleAlignmentItem(SvxRectangleAlignmentItem&&) = default;
|
|
SvxRectangleAlignmentItem& operator=(SvxRectangleAlignmentItem const&) = delete;
|
|
SvxRectangleAlignmentItem& operator=(SvxRectangleAlignmentItem&&) = delete;
|
|
|
|
virtual SvxRectangleAlignmentItem* Clone(SfxItemPool* pPool = nullptr) const override;
|
|
|
|
virtual sal_uInt16 GetValueCount() const override;
|
|
};
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|