diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-03-09 09:04:15 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-03-13 09:02:22 +0000 |
commit | 7e9857c2935bb2533806db4e71c6cd1e171c3478 (patch) | |
tree | d9f8a6d4f94e19f349b67141359cc7c49130b5fc /include/xmloff/xmluconv.hxx | |
parent | 7c0e3d0b37131b12262d0f610505b3384923c4a1 (diff) |
templatize SvXMLEnumMapEntry
in preparation for "scoped UNO enums".
This is a little hacky: In order to limit the scope of this change,
the templated SvXMLEnumMapEntry struct actually has a fixed size field,
and we cast it to SvXMLEnumMapEntry<sal_uInt16>* in various
places, to avoid carrying the type param around.
Change-Id: Idfbc5561303c557598dd5564b7a7259ae5261d83
Reviewed-on: https://gerrit.libreoffice.org/34987
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/xmloff/xmluconv.hxx')
-rw-r--r-- | include/xmloff/xmluconv.hxx | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/include/xmloff/xmluconv.hxx b/include/xmloff/xmluconv.hxx index 8c11ca48c9d3..e71880be867e 100644 --- a/include/xmloff/xmluconv.hxx +++ b/include/xmloff/xmluconv.hxx @@ -122,25 +122,48 @@ public: /** convert string to enum using given enum map, if the enum is not found in the map, this method will return false */ - static bool convertEnum( sal_uInt16& rEnum, + template<typename EnumT> + static bool convertEnum( EnumT& rEnum, const OUString& rValue, - const SvXMLEnumMapEntry *pMap ); + const SvXMLEnumMapEntry<EnumT> *pMap ) + { + sal_uInt16 nTmp; + bool bRet = convertEnumImpl(nTmp, rValue, + reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap)); + if (bRet) + rEnum = static_cast<EnumT>(nTmp); + return bRet; + } /** convert string to enum using given token map, if the enum is not found in the map, this method will return false */ - static bool convertEnum( sal_uInt16& rEnum, + template<typename EnumT> + static bool convertEnum( EnumT& rEnum, const OUString& rValue, - const SvXMLEnumStringMapEntry *pMap ); + const SvXMLEnumStringMapEntry<EnumT> *pMap ) + { + sal_uInt16 nTmp; + bool bRet = convertEnumImpl(nTmp, rValue, + reinterpret_cast<const SvXMLEnumStringMapEntry<sal_uInt16>*>(pMap)); + if (bRet) + rEnum = static_cast<EnumT>(nTmp); + return bRet; + } /** convert enum to string using given enum map with an optional default token. If the enum is not found in the map, this method will either use the given default or return false if not default is set */ + template<typename EnumT> static bool convertEnum( OUStringBuffer& rBuffer, - unsigned int nValue, - const SvXMLEnumMapEntry *pMap, - enum ::xmloff::token::XMLTokenEnum eDefault = - ::xmloff::token::XML_TOKEN_INVALID ); + EnumT nValue, + const SvXMLEnumMapEntry<EnumT> *pMap, + enum ::xmloff::token::XMLTokenEnum eDefault = + ::xmloff::token::XML_TOKEN_INVALID ) + { + return convertEnumImpl(rBuffer, nValue, + reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(pMap), eDefault); + } /** convert double number to string (using ::rtl::math) and DO convert to export MapUnit using meCoreMeasureUnit/meXMLMeasureUnit */ @@ -219,6 +242,20 @@ public: /** convert number (sal_uInt32) to string (hex) */ static void convertHex( OUStringBuffer& rBuffer, sal_uInt32 nVal ); + +private: + static bool convertEnumImpl( sal_uInt16& rEnum, + const OUString& rValue, + const SvXMLEnumMapEntry<sal_uInt16> *pMap ); + + static bool convertEnumImpl( sal_uInt16& rEnum, + const OUString& rValue, + const SvXMLEnumStringMapEntry<sal_uInt16> *pMap ); + + static bool convertEnumImpl( OUStringBuffer& rBuffer, + sal_uInt16 nValue, + const SvXMLEnumMapEntry<sal_uInt16> *pMap, + enum ::xmloff::token::XMLTokenEnum eDefault ); }; #endif // INCLUDED_XMLOFF_XMLUCONV_HXX |