Codechange: replace x.size() == 0 with x.empty()

This commit is contained in:
Rubidium 2023-10-20 20:09:58 +02:00 committed by rubidium42
parent f06b3e9846
commit c9276c2959
42 changed files with 58 additions and 58 deletions

View File

@ -5922,7 +5922,7 @@ namespace Catch {
}
void testCaseEnded(TestCaseStats const& testCaseStats) override {
auto node = std::make_shared<TestCaseNode>(testCaseStats);
assert(m_sectionStack.size() == 0);
assert(m_sectionStack.empty());
node->children.push_back(m_rootSection);
m_testCases.push_back(node);
m_rootSection.reset();

View File

@ -280,7 +280,7 @@ struct AIConfigWindow : public Window {
this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL);
this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL);
this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY);
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot)->GetConfigList()->empty());
this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));

View File

@ -94,7 +94,7 @@ AIInfo *AIScannerInfo::SelectRandomAI() const
AIInfo *AIScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match)
{
if (this->info_list.size() == 0) return nullptr;
if (this->info_list.empty()) return nullptr;
if (name.empty()) return nullptr;
if (version == -1) {

View File

@ -120,7 +120,7 @@ public:
#else
const char *default_blitter = "8bpp-optimized";
#endif
if (GetBlitters().size() == 0) return nullptr;
if (GetBlitters().empty()) return nullptr;
const char *bname = name.empty() ? default_blitter : name.c_str();
for (auto &it : GetBlitters()) {

View File

@ -53,7 +53,7 @@ class Kdtree {
/** Create one new node in the tree, return its index in the pool */
size_t AddNode(const T &element)
{
if (this->free_list.size() == 0) {
if (this->free_list.empty()) {
this->nodes.emplace_back(element);
return this->nodes.size() - 1;
} else {

View File

@ -20,7 +20,7 @@
{
PoolVector *pools = PoolBase::GetPools();
pools->erase(std::find(pools->begin(), pools->end(), this));
if (pools->size() == 0) delete pools;
if (pools->empty()) delete pools;
}
/**

View File

@ -84,7 +84,7 @@ public:
constexpr size_t size() const noexcept { return static_cast<size_t>( last - first ); }
constexpr std::ptrdiff_t ssize() const noexcept { return static_cast<std::ptrdiff_t>( last - first ); }
constexpr bool empty() const noexcept { return size() == 0; }
constexpr bool empty() const noexcept { return this->size() == 0; }
constexpr iterator begin() const noexcept { return iterator(first); }
constexpr iterator end() const noexcept { return iterator(last); }

View File

@ -109,7 +109,7 @@ void DriverFactoryBase::SelectDriver(const std::string &name, Driver::Type type)
*/
bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type type)
{
if (GetDrivers().size() == 0) return false;
if (GetDrivers().empty()) return false;
if (name.empty()) {
/* Probe for this driver, but do not fall back to dedicated/null! */

View File

@ -35,7 +35,7 @@ void GameScannerInfo::RegisterAPI(class Squirrel *engine)
GameInfo *GameScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match)
{
if (this->info_list.size() == 0) return nullptr;
if (this->info_list.empty()) return nullptr;
if (name.empty()) return nullptr;
if (version == -1) {

View File

@ -658,7 +658,7 @@ int DrawString(int left, int right, int top, std::string_view str, TextColour co
}
Layouter layout(str, INT32_MAX, colour, fontsize);
if (layout.size() == 0) return 0;
if (layout.empty()) return 0;
return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true);
}

View File

@ -155,7 +155,7 @@ int FallbackParagraphLayout::FallbackLine::GetLeading() const
*/
int FallbackParagraphLayout::FallbackLine::GetWidth() const
{
if (this->size() == 0) return 0;
if (this->empty()) return 0;
/*
* The last X position of a run contains is the end of that run.
@ -293,7 +293,7 @@ std::unique_ptr<const ParagraphLayouter::Line> FallbackParagraphLayout::NextLine
this->buffer++;
}
if (l->size() == 0 || last_char - begin > 0) {
if (l->empty() || last_char - begin > 0) {
int w = l->GetWidth();
l->emplace_back(iter->second, begin, last_char - begin, begin - this->buffer_begin, w);
}

View File

@ -380,7 +380,7 @@ std::vector<ICURun> ItemizeStyle(std::vector<ICURun> &runs_current, FontMap &fon
runs = ItemizeScript(buff, length, runs);
runs = ItemizeStyle(runs, font_mapping);
if (runs.size() == 0) return nullptr;
if (runs.empty()) return nullptr;
for (auto &run : runs) {
run.Shape(buff, length);

View File

@ -510,13 +510,13 @@ public:
this->vscroll->SetCount(this->vehgroups.size());
/* The drop down menu is out, *but* it may not be used, retract it. */
if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
if (this->vehicles.empty() && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
this->RaiseWidget(WID_GL_MANAGE_VEHICLES_DROPDOWN);
this->CloseChildWindows(WC_DROPDOWN_MENU);
}
/* Disable all lists management button when the list is empty */
this->SetWidgetsDisabledState(this->vehicles.size() == 0 || _local_company != this->vli.company,
this->SetWidgetsDisabledState(this->vehicles.empty() || _local_company != this->vli.company,
WID_GL_STOP_ALL,
WID_GL_START_ALL,
WID_GL_MANAGE_VEHICLES_DROPDOWN);

View File

@ -2683,7 +2683,7 @@ static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accept
*/
int WhoCanServiceIndustry(Industry *ind)
{
if (ind->stations_near.size() == 0) return 0; // No stations found at all => nobody services
if (ind->stations_near.empty()) return 0; // No stations found at all => nobody services
int result = 0;
for (const Vehicle *v : Vehicle::Iterate()) {

View File

@ -1670,7 +1670,7 @@ public:
case WID_ID_INDUSTRY_LIST: {
int n = 0;
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
if (this->industries.size() == 0) {
if (this->industries.empty()) {
DrawString(ir, STR_INDUSTRY_DIRECTORY_NONE);
break;
}

View File

@ -873,7 +873,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
}
/* If we couldn't load the file from the registry, try again at the default install path of the GM DLS file. */
if (dls_file.instruments.size() == 0) {
if (dls_file.instruments.empty()) {
static const wchar_t *DLS_GM_FILE = L"%windir%\\System32\\drivers\\gm.dls";
wchar_t path[MAX_PATH];
ExpandEnvironmentStrings(DLS_GM_FILE, path, lengthof(path));

View File

@ -347,7 +347,7 @@ static bool FixupMidiData(MidiFile &target)
std::sort(target.tempos.begin(), target.tempos.end(), TicktimeAscending<MidiFile::TempoChange>);
std::sort(target.blocks.begin(), target.blocks.end(), TicktimeAscending<MidiFile::DataBlock>);
if (target.tempos.size() == 0) {
if (target.tempos.empty()) {
/* No tempo information, assume 120 bpm (500,000 microseconds per beat */
target.tempos.push_back(MidiFile::TempoChange(0, 500000));
}
@ -359,9 +359,9 @@ static bool FixupMidiData(MidiFile &target)
uint32_t last_ticktime = 0;
for (size_t i = 0; i < target.blocks.size(); i++) {
MidiFile::DataBlock &block = target.blocks[i];
if (block.data.size() == 0) {
if (block.data.empty()) {
continue;
} else if (block.ticktime > last_ticktime || merged_blocks.size() == 0) {
} else if (block.ticktime > last_ticktime || merged_blocks.empty()) {
merged_blocks.push_back(block);
last_ticktime = block.ticktime;
} else {

View File

@ -203,7 +203,7 @@ void TCPConnecter::OnResolved(addrinfo *ai)
}
if (_debug_net_level >= 6) {
if (this->addresses.size() == 0) {
if (this->addresses.empty()) {
Debug(net, 6, "{} did not resolve", this->connection_string);
} else {
Debug(net, 6, "{} resolved in:", this->connection_string);

View File

@ -142,7 +142,7 @@ public:
*/
static bool Listen(uint16_t port)
{
assert(sockets.size() == 0);
assert(sockets.empty());
NetworkAddressList addresses;
GetBindAddresses(&addresses, port);
@ -151,7 +151,7 @@ public:
address.Listen(SOCK_STREAM, &sockets);
}
if (sockets.size() == 0) {
if (sockets.empty()) {
Debug(net, 0, "Could not start network: could not create listening socket");
ShowNetworkError(STR_NETWORK_ERROR_SERVER_START);
return false;

View File

@ -73,7 +73,7 @@ void NetworkUDPSocketHandler::CloseSocket()
*/
void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast)
{
if (this->sockets.size() == 0) this->Listen();
if (this->sockets.empty()) this->Listen();
for (auto &s : this->sockets) {
/* Make a local copy because if we resolve it we cannot

View File

@ -703,7 +703,7 @@ void GetBindAddresses(NetworkAddressList *addresses, uint16_t port)
}
/* No address, so bind to everything. */
if (addresses->size() == 0) {
if (addresses->empty()) {
addresses->emplace_back("", port);
}
}

View File

@ -899,7 +899,7 @@ public:
}
}
if (this->content.size() == 0) {
if (this->content.empty()) {
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
this->InvalidateData();

View File

@ -1192,7 +1192,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
break;
}
if (_cur.grffile->railtype_list.size() == 0) {
if (_cur.grffile->railtype_list.empty()) {
/* Use traction type to select between normal and electrified
* rail only when no translation list is in place. */
if (_gted[e->index].railtypelabel == RAILTYPE_RAIL_LABEL && engclass >= EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_ELECTRIC_LABEL;
@ -5242,7 +5242,7 @@ static void NewSpriteGroup(ByteReader *buf)
group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
group->error_group = ranges.size() > 0 ? ranges[0].group : group->default_group;
/* nvar == 0 is a special case -- we turn our value into a callback result */
group->calculated_result = ranges.size() == 0;
group->calculated_result = ranges.empty();
/* Sort ranges ascending. When ranges overlap, this may required clamping or splitting them */
std::vector<uint32_t> bounds;
@ -5511,7 +5511,7 @@ static CargoID TranslateCargo(uint8_t feature, uint8_t ctype)
if ((feature == GSF_STATIONS || feature == GSF_ROADSTOPS) && ctype == 0xFE) return CT_DEFAULT_NA;
if (ctype == 0xFF) return CT_PURCHASE;
if (_cur.grffile->cargo_list.size() == 0) {
if (_cur.grffile->cargo_list.empty()) {
/* No cargo table, so use bitnum values */
if (ctype >= 32) {
GrfMsg(1, "TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype);
@ -8855,7 +8855,7 @@ static void BuildCargoTranslationMap()
for (const CargoSpec *cs : CargoSpec::Iterate()) {
if (!cs->IsValid()) continue;
if (_cur.grffile->cargo_list.size() == 0) {
if (_cur.grffile->cargo_list.empty()) {
/* Default translation table, so just a straight mapping to bitnum */
_cur.grffile->cargo_map[cs->Index()] = cs->bitnum;
} else {

View File

@ -1578,7 +1578,7 @@ void ShowMissingContentWindow(const GRFConfig *list)
ci->md5sum = HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum;
cv.push_back(ci);
}
ShowNetworkContentListWindow(cv.size() == 0 ? nullptr : &cv, CONTENT_TYPE_NEWGRF);
ShowNetworkContentListWindow(cv.empty() ? nullptr : &cv, CONTENT_TYPE_NEWGRF);
}
Listing NewGRFWindow::last_sorting = {false, 0};

View File

@ -140,7 +140,7 @@ SpriteID GetCustomSignalSprite(const RailTypeInfo *rti, TileIndex tile, SignalTy
*/
RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile)
{
if (grffile == nullptr || grffile->railtype_list.size() == 0) {
if (grffile == nullptr || grffile->railtype_list.empty()) {
/* No railtype table present. Return railtype as-is (if valid), so it works for original railtypes. */
if (railtype >= RAILTYPE_END || GetRailTypeInfo(static_cast<RailType>(railtype))->label == 0) return INVALID_RAILTYPE;
@ -163,7 +163,7 @@ RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile)
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
{
/* No rail type table present, return rail type as-is */
if (grffile == nullptr || grffile->railtype_list.size() == 0) return railtype;
if (grffile == nullptr || grffile->railtype_list.empty()) return railtype;
/* Look for a matching rail type label in the table */
RailTypeLabel label = GetRailTypeInfo(railtype)->label;

View File

@ -156,7 +156,7 @@ uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
if (grffile == nullptr) return roadtype;
const std::vector<RoadTypeLabel> *list = RoadTypeIsRoad(roadtype) ? &grffile->roadtype_list : &grffile->tramtype_list;
if (list->size() == 0) return roadtype;
if (list->empty()) return roadtype;
/* Look for a matching road type label in the table */
RoadTypeLabel label = GetRoadTypeInfo(roadtype)->label;

View File

@ -276,7 +276,7 @@ int CoreTextParagraphLayout::CoreTextLine::GetLeading() const
*/
int CoreTextParagraphLayout::CoreTextLine::GetWidth() const
{
if (this->size() == 0) return 0;
if (this->empty()) return 0;
int total_width = 0;
for (const auto &run : *this) {

View File

@ -291,7 +291,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
/* Itemize text. */
std::vector<SCRIPT_ITEM> items = UniscribeItemizeString(buff, length);
if (items.size() == 0) return nullptr;
if (items.empty()) return nullptr;
/* Build ranges from the items and the font map. A range is a run of text
* that is part of a single item and formatted using a single font style. */

View File

@ -2384,7 +2384,7 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
}
}
if (list.size() == 0) {
if (list.empty()) {
/* Empty dropdowns are not allowed */
list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, INVALID_RAILTYPE, true));
}

View File

@ -1845,7 +1845,7 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
}
}
if (list.size() == 0) {
if (list.empty()) {
/* Empty dropdowns are not allowed */
list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, INVALID_ROADTYPE, true));
}
@ -1885,7 +1885,7 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
list.push_back(std::move(item));
}
if (list.size() == 0) {
if (list.empty()) {
/* Empty dropdowns are not allowed */
list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, -1, true));
}

View File

@ -172,7 +172,7 @@ struct GSTRChunkHandler : ChunkHandler {
}
/* If there were no strings in the savegame, set GameStrings to nullptr */
if (_current_data->raw_strings.size() == 0) {
if (_current_data->raw_strings.empty()) {
delete _current_data;
_current_data = nullptr;
return;

View File

@ -197,7 +197,7 @@ SaveLoadTable GetLinkGraphJobDesc()
static SaveLoadAddrProc * const proc = [](void *b, size_t extra) -> void * { return const_cast<void *>(static_cast<const void *>(reinterpret_cast<const char *>(std::addressof(static_cast<LinkGraphJob *>(b)->settings)) + extra)); };
/* Build the SaveLoad array on first call and don't touch it later on */
if (saveloads.size() == 0) {
if (saveloads.empty()) {
GetSaveLoadFromSettingTable(_linkgraph_settings, saveloads);
for (auto &sl : saveloads) {

View File

@ -172,7 +172,7 @@ struct ScriptAllocator {
~ScriptAllocator()
{
#ifdef SCRIPT_DEBUG_ALLOCATIONS
assert(this->allocations.size() == 0);
assert(this->allocations.empty());
#endif
}
};

View File

@ -309,7 +309,7 @@ static void DifficultyNoiseChange(int32_t)
static void MaxNoAIsChange(int32_t)
{
if (GetGameSettings().difficulty.max_no_competitors != 0 &&
AI::GetInfoList()->size() == 0 &&
AI::GetInfoList()->empty() &&
(!_networking || _network_server)) {
ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
}

View File

@ -253,7 +253,7 @@ void Station::MarkTilesDirty(bool cargo_change) const
/* Don't waste time updating if there are no custom station graphics
* that might change. Even if there are custom graphics, they might
* not change. Unfortunately we have no way of telling. */
if (this->speclist.size() == 0) return;
if (this->speclist.empty()) return;
}
for (h = 0; h < train_station.h; h++) {

View File

@ -622,8 +622,8 @@ public:
*/
void UpdatePrevNextDisabledState()
{
this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.size() == 0 || this->IsFirstPageSelected());
this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.size() == 0 || this->IsLastPageSelected());
this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.empty() || this->IsFirstPageSelected());
this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.empty() || this->IsLastPageSelected());
this->SetWidgetDirty(WID_SB_PREV_PAGE);
this->SetWidgetDirty(WID_SB_NEXT_PAGE);
}
@ -869,7 +869,7 @@ public:
this->BuildStoryPageList();
/* Was the last page removed? */
if (this->story_pages.size() == 0) {
if (this->story_pages.empty()) {
this->selected_generic_title.clear();
}
@ -884,7 +884,7 @@ public:
this->SetSelectedPage(this->story_pages[0]->index);
}
this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.size() == 0);
this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.empty());
this->SetWidgetDirty(WID_SB_SEL_PAGE);
this->UpdatePrevNextDisabledState();
} else if (data >= 0 && this->selected_page_id == data) {

View File

@ -56,7 +56,7 @@ public:
* Check whether any filter words were entered.
* @return true if no words were entered.
*/
bool IsEmpty() const { return this->word_index.size() == 0; }
bool IsEmpty() const { return this->word_index.empty(); }
void ResetState();
void AddLine(const char *str);

View File

@ -2044,7 +2044,7 @@ void InitializeLanguagePacks()
for (Searchpath sp : _valid_searchpaths) {
FillLanguageList(FioGetDirectory(sp, LANG_DIR));
}
if (_languages.size() == 0) UserError("No available language packs (invalid versions?)");
if (_languages.empty()) UserError("No available language packs (invalid versions?)");
/* Acquire the locale of the current system */
const char *lang = GetCurrentLocale("LC_MESSAGES");

View File

@ -122,7 +122,7 @@ uint TextfileWindow::ReflowContent()
uint TextfileWindow::GetContentHeight()
{
if (this->lines.size() == 0) return 0;
if (this->lines.empty()) return 0;
return this->lines.back().bottom;
}

View File

@ -823,7 +823,7 @@ public:
case WID_TD_LIST: {
int n = 0;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
if (this->towns.size() == 0) { // No towns available.
if (this->towns.empty()) { // No towns available.
DrawString(tr, STR_TOWN_DIRECTORY_NONE);
break;
}

View File

@ -854,7 +854,7 @@ static void MakeTrainBackup(TrainList &list, Train *t)
static void RestoreTrainBackup(TrainList &list)
{
/* No train, nothing to do. */
if (list.size() == 0) return;
if (list.empty()) return;
Train *prev = nullptr;
/* Iterate over the list and rebuild it. */

View File

@ -349,7 +349,7 @@ void BaseVehicleListWindow::SetCargoFilterArray()
void BaseVehicleListWindow::FilterVehicleList()
{
this->vehgroups.Filter(this->cargo_filter[this->cargo_filter_criteria]);
if (this->vehicles.size() == 0) {
if (this->vehicles.empty()) {
/* No vehicle passed through the filter, invalidate the previously selected vehicle */
this->vehicle_sel = INVALID_VEHICLE;
} else if (this->vehicle_sel != INVALID_VEHICLE && std::find(this->vehicles.begin(), this->vehicles.end(), Vehicle::Get(this->vehicle_sel)) == this->vehicles.end()) { // previously selected engine didn't pass the filter, remove selection
@ -668,7 +668,7 @@ struct RefitWindow : public Window {
if (!HasBit(cmask, cid)) continue;
auto &list = this->refit_list[cid];
bool first_vehicle = list.size() == 0;
bool first_vehicle = list.empty();
if (first_vehicle) {
/* Keeping the current subtype is always an option. It also serves as the option in case of no subtypes */
list.push_back({cid, UINT8_MAX, STR_EMPTY});
@ -1949,7 +1949,7 @@ public:
this->BuildVehicleList();
this->SortVehicleList();
if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_VL_MANAGE_VEHICLES_DROPDOWN)) {
if (this->vehicles.empty() && this->IsWidgetLowered(WID_VL_MANAGE_VEHICLES_DROPDOWN)) {
this->CloseChildWindows(WC_DROPDOWN_MENU);
}
@ -1963,7 +1963,7 @@ public:
}
if (this->owner == _local_company) {
this->SetWidgetDisabledState(WID_VL_AVAILABLE_VEHICLES, this->vli.type != VL_STANDARD);
this->SetWidgetsDisabledState(this->vehicles.size() == 0,
this->SetWidgetsDisabledState(this->vehicles.empty(),
WID_VL_MANAGE_VEHICLES_DROPDOWN,
WID_VL_STOP_ALL,
WID_VL_START_ALL);