summaryrefslogtreecommitdiff
path: root/src/industry_gui.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2019-04-02 21:31:24 +0200
committerMichael Lutz <michi@icosahedron.de>2019-04-09 22:45:15 +0200
commitc7b9987d081ae4e0103309b18c93deecc395dec9 (patch)
treee5b1f9553d6399e2eed9c05a2d91673205f9c912 /src/industry_gui.cpp
parentd3e113eb5f618ce0174fa0dfa2591cb96e999350 (diff)
downloadopenttd-c7b9987d081ae4e0103309b18c93deecc395dec9.tar.xz
Codechange: Switch DropDownList to directly use std::vector, thus making AutoDeleteSmallVector obsolete.
DropDownListItem are strongly managed using std::unique_ptr to ensure leak-free handling. Appropriate use of move-semantics make intent a lot clearer than parameter comments and allows the compiler to generate copy-free code for most situations.
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r--src/industry_gui.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index eff0a5f73..2796cd979 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -2709,34 +2709,30 @@ struct IndustryCargoesWindow : public Window {
break;
case WID_IC_CARGO_DROPDOWN: {
- DropDownList *lst = new DropDownList;
+ DropDownList lst;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
- lst->push_back(new DropDownListStringItem(cs->name, cs->Index(), false));
+ lst.emplace_back(new DropDownListStringItem(cs->name, cs->Index(), false));
}
- if (lst->size() == 0) {
- delete lst;
- break;
+ if (!lst.empty()) {
+ int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
+ ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN, 0, true);
}
- int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
- ShowDropDownList(this, lst, selected, WID_IC_CARGO_DROPDOWN, 0, true);
break;
}
case WID_IC_IND_DROPDOWN: {
- DropDownList *lst = new DropDownList;
+ DropDownList lst;
for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
IndustryType ind = _sorted_industry_types[i];
const IndustrySpec *indsp = GetIndustrySpec(ind);
if (!indsp->enabled) continue;
- lst->push_back(new DropDownListStringItem(indsp->name, ind, false));
+ lst.emplace_back(new DropDownListStringItem(indsp->name, ind, false));
}
- if (lst->size() == 0) {
- delete lst;
- break;
+ if (!lst.empty()) {
+ int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
+ ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN, 0, true);
}
- int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
- ShowDropDownList(this, lst, selected, WID_IC_IND_DROPDOWN, 0, true);
break;
}
}