From 061a51426f880c8c665271f94ee92f1f2d43d85b Mon Sep 17 00:00:00 2001 From: Katsuhisa Yuasa Date: Tue, 4 Sep 2018 21:03:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?auto=5Farray=5Fptr=20=E3=82=92=E5=BB=83?= =?UTF-8?q?=E6=AD=A2=E3=81=97=E3=81=A6=20std::unique=5Fptr=20=E3=81=AB?= =?UTF-8?q?=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura/sakura.vcxproj | 2 - sakura/sakura.vcxproj.filters | 6 -- sakura_core/CGrepAgent.cpp | 8 +-- sakura_core/CHokanMgr.cpp | 6 +- sakura_core/doc/CDocOutline.cpp | 4 +- sakura_core/doc/CEditDoc.cpp | 2 +- sakura_core/macro/CWSHIfObj.cpp | 8 +-- sakura_core/typeprop/CImpExpManager.cpp | 4 +- sakura_core/typeprop/CPropTypesRegex.cpp | 22 +++---- sakura_core/util/other_util.cpp | 2 - sakura_core/util/other_util.h | 77 ------------------------ 11 files changed, 27 insertions(+), 114 deletions(-) delete mode 100644 sakura_core/util/other_util.cpp delete mode 100644 sakura_core/util/other_util.h diff --git a/sakura/sakura.vcxproj b/sakura/sakura.vcxproj index 9b00d628d2..c0fca7bb18 100644 --- a/sakura/sakura.vcxproj +++ b/sakura/sakura.vcxproj @@ -497,7 +497,6 @@ - @@ -895,7 +894,6 @@ - diff --git a/sakura/sakura.vcxproj.filters b/sakura/sakura.vcxproj.filters index 6ddcbd4d68..328d858b5e 100644 --- a/sakura/sakura.vcxproj.filters +++ b/sakura/sakura.vcxproj.filters @@ -481,9 +481,6 @@ Cpp Source Files\util - - Cpp Source Files\util - Cpp Source Files\util @@ -1451,9 +1448,6 @@ Cpp Source Files\util - - Cpp Source Files\util - Cpp Source Files\util diff --git a/sakura_core/CGrepAgent.cpp b/sakura_core/CGrepAgent.cpp index aa29f3a1bc..d806e358cb 100644 --- a/sakura_core/CGrepAgent.cpp +++ b/sakura_core/CGrepAgent.cpp @@ -17,9 +17,9 @@ #include "io/CBinaryStream.h" #include "util/window.h" #include "util/module.h" -#include "util/other_util.h" #include "debug/CRunningTimer.h" #include +#include #include "sakura_rc.h" #define UICHECK_INTERVAL_MILLISEC 100 // UI確認の時間間隔 @@ -63,8 +63,8 @@ void CGrepAgent::OnAfterSave(const SSaveInfo& sSaveInfo) void CGrepAgent::CreateFolders( const TCHAR* pszPath, std::vector& vPaths ) { const int nPathLen = auto_strlen( pszPath ); - auto_array_ptr szPath(new TCHAR[nPathLen + 1]); - auto_array_ptr szTmp(new TCHAR[nPathLen + 1]); + auto szPath = std::make_unique(nPathLen + 1); + auto szTmp = std::make_unique(nPathLen + 1); auto_strcpy( &szPath[0], pszPath ); TCHAR* token; int nPathPos = 0; @@ -1138,7 +1138,7 @@ int CGrepAgent::DoGrepFile( X / O : (D)Folder(Abs) -> (G)RelPath(File) X / X : (H)FullPath */ - auto_array_ptr pszWork(new wchar_t[auto_strlen(pszFullPath) + auto_strlen(pszCodeName) + 10]); + auto pszWork = std::make_unique(auto_strlen(pszFullPath) + auto_strlen(pszCodeName) + 10); wchar_t* szWork0 = &pszWork[0]; if( sGrepOption.bGrepOutputBaseFolder || sGrepOption.bGrepSeparateFolder ){ if( !bOutputBaseFolder && sGrepOption.bGrepOutputBaseFolder ){ diff --git a/sakura_core/CHokanMgr.cpp b/sakura_core/CHokanMgr.cpp index 26742648c4..5df9ebe8ac 100644 --- a/sakura_core/CHokanMgr.cpp +++ b/sakura_core/CHokanMgr.cpp @@ -16,6 +16,7 @@ Please contact the copyright holders to use this code for other purpose. */ #include "StdAfx.h" +#include #include "CHokanMgr.h" #include "env/CShareData.h" #include "view/CEditView.h" @@ -23,7 +24,6 @@ #include "plugin/CComplementIfObj.h" #include "util/input.h" #include "util/os.h" -#include "util/other_util.h" #include "sakura_rc.h" WNDPROC gm_wpHokanListProc; @@ -577,7 +577,7 @@ BOOL CHokanMgr::DoHokan( int nVKey ) return FALSE; } int nLabelLen = List_GetTextLen( hwndList, nItem ); - auto_array_ptr wszLabel( new WCHAR [nLabelLen + 1] ); + auto wszLabel = std::make_unique(nLabelLen + 1); List_GetText( hwndList, nItem, &wszLabel[0] ); /* テキストを貼り付け */ @@ -688,7 +688,7 @@ void CHokanMgr::ShowTip() if( LB_ERR == nItem ) return ; int nLabelLen = List_GetTextLen( hwndCtrl, nItem ); - auto_array_ptr szLabel( new WCHAR [nLabelLen + 1] ); + auto szLabel = std::make_unique(nLabelLen + 1); List_GetText( hwndCtrl, nItem, &szLabel[0] ); // 選択中の単語を取得 pcEditView = reinterpret_cast(m_lParam); diff --git a/sakura_core/doc/CDocOutline.cpp b/sakura_core/doc/CDocOutline.cpp index ffff15f3ea..28741c9404 100644 --- a/sakura_core/doc/CDocOutline.cpp +++ b/sakura_core/doc/CDocOutline.cpp @@ -18,6 +18,7 @@ #include "StdAfx.h" #include +#include #include "doc/CDocOutline.h" #include "doc/CEditDoc.h" #include "doc/logic/CDocLine.h" @@ -27,7 +28,6 @@ #include "charset/charcode.h" #include "io/CTextStream.h" #include "extmodule/CBregexp.h" -#include "util/other_util.h" @@ -217,7 +217,7 @@ int CDocOutline::ReadRuleFile( const TCHAR* pszFilename, SOneRule* pcOneRule, in void CDocOutline::MakeFuncList_RuleFile( CFuncInfoArr* pcFuncInfoArr, std::tstring& sTitleOverride ) { /* ルールファイルの内容をバッファに読み込む */ - auto_array_ptr test(new SOneRule[1024]); // 1024個許可。 2007.11.29 kobake スタック使いすぎなので、ヒープに確保するように修正。 + auto test = std::make_unique(1024); // 1024個許可。 2007.11.29 kobake スタック使いすぎなので、ヒープに確保するように修正。 bool bRegex; std::wstring title; int nCount = ReadRuleFile(m_pcDocRef->m_cDocType.GetDocumentAttribute().m_szOutlineRuleFilename, test.get(), 1024, bRegex, title ); diff --git a/sakura_core/doc/CEditDoc.cpp b/sakura_core/doc/CEditDoc.cpp index cb324eff0e..2a4c4ccdef 100644 --- a/sakura_core/doc/CEditDoc.cpp +++ b/sakura_core/doc/CEditDoc.cpp @@ -43,6 +43,7 @@ #include "StdAfx.h" #include #include // Apr. 03, 2003 genta +#include #include #include "doc/CEditDoc.h" #include "doc/logic/CDocLine.h" /// 2002/2/3 aroka @@ -72,7 +73,6 @@ #include "util/file.h" #include "util/format.h" #include "util/module.h" -#include "util/other_util.h" #include "util/string_ex2.h" #include "util/window.h" #include "sakura_rc.h" diff --git a/sakura_core/macro/CWSHIfObj.cpp b/sakura_core/macro/CWSHIfObj.cpp index 51988b09ca..871c950975 100644 --- a/sakura_core/macro/CWSHIfObj.cpp +++ b/sakura_core/macro/CWSHIfObj.cpp @@ -32,10 +32,10 @@ */ #include "StdAfx.h" +#include #include "macro/CWSHIfObj.h" #include "macro/CSMacroMgr.h" // MacroFuncInfo #include "Funccode_enum.h" // EFunctionCode::FA_FROMMACRO -#include "util/other_util.h" // auto_array_ptr //コマンド・関数を準備する @@ -116,7 +116,7 @@ HRESULT CWSHIfObj::MacroCommand(int IntID, DISPPARAMS *Arguments, VARIANT* Resul VariantInit(&ret); // 2011.3.18 syat 引数の順序を正しい順にする - auto_array_ptr rgvargParam( new VARIANTARG[ArgCount] ); + auto rgvargParam = std::make_unique(ArgCount); for(I = 0; I < ArgCount; I++){ ::VariantInit(&rgvargParam[ArgCount - I - 1]); ::VariantCopy(&rgvargParam[ArgCount - I - 1], &Arguments->rgvarg[I]); @@ -136,8 +136,8 @@ HRESULT CWSHIfObj::MacroCommand(int IntID, DISPPARAMS *Arguments, VARIANT* Resul // 最低4つは確保 int argCountMin = t_max(4, ArgCount); // Nov. 29, 2005 FILE 引数を文字列で取得する - auto_array_ptr StrArgs( new LPWSTR[argCountMin] ); - auto_array_ptr strLengths( new int[argCountMin] ); + auto StrArgs = std::make_unique(argCountMin); + auto strLengths = std::make_unique(argCountMin); for(I = ArgCount; I < argCountMin; I++ ){ StrArgs[I] = NULL; strLengths[I] = 0; diff --git a/sakura_core/typeprop/CImpExpManager.cpp b/sakura_core/typeprop/CImpExpManager.cpp index 79fbbc38c3..e4e33d4c4b 100644 --- a/sakura_core/typeprop/CImpExpManager.cpp +++ b/sakura_core/typeprop/CImpExpManager.cpp @@ -29,6 +29,7 @@ */ #include "StdAfx.h" +#include #include "CImpExpManager.h" #include "typeprop/CDlgTypeAscertain.h" @@ -38,7 +39,6 @@ #include "plugin/CPlugin.h" #include "view/CEditView.h" #include "view/colors/CColorStrategy.h" -#include "util/other_util.h" /*----------------------------------------------------------------------- 定数 @@ -616,7 +616,7 @@ bool CImpExpRegex::Import( const wstring& sFileName, wstring& sErrMsg ) } RegexKeywordInfo regexKeyArr[MAX_REGEX_KEYWORD]; - auto_array_ptr szKeyWordList(new wchar_t [ MAX_REGEX_KEYWORDLISTLEN ]); + auto szKeyWordList = std::make_unique(MAX_REGEX_KEYWORDLISTLEN); wchar_t* pKeyword = &szKeyWordList[0]; int keywordPos = 0; TCHAR buff[MAX_REGEX_KEYWORDLEN + 20]; diff --git a/sakura_core/typeprop/CPropTypesRegex.cpp b/sakura_core/typeprop/CPropTypesRegex.cpp index 9deb78074b..fda722c722 100644 --- a/sakura_core/typeprop/CPropTypesRegex.cpp +++ b/sakura_core/typeprop/CPropTypesRegex.cpp @@ -17,12 +17,12 @@ //@@@ 2001.11.17 add start MIK #include "StdAfx.h" +#include #include "CPropTypes.h" #include "env/CShareData.h" #include "CRegexKeyword.h" #include "typeprop/CImpExpManager.h" // 2010/4/23 Uchi #include "util/shell.h" -#include "util/other_util.h" #include "view/colors/EColorIndexType.h" #include "sakura_rc.h" #include "sakura.hh" @@ -186,7 +186,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( case IDC_BUTTON_REGEX_INS: /* 挿入 */ { //挿入するキー情報を取得する。 - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); szKeyWord[0] = _T('\0'); ::DlgItem_GetText( hwndDlg, IDC_EDIT_REGEX, &szKeyWord[0], nKeyWordSize ); if( szKeyWord[0] == _T('\0') ) return FALSE; @@ -231,7 +231,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( case IDC_BUTTON_REGEX_ADD: /* 追加 */ { - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); //最後のキー番号を取得する。 nIndex = ListView_GetItemCount( hwndList ); //追加するキー情報を取得する。 @@ -270,7 +270,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( case IDC_BUTTON_REGEX_UPD: /* 更新 */ { - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); //選択中のキーを探す。 nIndex = ListView_GetNextItem( hwndList, -1, LVNI_ALL | LVNI_SELECTED ); if( -1 == nIndex ) @@ -321,7 +321,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( case IDC_BUTTON_REGEX_TOP: /* 先頭 */ { - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); szKeyWord[0] = _T('\0'); //選択中のキーを探す。 nIndex = ListView_GetNextItem( hwndList, -1, LVNI_ALL | LVNI_SELECTED ); @@ -351,7 +351,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( case IDC_BUTTON_REGEX_LAST: /* 最終 */ { - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); szKeyWord[0] = _T('\0'); nIndex = ListView_GetNextItem( hwndList, -1, LVNI_ALL | LVNI_SELECTED ); if( -1 == nIndex ) return FALSE; @@ -380,7 +380,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( case IDC_BUTTON_REGEX_UP: /* 上へ */ { - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); szKeyWord[0] = _T('\0'); nIndex = ListView_GetNextItem( hwndList, -1, LVNI_ALL | LVNI_SELECTED ); if( -1 == nIndex ) return FALSE; @@ -411,7 +411,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( case IDC_BUTTON_REGEX_DOWN: /* 下へ */ { - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); szKeyWord[0] = _T('\0'); nIndex = ListView_GetNextItem( hwndList, -1, LVNI_ALL | LVNI_SELECTED ); if( -1 == nIndex ) return FALSE; @@ -498,7 +498,7 @@ INT_PTR CPropTypesRegex::DispatchEvent( } if( nPrevIndex != nIndex ) //@@@ 2003.03.26 MIK { //更新時にListViewのSubItemを正しく取得できないので、その対策 - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); szKeyWord[0] = _T('\0'); ListView_GetItemText(hwndList, nIndex, 0, &szKeyWord[0], nKeyWordSize); ListView_GetItemText(hwndList, nIndex, 1, szColorIndex, _countof(szColorIndex)); @@ -622,7 +622,7 @@ int CPropTypesRegex::GetData( HWND hwndDlg ) HWND hwndList; int nIndex, i, j; const int szKeyWordSize = _countof(m_Types.m_RegexKeywordList) * 2 + 1; - auto_array_ptr szKeyWord(new TCHAR [ szKeyWordSize ]); + auto szKeyWord = std::make_unique(szKeyWordSize); TCHAR szColorIndex[256]; //使用する・使用しない @@ -712,7 +712,7 @@ bool CPropTypesRegex::CheckKeywordList(HWND hwndDlg, const TCHAR* szNewKeyWord, const int nKeyWordSize = MAX_REGEX_KEYWORDLEN; HWND hwndList = GetDlgItem( hwndDlg, IDC_LIST_REGEX ); int nIndex = ListView_GetItemCount(hwndList); - auto_array_ptr szKeyWord(new TCHAR [ nKeyWordSize ]); + auto szKeyWord = std::make_unique(nKeyWordSize); int nKeywordLen = auto_strlen(to_wchar(szNewKeyWord)) + 1; for(int i = 0; i < nIndex; i++){ if( i != nUpdateItem ){ diff --git a/sakura_core/util/other_util.cpp b/sakura_core/util/other_util.cpp deleted file mode 100644 index 049e3f0c17..0000000000 --- a/sakura_core/util/other_util.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "StdAfx.h" -#include "other_util.h" diff --git a/sakura_core/util/other_util.h b/sakura_core/util/other_util.h deleted file mode 100644 index 003e324cd6..0000000000 --- a/sakura_core/util/other_util.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - 2007.11.29 kobake - - 未分類小物類 -*/ -/* - Copyright (C) 2008, kobake - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; - you must not claim that you wrote the original software. - If you use this software in a product, an acknowledgment - in the product documentation would be appreciated but is - not required. - - 2. Altered source versions must be plainly marked as such, - and must not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*/ -#ifndef SAKURA_OTHER_UTIL_F0E0EBE0_94B6_4E28_8241_6D842C0E8B73_H_ -#define SAKURA_OTHER_UTIL_F0E0EBE0_94B6_4E28_8241_6D842C0E8B73_H_ - -/*! - auto_ptr の 配列版 - - 2007.11.29 kobake 作成 -*/ -template class auto_array_ptr{ -private: - typedef auto_array_ptr Me; -public: - //代入 - auto_array_ptr (T* rhs){ m_array = rhs; } - auto_array_ptr (Me& rhs){ m_array = rhs.detach(); } - Me& operator = (T* rhs){ reset(rhs ); return *this; } - Me& operator = (Me& rhs){ reset(rhs.detach()); return *this; } - - //破棄 - ~auto_array_ptr(){ delete[] m_array; } - - //手放す (解放はしない) - T* detach() - { - T* p = m_array; - m_array = NULL; - return p; - } - - //保持値を変更する - void reset(T* p) - { - if(m_array==p)return; - delete[] m_array; - m_array = p; - } - - //保持値にアクセス - T* get(){ return m_array; } - - //配列要素にアクセス - T& operator[](int i){ return m_array[i]; } - -private: - T* m_array; -}; - -#endif /* SAKURA_OTHER_UTIL_F0E0EBE0_94B6_4E28_8241_6D842C0E8B73_H_ */ -/*[EOF]*/ From c1a9fe4d91507916b6c562d73f29251a1f2ad20d Mon Sep 17 00:00:00 2001 From: Katsuhisa Yuasa Date: Tue, 4 Sep 2018 23:27:41 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E6=8C=87=E6=91=98=E7=82=B9=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sakura_core/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/sakura_core/Makefile b/sakura_core/Makefile index 4cdb348a32..fd8284a892 100644 --- a/sakura_core/Makefile +++ b/sakura_core/Makefile @@ -343,7 +343,6 @@ util/MessageBoxF.o \ util/module.o \ util/ole_convert.o \ util/os.o \ -util/other_util.o \ util/relation_tool.o \ util/shell.o \ util/string_ex.o \