diff options
Diffstat (limited to 'include/svl/eitem.hxx')
-rw-r--r-- | include/svl/eitem.hxx | 64 |
1 files changed, 48 insertions, 16 deletions
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 |