diff options
-rw-r--r-- | sw/inc/iodetect.hxx | 26 | ||||
-rw-r--r-- | sw/source/filter/basflt/fltini.cxx | 32 | ||||
-rw-r--r-- | sw/source/filter/basflt/iodetect.cxx | 8 |
3 files changed, 35 insertions, 31 deletions
diff --git a/sw/inc/iodetect.hxx b/sw/inc/iodetect.hxx index 91ee8ae56d21..33673cc83742 100644 --- a/sw/inc/iodetect.hxx +++ b/sw/inc/iodetect.hxx @@ -58,21 +58,21 @@ struct SwIoDetect } }; -enum ReaderWriterEnum { - READER_WRITER_RTF, - READER_WRITER_BAS, - READER_WRITER_WW6, - READER_WRITER_WW8, - READER_WRITER_RTF_WH, - READER_WRITER_HTML, - READER_WRITER_WW5, - READER_WRITER_XML, - READER_WRITER_TEXT_DLG, - READER_WRITER_TEXT, - MAXFILTER +enum class ReaderWriterType { + Rtf, + Bas, + Ww6, + Ww8, + RtfWh, + Html, + Ww5, + Xml, + TextDlg, + Text, + LAST = Text }; -extern SwIoDetect aFilterDetect[]; +SwIoDetect& GetSwIoDetect(ReaderWriterType); /** The following class is a wrapper for basic i/o functions of Writer 3.0. Everything is static. All filter names mentioned are Writer-internal diff --git a/sw/source/filter/basflt/fltini.cxx b/sw/source/filter/basflt/fltini.cxx index 071751bd7006..8534eac44690 100644 --- a/sw/source/filter/basflt/fltini.cxx +++ b/sw/source/filter/basflt/fltini.cxx @@ -57,6 +57,8 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/util/XMacroExpander.hpp> #include <rtl/bootstrap.hxx> +#include <o3tl/enumarray.hxx> +#include <o3tl/enumrange.hxx> using namespace utl; using namespace com::sun::star::uno; @@ -68,8 +70,8 @@ Reader* GetRTFReader(); Reader* GetWW8Reader(); // Note: if editing, please don't forget to modify also the enum -// ReaderWriterEnum and aFilterDetect in shellio.hxx -SwReaderWriterEntry aReaderWriter[] = +// ReaderWriterType and aFilterDetect in iodetect.cxx +o3tl::enumarray<ReaderWriterType, SwReaderWriterEntry> aReaderWriter = { SwReaderWriterEntry( &::GetRTFReader, &::GetRTFWriter, true ), SwReaderWriterEntry( nullptr, &::GetASCWriter, false ), @@ -108,20 +110,16 @@ SwRead SwGetReaderXML() // SW_DLLPUBLIC return ReadXML; } -inline void SetFltPtr( sal_uInt16 rPos, SwRead pReader ) -{ - aReaderWriter[ rPos ].pReader = pReader; -} namespace sw { Filters::Filters() { - SetFltPtr( READER_WRITER_BAS, (ReadAscii = new AsciiReader) ); - SetFltPtr( READER_WRITER_HTML, (ReadHTML = new HTMLReader) ); - SetFltPtr( READER_WRITER_XML, (ReadXML = new XMLReader) ); - SetFltPtr( READER_WRITER_TEXT_DLG, ReadAscii ); - SetFltPtr( READER_WRITER_TEXT, ReadAscii ); + aReaderWriter[ ReaderWriterType::Bas ].pReader = ReadAscii = new AsciiReader; + aReaderWriter[ ReaderWriterType::Html ].pReader = ReadHTML = new HTMLReader; + aReaderWriter[ ReaderWriterType::Xml ].pReader = ReadXML = new XMLReader; + aReaderWriter[ ReaderWriterType::TextDlg ].pReader = ReadAscii; + aReaderWriter[ ReaderWriterType::Text ].pReader = ReadAscii; } Filters::~Filters() @@ -161,15 +159,15 @@ namespace SwReaderWriter { Reader* GetRtfReader() { - return aReaderWriter[READER_WRITER_RTF].GetReader(); + return aReaderWriter[ReaderWriterType::Rtf].GetReader(); } void GetWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& xRet ) { - for( int n = 0; n < MAXFILTER; ++n ) - if ( aFilterDetect[n].IsFilter( rFltName ) ) + for( ReaderWriterType aType : o3tl::enumrange<ReaderWriterType>() ) + if ( GetSwIoDetect(aType).IsFilter( rFltName ) ) { - aReaderWriter[n].GetWriter( rFltName, rBaseURL, xRet ); + aReaderWriter[aType].GetWriter( rFltName, rBaseURL, xRet ); break; } } @@ -177,9 +175,9 @@ void GetWriter( const OUString& rFltName, const OUString& rBaseURL, WriterRef& x SwRead GetReader( const OUString& rFltName ) { SwRead pRead = nullptr; - for( int n = 0; n < MAXFILTER; ++n ) + for( ReaderWriterType n : o3tl::enumrange<ReaderWriterType>() ) { - if ( aFilterDetect[n].IsFilter( rFltName ) ) + if ( GetSwIoDetect(n).IsFilter( rFltName ) ) { pRead = aReaderWriter[n].GetReader(); // add special treatment for some readers diff --git a/sw/source/filter/basflt/iodetect.cxx b/sw/source/filter/basflt/iodetect.cxx index 5b6e92ff8a91..2fc3c0909b1c 100644 --- a/sw/source/filter/basflt/iodetect.cxx +++ b/sw/source/filter/basflt/iodetect.cxx @@ -24,6 +24,7 @@ #include <svtools/parhtml.hxx> #include <tools/urlobj.hxx> #include <unotools/moduleoptions.hxx> +#include <o3tl/enumarray.hxx> using namespace ::com::sun::star; @@ -33,7 +34,7 @@ static bool IsDocShellRegistered() return SvtModuleOptions().IsWriter(); } -SwIoDetect aFilterDetect[] = +o3tl::enumarray<ReaderWriterType, SwIoDetect> aFilterDetect = { SwIoDetect( FILTER_RTF ), SwIoDetect( FILTER_BAS ), @@ -47,6 +48,11 @@ SwIoDetect aFilterDetect[] = SwIoDetect( FILTER_TEXT ) }; +SwIoDetect& GetSwIoDetect(ReaderWriterType eType) +{ + return aFilterDetect[eType]; +} + const OUString SwIoSystem::GetSubStorageName( const SfxFilter& rFltr ) { // for StorageFilters also set the SubStorageName |