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

Remove AutoDeleteSmallVector and AutoFreeSmallVector #7453

Merged
merged 9 commits into from
Apr 9, 2019
6 changes: 3 additions & 3 deletions src/ai/ai_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ struct AISettingsWindow : public Window {
this->clicked_dropdown = true;
this->closing_dropdown = false;

DropDownList *list = new DropDownList();
DropDownList list;
for (int i = config_item.min_value; i <= config_item.max_value; i++) {
list->push_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
}

ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true);
ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true);
}
}
} else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
Expand Down
6 changes: 3 additions & 3 deletions src/airport_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ class BuildAirportWindow : public PickerWindowBase {
Scrollbar *vscroll;

/** Build a dropdown list of available airport classes */
static DropDownList *BuildAirportClassDropDown()
static DropDownList BuildAirportClassDropDown()
{
DropDownList *list = new DropDownList();
DropDownList list;

for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
list->push_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false));
list.emplace_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false));
}

return list;
Expand Down
8 changes: 4 additions & 4 deletions src/autoreplace_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ class ReplaceVehicleWindow : public Window {
break;

case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
DropDownList *list = new DropDownList();
list->push_back(new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false));
list->push_back(new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false));
ShowDropDownList(this, list, this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
DropDownList list;
list.emplace_back(new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false));
list.emplace_back(new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false));
ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
break;
}

Expand Down
8 changes: 4 additions & 4 deletions src/company_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,18 +602,18 @@ struct SelectCompanyLiveryWindow : public Window {
}
}

DropDownList *list = new DropDownList();
DropDownList list;
if (default_livery != NULL) {
/* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */
default_col = (primary ? default_livery->colour1 : default_livery->colour2) + COLOUR_END;
list->push_back(new DropDownListColourItem(default_col, false));
list.emplace_back(new DropDownListColourItem(default_col, false));
}
for (uint i = 0; i < lengthof(_colour_dropdown); i++) {
list->push_back(new DropDownListColourItem(i, HasBit(used_colours, i)));
list.emplace_back(new DropDownListColourItem(i, HasBit(used_colours, i)));
}

byte sel = (default_livery == NULL || HasBit(livery->in_use, primary ? 0 : 1)) ? (primary ? livery->colour1 : livery->colour2) : default_col;
ShowDropDownList(this, list, sel, widget);
ShowDropDownList(this, std::move(list), sel, widget);
}

static int CDECL GroupNameSorter(const Group * const *a, const Group * const *b)
Expand Down
9 changes: 4 additions & 5 deletions src/console_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ DEF_CONSOLE_CMD(ConUnBan)
/* Try by IP. */
uint index;
for (index = 0; index < _network_ban_list.size(); index++) {
if (strcmp(_network_ban_list[index], argv[1]) == 0) break;
if (_network_ban_list[index] == argv[1]) break;
}

/* Try by index. */
Expand All @@ -563,9 +563,8 @@ DEF_CONSOLE_CMD(ConUnBan)

if (index < _network_ban_list.size()) {
char msg[64];
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index].c_str());
IConsolePrint(CC_DEFAULT, msg);
free(_network_ban_list[index]);
_network_ban_list.erase(_network_ban_list.begin() + index);
} else {
IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
Expand All @@ -585,8 +584,8 @@ DEF_CONSOLE_CMD(ConBanList)
IConsolePrint(CC_DEFAULT, "Banlist: ");

uint i = 1;
for (char *entry : _network_ban_list) {
IConsolePrintF(CC_DEFAULT, " %d) %s", i, entry);
for (const auto &entry : _network_ban_list) {
IConsolePrintF(CC_DEFAULT, " %d) %s", i, entry.c_str());
}

return true;
Expand Down
62 changes: 0 additions & 62 deletions src/core/smallvec_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,66 +69,4 @@ T* grow(std::vector<T>& vec, std::size_t num)
return vec.data() + pos;
}

/**
* Simple vector template class, with automatic free.
*
* @note There are no asserts in the class so you have
* to care about that you grab an item which is
* inside the list.
*
* @param T The type of the items stored, must be a pointer
*/
template <typename T>
class AutoFreeSmallVector : public std::vector<T> {
public:
~AutoFreeSmallVector()
{
this->Clear();
}

/**
* Remove all items from the list.
*/
inline void Clear()
{
for (T p : *this) {
free(p);
}

std::vector<T>::clear();
}
};

/**
* Simple vector template class, with automatic delete.
*
* @note There are no asserts in the class so you have
* to care about that you grab an item which is
* inside the list.
*
* @param T The type of the items stored, must be a pointer
*/
template <typename T>
class AutoDeleteSmallVector : public std::vector<T> {
public:
~AutoDeleteSmallVector()
{
this->Clear();
}

/**
* Remove all items from the list.
*/
inline void Clear()
{
for (T p : *this) {
delete p;
}

std::vector<T>::clear();
}
};

typedef AutoFreeSmallVector<char*> StringList; ///< Type for a list of strings.

#endif /* SMALLVEC_TYPE_HPP */
10 changes: 5 additions & 5 deletions src/date_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ struct SetDateWindow : Window {
void ShowDateDropDown(int widget)
{
int selected;
DropDownList *list = new DropDownList();
DropDownList list;

switch (widget) {
default: NOT_REACHED();

case WID_SD_DAY:
for (uint i = 0; i < 31; i++) {
list->push_back(new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false));
list.emplace_back(new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false));
}
selected = this->date.day;
break;

case WID_SD_MONTH:
for (uint i = 0; i < 12; i++) {
list->push_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false));
list.emplace_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false));
}
selected = this->date.month;
break;
Expand All @@ -91,13 +91,13 @@ struct SetDateWindow : Window {
for (Year i = this->min_year; i <= this->max_year; i++) {
DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
item->SetParam(0, i);
list->push_back(item);
list.emplace_back(item);
}
selected = this->date.year;
break;
}

ShowDropDownList(this, list, selected, widget);
ShowDropDownList(this, std::move(list), selected, widget);
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Expand Down
Loading