Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto キーワードを使って iterator 変数の宣言を簡潔にする #288

Merged
merged 2 commits into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sakura_core/CHokanMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ int CHokanMgr::Search(
}
}

for( CPlug::Array::iterator it = plugs.begin(); it != plugs.end(); ++it ){
for( auto it = plugs.begin(); it != plugs.end(); ++it ){
//�C���^�t�F�[�X�I�u�W�F�N�g����
CWSHIfObj::List params;
std::wstring curWord = pszCurWord;
Expand Down
36 changes: 10 additions & 26 deletions sakura_core/CProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,10 @@ bool CProfile::WriteProfile(
vecLine.push_back( LTEXT(";") + wstring( pszComment ) ); // //->; 2008/5/24 Uchi
vecLine.push_back( LTEXT("") );
}
std::vector< Section >::iterator iter;
std::vector< Section >::iterator iterEnd = m_ProfileData.end();
MAP_STR_STR::iterator mapiter;
MAP_STR_STR::iterator mapiterEnd;
for( iter = m_ProfileData.begin(); iter != iterEnd; iter++ ) {
for(auto iter = m_ProfileData.begin(); iter != m_ProfileData.end(); iter++ ) {
//�Z�N�V����������������
vecLine.push_back( LTEXT("[") + iter->strSectionName + LTEXT("]") );
mapiterEnd = iter->mapEntries.end();
for( mapiter = iter->mapEntries.begin(); mapiter != mapiterEnd; mapiter++ ) {
for(auto mapiter = iter->mapEntries.cbegin(); mapiter != iter->mapEntries.end(); mapiter++ ) {
//�G���g������������
vecLine.push_back( mapiter->first + LTEXT("=") + mapiter->second );
}
Expand Down Expand Up @@ -329,12 +324,9 @@ bool CProfile::GetProfileDataImp(
wstring& strEntryValue //!< [out] �G���g���l
)
{
std::vector< Section >::iterator iter;
std::vector< Section >::iterator iterEnd = m_ProfileData.end();
MAP_STR_STR::iterator mapiter;
for( iter = m_ProfileData.begin(); iter != iterEnd; iter++ ) {
for(auto iter = m_ProfileData.begin(); iter != m_ProfileData.end(); iter++ ) {
if( iter->strSectionName == strSectionName ) {
mapiter = iter->mapEntries.find( strEntryKey );
auto mapiter = iter->mapEntries.find( strEntryKey );
if( iter->mapEntries.end() != mapiter ) {
strEntryValue = mapiter->second;
return true;
Expand All @@ -357,14 +349,11 @@ bool CProfile::SetProfileDataImp(
const wstring& strEntryValue //!< [in] �G���g���l
)
{
std::vector< Section >::iterator iter;
std::vector< Section >::iterator iterEnd = m_ProfileData.end();
MAP_STR_STR::iterator mapiter;
MAP_STR_STR::iterator mapiterEnd;
for( iter = m_ProfileData.begin(); iter != iterEnd; iter++ ) {
auto iter = m_ProfileData.begin();
for(; iter != m_ProfileData.end(); iter++ ) {
if( iter->strSectionName == strSectionName ) {
//�����̃Z�N�V�����̏ꍇ
mapiter = iter->mapEntries.find( strEntryKey );
auto mapiter = iter->mapEntries.find( strEntryKey );
if( iter->mapEntries.end() != mapiter ) {
//�����̃G���g���̏ꍇ�͒l���㏑��
mapiter->second = strEntryValue;
Expand All @@ -378,7 +367,7 @@ bool CProfile::SetProfileDataImp(
}
}
//�����̃Z�N�V�����ł͂Ȃ��ꍇ�C�Z�N�V�����y�уG���g����lj�
if( iterEnd == iter ) {
if( iter != m_ProfileData.end() ) {
Section Buffer;
Buffer.strSectionName = strSectionName;
Buffer.mapEntries.insert( PAIR_STR_STR( strEntryKey, strEntryValue ) );
Expand All @@ -392,16 +381,11 @@ bool CProfile::SetProfileDataImp(
void CProfile::DUMP( void )
{
#ifdef _DEBUG
std::vector< Section >::iterator iter;
std::vector< Section >::iterator iterEnd = m_ProfileData.end();
// 2006.02.20 ryoji: MAP_STR_STR_ITER�폜���̏C���R��ɂ��R���p�C���G���[�C��
MAP_STR_STR::iterator mapiter;
MAP_STR_STR::iterator mapiterEnd;
MYTRACE( _T("\n\nCProfile::DUMP()======================") );
for( iter = m_ProfileData.begin(); iter != iterEnd; iter++ ) {
for(auto iter = m_ProfileData.begin(); iter != m_ProfileData.end(); iter++ ) {
MYTRACE( _T("\n��strSectionName=%ls"), iter->strSectionName.c_str() );
mapiterEnd = iter->mapEntries.end();
for( mapiter = iter->mapEntries.begin(); mapiter != mapiterEnd; mapiter++ ) {
for(auto mapiter = iter->mapEntries.begin(); mapiter != iter->mapEntries.end(); mapiter++ ) {
MYTRACE( _T("\"%ls\" = \"%ls\"\n"), mapiter->first.c_str(), mapiter->second.c_str() );
}
}
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/CSelectLang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CSelectLang::PSSelLangInfoList CSelectLang::m_psLangInfoList;
*/
CSelectLang::~CSelectLang( void )
{
for (PSSelLangInfoList::iterator it = m_psLangInfoList.begin(); it != m_psLangInfoList.end(); it++) {
for (auto it = m_psLangInfoList.begin(); it != m_psLangInfoList.end(); it++) {
if( (*it)->hInstance ){
FreeLibrary( (*it)->hInstance );
(*it)->hInstance = NULL;
Expand Down
4 changes: 2 additions & 2 deletions sakura_core/charset/CCodePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ CCodePage::CodePageList& CCodePage::GetCodePageList()
#endif
pfn_GetCPInfoExT_t pfn_GetCPInfoExT = (pfn_GetCPInfoExT_t)::GetProcAddress(hDLLkernel, strFunc_GetCPInfoEx);
CPINFOEX cpInfo;
for( CodePageList::iterator it = result.begin(); it != result.end(); ++it ){
for( auto it = result.begin(); it != result.end(); ++it ){
cpInfo.CodePageName[0] = _T('\0');
if( pfn_GetCPInfoExT && pfn_GetCPInfoExT(it->first, 0, &cpInfo) ){
it->second = to_wchar(cpInfo.CodePageName);
Expand Down Expand Up @@ -482,7 +482,7 @@ int CCodePage::AddComboCodePages(HWND hwnd, HWND combo, int nSelCode)
}
Combo_SetItemData( combo, nIdx, CODE_CPOEM );
CCodePage::CodePageList& cpList = CCodePage::GetCodePageList();
for( CCodePage::CodePageList::iterator it = cpList.begin(); it != cpList.end(); ++it ){
for( auto it = cpList.begin(); it != cpList.end(); ++it ){
nIdx = Combo_AddString(combo, it->second.c_str());
Combo_SetItemData(combo, nIdx, it->first);
if( nSelCode == it->first ){
Expand Down
6 changes: 3 additions & 3 deletions sakura_core/dlg/CDlgPluginOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void CDlgPluginOption::SetData( void )
selects = cOpt->GetSelects();

_tcscpy( buf, _T("") );
for (std::vector<wstring>::iterator it = selects.begin(); it != selects.end(); it++) {
for (auto it = selects.begin(); it != selects.end(); it++) {
SepSelect(*it, &sView, &sTrg);
if (sValue == sTrg) {
auto_snprintf_s( buf, _countof(buf), _T("%ls"), sView.c_str());
Expand Down Expand Up @@ -261,7 +261,7 @@ int CDlgPluginOption::GetData( void )
selects = cOpt->GetSelects();
wstring sWbuf = to_wchar(buf);

for (std::vector<wstring>::iterator it = selects.begin(); it != selects.end(); it++) {
for (auto it = selects.begin(); it != selects.end(); it++) {
SepSelect(*it, &sView, &sTrg);
if (sView == sWbuf) {
auto_sprintf( buf, _T("%ls"), sTrg.c_str());
Expand Down Expand Up @@ -611,7 +611,7 @@ void CDlgPluginOption::SetToEdit( int iLine )
wstring sWbuf = to_wchar(buf);
nSelIdx = -1; // �I��
i = 0;
for (std::vector<wstring>::iterator it = selects.begin(); it != selects.end(); it++) {
for (auto it = selects.begin(); it != selects.end(); it++) {
SepSelect(*it, &sView, &sValue);
nItemIdx = Combo_AddString( hwndCombo, sView.c_str() );
if (sView == sWbuf) {
Expand Down
10 changes: 5 additions & 5 deletions sakura_core/macro/CCookieManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SysString CCookieManager::GetCookie(LPCWSTR scope, LPCWSTR cookieName) const
return SysString(L"", 0);
}
wstring key = cookieName;
std::map<wstring, wstring>::const_iterator keyVal = cookies->find(key);
const auto& keyVal = cookies->find(key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

イテレータを参照型で受け取るのって一般的です?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

素直に auto keyVal = cookies->find(key); でも keyVal の型は自動的に std::map<wstring, wstring>::const_iterator になりますが、それでは不十分と判断されたのでしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かに素直に auto にしておいた方が良さそうですね。

if( keyVal == cookies->end() ){
return SysString(L"", 0);
}
Expand All @@ -51,7 +51,7 @@ SysString CCookieManager::GetCookieDefault(LPCWSTR scope, LPCWSTR cookieName, LP
return SysString(L"", 0);
}
wstring key = cookieName;
std::map<wstring, wstring>::iterator keyVal = cookies->find(key);
const auto& keyVal = cookies->find(key);
if( keyVal == cookies->end() ){
return SysString(defVal, len);
}
Expand Down Expand Up @@ -81,7 +81,7 @@ int CCookieManager::DeleteCookie(LPCWSTR scope, LPCWSTR cookieName)
return 2;
}
wstring key = cookieName;
std::map<wstring, wstring>::iterator keyVal = cookies->find(key);
const auto& keyVal = cookies->find(key);
if( keyVal == cookies->end() ){
return 5;
}
Expand All @@ -91,11 +91,11 @@ int CCookieManager::DeleteCookie(LPCWSTR scope, LPCWSTR cookieName)

SysString CCookieManager::GetCookieNames(LPCWSTR scope) const
{
std::map<wstring, wstring>* cookies = SelectCookieType(scope);
const std::map<wstring, wstring>* cookies = SelectCookieType(scope);
if( cookies == NULL ){
return SysString(L"", 0);
}
std::map<wstring, wstring>::iterator it = cookies->begin();
auto& it = cookies->begin();
wstring keyNames;
if( it != cookies->end() ){
keyNames += it->first;
Expand Down
8 changes: 3 additions & 5 deletions sakura_core/macro/CMacroFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ bool CMacroFactory::RegisterCreator( Creator f )
bool CMacroFactory::Unregister( Creator f )
{
// Creator Listからの削除
MacroEngineRep::iterator c_it = m_mMacroCreators.begin();
auto& c_it = m_mMacroCreators.begin();
while( c_it != m_mMacroCreators.end() ){
if( *c_it == f ){
MacroEngineRep::iterator tmp_it;

// いきなり削除するとiteratorが無効になるので,
// iteratorを1つ進めてから現在位置を削除する.
tmp_it = c_it++;
auto tmp_it = c_it++;
m_mMacroCreators.erase( tmp_it );
// 重複登録されている場合を考慮して,
// 1つ見つかっても最後までチェックする
Expand All @@ -123,7 +121,7 @@ CMacroManagerBase* CMacroFactory::Create(const TCHAR* ext)
std::tstring key = Ext2Key( ext );

// Creatorを順に試す
for( MacroEngineRep::iterator c_it = m_mMacroCreators.begin();
for( auto c_it = m_mMacroCreators.begin();
c_it != m_mMacroCreators.end(); ++ c_it ){
CMacroManagerBase* pobj = (*c_it)(key.c_str());
if( pobj != NULL ){
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/plugin/CJackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ bool CJackManager::GetUsablePlug(
CPlug::Array* plugs //!< [out] ���p�”\�v���O�̃��X�g
)
{
for( CPlug::Array::iterator it = m_Jacks[jack].plugs.begin(); it != m_Jacks[jack].plugs.end(); it++ ){
for( auto it = m_Jacks[jack].plugs.begin(); it != m_Jacks[jack].plugs.end(); it++ ){
if( plugId == 0 || plugId == (*it)->GetFunctionCode() ){
plugs->push_back( *it );
}
Expand Down
3 changes: 1 addition & 2 deletions sakura_core/prop/CPropComMainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,6 @@ bool CPropMainMenu::Check_MainMenu_Sub(
TV_ITEM tvi; // �擾�p
SMainMenuWork* pFuncWk; // �@�\(work)
std::map< WCHAR, HTREEITEM > mKey; // �d���G���[���o�p
std::map< WCHAR, HTREEITEM >::iterator itKey; // ����

if (nLevel == 0) {
bOptionOk = false;
Expand Down Expand Up @@ -1309,7 +1308,7 @@ bool CPropMainMenu::Check_MainMenu_Sub(
}
}
else {
itKey = mKey.find( pFuncWk->m_sKey[0] );
auto itKey = mKey.find( pFuncWk->m_sKey[0] );
if (itKey == mKey.end()) {
mKey[pFuncWk->m_sKey[0]] = s;

Expand Down