[Libreoffice-commits] core.git: 3 commits - include/svx lingucomponent/source svx/source
Noel Grandin
noel.grandin at collabora.co.uk
Sat Feb 17 06:07:17 UTC 2018
include/svx/fmgridif.hxx | 3
lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx | 68 ++++++--------
lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx | 7 -
lingucomponent/source/thesaurus/libnth/nthesimp.cxx | 83 ++++--------------
lingucomponent/source/thesaurus/libnth/nthesimp.hxx | 17 ++-
svx/source/fmcomp/fmgridif.cxx | 7 -
6 files changed, 66 insertions(+), 119 deletions(-)
New commits:
commit 794066fa1ac67b6e352c17e78245a2698b0c470b
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Feb 6 11:38:34 2018 +0200
loplugin:useuniqueptr in FmXGridPeer
Change-Id: Ie9a705852035eb99c9d0e5862c4d9f6bdb4c6a05
Reviewed-on: https://gerrit.libreoffice.org/49877
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/svx/fmgridif.hxx b/include/svx/fmgridif.hxx
index 5aa857005c69..fbec6ea6435f 100644
--- a/include/svx/fmgridif.hxx
+++ b/include/svx/fmgridif.hxx
@@ -48,6 +48,7 @@
#include <comphelper/uno3.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/implbase10.hxx>
+#include <memory>
class DbGridColumn;
enum class DbGridControlNavigationBarState;
@@ -359,7 +360,7 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC FmXGridPeer:
class GridListenerDelegator;
friend class GridListenerDelegator;
- GridListenerDelegator* m_pGridListener;
+ std::unique_ptr<GridListenerDelegator> m_pGridListener;
protected:
css::uno::Reference< css::uno::XComponentContext > m_xContext;
diff --git a/svx/source/fmcomp/fmgridif.cxx b/svx/source/fmcomp/fmgridif.cxx
index 31280a401825..262d4d47f5bc 100644
--- a/svx/source/fmcomp/fmgridif.cxx
+++ b/svx/source/fmcomp/fmgridif.cxx
@@ -1041,11 +1041,10 @@ FmXGridPeer::FmXGridPeer(const Reference< XComponentContext >& _rxContext)
,m_bInterceptingDispatch(false)
,m_pStateCache(nullptr)
,m_pDispatchers(nullptr)
- ,m_pGridListener(nullptr)
,m_xContext(_rxContext)
{
// Create must be called after this constructor
- m_pGridListener = new GridListenerDelegator( this );
+ m_pGridListener.reset( new GridListenerDelegator( this ) );
}
@@ -1064,7 +1063,7 @@ void FmXGridPeer::Create(vcl::Window* pParent, WinBits nStyle)
pWin->SetSlotExecutor(LINK(this, FmXGridPeer, OnExecuteGridSlot));
// want to hear about row selections
- pWin->setGridListener( m_pGridListener );
+ pWin->setGridListener( m_pGridListener.get() );
// Init must always be called
pWin->Init();
@@ -1078,8 +1077,6 @@ FmXGridPeer::~FmXGridPeer()
{
setRowSet(Reference< XRowSet > ());
setColumns(Reference< XIndexContainer > ());
-
- delete m_pGridListener;
}
namespace
commit c503df794f942488840ac2d69e61895e42a35b2a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Feb 6 11:35:31 2018 +0200
loplugin:useuniqueptr in Hyphenator
Change-Id: Icc45a38858004e1b8ea3a19df40f3cd71c469fdf
Reviewed-on: https://gerrit.libreoffice.org/49876
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
index 4da78de3995b..8f9480e3ff0f 100644
--- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
+++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
@@ -64,28 +64,19 @@ Hyphenator::Hyphenator() :
aEvtListeners ( GetLinguMutex() )
{
bDisposing = false;
- pPropHelper = nullptr;
- aDicts = nullptr;
- numdict = 0;
}
Hyphenator::~Hyphenator()
{
- if (numdict && aDicts)
+ for (auto & rInfo : mvDicts)
{
- for (int i=0; i < numdict; ++i)
- {
- delete aDicts[i].apCC;
- if (aDicts[i].aPtr)
- hnj_hyphen_free(aDicts[i].aPtr);
- }
+ if (rInfo.aPtr)
+ hnj_hyphen_free(rInfo.aPtr);
}
- delete[] aDicts;
if (pPropHelper)
{
pPropHelper->RemoveAsPropListener();
- delete pPropHelper;
}
}
@@ -95,7 +86,7 @@ PropertyHelper_Hyphenation& Hyphenator::GetPropHelper_Impl()
{
Reference< XLinguProperties > xPropSet( GetLinguProperties(), UNO_QUERY );
- pPropHelper = new PropertyHelper_Hyphenation (static_cast<XHyphenator *>(this), xPropSet );
+ pPropHelper.reset( new PropertyHelper_Hyphenation (static_cast<XHyphenator *>(this), xPropSet ) );
pPropHelper->AddAsPropListener(); //! after a reference is established
}
return *pPropHelper;
@@ -107,7 +98,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// this routine should return the locales supported by the installed
// dictionaries.
- if (!numdict)
+ if (!mvDicts.size())
{
SvtLinguConfig aLinguCfg;
@@ -137,7 +128,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
// is not yet supported by the list od new style dictionaries
MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
- numdict = aDics.size();
+ sal_Int32 numdict = aDics.size();
if (numdict)
{
// get supported locales from the dictionaries-to-use...
@@ -171,7 +162,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
numdict = numdict + dict.aLocaleNames.getLength();
// add dictionary information
- aDicts = new HDInfo[numdict];
+ mvDicts.resize(numdict);
k = 0;
for (auto const& dict : aDics)
@@ -188,17 +179,17 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
for (sal_Int32 i = 0; i < nLocales; ++i)
{
LanguageTag aLanguageTag(dict.aLocaleNames[i]);
- aDicts[k].aPtr = nullptr;
- aDicts[k].eEnc = RTL_TEXTENCODING_DONTKNOW;
- aDicts[k].aLoc = aLanguageTag.getLocale();
- aDicts[k].apCC = new CharClass( aLanguageTag );
+ mvDicts[k].aPtr = nullptr;
+ mvDicts[k].eEnc = RTL_TEXTENCODING_DONTKNOW;
+ mvDicts[k].aLoc = aLanguageTag.getLocale();
+ mvDicts[k].apCC.reset( new CharClass( aLanguageTag ) );
// also both files have to be in the same directory and the
// file names must only differ in the extension (.aff/.dic).
// Thus we use the first location only and strip the extension part.
OUString aLocation = dict.aLocations[0];
sal_Int32 nPos = aLocation.lastIndexOf( '.' );
aLocation = aLocation.copy( 0, nPos );
- aDicts[k].aName = aLocation;
+ mvDicts[k].aName = aLocation;
++k;
}
@@ -210,7 +201,7 @@ Sequence< Locale > SAL_CALL Hyphenator::getLocales()
{
// no dictionary found so register no dictionaries
numdict = 0;
- aDicts = nullptr;
+ mvDicts.clear();
aSuppLocales.realloc(0);
}
}
@@ -286,9 +277,9 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
Reference< XHyphenatedWord > xRes;
k = -1;
- for (int j = 0; j < numdict; j++)
+ for (size_t j = 0; j < mvDicts.size(); j++)
{
- if (aLocale == aDicts[j].aLoc)
+ if (aLocale == mvDicts[j].aLoc)
k = j;
}
@@ -300,16 +291,16 @@ Reference< XHyphenatedWord > SAL_CALL Hyphenator::hyphenate( const OUString& aWo
int nHyphenationPosAltHyph = -1;
// if this dictionary has not been loaded yet do that
- if (!aDicts[k].aPtr)
+ if (!mvDicts[k].aPtr)
{
- if (!LoadDictionary(aDicts[k]))
+ if (!LoadDictionary(mvDicts[k]))
return nullptr;
}
// other wise hyphenate the word with that dictionary
- dict = aDicts[k].aPtr;
- eEnc = aDicts[k].eEnc;
- CharClass * pCC = aDicts[k].apCC;
+ dict = mvDicts[k].aPtr;
+ eEnc = mvDicts[k].eEnc;
+ CharClass * pCC = mvDicts[k].apCC.get();
// we don't want to work with a default text encoding since following incorrect
// results may occur only for specific text and thus may be hard to notice.
@@ -529,9 +520,9 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
}
int k = -1;
- for (int j = 0; j < numdict; j++)
+ for (size_t j = 0; j < mvDicts.size(); j++)
{
- if (aLocale == aDicts[j].aLoc) k = j;
+ if (aLocale == mvDicts[j].aLoc) k = j;
}
// if we have a hyphenation dictionary matching this locale
@@ -539,16 +530,16 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
{
HyphenDict *dict = nullptr;
// if this dictionary has not been loaded yet do that
- if (!aDicts[k].aPtr)
+ if (!mvDicts[k].aPtr)
{
- if (!LoadDictionary(aDicts[k]))
+ if (!LoadDictionary(mvDicts[k]))
return nullptr;
}
// other wise hyphenate the word with that dictionary
- dict = aDicts[k].aPtr;
- rtl_TextEncoding eEnc = aDicts[k].eEnc;
- CharClass* pCC = aDicts[k].apCC;
+ dict = mvDicts[k].aPtr;
+ rtl_TextEncoding eEnc = mvDicts[k].eEnc;
+ CharClass* pCC = mvDicts[k].apCC.get();
// we don't want to work with a default text encoding since following incorrect
// results may occur only for specific text and thus may be hard to notice.
@@ -765,7 +756,7 @@ void SAL_CALL Hyphenator::initialize( const Sequence< Any >& rArguments )
//! And the reference to the UNO-functions while increasing
//! the ref-count and will implicitly free the memory
//! when the object is no longer used.
- pPropHelper = new PropertyHelper_Hyphenation( static_cast<XHyphenator *>(this), xPropSet );
+ pPropHelper.reset( new PropertyHelper_Hyphenation( static_cast<XHyphenator *>(this), xPropSet ) );
pPropHelper->AddAsPropListener(); //! after a reference is established
}
else {
@@ -786,8 +777,7 @@ void SAL_CALL Hyphenator::dispose()
if (pPropHelper)
{
pPropHelper->RemoveAsPropListener();
- delete pPropHelper;
- pPropHelper = nullptr;
+ pPropHelper.reset();
}
}
}
diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx
index abaafef3ec6d..a5257dd84380 100644
--- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx
+++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.hxx
@@ -50,7 +50,7 @@ struct HDInfo {
OUString aName;
Locale aLoc;
rtl_TextEncoding eEnc;
- CharClass * apCC;
+ std::unique_ptr<CharClass> apCC;
};
class Hyphenator :
@@ -65,11 +65,10 @@ class Hyphenator :
>
{
Sequence< Locale > aSuppLocales;
- HDInfo * aDicts;
- sal_Int32 numdict;
+ std::vector< HDInfo > mvDicts;
::comphelper::OInterfaceContainerHelper2 aEvtListeners;
- linguistic::PropertyHelper_Hyphenation* pPropHelper;
+ std::unique_ptr<linguistic::PropertyHelper_Hyphenation> pPropHelper;
bool bDisposing;
Hyphenator(const Hyphenator &) = delete;
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
index c3b5bb08cabf..7f9dca4f9ce2 100644
--- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
+++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
@@ -80,7 +80,6 @@ Thesaurus::~Thesaurus()
if (pPropHelper)
{
pPropHelper->RemoveAsPropListener();
- delete pPropHelper;
}
}
commit abf173db4b46afd6925c5138f24f1f5146c96525
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Feb 6 11:28:06 2018 +0200
loplugin:useuniqueptr in Thesaurus
Change-Id: I59a2cbeb08242ec1929b0c70f28e1d059dec70ca
Reviewed-on: https://gerrit.libreoffice.org/49875
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
index ce1d4a07f492..c3b5bb08cabf 100644
--- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
+++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
@@ -71,45 +71,12 @@ Thesaurus::Thesaurus() :
{
bDisposing = false;
pPropHelper = nullptr;
- aThes = nullptr;
- aCharSetInfo = nullptr;
- aTEncs = nullptr;
- aTLocs = nullptr;
- aTNames = nullptr;
- numthes = 0;
prevLocale = LANGUAGE_DONTKNOW;
}
Thesaurus::~Thesaurus()
{
- if (aThes)
- {
- for (int i = 0; i < numthes; i++)
- {
- if (aThes[i]) delete aThes[i];
- aThes[i] = nullptr;
- }
- delete[] aThes;
- }
- aThes = nullptr;
- if (aCharSetInfo)
- {
- for (int i = 0; i < numthes; i++)
- {
- if (aCharSetInfo[i]) delete aCharSetInfo[i];
- aCharSetInfo[i] = nullptr;
- }
- delete[] aCharSetInfo;
- }
- aCharSetInfo = nullptr;
- numthes = 0;
- if (aTEncs) delete[] aTEncs;
- aTEncs = nullptr;
- if (aTLocs) delete[] aTLocs;
- aTLocs = nullptr;
- if (aTNames) delete[] aTNames;
- aTNames = nullptr;
-
+ mvThesInfo.clear();
if (pPropHelper)
{
pPropHelper->RemoveAsPropListener();
@@ -135,7 +102,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
// this routine should return the locales supported by the installed
// dictionaries.
- if (!numthes)
+ if (!mvThesInfo.size())
{
SvtLinguConfig aLinguCfg;
@@ -163,7 +130,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
// is not yet supported by the list od new style dictionaries
MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
- numthes = aDics.size();
+ sal_Int32 numthes = aDics.size();
if (numthes)
{
// get supported locales from the dictionaries-to-use...
@@ -201,11 +168,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
numthes = numthes + dict.aLocaleNames.getLength();
// add dictionary information
- aThes = new MyThes* [numthes];
- aTEncs = new rtl_TextEncoding [numthes];
- aTLocs = new Locale [numthes];
- aTNames = new OUString [numthes];
- aCharSetInfo = new CharClass* [numthes];
+ mvThesInfo.resize(numthes);
k = 0;
for (auto const& dict : aDics)
@@ -222,17 +185,16 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
for (sal_Int32 i = 0; i < nLocales; ++i)
{
LanguageTag aLanguageTag(dict.aLocaleNames[i]);
- aThes[k] = nullptr;
- aTEncs[k] = RTL_TEXTENCODING_DONTKNOW;
- aTLocs[k] = aLanguageTag.getLocale();
- aCharSetInfo[k] = new CharClass( aLanguageTag );
+ mvThesInfo[k].aEncoding = RTL_TEXTENCODING_DONTKNOW;
+ mvThesInfo[k].aLocale = aLanguageTag.getLocale();
+ mvThesInfo[k].aCharSetInfo.reset( new CharClass( aLanguageTag ) );
// also both files have to be in the same directory and the
// file names must only differ in the extension (.aff/.dic).
// Thus we use the first location only and strip the extension part.
OUString aLocation = dict.aLocations[0];
sal_Int32 nPos = aLocation.lastIndexOf( '.' );
aLocation = aLocation.copy( 0, nPos );
- aTNames[k] = aLocation;
+ mvThesInfo[k].aName = aLocation;
++k;
}
@@ -243,12 +205,7 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
else
{
/* no dictionary found so register no dictionaries */
- numthes = 0;
- aThes = nullptr;
- aTEncs = nullptr;
- aTLocs = nullptr;
- aTNames = nullptr;
- aCharSetInfo = nullptr;
+ mvThesInfo.clear();
aSuppLocales.realloc(0);
}
}
@@ -319,15 +276,15 @@ Sequence < Reference < css::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryM
CharClass * pCC = nullptr;
// find the first thesaurus that matches the locale
- for (int i =0; i < numthes; i++)
+ for (size_t i =0; i < mvThesInfo.size(); i++)
{
- if (rLocale == aTLocs[i])
+ if (rLocale == mvThesInfo[i].aLocale)
{
// open up and initialize this thesaurus if need be
- if (!aThes[i])
+ if (!mvThesInfo[i].aThes)
{
- OUString datpath = aTNames[i] + ".dat";
- OUString idxpath = aTNames[i] + ".idx";
+ OUString datpath = mvThesInfo[i].aName + ".dat";
+ OUString idxpath = mvThesInfo[i].aName + ".idx";
OUString ndat;
OUString nidx;
osl::FileBase::getSystemPathFromFileURL(datpath,ndat);
@@ -342,13 +299,12 @@ Sequence < Reference < css::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryM
OString aTmpdat(OU2ENC(ndat,osl_getThreadTextEncoding()));
#endif
- aThes[i] = new MyThes(aTmpidx.getStr(),aTmpdat.getStr());
- if (aThes[i])
- aTEncs[i] = getTextEncodingFromCharset(aThes[i]->get_th_encoding());
+ mvThesInfo[i].aThes.reset( new MyThes(aTmpidx.getStr(),aTmpdat.getStr()) );
+ mvThesInfo[i].aEncoding = getTextEncodingFromCharset(mvThesInfo[i].aThes->get_th_encoding());
}
- pTH = aThes[i];
- eEnc = aTEncs[i];
- pCC = aCharSetInfo[i];
+ pTH = mvThesInfo[i].aThes.get();
+ eEnc = mvThesInfo[i].aEncoding;
+ pCC = mvThesInfo[i].aCharSetInfo.get();
if (pTH)
break;
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.hxx b/lingucomponent/source/thesaurus/libnth/nthesimp.hxx
index f1c27822b859..34ad5ca092c9 100644
--- a/lingucomponent/source/thesaurus/libnth/nthesimp.hxx
+++ b/lingucomponent/source/thesaurus/libnth/nthesimp.hxx
@@ -41,6 +41,8 @@
#include <osl/file.hxx>
#include <mythes.hxx>
+#include <memory>
+#include <vector>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
@@ -66,12 +68,15 @@ class Thesaurus :
::comphelper::OInterfaceContainerHelper2 aEvtListeners;
linguistic::PropertyHelper_Thesaurus* pPropHelper;
bool bDisposing;
- CharClass ** aCharSetInfo;
- MyThes ** aThes;
- rtl_TextEncoding * aTEncs;
- Locale * aTLocs;
- OUString * aTNames;
- sal_Int32 numthes;
+ struct ThesInfo
+ {
+ std::unique_ptr<CharClass> aCharSetInfo;
+ std::unique_ptr<MyThes> aThes;
+ rtl_TextEncoding aEncoding;
+ Locale aLocale;
+ OUString aName;
+ };
+ std::vector<ThesInfo> mvThesInfo;
// cache for the Thesaurus dialog
Sequence < Reference < css::linguistic2::XMeaning > > prevMeanings;
More information about the Libreoffice-commits
mailing list