From cea14517392abeb8de85b7608f97489b1992d397 Mon Sep 17 00:00:00 2001 From: Habu Date: Tue, 12 Oct 2021 07:20:30 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20StoreSaleType=20=E3=81=AE=E7=AF=84?= =?utf8?q?=E5=9B=B2=E3=81=AB=E5=AF=BE=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 汎用性に欠けるので StoreSaleType のイテレーション専用の関数群を削除し、 EnumRange クラスを代わりに使用する。 --- src/birth/character-builder.cpp | 2 +- src/market/building-initializer.cpp | 2 +- src/store/black-market.cpp | 2 +- src/store/store-util.cpp | 20 -------------------- src/store/store-util.h | 7 +++---- 5 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/birth/character-builder.cpp b/src/birth/character-builder.cpp index 6351c0e46..301e1e100 100644 --- a/src/birth/character-builder.cpp +++ b/src/birth/character-builder.cpp @@ -100,7 +100,7 @@ void player_birth(player_type *player_ptr) write_birth_diary(player_ptr); for (int i = 1; i < max_towns; i++) { - for (auto sst : StoreSaleType()) { + for (auto sst : STORE_SALE_TYPE_LIST) { store_init(i, sst); } } diff --git a/src/market/building-initializer.cpp b/src/market/building-initializer.cpp index 76d227d2e..9a391bc63 100644 --- a/src/market/building-initializer.cpp +++ b/src/market/building-initializer.cpp @@ -19,7 +19,7 @@ errr init_towns(void) town_info = std::vector(max_towns); for (int i = 1; i < max_towns; i++) { town_info[i].store = std::vector(MAX_STORES); - for (auto sst : StoreSaleType()) { + for (auto sst : STORE_SALE_TYPE_LIST) { store_type *store_ptr = &town_info[i].store[enum2i(sst)]; if ((i > 1) && (sst == StoreSaleType::MUSEUM || sst == StoreSaleType::HOME)) continue; diff --git a/src/store/black-market.cpp b/src/store/black-market.cpp index 4a1089cd2..066b0c25e 100644 --- a/src/store/black-market.cpp +++ b/src/store/black-market.cpp @@ -31,7 +31,7 @@ bool black_market_crap(player_type *player_ptr, object_type *o_ptr) if (o_ptr->to_d > 0) return false; - for (auto sst : StoreSaleType()) { + for (auto sst : STORE_SALE_TYPE_LIST) { if (sst == StoreSaleType::HOME || sst == StoreSaleType::MUSEUM) { continue; } diff --git a/src/store/store-util.cpp b/src/store/store-util.cpp index 248c0b7c3..102fae9ef 100644 --- a/src/store/store-util.cpp +++ b/src/store/store-util.cpp @@ -20,26 +20,6 @@ StoreSaleType cur_store_num = StoreSaleType::GENERAL; store_type *st_ptr = nullptr; -StoreSaleType begin(StoreSaleType) -{ - return StoreSaleType::GENERAL; -} - -StoreSaleType end(StoreSaleType) -{ - return StoreSaleType::MAX; -} - -StoreSaleType operator*(StoreSaleType s) -{ - return s; -} - -StoreSaleType operator++(StoreSaleType &s) -{ - return s = StoreSaleType(std::underlying_type::type(s) + 1); -} - /*! * @brief 店舗のオブジェクト数を増やす / * Add the item "o_ptr" to a real stores inventory. diff --git a/src/store/store-util.h b/src/store/store-util.h index 7dd1e81c3..44e4227f0 100644 --- a/src/store/store-util.h +++ b/src/store/store-util.h @@ -2,6 +2,8 @@ #include "system/angband.h" +#include "util/enum-range.h" + #include #include @@ -21,10 +23,7 @@ enum class StoreSaleType { MAX = 10 }; -StoreSaleType begin(StoreSaleType); -StoreSaleType end(StoreSaleType); -StoreSaleType operator*(StoreSaleType s); -StoreSaleType operator++(StoreSaleType &s); +constexpr auto STORE_SALE_TYPE_LIST = EnumRange(StoreSaleType::GENERAL, StoreSaleType::MUSEUM); using store_k_idx = std::vector; -- 2.11.0