From 4452c06c3e892aa2d9fef4ebfbe007aed30c9176 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Mon, 28 Nov 2022 22:54:31 -0500 Subject: [PATCH] Replace sptr with std::shared_ptr * Make sptr an alias of std::shared_ptr * Make old sptr's implicit conversion explict through std::make_shared --- aard.cc | 6 +- article_maker.cc | 16 ++--- article_netmgr.cc | 4 +- articleview.cc | 6 +- belarusiantranslit.cc | 6 +- bgl.cc | 12 ++-- btreeidx.cc | 4 +- chinese.cc | 6 +- dictdfiles.cc | 10 +-- dictionary.cc | 8 +-- dictserver.cc | 10 +-- dsl.cc | 10 +-- editdictionaries.cc | 2 +- epwing.cc | 12 ++-- forvo.cc | 10 +-- ftshelpers.cc | 2 +- german.cc | 2 +- gls.cc | 12 ++-- greektranslit.cc | 2 +- hunspell.cc | 8 +-- lsa.cc | 12 ++-- mainwindow.cc | 6 +- mdx.cc | 14 ++-- mediawiki.cc | 12 ++-- programs.cc | 12 ++-- romaji.cc | 4 +- russiantranslit.cc | 2 +- sdict.cc | 6 +- slob.cc | 8 +-- sounddir.cc | 16 ++--- sptr.hh | 149 ++---------------------------------------- stardict.cc | 10 +-- transliteration.cc | 6 +- voiceengines.cc | 6 +- website.cc | 10 +-- xdxf.cc | 10 +-- zim.cc | 8 +-- zipsounds.cc | 16 ++--- 38 files changed, 157 insertions(+), 298 deletions(-) diff --git a/aard.cc b/aard.cc index 544747ed..a0072932 100644 --- a/aard.cc +++ b/aard.cc @@ -642,7 +642,7 @@ sptr< Dictionary::DataRequest > AardDictionary::getSearchResults( QString const bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } /// AardDictionary::getArticle() @@ -829,7 +829,7 @@ sptr< Dictionary::DataRequest > AardDictionary::getArticle( wstring const & word bool ignoreDiacritics ) { - return new AardArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } } // anonymous namespace @@ -1070,7 +1070,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } // if need to rebuild try { - dictionaries.push_back( new AardDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles ) ); } diff --git a/article_maker.cc b/article_maker.cc index d93273f6..858b6c0a 100644 --- a/article_maker.cc +++ b/article_maker.cc @@ -224,7 +224,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( string header = makeHtmlHeader( phrase.phrase, QString(), true ); - return new ArticleRequest( phrase, "", + return std::make_shared( phrase, "", contexts, ftsDicts, header, -1, true ); } @@ -278,7 +278,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( result += ""; - sptr< Dictionary::DataRequestInstant > r = new Dictionary::DataRequestInstant( true ); + sptr< Dictionary::DataRequestInstant > r = std::make_shared( true ); r->getData().resize( result.size() ); memcpy( &( r->getData().front() ), result.data(), result.size() ); @@ -318,13 +318,13 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString::fromStdString( activeDicts[ x ]->getId() ) ) ) unmutedDicts.push_back( activeDicts[ x ] ); - return new ArticleRequest( phrase, activeGroup ? activeGroup->name : "", + return std::make_shared( phrase, activeGroup ? activeGroup->name : "", contexts, unmutedDicts, header, collapseBigArticles ? articleLimitSize : -1, needExpandOptionalParts, ignoreDiacritics ); } else - return new ArticleRequest( phrase, activeGroup ? activeGroup->name : "", + return std::make_shared( phrase, activeGroup ? activeGroup->name : "", contexts, activeDicts, header, collapseBigArticles ? articleLimitSize : -1, needExpandOptionalParts, ignoreDiacritics ); @@ -336,7 +336,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeNotFoundTextFor( string result = makeHtmlHeader( word, QString(), true ) + makeNotFoundBody( word, group ) + ""; - sptr< Dictionary::DataRequestInstant > r = new Dictionary::DataRequestInstant( true ); + sptr< Dictionary::DataRequestInstant > r = std::make_shared( true ); r->getData().resize( result.size() ); memcpy( &( r->getData().front() ), result.data(), result.size() ); @@ -350,7 +350,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeEmptyPage() const ""; sptr< Dictionary::DataRequestInstant > r = - new Dictionary::DataRequestInstant( true ); + std::make_shared( true ); r->getData().resize( result.size() ); memcpy( &( r->getData().front() ), result.data(), result.size() ); @@ -366,7 +366,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makePicturePage( string const & ur + ""; sptr< Dictionary::DataRequestInstant > r = - new Dictionary::DataRequestInstant( true ); + std::make_shared( true ); r->getData().resize( result.size() ); memcpy( &( r->getData().front() ), result.data(), result.size() ); @@ -713,7 +713,7 @@ void ArticleRequest::bodyFinished() footer += ArticleMaker::makeNotFoundBody( word.size() < 40 ? word : "", group ); // When there were no definitions, we run stemmed search. - stemmedWordFinder = new WordFinder( this ); + stemmedWordFinder = std::make_shared( this ); connect( stemmedWordFinder.get(), SIGNAL( finished() ), this, SLOT( stemmedSearchFinished() ), Qt::QueuedConnection ); diff --git a/article_netmgr.cc b/article_netmgr.cc index 3a4e6037..6d565284 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -263,7 +263,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( if( !url.host().isEmpty() && url.host() != "localhost" ) { // Strange request - ignore it - return new Dictionary::DataRequestInstant( false ); + return std::make_shared( false ); } contentType = "text/html"; @@ -339,7 +339,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( buffer.open(QIODevice::WriteOnly); dictionaries[ x ]->getIcon().pixmap( 64 ).save(&buffer, "PNG"); buffer.close(); - sptr< Dictionary::DataRequestInstant > ico = new Dictionary::DataRequestInstant( true ); + sptr< Dictionary::DataRequestInstant > ico = std::make_shared( true ); ico->getData().resize( bytes.size() ); memcpy( &( ico->getData().front() ), bytes.data(), bytes.size() ); return ico; diff --git a/articleview.cc b/articleview.cc index 5063b026..54fb14db 100644 --- a/articleview.cc +++ b/articleview.cc @@ -1217,7 +1217,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, if ( Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) { sptr< Dictionary::DataRequest > req = - new Dictionary::WebMultimediaDownload( url, articleNetMgr ); + std::make_shared( url, articleNetMgr ); resourceDownloadRequests.push_back( req ); @@ -1552,7 +1552,7 @@ ResourceToSaveHandler * ArticleView::saveResource( const QUrl & url, const QUrl } else { - req = new Dictionary::WebMultimediaDownload( url, articleNetMgr ); + req = std::make_shared( url, articleNetMgr ); handler->addRequest( req ); } @@ -2550,7 +2550,7 @@ void ArticleView::highlightFTSResults() if( regexp.pattern().isEmpty() || !regexp.isValid() ) return; - sptr< AccentMarkHandler > marksHandler = ignoreDiacritics ? new DiacriticsHandler : new AccentMarkHandler; + sptr< AccentMarkHandler > marksHandler = ignoreDiacritics ? std::make_shared() : std::make_shared(); marksHandler->setText( pageText ); diff --git a/belarusiantranslit.cc b/belarusiantranslit.cc index 80fa06ad..7fbf8f12 100644 --- a/belarusiantranslit.cc +++ b/belarusiantranslit.cc @@ -413,13 +413,13 @@ std::vector< sptr< Dictionary::Class > > makeDictionaries() static BelarusianSchoolToClassicTable t2; std::vector< sptr< Dictionary::Class > > dicts; - dicts.push_back( new Transliteration::TransliterationDictionary( "c31b24abf412abc9b23bb40a898f1040", + dicts.push_back( std::make_shared( "c31b24abf412abc9b23bb40a898f1040", QCoreApplication::translate( "BelarusianTranslit", "Belarusian transliteration from latin to cyrillic (classic orthography)" ).toUtf8().data(), QIcon( ":/flags/by.png" ), t0, false ) ); - dicts.push_back( new Transliteration::TransliterationDictionary( "c31b24abf412abc9b23bb40a898f1041", + dicts.push_back( std::make_shared( "c31b24abf412abc9b23bb40a898f1041", QCoreApplication::translate( "BelarusianTranslit", "Belarusian transliteration from latin to cyrillic (school orthography)" ).toUtf8().data(), QIcon( ":/flags/by.png" ), t1, false ) ); - dicts.push_back( new Transliteration::TransliterationDictionary( "c31b24abf412abc9b23bb40a898f1042", + dicts.push_back( std::make_shared( "c31b24abf412abc9b23bb40a898f1042", QCoreApplication::translate( "BelarusianTranslit", "Belarusian transliteration (smoothes out the difference\n" "between classic and school orthography in cyrillic)" ).toUtf8().data(), QIcon( ":/flags/by.png" ), t2, false ) ); diff --git a/bgl.cc b/bgl.cc index f6da3420..be2bdf4a 100644 --- a/bgl.cc +++ b/bgl.cc @@ -602,7 +602,7 @@ sptr< Dictionary::WordSearchRequest > BglDictionary::findHeadwordsForSynonym( wstring const & word ) { - return synonymSearchEnabled ? new BglHeadwordsRequest( word, *this ) : + return synonymSearchEnabled ? std::make_shared( word, *this ) : Class::findHeadwordsForSynonym( word ); } @@ -926,7 +926,7 @@ sptr< Dictionary::DataRequest > BglDictionary::getArticle( wstring const & word, bool ignoreDiacritics ) { - return new BglArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } @@ -1070,8 +1070,8 @@ void BglResourceRequest::run() sptr< Dictionary::DataRequest > BglDictionary::getResource( string const & name ) { - return new BglResourceRequest( idxMutex, idx, idxHeader.resourceListOffset, - idxHeader.resourcesCount, name ); + return std::shared_ptr(new BglResourceRequest(idxMutex, idx, idxHeader.resourceListOffset, + idxHeader.resourcesCount, name )); } /// Replaces 1234; occurrences with ሴ @@ -1161,7 +1161,7 @@ sptr< Dictionary::DataRequest > BglDictionary::getSearchResults( QString const & bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } @@ -1347,7 +1347,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( try { - dictionaries.push_back( new BglDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, *i ) ); } diff --git a/btreeidx.cc b/btreeidx.cc index 3667abe1..4a48bb37 100644 --- a/btreeidx.cc +++ b/btreeidx.cc @@ -450,7 +450,7 @@ sptr< Dictionary::WordSearchRequest > BtreeDictionary::prefixMatch( wstring const & str, unsigned long maxResults ) { - return new BtreeWordSearchRequest( *this, str, 0, -1, true, maxResults ); + return std::make_shared( *this, str, 0, -1, true, maxResults ); } sptr< Dictionary::WordSearchRequest > BtreeDictionary::stemmedMatch( @@ -458,7 +458,7 @@ sptr< Dictionary::WordSearchRequest > BtreeDictionary::stemmedMatch( unsigned long maxResults ) { - return new BtreeWordSearchRequest( *this, str, minLength, (int)maxSuffixVariation, + return std::make_shared( *this, str, minLength, (int)maxSuffixVariation, false, maxResults ); } diff --git a/chinese.cc b/chinese.cc index 35a092f8..8f272f7f 100644 --- a/chinese.cc +++ b/chinese.cc @@ -125,21 +125,21 @@ std::vector< sptr< Dictionary::Class > > makeDictionaries( Config::Chinese const { if ( cfg.enableSCToTWConversion ) { - result.push_back( new CharacterConversionDictionary( "bf1c33a59cbacea8f39b5b5475787cfd", + result.push_back( std::make_shared( "bf1c33a59cbacea8f39b5b5475787cfd", QCoreApplication::translate( "ChineseConversion", "Simplified to traditional Chinese (Taiwan variant) conversion" ).toUtf8().data(), QIcon( ":/flags/tw.png" ), configDir + "s2tw.json" ) ); } if ( cfg.enableSCToHKConversion ) { - result.push_back( new CharacterConversionDictionary( "9e0681fb9e1c0b6c90e6fb46111d96b5", + result.push_back( std::make_shared( "9e0681fb9e1c0b6c90e6fb46111d96b5", QCoreApplication::translate( "ChineseConversion", "Simplified to traditional Chinese (Hong Kong variant) conversion" ).toUtf8().data(), QIcon( ":/flags/hk.png" ), configDir + "s2hk.json" ) ); } if ( cfg.enableTCToSCConversion ) { - result.push_back( new CharacterConversionDictionary( "0db536ce0bdc52ea30d11a82c5db4a27", + result.push_back( std::make_shared( "0db536ce0bdc52ea30d11a82c5db4a27", QCoreApplication::translate( "ChineseConversion", "Traditional to simplified Chinese conversion" ).toUtf8().data(), QIcon( ":/flags/cn.png" ), configDir + "t2s.json" ) ); } diff --git a/dictdfiles.cc b/dictdfiles.cc index 4ef77ce9..00d94962 100644 --- a/dictdfiles.cc +++ b/dictdfiles.cc @@ -418,7 +418,7 @@ sptr< Dictionary::DataRequest > DictdDictionary::getArticle( wstring const & wor } if ( mainArticles.empty() && alternateArticles.empty() ) - return new Dictionary::DataRequestInstant( false ); + return std::make_shared( false ); string result; @@ -431,7 +431,7 @@ sptr< Dictionary::DataRequest > DictdDictionary::getArticle( wstring const & wor result += i->second; sptr< Dictionary::DataRequestInstant > ret = - new Dictionary::DataRequestInstant( true ); + std::make_shared( true ); ret->getData().resize( result.size() ); @@ -441,7 +441,7 @@ sptr< Dictionary::DataRequest > DictdDictionary::getArticle( wstring const & wor } catch( std::exception & e ) { - return new Dictionary::DataRequestInstant( QString( e.what() ) ); + return std::make_shared( QString( e.what() ) ); } } @@ -574,7 +574,7 @@ sptr< Dictionary::DataRequest > DictdDictionary::getSearchResults( QString const bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } } // anonymous namespace @@ -771,7 +771,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( idx.write( &idxHeader, sizeof( idxHeader ) ); } - dictionaries.push_back( new DictdDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles ) ); } diff --git a/dictionary.cc b/dictionary.cc index 45a9a97b..9ef7d6e9 100644 --- a/dictionary.cc +++ b/dictionary.cc @@ -147,13 +147,13 @@ sptr< WordSearchRequest > Class::stemmedMatch( wstring const & /*str*/, unsigned long /*maxResults*/ ) { - return new WordSearchRequestInstant(); + return std::make_shared(); } sptr< WordSearchRequest > Class::findHeadwordsForSynonym( wstring const & ) { - return new WordSearchRequestInstant(); + return std::make_shared(); } vector< wstring > Class::getAlternateWritings( wstring const & ) @@ -165,12 +165,12 @@ vector< wstring > Class::getAlternateWritings( wstring const & ) sptr< DataRequest > Class::getResource( string const & /*name*/ ) { - return new DataRequestInstant( false ); + return std::make_shared( false ); } sptr< DataRequest > Class::getSearchResults(const QString &, int, bool, int, int, bool, bool ) { - return new DataRequestInstant( false ); + return std::make_shared( false ); } QString const& Class::getDescription() diff --git a/dictserver.cc b/dictserver.cc index 70f3424b..ab49615f 100644 --- a/dictserver.cc +++ b/dictserver.cc @@ -925,10 +925,10 @@ sptr< WordSearchRequest > DictServerDictionary::prefixMatch( wstring const & wor { // Don't make excessively large queries -- they're fruitless anyway - return new WordSearchRequestInstant(); + return std::make_shared(); } else - return new DictServerWordSearchRequest( word, *this ); + return std::make_shared( word, *this ); } sptr< DataRequest > DictServerDictionary::getArticle( wstring const & word, @@ -940,10 +940,10 @@ sptr< DataRequest > DictServerDictionary::getArticle( wstring const & word, { // Don't make excessively large queries -- they're fruitless anyway - return new DataRequestInstant( false ); + return std::make_shared( false ); } else - return new DictServerArticleRequest( word, *this ); + return std::make_shared( word, *this ); } } // Anonimuos namespace @@ -956,7 +956,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::DictServers const for( int x = 0; x < servers.size(); ++x ) { if ( servers[ x ].enabled ) - result.push_back( new DictServerDictionary( servers[ x ].id.toStdString(), + result.push_back( std::make_shared( servers[ x ].id.toStdString(), servers[ x ].name.toUtf8().data(), servers[ x ].url, servers[ x ].databases, diff --git a/dsl.cc b/dsl.cc index b8c69688..a808b48b 100644 --- a/dsl.cc +++ b/dsl.cc @@ -386,7 +386,7 @@ void DslDictionary::doDeferredInit() // the init is complete. //Mutex::Lock _( idxMutex ); - chunks = new ChunkedStorage::Reader( idx, idxHeader.chunksOffset ); + chunks = std::shared_ptr(new ChunkedStorage::Reader(idx, idxHeader.chunksOffset)); // Open the .dsl file @@ -1727,7 +1727,7 @@ sptr< Dictionary::DataRequest > DslDictionary::getArticle( wstring const & word, bool ignoreDiacritics ) { - return new DslArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } //// DslDictionary::getResource() @@ -1861,7 +1861,7 @@ void DslResourceRequest::run() sptr< Dictionary::DataRequest > DslDictionary::getResource( string const & name ) { - return new DslResourceRequest( *this, name ); + return std::make_shared( *this, name ); } @@ -1872,7 +1872,7 @@ sptr< Dictionary::DataRequest > DslDictionary::getSearchResults( QString const & bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } } // anonymous namespace @@ -2389,7 +2389,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } // if need to rebuild - dictionaries.push_back( new DslDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles, maxPictureWidth ) ); diff --git a/editdictionaries.cc b/editdictionaries.cc index 1da47be7..70b19663 100644 --- a/editdictionaries.cc +++ b/editdictionaries.cc @@ -240,7 +240,7 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups ) if ( rebuildGroups ) { orderAndProps = new OrderAndProps( this, savedOrder, savedInactive, dictionaries ); - groups = new Groups( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() ); + groups = std::make_shared( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() ); ui.tabs->removeTab( 1 ); ui.tabs->removeTab( 1 ); diff --git a/epwing.cc b/epwing.cc index c1e59e7a..d01b2205 100644 --- a/epwing.cc +++ b/epwing.cc @@ -653,7 +653,7 @@ sptr< Dictionary::DataRequest > EpwingDictionary::getArticle( wstring const & wo bool ignoreDiacritics ) { - return new EpwingArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } //// EpwingDictionary::getResource() @@ -781,7 +781,7 @@ void EpwingResourceRequest::run() sptr< Dictionary::DataRequest > EpwingDictionary::getResource( string const & name ) { - return new EpwingResourceRequest( *this, name ); + return std::make_shared( *this, name ); } @@ -792,7 +792,7 @@ sptr< Dictionary::DataRequest > EpwingDictionary::getSearchResults( QString cons bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } int EpwingDictionary::japaneseWriting( gd::wchar ch ) @@ -928,7 +928,7 @@ sptr< Dictionary::WordSearchRequest > EpwingDictionary::prefixMatch( wstring const & str, unsigned long maxResults ) { - return new EpwingWordSearchRequest( *this, str, 0, -1, true, maxResults ); + return std::make_shared( *this, str, 0, -1, true, maxResults ); } sptr< Dictionary::WordSearchRequest > EpwingDictionary::stemmedMatch( @@ -936,7 +936,7 @@ sptr< Dictionary::WordSearchRequest > EpwingDictionary::stemmedMatch( unsigned long maxResults ) { - return new EpwingWordSearchRequest( *this, str, minLength, (int)maxSuffixVariation, + return std::make_shared( *this, str, minLength, (int)maxSuffixVariation, false, maxResults ); } @@ -1189,7 +1189,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } // If need to rebuild - dictionaries.push_back( new EpwingDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles, sb ) ); diff --git a/forvo.cc b/forvo.cc index 0b2ade62..321f0145 100644 --- a/forvo.cc +++ b/forvo.cc @@ -57,7 +57,7 @@ public: virtual sptr< WordSearchRequest > prefixMatch( wstring const & /*word*/, unsigned long /*maxResults*/ ) { - sptr< WordSearchRequestInstant > sr = new WordSearchRequestInstant; + sptr< WordSearchRequestInstant > sr = std::make_shared(); sr->setUncertain( true ); @@ -83,11 +83,11 @@ sptr< DataRequest > ForvoDictionary::getArticle( wstring const & word, { // Don't make excessively large queries -- they're fruitless anyway - return new DataRequestInstant( false ); + return std::make_shared( false ); } else { - return new ForvoArticleRequest( word, alts, apiKey, languageCode, getId(), + return std::make_shared( word, alts, apiKey, languageCode, getId(), netMgr ); } } @@ -146,7 +146,7 @@ void ForvoArticleRequest::addQuery( QNetworkAccessManager & mgr, // GD_DPRINTF( "req: %s\n", reqUrl.toEncoded().data() ); - sptr< QNetworkReply > netReply = mgr.get( QNetworkRequest( reqUrl ) ); + sptr< QNetworkReply > netReply = std::shared_ptr(mgr.get( QNetworkRequest( reqUrl ) )); netReplies.push_back( NetReply( netReply, Utf8::encode( str ) ) ); } @@ -368,7 +368,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( displayedCode[ 0 ] = displayedCode[ 0 ].toUpper(); result.push_back( - new ForvoDictionary( hash.result().toHex().data(), + std::make_shared( hash.result().toHex().data(), QString( "Forvo (%1)" ).arg( displayedCode ).toUtf8().data(), forvo.apiKey, code, mgr ) ); diff --git a/ftshelpers.cc b/ftshelpers.cc index 5f50f37e..452bf53d 100644 --- a/ftshelpers.cc +++ b/ftshelpers.cc @@ -1247,7 +1247,7 @@ void FTSResultsRequest::run() ftsIdxHeader.indexRootOffset ), ftsIdx, dict.getFtsMutex() ); - chunks = new ChunkedStorage::Reader( ftsIdx, ftsIdxHeader.chunksOffset ); + chunks = std::shared_ptr(new ChunkedStorage::Reader(ftsIdx, ftsIdxHeader.chunksOffset)); } if( hasCJK ) diff --git a/german.cc b/german.cc index 7caaadaf..2a87f3e9 100644 --- a/german.cc +++ b/german.cc @@ -44,7 +44,7 @@ sptr< Dictionary::Class > makeDictionary() { static GermanTable t; - return new Transliteration::TransliterationDictionary( "cf1b74acd98adea9b2bba16af38f1081", + return std::make_shared( "cf1b74acd98adea9b2bba16af38f1081", QCoreApplication::translate( "GermanTranslit", "German Transliteration" ).toUtf8().data(), QIcon( ":/flags/de.png" ), t ); } diff --git a/gls.cc b/gls.cc index cd583994..28030d8b 100644 --- a/gls.cc +++ b/gls.cc @@ -979,8 +979,8 @@ sptr< Dictionary::WordSearchRequest > GlsDictionary::findHeadwordsForSynonym( wstring const & word ) { - return synonymSearchEnabled ? new GlsHeadwordsRequest( word, *this ) : - Class::findHeadwordsForSynonym( word ); + return synonymSearchEnabled ? std::make_shared( word, *this ) : + Class::findHeadwordsForSynonym( word ); } @@ -1161,7 +1161,7 @@ sptr< Dictionary::DataRequest > GlsDictionary::getArticle( wstring const & word, bool ignoreDiacritics ) { - return new GlsArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } //////////////// GlsDictionary::getResource() @@ -1355,7 +1355,7 @@ void GlsResourceRequest::run() sptr< Dictionary::DataRequest > GlsDictionary::getResource( string const & name ) { - return new GlsResourceRequest( *this, name ); + return std::make_shared( *this, name ); } sptr< Dictionary::DataRequest > GlsDictionary::getSearchResults( QString const & searchString, @@ -1365,7 +1365,7 @@ sptr< Dictionary::DataRequest > GlsDictionary::getSearchResults( QString const & bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } } // anonymous namespace @@ -1594,7 +1594,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } } // if need to rebuild - dictionaries.push_back( new GlsDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles ) ); } diff --git a/greektranslit.cc b/greektranslit.cc index 8f4f8dc4..5b3deccf 100644 --- a/greektranslit.cc +++ b/greektranslit.cc @@ -835,7 +835,7 @@ sptr< Dictionary::Class > makeDictionary() { static GreekTable t; - return new Transliteration::TransliterationDictionary( "baa9e37a1aa69cdb5daca14a48ffe5ae", + return std::make_shared( "baa9e37a1aa69cdb5daca14a48ffe5ae", QCoreApplication::translate( "GreekTranslit", "Greek Transliteration" ).toUtf8().data(), QIcon( ":/flags/gr.png" ), t ); } diff --git a/hunspell.cc b/hunspell.cc index eb483b3b..58d61bff 100644 --- a/hunspell.cc +++ b/hunspell.cc @@ -339,7 +339,7 @@ sptr< DataRequest > HunspellDictionary::getArticle( wstring const & word, wstring const &, bool ) { - return new HunspellArticleRequest( word, getHunspellMutex(), hunspell ); + return std::make_shared( word, getHunspellMutex(), hunspell ); } /// HunspellDictionary::findHeadwordsForSynonym() @@ -513,7 +513,7 @@ QVector< wstring > suggest( wstring & word, Mutex & hunspellMutex, Hunspell & hu sptr< WordSearchRequest > HunspellDictionary::findHeadwordsForSynonym( wstring const & word ) { - return new HunspellHeadwordsRequest( word, getHunspellMutex(), hunspell ); + return std::make_shared( word, getHunspellMutex(), hunspell ); } @@ -628,7 +628,7 @@ sptr< WordSearchRequest > HunspellDictionary::prefixMatch( wstring const & word, unsigned long /*maxResults*/ ) { - return new HunspellPrefixMatchRequest( word, getHunspellMutex(), hunspell ); + return std::make_shared( word, getHunspellMutex(), hunspell ); } void getSuggestionsForExpression( wstring const & expression, @@ -787,7 +787,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::Hunspell const & c FsEncoding::encode( QDir::toNativeSeparators( dataFiles[ d ].dicFileName ) ) ); result.push_back( - new HunspellDictionary( Dictionary::makeDictionaryId( dictFiles ), + std::make_shared( Dictionary::makeDictionaryId( dictFiles ), dataFiles[ d ].dictName.toUtf8().data(), dictFiles ) ); break; diff --git a/lsa.cc b/lsa.cc index f30d1d6c..7695cc5d 100644 --- a/lsa.cc +++ b/lsa.cc @@ -266,7 +266,7 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( wstring const & word, } if ( mainArticles.empty() && alternateArticles.empty() ) - return new Dictionary::DataRequestInstant( false ); // No such word + return std::make_shared( false ); // No such word string result; @@ -318,7 +318,7 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( wstring const & word, memcpy( &(ret->getData().front()), result.data(), result.size() ); - return ret; + return std::shared_ptr(ret); } /// This wraps around file operations @@ -410,7 +410,7 @@ sptr< Dictionary::DataRequest > LsaDictionary::getResource( string const & name vector< WordArticleLink > chain = findArticles( Utf8::decode( strippedName ) ); if ( chain.empty() ) - return new Dictionary::DataRequestInstant( false ); // No such resource + return std::make_shared( false ); // No such resource File::Class f( getDictionaryFilenames()[ 0 ], "rb" ); @@ -440,8 +440,8 @@ sptr< Dictionary::DataRequest > LsaDictionary::getResource( string const & name throw exFailedToRetrieveVorbisInfo(); } - sptr< Dictionary::DataRequestInstant > dr = new - Dictionary::DataRequestInstant( true ); + sptr< Dictionary::DataRequestInstant > dr = std::make_shared< + Dictionary::DataRequestInstant>( true ); vector< char > & data = dr->getData(); @@ -633,7 +633,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( idx.write( &idxHeader, sizeof( idxHeader ) ); } - dictionaries.push_back( new LsaDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles ) ); } diff --git a/mainwindow.cc b/mainwindow.cc index 72530b33..6307fc78 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1170,7 +1170,7 @@ QPrinter & MainWindow::getPrinter() if ( printer.get() ) return *printer; - printer = new QPrinter( QPrinter::HighResolution ); + printer = std::make_shared( QPrinter::HighResolution ); return *printer; } @@ -1527,7 +1527,7 @@ void MainWindow::makeScanPopup() { scanPopup.reset(); - scanPopup = new ScanPopup( 0, cfg, articleNetMgr, audioPlayerFactory.player(), + scanPopup = std::make_shared( nullptr, cfg, articleNetMgr, audioPlayerFactory.player(), dictionaries, groupInstances, history ); scanPopup->setStyleSheet( styleSheet() ); @@ -2995,7 +2995,7 @@ void MainWindow::installHotKeys() { try { - hotkeyWrapper = new HotkeyWrapper( this ); + hotkeyWrapper = std::make_shared( this ); } catch( HotkeyWrapper::exInit & ) { diff --git a/mdx.cc b/mdx.cc index 8d821904..9f2b0f60 100644 --- a/mdx.cc +++ b/mdx.cc @@ -453,7 +453,7 @@ void MdxDictionary::doDeferredInit() if ( fi.fileName() != mddFileName || !fi.exists() ) continue; - sptr< IndexedMdd > mdd = new IndexedMdd( idxMutex, chunks ); + sptr< IndexedMdd > mdd = std::make_shared( idxMutex, chunks ); mdd->openIndex( mddIndexInfos[ i - 1 ], idx, idxMutex ); mdd->open( dictFiles[ i ].c_str() ); mddResources.push_back( mdd ); @@ -525,7 +525,7 @@ sptr< Dictionary::DataRequest > MdxDictionary::getSearchResults( QString const & bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } /// MdxDictionary::getArticle @@ -686,7 +686,7 @@ void MdxArticleRequest::run() sptr MdxDictionary::getArticle( const wstring & word, const vector & alts, const wstring &, bool ignoreDiacritics ) { - return new MdxArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } /// MdxDictionary::getResource @@ -868,7 +868,7 @@ void MddResourceRequest::run() sptr MdxDictionary::getResource( const string & name ) { - return new MddResourceRequest( *this, name ); + return std::make_shared( *this, name ); } const QString & MdxDictionary::getDescription() @@ -1453,7 +1453,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f { if ( File::exists( *mddIter ) ) { - sptr< MdictParser > mddParser = new MdictParser(); + sptr< MdictParser > mddParser = std::make_shared(); if ( !mddParser->open( mddIter->c_str() ) ) { gdWarning( "Broken mdd (resource) file: %s\n", mddIter->c_str() ); @@ -1514,7 +1514,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f while ( !mddParsers.empty() ) { sptr< MdictParser > mddParser = mddParsers.front(); - sptr< IndexedWords > mddIndexedWords = new IndexedWords(); + sptr< IndexedWords > mddIndexedWords = std::make_shared(); MdictParser::HeadWordIndex resourcesIndex; ResourceHandler resourceHandler( chunks, *mddIndexedWords ); @@ -1610,7 +1610,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f idx.write( &idxHeader, sizeof( idxHeader ) ); } - dictionaries.push_back( new MdxDictionary( dictId, indexFile, dictFiles ) ); + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles ) ); } return dictionaries; diff --git a/mediawiki.cc b/mediawiki.cc index 59515bfa..678db47a 100644 --- a/mediawiki.cc +++ b/mediawiki.cc @@ -130,7 +130,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str, Utils::Url::addQueryItem( reqUrl, "apfrom", gd::toQString( str ).replace( '+', "%2B" ) ); - netReply = mgr.get( QNetworkRequest( reqUrl ) ); + netReply = std::shared_ptr(mgr.get( QNetworkRequest( reqUrl ) )); connect( netReply.get(), SIGNAL( finished() ), this, SLOT( downloadFinished() ) ); @@ -534,10 +534,10 @@ sptr< WordSearchRequest > MediaWikiDictionary::prefixMatch( wstring const & word { // Don't make excessively large queries -- they're fruitless anyway - return new WordSearchRequestInstant(); + return std::make_shared(); } else - return new MediaWikiWordSearchRequest( word, url, netMgr ); + return std::make_shared< MediaWikiWordSearchRequest>( word, url, netMgr ); } sptr< DataRequest > MediaWikiDictionary::getArticle( wstring const & word, @@ -549,10 +549,10 @@ sptr< DataRequest > MediaWikiDictionary::getArticle( wstring const & word, { // Don't make excessively large queries -- they're fruitless anyway - return new DataRequestInstant( false ); + return std::make_shared( false ); } else - return new MediaWikiArticleRequest( word, alts, url, netMgr, this ); + return std::make_shared( word, alts, url, netMgr, this ); } } @@ -568,7 +568,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( for( int x = 0; x < wikis.size(); ++x ) { if ( wikis[ x ].enabled ) - result.push_back( new MediaWikiDictionary( wikis[ x ].id.toStdString(), + result.push_back( std::make_shared( wikis[ x ].id.toStdString(), wikis[ x ].name.toUtf8().data(), wikis[ x ].url, wikis[ x ].icon, diff --git a/programs.cc b/programs.cc index f3a619ca..3085cd3b 100644 --- a/programs.cc +++ b/programs.cc @@ -61,10 +61,10 @@ sptr< WordSearchRequest > ProgramsDictionary::prefixMatch( wstring const & word, { if ( prg.type == Config::Program::PrefixMatch ) - return new ProgramWordSearchRequest( gd::toQString( word ), prg ); + return std::make_shared( gd::toQString( word ), prg ); else { - sptr< WordSearchRequestInstant > sr = new WordSearchRequestInstant; + sptr< WordSearchRequestInstant > sr = std::make_shared(); sr->setUncertain( true ); @@ -101,7 +101,7 @@ sptr< Dictionary::DataRequest > ProgramsDictionary::getArticle( Html::escape( wordUtf8 ) + ""; result += ""; - sptr< DataRequestInstant > ret = new DataRequestInstant( true ); + sptr< DataRequestInstant > ret = std::make_shared( true ); ret->getData().resize( result.size() ); @@ -111,10 +111,10 @@ sptr< Dictionary::DataRequest > ProgramsDictionary::getArticle( case Config::Program::Html: case Config::Program::PlainText: - return new ProgramDataRequest( gd::toQString( word ), prg ); + return std::make_shared( gd::toQString( word ), prg ); default: - return new DataRequestInstant( false ); + return std::make_shared( false ); } } @@ -379,7 +379,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( for( Config::Programs::const_iterator i = programs.begin(); i != programs.end(); ++i ) if ( i->enabled ) - result.push_back( new ProgramsDictionary( *i ) ); + result.push_back( std::make_shared( *i ) ); return result; } diff --git a/romaji.cc b/romaji.cc index 10ebc4ea..2238e28b 100644 --- a/romaji.cc +++ b/romaji.cc @@ -104,7 +104,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::Romaji const & r ) { static HepburnHiragana t; - result.push_back( new Transliteration::TransliterationDictionary( "94eae5a5aaf5b0a900490f4d6b36aac0", + result.push_back( std::make_shared( "94eae5a5aaf5b0a900490f4d6b36aac0", QCoreApplication::translate( "Romaji", "Hepburn Romaji for Hiragana" ).toUtf8().data(), QIcon( ":/flags/jp.png" ), t, false ) ); } @@ -113,7 +113,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::Romaji const & r ) { static HepburnKatakana t; - result.push_back( new Transliteration::TransliterationDictionary( "3252a35767d3f6e85e3e39069800dd2f", + result.push_back( std::make_shared< Transliteration::TransliterationDictionary>( "3252a35767d3f6e85e3e39069800dd2f", QCoreApplication::translate( "Romaji", "Hepburn Romaji for Katakana" ).toUtf8().data(), QIcon( ":/flags/jp.png" ), t, false ) ); } diff --git a/russiantranslit.cc b/russiantranslit.cc index 56f44d95..ba181612 100644 --- a/russiantranslit.cc +++ b/russiantranslit.cc @@ -103,7 +103,7 @@ sptr< Dictionary::Class > makeDictionary() { static RussianTable t; - return new Transliteration::TransliterationDictionary( "cf1b74acd98adea9b2bba16af38f1086", + return std::make_shared( "cf1b74acd98adea9b2bba16af38f1086", QCoreApplication::translate( "RussianTranslit", "Russian Transliteration" ).toUtf8().data(), QIcon( ":/flags/ru.png" ), t ); } diff --git a/sdict.cc b/sdict.cc index 0246405d..e7651b09 100644 --- a/sdict.cc +++ b/sdict.cc @@ -476,7 +476,7 @@ sptr< Dictionary::DataRequest > SdictDictionary::getSearchResults( QString const bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } /// SdictDictionary::getArticle() @@ -669,7 +669,7 @@ sptr< Dictionary::DataRequest > SdictDictionary::getArticle( wstring const & wor bool ignoreDiacritics ) { - return new SdictArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } QString const& SdictDictionary::getDescription() @@ -890,7 +890,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } // if need to rebuild try { - dictionaries.push_back( new SdictDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles ) ); } diff --git a/slob.cc b/slob.cc index 3f64236a..7aa0a14e 100644 --- a/slob.cc +++ b/slob.cc @@ -1304,7 +1304,7 @@ sptr< Dictionary::DataRequest > SlobDictionary::getSearchResults( QString const bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString, searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString, searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } @@ -1494,7 +1494,7 @@ sptr< Dictionary::DataRequest > SlobDictionary::getArticle( wstring const & word bool ignoreDiacritics ) { - return new SlobArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } //// SlobDictionary::getResource() @@ -1619,7 +1619,7 @@ void SlobResourceRequest::run() sptr< Dictionary::DataRequest > SlobDictionary::getResource( string const & name ) { - return new SlobResourceRequest( *this, name ); + return std::make_shared( *this, name ); } @@ -1752,7 +1752,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( idx.write( &idxHeader, sizeof( idxHeader ) ); } - dictionaries.push_back( new SlobDictionary( dictId, + dictionaries.push_back(std::make_shared( dictId, indexFile, dictFiles ) ); } diff --git a/sounddir.cc b/sounddir.cc index 095b3abf..6883f8f5 100644 --- a/sounddir.cc +++ b/sounddir.cc @@ -178,7 +178,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( wstring const & } if ( mainArticles.empty() && alternateArticles.empty() ) - return new Dictionary::DataRequestInstant( false ); // No such word + return std::make_shared( false ); // No such word string result; @@ -286,7 +286,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( wstring const & memcpy( &(ret->getData().front()), result.data(), result.size() ); - return ret; + return std::shared_ptr(ret); } void SoundDirDictionary::loadIcon() noexcept @@ -313,7 +313,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getResource( string const & uint32_t articleOffset = QString::fromUtf8( name.c_str() ).toULong( &isNumber ); if ( !isNumber ) - return new Dictionary::DataRequestInstant( false ); // No such resource + return std::make_shared( false ); // No such resource vector< char > chunk; char * articleData; @@ -334,7 +334,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getResource( string const & catch( ChunkedStorage::exAddressOutOfRange & ) { // Bad address - return new Dictionary::DataRequestInstant( false ); // No such resource + return std::make_shared( false ); // No such resource } chunk.back() = 0; // It must end with 0 anyway, but just in case @@ -349,8 +349,8 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getResource( string const & { File::Class f( FsEncoding::encode( fileName ), "rb" ); - sptr< Dictionary::DataRequestInstant > dr = new - Dictionary::DataRequestInstant( true ); + sptr< Dictionary::DataRequestInstant > dr = + std::make_shared( true ); vector< char > & data = dr->getData(); @@ -365,7 +365,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getResource( string const & } catch( File::Ex & ) { - return new Dictionary::DataRequestInstant( false ); // No such resource + return std::make_shared( false ); // No such resource } } @@ -481,7 +481,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::SoundDirs const & idx.write( &idxHeader, sizeof( idxHeader ) ); } - dictionaries.push_back( new SoundDirDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, i->name.toUtf8().data(), indexFile, dictFiles, diff --git a/sptr.hh b/sptr.hh index a122b8d4..5da8fe16 100644 --- a/sptr.hh +++ b/sptr.hh @@ -4,150 +4,9 @@ #ifndef __SPTR_HH_INCLUDED__ #define __SPTR_HH_INCLUDED__ -// A generic non-intrusive smart-pointer template. We could use boost::, tr1:: -// or whatever, but since there's no standard solution yet, it isn't worth -// the dependency given the simplicity of the template. - -template< class T > -class sptr_base -{ - template< class TT > friend class sptr_base; - - T * p; - unsigned * count; - - - void increment() - { - if ( count ) - ++*count; - } - -public: - - sptr_base(): p( 0 ), count( 0 ) {} - - sptr_base( T * p_ ): p( p_ ), count( p ? new unsigned( 1 ) : 0 ) - { - } - - sptr_base( sptr_base< T > const & other ): p( other.p ), count( other.count ) - { increment(); } - - // TT is meant to be a derivative of T - template< class TT > - sptr_base( sptr_base< TT > const & other ): p( ( T * ) other.p ), - count( other.count ) - { increment(); } - - void reset() - { - if ( count ) - { - if ( ! -- *count ) - { - delete count; - - count = 0; - - if ( p ) - { - T * p_ = p; - - p = 0; - - delete p_; - } - } - else - { - p = 0; - count = 0; - } - } - } - - sptr_base & operator = ( sptr_base const & other ) - { if ( &other != this ) { reset(); p = other.p; count = other.count; increment(); } - return * this; } - - bool operator ! ( void ) const - { return !p; } - - bool operator == ( sptr_base const & other ) const - { return p == other.p; } - - bool operator != ( sptr_base const & other ) const - { return p != other.p; } - - ~sptr_base() - { reset(); } - -protected: - - T * get_base( void ) const - { return p; } -}; - -template< class T > -class sptr: public sptr_base< T > -{ -public: - - sptr() {} - - sptr( T * p ): sptr_base< T >( p ) {} - - // TT is meant to be a derivative of T - template< class TT > - sptr( sptr< TT > const & other ): sptr_base< T >( other ) {} - - // Retrieval - T * get( void ) const - { return sptr_base< T > :: get_base(); } - - T * operator -> ( void ) const - { return get(); } - - T & operator * ( void ) const - { return * get(); } - - // Check - - operator bool( void ) const - { return get(); } - - bool operator ! ( void ) const - { return !get(); } -}; - -template< class T > -class const_sptr: public sptr_base< T > -{ -public: - - const_sptr() {} - - const_sptr( T * p_ ): sptr_base< T >( p_ ) {} - - const_sptr( sptr< T > const & other ): sptr_base< T >( other ) {} - - // TT is meant to be a derivative of T - template< class TT > - const_sptr( sptr_base< TT > const & other ): sptr_base< T >( other ) {} - - // Retrieval - - T const * get( void ) const - { return sptr_base< T > :: get_base(); } - - T const * operator -> ( void ) const - { return get(); } - - T const & operator * ( void ) const - { return * get(); } -}; - - +#include +// A shorthand for std::shared_ptr +template +using sptr = std::shared_ptr; #endif diff --git a/stardict.cc b/stardict.cc index 7f5617c6..b378b5ad 100644 --- a/stardict.cc +++ b/stardict.cc @@ -1202,7 +1202,7 @@ sptr< Dictionary::DataRequest > StardictDictionary::getSearchResults( QString co bool ignoreWordsOrder, bool ignoreDiacritics ) { - return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); + return std::make_shared( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); } /// StardictDictionary::findHeadwordsForSynonym() @@ -1319,7 +1319,7 @@ sptr< Dictionary::WordSearchRequest > StardictDictionary::findHeadwordsForSynonym( wstring const & word ) { - return synonymSearchEnabled ? new StardictHeadwordsRequest( word, *this ) : + return synonymSearchEnabled ? std::make_shared( word, *this ) : Class::findHeadwordsForSynonym( word ); } @@ -1524,7 +1524,7 @@ sptr< Dictionary::DataRequest > StardictDictionary::getArticle( wstring const & bool ignoreDiacritics ) { - return new StardictArticleRequest( word, alts, *this, ignoreDiacritics ); + return std::make_shared( word, alts, *this, ignoreDiacritics ); } @@ -1806,7 +1806,7 @@ void StardictResourceRequest::run() sptr< Dictionary::DataRequest > StardictDictionary::getResource( string const & name ) { - return new StardictResourceRequest( *this, name ); + return std::make_shared( *this, name ); } } // anonymous namespace @@ -2178,7 +2178,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( idx.write( &idxHeader, sizeof( idxHeader ) ); } - dictionaries.push_back( new StardictDictionary( dictId, + dictionaries.push_back( std::make_shared( dictId, indexFile, dictFiles ) ); } diff --git a/transliteration.cc b/transliteration.cc index fc8604ae..7548fae6 100644 --- a/transliteration.cc +++ b/transliteration.cc @@ -36,18 +36,18 @@ unsigned long BaseTransliterationDictionary::getWordCount() noexcept sptr< Dictionary::WordSearchRequest > BaseTransliterationDictionary::prefixMatch( wstring const &, unsigned long ) -{ return new Dictionary::WordSearchRequestInstant(); } +{ return std::make_shared(); } sptr< Dictionary::DataRequest > BaseTransliterationDictionary::getArticle( wstring const &, vector< wstring > const &, wstring const &, bool ) -{ return new Dictionary::DataRequestInstant( false ); } +{ return std::make_shared( false ); } sptr< Dictionary::WordSearchRequest > BaseTransliterationDictionary::findHeadwordsForSynonym( wstring const & str ) { - sptr< Dictionary::WordSearchRequestInstant > result = new Dictionary::WordSearchRequestInstant(); + sptr< Dictionary::WordSearchRequestInstant > result = std::make_shared(); vector< wstring > alts = getAlternateWritings( str ); diff --git a/voiceengines.cc b/voiceengines.cc index 555c5532..7a29a439 100644 --- a/voiceengines.cc +++ b/voiceengines.cc @@ -76,7 +76,7 @@ sptr< WordSearchRequest > VoiceEnginesDictionary::prefixMatch( wstring const & / { WordSearchRequestInstant * sr = new WordSearchRequestInstant(); sr->setUncertain( true ); - return sr; + return std::shared_ptr(sr); } sptr< Dictionary::DataRequest > VoiceEnginesDictionary::getArticle( @@ -104,7 +104,7 @@ sptr< Dictionary::DataRequest > VoiceEnginesDictionary::getArticle( result += "" + Html::escape( wordUtf8 ) + ""; result += ""; - sptr< DataRequestInstant > ret = new DataRequestInstant( true ); + sptr< DataRequestInstant > ret = std::make_shared( true ); ret->getData().resize( result.size() ); memcpy( &( ret->getData().front() ), result.data(), result.size() ); return ret; @@ -135,7 +135,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( for ( Config::VoiceEngines::const_iterator i = voiceEngines.begin(); i != voiceEngines.end(); ++i ) { if ( i->enabled ) - result.push_back( new VoiceEnginesDictionary( *i ) ); + result.push_back( std::make_shared( *i ) ); } return result; diff --git a/website.cc b/website.cc index 1b95e4c3..e5012498 100644 --- a/website.cc +++ b/website.cc @@ -86,7 +86,7 @@ protected: sptr< WordSearchRequest > WebSiteDictionary::prefixMatch( wstring const & /*word*/, unsigned long ) { - sptr< WordSearchRequestInstant > sr = new WordSearchRequestInstant; + sptr< WordSearchRequestInstant > sr = std::make_shared(); sr->setUncertain( true ); @@ -378,7 +378,7 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, { // Just insert link in