diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-03-01 14:17:08 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-03-03 06:44:41 +0000 |
commit | f091259ad2ec1590714645839668580cd7b8c7c4 (patch) | |
tree | 3bf6b328637358365848bc98a18cbf82ccd4b2d0 /include/svl | |
parent | d0cc5fcd5bacd8e5e0fa7fe62a78907c2febb867 (diff) |
convert SfxEnumItem to type-safe template class
and drop the SvxChartTextOrientItem class, unused.
Change-Id: I99100837d1beb953450f57b2cda47d165df1620c
Reviewed-on: https://gerrit.libreoffice.org/34747
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/svl')
-rw-r--r-- | include/svl/aeitem.hxx | 2 | ||||
-rw-r--r-- | include/svl/eitem.hxx | 64 |
2 files changed, 49 insertions, 17 deletions
diff --git a/include/svl/aeitem.hxx b/include/svl/aeitem.hxx index fb9125ee1443..ee38084a04c7 100644 --- a/include/svl/aeitem.hxx +++ b/include/svl/aeitem.hxx @@ -26,7 +26,7 @@ class SfxAllEnumValueArr; -class SVL_DLLPUBLIC SfxAllEnumItem: public SfxEnumItem +class SVL_DLLPUBLIC SfxAllEnumItem: public SfxEnumItem<sal_uInt16> { SfxAllEnumValueArr* pValues; std::vector<sal_uInt16>* pDisabledValues; diff --git a/include/svl/eitem.hxx b/include/svl/eitem.hxx index 16518a7bea38..93c122b10888 100644 --- a/include/svl/eitem.hxx +++ b/include/svl/eitem.hxx @@ -22,15 +22,16 @@ #include <svl/svldllapi.h> #include <svl/cenumitm.hxx> +#include <tools/stream.hxx> -class SVL_DLLPUBLIC SfxEnumItem - : public SfxEnumItemInterface +template<typename EnumT> +class SfxEnumItem : public SfxEnumItemInterface { - sal_uInt16 m_nValue; + EnumT m_nValue; protected: - explicit SfxEnumItem(sal_uInt16 const nWhich =0, sal_uInt16 const nValue =0) + explicit SfxEnumItem(sal_uInt16 const nWhich, EnumT const nValue) : SfxEnumItemInterface(nWhich) , m_nValue(nValue) { } @@ -40,23 +41,54 @@ protected: , m_nValue(rItem.m_nValue) { } - SfxEnumItem(sal_uInt16 const nWhich, SvStream & rStream); + SfxEnumItem(sal_uInt16 const nWhich, SvStream & rStream) + : SfxEnumItemInterface(nWhich) + { + sal_uInt16 nTmp = 0; + rStream.ReadUInt16( nTmp ); + m_nValue = static_cast<EnumT>(nTmp); + } public: - sal_uInt16 GetValue() const { return m_nValue; } - - void SetValue(sal_uInt16 nTheValue); - - // SfxPoolItem - virtual SvStream & Store(SvStream & rStream, sal_uInt16) const override; - - virtual sal_uInt16 GetEnumValue() const override; - - virtual void SetEnumValue(sal_uInt16 nTheValue) override; - + EnumT GetValue() const { return m_nValue; } + + void SetValue(EnumT nTheValue) + { + assert(GetRefCount() == 0 && "SfxEnumItem::SetValue(): Pooled item"); + m_nValue = nTheValue; + } + + virtual SvStream & Store(SvStream & rStream, sal_uInt16) const override + { + rStream.WriteUInt16( static_cast<sal_uInt16>(m_nValue) ); + return rStream; + } + + virtual sal_uInt16 GetEnumValue() const override + { + return static_cast<sal_uInt16>(GetValue()); + } + + virtual void SetEnumValue(sal_uInt16 nTheValue) override + { + SetValue(static_cast<EnumT>(nTheValue)); + } + + virtual bool operator==(SfxPoolItem const & other) const override + { + return SfxEnumItemInterface::operator==(other) && + m_nValue == static_cast<const SfxEnumItem<EnumT> &>(other).m_nValue; + } }; +// We need to have this one instantiated only once to prevent LNK2005 "already defined" on 32-bit MSVC. +// But then we run into the problem that "extern" and SVL_DLLPUBLIC are mutually exclusive on templates for MSVC. +#ifdef _WIN32 +extern template class SfxEnumItem<sal_uInt16>; +#else +extern template class SVL_DLLPUBLIC SfxEnumItem<sal_uInt16>; +#endif class SVL_DLLPUBLIC SfxBoolItem : public SfxPoolItem |