Codechange: Use std::map instead of custom SmallMap.

This commit is contained in:
Peter Nelson 2023-05-16 20:50:41 +01:00 committed by PeterN
parent 72018badff
commit c38df2d589
30 changed files with 81 additions and 235 deletions

View File

@ -11,7 +11,6 @@
#define BASE_MEDIA_BASE_H
#include "fileio_func.h"
#include "core/smallmap_type.hpp"
#include "gfx_type.h"
#include "textfile_type.h"
#include "textfile_gui.h"

View File

@ -22,7 +22,6 @@ add_files(
pool_type.hpp
random_func.cpp
random_func.hpp
smallmap_type.hpp
smallstack_type.hpp
smallvec_type.hpp
span_type.hpp

View File

@ -1,147 +0,0 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file smallmap_type.hpp Simple mapping class targeted for small sets of data. Stored data shall be POD ("Plain Old Data")! */
#ifndef SMALLMAP_TYPE_HPP
#define SMALLMAP_TYPE_HPP
#include "smallvec_type.hpp"
#include <utility>
/**
* Implementation of simple mapping class.
* It has inherited accessors from std::vector().
* @tparam T Key type.
* @tparam U Value type.
* @tparam S Unit of allocation.
*
* @see std::vector
*/
template <typename T, typename U>
struct SmallMap : std::vector<std::pair<T, U> > {
typedef std::pair<T, U> Pair;
typedef Pair *iterator;
typedef const Pair *const_iterator;
/** Creates new SmallMap. Data are initialized in std::vector constructor */
inline SmallMap() { }
/** Data are freed in std::vector destructor */
inline ~SmallMap() { }
/**
* Finds given key in this map
* @param key key to find
* @return &Pair(key, data) if found, this->End() if not
*/
inline typename std::vector<Pair>::const_iterator Find(const T &key) const
{
return std::find_if(std::vector<Pair>::begin(), std::vector<Pair>::end(), [&key](const Pair &pair) { return key == pair.first; });
}
/**
* Finds given key in this map
* @param key key to find
* @return &Pair(key, data) if found, this->End() if not
*/
inline Pair *Find(const T &key)
{
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
if (key == std::vector<Pair>::operator[](i).first) return &std::vector<Pair>::operator[](i);
}
return this->End();
}
inline const Pair *End() const
{
return std::vector<Pair>::data() + std::vector<Pair>::size();
}
inline Pair *End()
{
return std::vector<Pair>::data() + std::vector<Pair>::size();
}
/**
* Tests whether a key is assigned in this map.
* @param key key to test
* @return true iff the item is present
*/
inline bool Contains(const T &key) const
{
return this->Find(key) != std::vector<Pair>::end();
}
/**
* Tests whether a key is assigned in this map.
* @param key key to test
* @return true iff the item is present
*/
inline bool Contains(const T &key)
{
return this->Find(key) != this->End();
}
/**
* Removes given pair from this map
* @param pair pair to remove
* @note it has to be pointer to pair in this map. It is overwritten by the last item.
*/
inline void Erase(Pair *pair)
{
assert(pair >= std::vector<Pair>::data() && pair < this->End());
auto distance = pair - std::vector<Pair>::data();
std::vector<Pair>::erase(std::vector<Pair>::begin() + distance);
}
/**
* Removes given key from this map
* @param key key to remove
* @return true iff the key was found
* @note last item is moved to its place, so don't increase your iterator if true is returned!
*/
inline bool Erase(const T &key)
{
auto *pair = this->Find(key);
if (pair == this->End()) return false;
this->Erase(pair);
return true;
}
/**
* Adds new item to this map.
* @param key key
* @param data data
* @return true iff the key wasn't already present
*/
inline bool Insert(const T &key, const U &data)
{
if (this->Contains(key)) return false;
std::vector<Pair>::emplace_back(key, data);
return true;
}
/**
* Returns data belonging to this key
* @param key key
* @return data belonging to this key
* @note if this key wasn't present, new entry is created
*/
inline U &operator[](const T &key)
{
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
if (key == std::vector<Pair>::operator[](i).first) return std::vector<Pair>::operator[](i).second;
}
Pair &n = std::vector<Pair>::emplace_back();
n.first = key;
return n.second;
}
};
#endif /* SMALLMAP_TYPE_HPP */

View File

@ -25,7 +25,7 @@ enum SaveLoadInvalidateWindowData {
SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox)
};
typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
using CompanyPropertiesMap = std::map<uint, CompanyProperties *>;
/**
* Container for loading in mode SL_LOAD_CHECK.

View File

@ -167,14 +167,14 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
const void *TrueTypeFontCache::GetFontTable(uint32 tag, size_t &length)
{
const FontTable::iterator iter = this->font_tables.Find(tag);
if (iter != this->font_tables.data() + this->font_tables.size()) {
const auto iter = this->font_tables.find(tag);
if (iter != this->font_tables.end()) {
length = iter->second.first;
return iter->second.second;
}
const void *result = this->InternalGetFontTable(tag, length);
this->font_tables.Insert(tag, std::pair<size_t, const void *>(length, result));
this->font_tables[tag] = std::pair<size_t, const void *>(length, result);
return result;
}

View File

@ -10,7 +10,6 @@
#ifndef TRUETYPEFONTCACHE_H
#define TRUETYPEFONTCACHE_H
#include "../core/smallmap_type.hpp"
#include "../fontcache.h"
@ -28,7 +27,7 @@ protected:
int req_size; ///< Requested font size.
int used_size; ///< Used font size.
typedef SmallMap<uint32, std::pair<size_t, const void *> > FontTable; ///< Table with font table cache
using FontTable = std::map<uint32_t, std::pair<size_t, const void *>>; ///< Table with font table cache
FontTable font_tables; ///< Cached font tables.
/** Container for information about a glyph. */

View File

@ -233,25 +233,25 @@ void Gamelog::Print(std::function<void(const std::string &)> proc)
const GRFConfig *gc = FindGRFConfig(this->grfid, FGCM_EXACT, this->md5sum);
fmt::format_to(output_iterator, "Added NewGRF: ");
AddGrfInfo(output_iterator, this->grfid, this->md5sum, gc);
GrfIDMapping::Pair *gm = grf_names.Find(this->grfid);
if (gm != grf_names.End() && !gm->second.was_missing) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was already added!");
auto gm = grf_names.find(this->grfid);
if (gm != grf_names.end() && !gm->second.was_missing) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was already added!");
grf_names[this->grfid] = gc;
}
/* virtual */ void LoggedChangeGRFRemoved::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)
{
/* A NewGRF got removed from the game, either manually or by it missing when loading the game. */
GrfIDMapping::Pair *gm = grf_names.Find(this->grfid);
auto gm = grf_names.find(this->grfid);
fmt::format_to(output_iterator, action_type == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: ");
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
if (gm == grf_names.End()) {
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
if (gm == grf_names.end()) {
fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
} else {
if (action_type == GLAT_LOAD) {
/* Missing grfs on load are not removed from the configuration */
gm->second.was_missing = true;
} else {
grf_names.Erase(gm);
grf_names.erase(gm);
}
}
}
@ -262,38 +262,38 @@ void Gamelog::Print(std::function<void(const std::string &)> proc)
const GRFConfig *gc = FindGRFConfig(this->grfid, FGCM_EXACT, this->md5sum);
fmt::format_to(output_iterator, "Compatible NewGRF loaded: ");
AddGrfInfo(output_iterator, this->grfid, this->md5sum, gc);
if (!grf_names.Contains(this->grfid)) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
if (grf_names.count(this->grfid) == 0) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
grf_names[this->grfid] = gc;
}
/* virtual */ void LoggedChangeGRFParameterChanged::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)
{
/* A parameter of a NewGRF got changed after the game was started. */
GrfIDMapping::Pair *gm = grf_names.Find(this->grfid);
auto gm = grf_names.find(this->grfid);
fmt::format_to(output_iterator, "GRF parameter changed: ");
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
if (gm == grf_names.End()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
}
/* virtual */ void LoggedChangeGRFMoved::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)
{
/* The order of NewGRFs got changed, which might cause some other NewGRFs to behave differently. */
GrfIDMapping::Pair *gm = grf_names.Find(this->grfid);
auto gm = grf_names.find(this->grfid);
fmt::format_to(output_iterator, "GRF order changed: {:08X} moved {} places {}",
BSWAP32(this->grfid), abs(this->offset), this->offset >= 0 ? "down" : "up" );
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
if (gm == grf_names.End()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
}
/* virtual */ void LoggedChangeGRFBug::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)
{
/* A specific bug in a NewGRF, that could cause wide spread problems, has been noted during the execution of the game. */
GrfIDMapping::Pair *gm = grf_names.Find(this->grfid);
auto gm = grf_names.find(this->grfid);
assert(this->bug == GBUG_VEH_LENGTH);
fmt::format_to(output_iterator, "Rail vehicle changes length outside a depot: GRF ID {:08X}, internal ID 0x{:X}", BSWAP32(this->grfid), this->data);
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr);
if (gm == grf_names.End()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!");
}
/* virtual */ void LoggedChangeEmergencySave::FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type)

View File

@ -19,14 +19,14 @@
* So if the gamelog tells a Grf is missing we do not know whether it was readded or completely removed
* at some later point.
*/
struct GRFPresence{
struct GRFPresence {
const GRFConfig *gc; ///< GRFConfig, if known
bool was_missing; ///< Grf was missing during some gameload in the past
GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {}
GRFPresence() = default;
};
typedef SmallMap<uint32_t, GRFPresence> GrfIDMapping;
using GrfIDMapping = std::map<uint32_t, GRFPresence>;
struct LoggedChange {
LoggedChange(GamelogChangeType type = GLCT_NONE) : ct(type) {}

View File

@ -103,8 +103,8 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view s
continue;
}
if (!fontMapping.Contains(buff - buff_begin)) {
fontMapping.Insert(buff - buff_begin, f);
if (fontMapping.count(buff - buff_begin) == 0) {
fontMapping[buff - buff_begin] = f;
}
f = Layouter::GetFont(state.fontsize, state.cur_colour);
}
@ -112,8 +112,8 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view s
/* Better safe than sorry. */
*buff = '\0';
if (!fontMapping.Contains(buff - buff_begin)) {
fontMapping.Insert(buff - buff_begin, f);
if (fontMapping.count(buff - buff_begin) == 0) {
fontMapping[buff - buff_begin] = f;
}
line.layout = T::GetParagraphLayout(buff_begin, buff, fontMapping);
line.state_after = state;
@ -296,12 +296,11 @@ ptrdiff_t Layouter::GetCharAtPosition(int x) const
*/
Font *Layouter::GetFont(FontSize size, TextColour colour)
{
FontColourMap::iterator it = fonts[size].Find(colour);
if (it != fonts[size].End()) return it->second;
FontColourMap::iterator it = fonts[size].find(colour);
if (it != fonts[size].end()) return it->second;
Font *f = new Font(size, colour);
fonts[size].emplace_back(colour, f);
return f;
fonts[size][colour] = new Font(size, colour);
return fonts[size][colour];
}
/**

View File

@ -12,7 +12,7 @@
#include "fontcache.h"
#include "gfx_func.h"
#include "core/smallmap_type.hpp"
#include "core/math_func.hpp"
#include <stack>
#include <string_view>
@ -81,7 +81,7 @@ public:
};
/** Mapping from index to font. */
typedef SmallMap<int, Font *> FontMap;
using FontMap = std::map<int, Font *>;
/**
* Interface to glue fallback and normal layouter into one.
@ -169,7 +169,7 @@ private:
static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state);
typedef SmallMap<TextColour, Font *> FontColourMap;
using FontColourMap = std::map<TextColour, Font *>;
static FontColourMap fonts[FS_END];
public:
static Font *GetFont(FontSize size, TextColour colour);

View File

@ -266,7 +266,7 @@ const ParagraphLayouter::VisualRun &FallbackParagraphLayout::FallbackLine::GetVi
*/
FallbackParagraphLayout::FallbackParagraphLayout(WChar *buffer, int length, FontMap &runs) : buffer_begin(buffer), buffer(buffer), runs(runs)
{
assert(runs.End()[-1].first == length);
assert(runs.rbegin()->first == length);
}
/**
@ -295,15 +295,15 @@ std::unique_ptr<const ParagraphLayouter::Line> FallbackParagraphLayout::NextLine
if (*this->buffer == '\0') {
/* Only a newline. */
this->buffer = nullptr;
l->emplace_back(this->runs.front().second, this->buffer, 0, 0);
l->emplace_back(this->runs.begin()->second, this->buffer, 0, 0);
return l;
}
int offset = this->buffer - this->buffer_begin;
FontMap::iterator iter = this->runs.data();
FontMap::iterator iter = this->runs.begin();
while (iter->first <= offset) {
iter++;
assert(iter != this->runs.End());
++iter;
assert(iter != this->runs.end());
}
const FontCache *fc = iter->second->fc;
@ -325,8 +325,8 @@ std::unique_ptr<const ParagraphLayouter::Line> FallbackParagraphLayout::NextLine
if (this->buffer == next_run) {
int w = l->GetWidth();
l->emplace_back(iter->second, begin, this->buffer - begin, w);
iter++;
assert(iter != this->runs.End());
++iter;
assert(iter != this->runs.end());
next_run = this->buffer_begin + iter->first;
begin = this->buffer;

View File

@ -11,7 +11,6 @@
#define LINKGRAPH_H
#include "../core/pool_type.hpp"
#include "../core/smallmap_type.hpp"
#include "../station_base.h"
#include "../cargotype.h"
#include "../date_type.h"

View File

@ -14,12 +14,11 @@
#include "config.h"
#include "../../company_type.h"
#include "../../string_func.h"
#include "../../core/smallmap_type.hpp"
class NetworkAddress;
typedef std::vector<NetworkAddress> NetworkAddressList; ///< Type for a list of addresses.
typedef SmallMap<SOCKET, NetworkAddress> SocketList; ///< Type for a mapping between address and socket.
using SocketList = std::map<SOCKET, NetworkAddress>; ///< Type for a mapping between address and socket.
/**
* Wrapper for (un)resolved network addresses; there's no reason to transform

View File

@ -8372,13 +8372,13 @@ static bool ChangeGRFParamValueNames(ByteReader *buf)
byte langid = buf->ReadByte();
const char *name_string = buf->ReadString();
std::pair<uint32, GRFTextList> *val_name = _cur_parameter->value_names.Find(id);
if (val_name != _cur_parameter->value_names.End()) {
auto val_name = _cur_parameter->value_names.find(id);
if (val_name != _cur_parameter->value_names.end()) {
AddGRFTextToList(val_name->second, langid, _cur.grfconfig->ident.grfid, false, name_string);
} else {
GRFTextList list;
AddGRFTextToList(list, langid, _cur.grfconfig->ident.grfid, false, name_string);
_cur_parameter->value_names.Insert(id, list);
_cur_parameter->value_names[id] = list;
}
type = buf->ReadByte();

View File

@ -264,7 +264,7 @@ void GRFParameterInfo::Finalize()
{
this->complete_labels = true;
for (uint32 value = this->min_value; value <= this->max_value; value++) {
if (!this->value_names.Contains(value)) {
if (this->value_names.count(value) == 0) {
this->complete_labels = false;
break;
}

View File

@ -12,7 +12,6 @@
#include "strings_type.h"
#include "core/alloc_type.hpp"
#include "core/smallmap_type.hpp"
#include "misc/countedptr.hpp"
#include "fileio_type.h"
#include "textfile_type.h"
@ -143,7 +142,7 @@ struct GRFParameterInfo {
byte param_nr; ///< GRF parameter to store content in
byte first_bit; ///< First bit to use in the GRF parameter
byte num_bit; ///< Number of bits to use for this parameter
SmallMap<uint32, GRFTextList> value_names; ///< Names for each value.
std::map<uint32_t, GRFTextList> value_names; ///< Names for each value.
bool complete_labels; ///< True if all values have a label.
uint32 GetValue(struct GRFConfig *config) const;

View File

@ -818,7 +818,7 @@ struct SpriteAlignerWindow : Window {
SpriteID current_sprite; ///< The currently shown sprite.
Scrollbar *vscroll;
SmallMap<SpriteID, XyOffs> offs_start_map; ///< Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window.
std::map<SpriteID, XyOffs> offs_start_map; ///< Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window.
static bool centre;
static bool crosshair;
@ -854,7 +854,7 @@ struct SpriteAlignerWindow : Window {
/* Relative offset is new absolute offset - starting absolute offset.
* Show 0, 0 as the relative offsets if entry is not in the map (meaning they have not been changed yet).
*/
const auto key_offs_pair = this->offs_start_map.Find(this->current_sprite);
const auto key_offs_pair = this->offs_start_map.find(this->current_sprite);
if (key_offs_pair != this->offs_start_map.end()) {
SetDParam(0, spr->x_offs - key_offs_pair->second.first);
SetDParam(1, spr->y_offs - key_offs_pair->second.second);
@ -992,8 +992,8 @@ struct SpriteAlignerWindow : Window {
Sprite *spr = const_cast<Sprite *>(GetSprite(this->current_sprite, SpriteType::Normal));
/* Remember the original offsets of the current sprite, if not already in mapping. */
if (!(this->offs_start_map.Contains(this->current_sprite))) {
this->offs_start_map.Insert(this->current_sprite, XyOffs(spr->x_offs, spr->y_offs));
if (this->offs_start_map.count(this->current_sprite) == 0) {
this->offs_start_map[this->current_sprite] = XyOffs(spr->x_offs, spr->y_offs);
}
switch (widget) {
/* Move eight units at a time if ctrl is pressed. */
@ -1010,7 +1010,7 @@ struct SpriteAlignerWindow : Window {
case WID_SA_RESET_REL:
/* Reset the starting offsets for the current sprite. */
this->offs_start_map.Erase(this->current_sprite);
this->offs_start_map.erase(this->current_sprite);
this->SetDirty();
break;

View File

@ -283,8 +283,9 @@ struct NewGRFParametersWindow : public Window {
}
SetDParam(2, STR_JUST_INT);
SetDParam(3, current_value);
if (par_info->value_names.Contains(current_value)) {
const char *label = GetGRFStringFromGRFText(par_info->value_names.Find(current_value)->second);
auto it = par_info->value_names.find(current_value);
if (it != par_info->value_names.end()) {
const char *label = GetGRFStringFromGRFText(it->second);
if (label != nullptr) {
SetDParam(2, STR_JUST_RAW_STRING);
SetDParamStr(3, label);
@ -380,7 +381,7 @@ struct NewGRFParametersWindow : public Window {
DropDownList list;
for (uint32 i = par_info->min_value; i <= par_info->max_value; i++) {
list.emplace_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false));
list.emplace_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.find(i)->second), i, false));
}
ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE);

View File

@ -26,7 +26,6 @@
#include "date_type.h"
#include "debug.h"
#include "core/alloc_type.hpp"
#include "core/smallmap_type.hpp"
#include "language.h"
#include <sstream>

View File

@ -10,6 +10,7 @@
#include "../../stdafx.h"
#include "../../debug.h"
#include "font_osx.h"
#include "../../core/math_func.hpp"
#include "../../blitter/factory.hpp"
#include "../../error_func.h"
#include "../../fileio_func.h"

View File

@ -102,8 +102,7 @@ public:
/* Extract font information for this run. */
CFRange chars = CTRunGetStringRange(run);
auto map = fontMapping.begin();
while (map < fontMapping.end() - 1 && map->first <= chars.location) map++;
auto map = fontMapping.upper_bound(chars.location);
this->emplace_back(run, map->second, buff);
}

View File

@ -12,6 +12,7 @@
#include "../../blitter/factory.hpp"
#include "../../core/alloc_func.hpp"
#include "../../core/math_func.hpp"
#include "../../core/mem_func.hpp"
#include "../../error_func.h"
#include "../../fileio_func.h"
#include "../../fontdetection.h"

View File

@ -50,8 +50,8 @@ struct OskWindow : public Window {
NWidgetCore *par_wid = parent->GetWidget<NWidgetCore>(button);
assert(par_wid != nullptr);
assert(parent->querystrings.Contains(button));
this->qs = parent->querystrings.Find(button)->second;
assert(parent->querystrings.count(button) != 0);
this->qs = parent->querystrings.find(button)->second;
this->caption = (par_wid->widget_data != STR_NULL) ? par_wid->widget_data : this->qs->caption;
this->text_btn = button;
this->text = &this->qs->text;

View File

@ -548,7 +548,11 @@ struct PLYRChunkHandler : ChunkHandler {
cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
}
if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
if (_load_check_data.companies.count(index) == 0) {
_load_check_data.companies[index] = cprops;
} else {
delete cprops;
}
}
}

View File

@ -10,7 +10,6 @@
#ifndef SCRIPT_CONFIG_HPP
#define SCRIPT_CONFIG_HPP
#include "../core/smallmap_type.hpp"
#include "../company_type.h"
#include "../textfile_gui.h"
#include "script_instance.hpp"

View File

@ -3645,7 +3645,7 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold)
}
static bool _town_rating_test = false; ///< If \c true, town rating is in test-mode.
static SmallMap<const Town *, int> _town_test_ratings; ///< Map of towns to modified ratings, while in town rating test-mode.
static std::map<const Town *, int> _town_test_ratings; ///< Map of towns to modified ratings, while in town rating test-mode.
/**
* Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings.
@ -3675,8 +3675,8 @@ void SetTownRatingTestMode(bool mode)
static int GetRating(const Town *t)
{
if (_town_rating_test) {
SmallMap<const Town *, int>::iterator it = _town_test_ratings.Find(t);
if (it != _town_test_ratings.End()) {
auto it = _town_test_ratings.find(t);
if (it != _town_test_ratings.end()) {
return it->second;
}
}

View File

@ -678,13 +678,12 @@ void ResetVehicleColourMap()
* List of vehicles that should check for autoreplace this tick.
* Mapping of vehicle -> leave depot immediately after autoreplace.
*/
typedef SmallMap<Vehicle *, bool> AutoreplaceMap;
using AutoreplaceMap = std::map<Vehicle *, bool>;
static AutoreplaceMap _vehicles_to_autoreplace;
void InitializeVehicles()
{
_vehicles_to_autoreplace.clear();
_vehicles_to_autoreplace.shrink_to_fit();
ResetVehicleHash();
}
@ -2357,13 +2356,13 @@ void Vehicle::HandleLoading(bool mode)
* Get a map of cargoes and free capacities in the consist.
* @param capacities Map to be filled with cargoes and capacities.
*/
void Vehicle::GetConsistFreeCapacities(SmallMap<CargoID, uint> &capacities) const
void Vehicle::GetConsistFreeCapacities(std::map<CargoID, uint> &capacities) const
{
for (const Vehicle *v = this; v != nullptr; v = v->Next()) {
if (v->cargo_cap == 0) continue;
std::pair<CargoID, uint> *pair = capacities.Find(v->cargo_type);
if (pair == capacities.End()) {
capacities.push_back({v->cargo_type, v->cargo_cap - v->cargo.StoredCount()});
auto pair = capacities.find(v->cargo_type);
if (pair == capacities.end()) {
capacities[v->cargo_type] = v->cargo_cap - v->cargo.StoredCount();
} else {
pair->second += v->cargo_cap - v->cargo.StoredCount();
}

View File

@ -10,7 +10,6 @@
#ifndef VEHICLE_BASE_H
#define VEHICLE_BASE_H
#include "core/smallmap_type.hpp"
#include "track_type.h"
#include "command_type.h"
#include "order_base.h"
@ -391,7 +390,7 @@ public:
void HandleLoading(bool mode = false);
void GetConsistFreeCapacities(SmallMap<CargoID, uint> &capacities) const;
void GetConsistFreeCapacities(std::map<CargoID, uint> &capacities) const;
uint GetConsistTotalCapacity() const;

View File

@ -340,7 +340,7 @@ Scrollbar *Window::GetScrollbar(uint widnum)
*/
const QueryString *Window::GetQueryString(uint widnum) const
{
auto query = this->querystrings.Find(widnum);
auto query = this->querystrings.find(widnum);
return query != this->querystrings.end() ? query->second : nullptr;
}
@ -351,8 +351,8 @@ const QueryString *Window::GetQueryString(uint widnum) const
*/
QueryString *Window::GetQueryString(uint widnum)
{
SmallMap<int, QueryString*>::Pair *query = this->querystrings.Find(widnum);
return query != this->querystrings.End() ? query->second : nullptr;
auto query = this->querystrings.find(widnum);
return query != this->querystrings.end() ? query->second : nullptr;
}
/**
@ -360,8 +360,7 @@ QueryString *Window::GetQueryString(uint widnum)
*/
void Window::UpdateQueryStringSize()
{
for (auto &qs : this->querystrings)
{
for (auto &qs : this->querystrings) {
qs.second->text.UpdateSize();
}
}
@ -1912,7 +1911,7 @@ static void DecreaseWindowCounters()
}
/* Handle editboxes */
for (SmallMap<int, QueryString*>::Pair &pair : w->querystrings) {
for (auto &pair : w->querystrings) {
pair.second->HandleEditBox(w, pair.first);
}

View File

@ -17,7 +17,6 @@
#include "tile_type.h"
#include "widget_type.h"
#include "core/smallvec_type.hpp"
#include "core/smallmap_type.hpp"
#include "string_type.h"
/**
@ -250,7 +249,7 @@ public:
ViewportData *viewport; ///< Pointer to viewport data, if present.
const NWidgetCore *nested_focus; ///< Currently focused nested widget, or \c nullptr if no nested widget has focus.
SmallMap<int, QueryString*> querystrings; ///< QueryString associated to WWT_EDITBOX widgets.
std::map<int, QueryString*> querystrings; ///< QueryString associated to WWT_EDITBOX widgets.
NWidgetBase *nested_root; ///< Root of the nested tree.
NWidgetBase **nested_array; ///< Array of pointers into the tree. Do not access directly, use #Window::GetWidget() instead.
uint nested_array_size; ///< Size of the nested array.