summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-28 15:19:20 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-29 17:50:36 +0200
commitf57c2e65a50585ef4a282549c13655d9afc83d86 (patch)
treef6c105ca7cf14ee1f33291916b596ad58cb0256a /vcl
parentb3cd042285af08a0bdc5dea608d131424d850f9c (diff)
std::unique_ptr->std::optional
Change-Id: Ie3e0eb7cb7ca25536e825e30c53e112bf537b325 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116379 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/accmgr.hxx6
-rw-r--r--vcl/source/window/accmgr.cxx44
-rw-r--r--vcl/unx/generic/printer/ppdparser.cxx26
3 files changed, 38 insertions, 38 deletions
diff --git a/vcl/inc/accmgr.hxx b/vcl/inc/accmgr.hxx
index 1e57ed44dd07..55e028f69a1b 100644
--- a/vcl/inc/accmgr.hxx
+++ b/vcl/inc/accmgr.hxx
@@ -21,7 +21,7 @@
#define INCLUDED_VCL_INC_ACCMGR_HXX
#include <vector>
-#include <memory>
+#include <optional>
#include <vcl/keycod.hxx>
@@ -30,8 +30,8 @@ class Accelerator;
class ImplAccelManager
{
private:
- std::unique_ptr<std::vector< Accelerator* >> mpAccelList;
- std::unique_ptr<std::vector< Accelerator* >> mpSequenceList;
+ std::optional<std::vector< Accelerator* >> mxAccelList;
+ std::optional<std::vector< Accelerator* >> mxSequenceList;
public:
ImplAccelManager()
diff --git a/vcl/source/window/accmgr.cxx b/vcl/source/window/accmgr.cxx
index 003e09343bc3..5ab0279b3a10 100644
--- a/vcl/source/window/accmgr.cxx
+++ b/vcl/source/window/accmgr.cxx
@@ -30,34 +30,34 @@ ImplAccelManager::~ImplAccelManager()
bool ImplAccelManager::InsertAccel( Accelerator* pAccel )
{
- if ( !mpAccelList ) {
- mpAccelList.reset( new std::vector< Accelerator* > );
+ if ( !mxAccelList ) {
+ mxAccelList.emplace();
} else {
- for (Accelerator* i : *mpAccelList) {
+ for (Accelerator* i : *mxAccelList) {
if ( i == pAccel ) {
return false;
}
}
}
- mpAccelList->insert( mpAccelList->begin(), pAccel );
+ mxAccelList->insert( mxAccelList->begin(), pAccel );
return true;
}
void ImplAccelManager::RemoveAccel( Accelerator const * pAccel )
{
// do we have a list ?
- if ( !mpAccelList )
+ if ( !mxAccelList )
return;
//e.g. #i90599#. Someone starts typing a sequence in a dialog, but doesn't
//end it, and then closes the dialog, deleting the accelerators. So if
//we're removing an accelerator that a sub-accelerator which is in the
//sequence list, throw away the entire sequence
- if ( mpSequenceList ) {
+ if ( mxSequenceList ) {
for (sal_uInt16 i = 0; i < pAccel->GetItemCount(); ++i) {
Accelerator* pSubAccel = pAccel->GetAccel( pAccel->GetItemId(i) );
- for (Accelerator* j : *mpSequenceList) {
+ for (Accelerator* j : *mxSequenceList) {
if ( j == pSubAccel ) {
EndSequence();
i = pAccel->GetItemCount();
@@ -68,24 +68,24 @@ void ImplAccelManager::RemoveAccel( Accelerator const * pAccel )
}
// throw it away
- auto it = std::find(mpAccelList->begin(), mpAccelList->end(), pAccel);
- if (it != mpAccelList->end())
- mpAccelList->erase( it );
+ auto it = std::find(mxAccelList->begin(), mxAccelList->end(), pAccel);
+ if (it != mxAccelList->end())
+ mxAccelList->erase( it );
}
void ImplAccelManager::EndSequence()
{
// are we in a list ?
- if ( !mpSequenceList )
+ if ( !mxSequenceList )
return;
- for (Accelerator* pTempAccel : *mpSequenceList)
+ for (Accelerator* pTempAccel : *mxSequenceList)
{
pTempAccel->mpDel = nullptr;
}
// delete sequence-list
- mpSequenceList.reset();
+ mxSequenceList.reset();
}
bool ImplAccelManager::IsAccelKey( const vcl::KeyCode& rKeyCode )
@@ -93,15 +93,15 @@ bool ImplAccelManager::IsAccelKey( const vcl::KeyCode& rKeyCode )
Accelerator* pAccel;
// do we have accelerators ??
- if ( !mpAccelList )
+ if ( !mxAccelList )
return false;
- if ( mpAccelList->empty() )
+ if ( mxAccelList->empty() )
return false;
// are we in a sequence ?
- if ( mpSequenceList )
+ if ( mxSequenceList )
{
- pAccel = mpSequenceList->empty() ? nullptr : (*mpSequenceList)[ 0 ];
+ pAccel = mxSequenceList->empty() ? nullptr : (*mxSequenceList)[ 0 ];
// not found ?
if ( !pAccel )
@@ -121,7 +121,7 @@ bool ImplAccelManager::IsAccelKey( const vcl::KeyCode& rKeyCode )
if ( pNextAccel )
{
- mpSequenceList->insert( mpSequenceList->begin(), pNextAccel );
+ mxSequenceList->insert( mxSequenceList->begin(), pNextAccel );
// call Activate-Handler of the new one
pNextAccel->Activate();
@@ -169,7 +169,7 @@ bool ImplAccelManager::IsAccelKey( const vcl::KeyCode& rKeyCode )
}
// step through the list of accelerators
- for (Accelerator* i : *mpAccelList)
+ for (Accelerator* i : *mxAccelList)
{
pAccel = i;
@@ -184,9 +184,9 @@ bool ImplAccelManager::IsAccelKey( const vcl::KeyCode& rKeyCode )
{
// create sequence list
- mpSequenceList.reset( new std::vector< Accelerator* > );
- mpSequenceList->insert( mpSequenceList->begin(), pAccel );
- mpSequenceList->insert( mpSequenceList->begin(), pNextAccel );
+ mxSequenceList.emplace();
+ mxSequenceList->insert( mxSequenceList->begin(), pAccel );
+ mxSequenceList->insert( mxSequenceList->begin(), pNextAccel );
// call activate-Handler of the new one
pNextAccel->Activate();
diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx
index ecafa66a1620..c976a2f7519d 100644
--- a/vcl/unx/generic/printer/ppdparser.cxx
+++ b/vcl/unx/generic/printer/ppdparser.cxx
@@ -245,7 +245,7 @@ namespace psp
{
public:
std::vector< std::unique_ptr<PPDParser> > aAllParsers;
- std::unique_ptr<std::unordered_map< OUString, OUString >> pAllPPDFiles;
+ std::optional<std::unordered_map< OUString, OUString >> xAllPPDFiles;
};
}
@@ -417,7 +417,7 @@ void PPDParser::scanPPDDir( const OUString& rDir )
{
if( aFileName.endsWithIgnoreAsciiCaseAsciiL( rSuffix.pSuffix, rSuffix.nSuffixLen ) )
{
- (*rPPDCache.pAllPPDFiles)[ aFileName.copy( 0, aFileName.getLength() - rSuffix.nSuffixLen ) ] = aPPDFile.PathToFileName();
+ (*rPPDCache.xAllPPDFiles)[ aFileName.copy( 0, aFileName.getLength() - rSuffix.nSuffixLen ) ] = aPPDFile.PathToFileName();
break;
}
}
@@ -435,10 +435,10 @@ void PPDParser::scanPPDDir( const OUString& rDir )
void PPDParser::initPPDFiles(PPDCache &rPPDCache)
{
- if( rPPDCache.pAllPPDFiles )
+ if( rPPDCache.xAllPPDFiles )
return;
- rPPDCache.pAllPPDFiles.reset(new std::unordered_map< OUString, OUString >);
+ rPPDCache.xAllPPDFiles.emplace();
// check installation directories
std::vector< OUString > aPathList;
@@ -448,7 +448,7 @@ void PPDParser::initPPDFiles(PPDCache &rPPDCache)
INetURLObject aPPDDir( path, INetProtocol::File, INetURLObject::EncodeMechanism::All );
scanPPDDir( aPPDDir.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
}
- if( rPPDCache.pAllPPDFiles->find( OUString( "SGENPRT" ) ) != rPPDCache.pAllPPDFiles->end() )
+ if( rPPDCache.xAllPPDFiles->find( OUString( "SGENPRT" ) ) != rPPDCache.xAllPPDFiles->end() )
return;
// last try: search in directory of executable (mainly for setup)
@@ -461,8 +461,8 @@ void PPDParser::initPPDFiles(PPDCache &rPPDCache)
<< aDir.GetMainURL(INetURLObject::DecodeMechanism::NONE));
scanPPDDir( aDir.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
SAL_INFO("vcl.unx.print", "SGENPRT "
- << (rPPDCache.pAllPPDFiles->find("SGENPRT") ==
- rPPDCache.pAllPPDFiles->end() ? "not found" : "found"));
+ << (rPPDCache.xAllPPDFiles->find("SGENPRT") ==
+ rPPDCache.xAllPPDFiles->end() ? "not found" : "found"));
}
}
@@ -488,23 +488,23 @@ OUString PPDParser::getPPDFile( const OUString& rFile )
aBase = aBase.copy( nLastIndex+1 );
do
{
- it = rPPDCache.pAllPPDFiles->find( aBase );
+ it = rPPDCache.xAllPPDFiles->find( aBase );
nLastIndex = aBase.lastIndexOf( '.' );
if( nLastIndex > 0 )
aBase = aBase.copy( 0, nLastIndex );
- } while( it == rPPDCache.pAllPPDFiles->end() && nLastIndex > 0 );
+ } while( it == rPPDCache.xAllPPDFiles->end() && nLastIndex > 0 );
- if( it == rPPDCache.pAllPPDFiles->end() && bRetry )
+ if( it == rPPDCache.xAllPPDFiles->end() && bRetry )
{
// a new file ? rehash
- rPPDCache.pAllPPDFiles.reset();
+ rPPDCache.xAllPPDFiles.reset();
bRetry = false;
// note this is optimized for office start where
// no new files occur and initPPDFiles is called only once
}
- } while( ! rPPDCache.pAllPPDFiles );
+ } while( ! rPPDCache.xAllPPDFiles );
- if( it != rPPDCache.pAllPPDFiles->end() )
+ if( it != rPPDCache.xAllPPDFiles->end() )
aStream.Open( it->second );
}