Changeset - r28492:0d3d4fd5e362
[Not reviewed]
master
1 14 0
Patric Stout - 11 months ago 2024-01-16 21:46:00
truebrain@openttd.org
Remove: replace custom span with std::span
15 files changed with 22 insertions and 138 deletions:
0 comments (0 inline, 0 general)
src/cargotype.cpp
Show inline comments
 
@@ -155,13 +155,13 @@ SpriteID CargoSpec::GetCargoIcon() const
 

	
 
	return sprite;
 
}
 

	
 
std::array<uint8_t, NUM_CARGO> _sorted_cargo_types; ///< Sort order of cargoes by cargo ID.
 
std::vector<const CargoSpec *> _sorted_cargo_specs;   ///< Cargo specifications sorted alphabetically by name.
 
span<const CargoSpec *> _sorted_standard_cargo_specs; ///< Standard cargo specifications sorted alphabetically by name.
 
std::span<const CargoSpec *> _sorted_standard_cargo_specs; ///< Standard cargo specifications sorted alphabetically by name.
 

	
 
/** Sort cargo specifications by their name. */
 
static bool CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b)
 
{
 
	std::string a_name = GetString(a->name);
 
	std::string b_name = GetString(b->name);
src/cargotype.h
Show inline comments
 
@@ -13,13 +13,12 @@
 
#include "economy_type.h"
 
#include "cargo_type.h"
 
#include "gfx_type.h"
 
#include "strings_type.h"
 
#include "landscape_type.h"
 
#include "core/bitmath_func.hpp"
 
#include "core/span_type.hpp"
 

	
 
/** Globally unique label of a cargo type. */
 
typedef uint32_t CargoLabel;
 

	
 
/** Town growth effect when delivering cargo. */
 
enum TownEffect : byte {
 
@@ -187,13 +186,13 @@ CargoID GetCargoIDByBitnum(uint8_t bitnu
 
CargoID GetDefaultCargoID(LandscapeID l, CargoType ct);
 
Dimension GetLargestCargoIconSize();
 

	
 
void InitializeSortedCargoSpecs();
 
extern std::array<uint8_t, NUM_CARGO> _sorted_cargo_types;
 
extern std::vector<const CargoSpec *> _sorted_cargo_specs;
 
extern span<const CargoSpec *> _sorted_standard_cargo_specs;
 
extern std::span<const CargoSpec *> _sorted_standard_cargo_specs;
 

	
 
/**
 
 * Does cargo \a c have cargo class \a cc?
 
 * @param c  Cargo type.
 
 * @param cc Cargo class.
 
 * @return The type fits in the class.
src/core/CMakeLists.txt
Show inline comments
 
@@ -22,9 +22,8 @@ add_files(
 
    pool_func.hpp
 
    pool_type.hpp
 
    random_func.cpp
 
    random_func.hpp
 
    smallstack_type.hpp
 
    container_func.hpp
 
    span_type.hpp
 
    strong_typedef_type.hpp
 
)
src/core/span_type.hpp
Show inline comments
 
deleted file
src/misc/endian_buffer.hpp
Show inline comments
 
@@ -8,13 +8,12 @@
 
/** @file endian_buffer.hpp Endian-aware buffer. */
 

	
 
#ifndef ENDIAN_BUFFER_HPP
 
#define ENDIAN_BUFFER_HPP
 

	
 
#include <string_view>
 
#include "../core/span_type.hpp"
 
#include "../core/bitmath_func.hpp"
 
#include "../core/overflowsafe_type.hpp"
 

	
 
struct StrongTypedefBase;
 

	
 
/**
 
@@ -116,18 +115,18 @@ private:
 
 * @note This class uses operator overloading (>>, just like streams) for reading
 
 * as this allows providing custom operator overloads for more complex types
 
 * like e.g. structs without needing to modify this class.
 
 */
 
class EndianBufferReader {
 
	/** Reference to storage buffer. */
 
	span<const byte> buffer;
 
	std::span<const byte> buffer;
 
	/** Current read position. */
 
	size_t read_pos = 0;
 

	
 
public:
 
	EndianBufferReader(span<const byte> buffer) : buffer(buffer) {}
 
	EndianBufferReader(std::span<const byte> buffer) : buffer(buffer) {}
 

	
 
	void rewind() { this->read_pos = 0; }
 

	
 
	EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; }
 
	EndianBufferReader &operator >>(bool &data) { data = this->Read<byte>() != 0; return *this; }
 

	
 
@@ -152,13 +151,13 @@ public:
 
			data = this->Read<T>();
 
		}
 
		return *this;
 
	}
 

	
 
	template <typename Tvalue>
 
	static Tvalue ToValue(span<const byte> buffer)
 
	static Tvalue ToValue(std::span<const byte> buffer)
 
	{
 
		Tvalue result{};
 
		EndianBufferReader reader{ buffer };
 
		reader >> result;
 
		return result;
 
	}
src/news_gui.cpp
Show inline comments
 
@@ -583,13 +583,13 @@ private:
 
		AddDirtyBlock(this->left, mintop, this->left + this->width, maxtop + this->height);
 
	}
 

	
 
	StringID GetCompanyMessageString() const
 
	{
 
		/* Company news with a face have a separate headline, so the normal message is shifted by two params */
 
		CopyInDParam(span(this->ni->params.data() + 2, this->ni->params.size() - 2));
 
		CopyInDParam(std::span(this->ni->params.data() + 2, this->ni->params.size() - 2));
 
		return this->ni->params[1].data;
 
	}
 

	
 
	StringID GetNewVehicleMessageString(WidgetID widget) const
 
	{
 
		assert(this->ni->reftype1 == NR_ENGINE);
src/saveload/saveload.h
Show inline comments
 
@@ -10,13 +10,12 @@
 
#ifndef SAVELOAD_H
 
#define SAVELOAD_H
 

	
 
#include "saveload_error.hpp"
 
#include "../fileio_type.h"
 
#include "../fios.h"
 
#include "../core/span_type.hpp"
 

	
 
/** SaveLoad versions
 
 * Previous savegame versions, the trunk revision where they were
 
 * introduced and the released version that had that particular
 
 * savegame version.
 
 * Up to savegame version 18 there is a minor version as well.
 
@@ -477,19 +476,19 @@ struct ChunkHandler {
 
};
 

	
 
/** A reference to ChunkHandler. */
 
using ChunkHandlerRef = std::reference_wrapper<const ChunkHandler>;
 

	
 
/** A table of ChunkHandler entries. */
 
using ChunkHandlerTable = span<const ChunkHandlerRef>;
 
using ChunkHandlerTable = std::span<const ChunkHandlerRef>;
 

	
 
/** A table of SaveLoad entries. */
 
using SaveLoadTable = span<const struct SaveLoad>;
 
using SaveLoadTable = std::span<const struct SaveLoad>;
 

	
 
/** A table of SaveLoadCompat entries. */
 
using SaveLoadCompatTable = span<const struct SaveLoadCompat>;
 
using SaveLoadCompatTable = std::span<const struct SaveLoadCompat>;
 

	
 
/** Handler for saving/loading an object to/from disk. */
 
class SaveLoadHandler {
 
public:
 
	std::optional<std::vector<SaveLoad>> load_description;
 

	
src/settings_internal.h
Show inline comments
 
@@ -357,13 +357,13 @@ typedef std::variant<IntSettingDesc, Boo
 
 */
 
static constexpr const SettingDesc *GetSettingDesc(const SettingVariant &desc)
 
{
 
	return std::visit([](auto&& arg) -> const SettingDesc * { return &arg; }, desc);
 
}
 

	
 
typedef span<const SettingVariant> SettingTable;
 
typedef std::span<const SettingVariant> SettingTable;
 

	
 
const SettingDesc *GetSettingFromName(const std::string_view name);
 
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector<SaveLoad> &saveloads);
 
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame = false);
 
bool SetSettingValue(const StringSettingDesc *sd, const std::string value, bool force_newgame = false);
 

	
src/stdafx.h
Show inline comments
 
@@ -67,12 +67,13 @@
 
#include <limits>
 
#include <map>
 
#include <memory>
 
#include <numeric>
 
#include <optional>
 
#include <set>
 
#include <span>
 
#include <stdexcept>
 
#include <string>
 
#include <type_traits>
 
#include <variant>
 
#include <vector>
 

	
src/string.cpp
Show inline comments
 
@@ -82,13 +82,13 @@ char *strecpy(char *dst, const char *src
 

	
 
/**
 
 * Format a byte array into a continuous hex string.
 
 * @param data Array to format
 
 * @return Converted string.
 
 */
 
std::string FormatArrayAsHex(span<const byte> data)
 
std::string FormatArrayAsHex(std::span<const byte> data)
 
{
 
	std::string str;
 
	str.reserve(data.size() * 2 + 1);
 

	
 
	for (auto b : data) {
 
		fmt::format_to(std::back_inserter(str), "{:02X}", b);
src/string_func.h
Show inline comments
 
@@ -12,18 +12,17 @@
 
#ifndef STRING_FUNC_H
 
#define STRING_FUNC_H
 

	
 
#include <iosfwd>
 

	
 
#include "core/bitmath_func.hpp"
 
#include "core/span_type.hpp"
 
#include "string_type.h"
 

	
 
char *strecpy(char *dst, const char *src, const char *last) NOACCESS(3);
 

	
 
std::string FormatArrayAsHex(span<const byte> data);
 
std::string FormatArrayAsHex(std::span<const byte> data);
 

	
 
void StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK) NOACCESS(2);
 
[[nodiscard]] std::string StrMakeValid(std::string_view str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
 
void StrMakeValidInPlace(char *str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
 

	
 
bool strtolower(std::string &str, std::string::size_type offs = 0);
src/strings.cpp
Show inline comments
 
@@ -152,13 +152,13 @@ void SetDParamMaxDigits(size_t n, uint c
 
}
 

	
 
/**
 
 * Copy the parameters from the backup into the global string parameter array.
 
 * @param backup The backup to copy from.
 
 */
 
void CopyInDParam(const span<const StringParameterBackup> backup)
 
void CopyInDParam(const std::span<const StringParameterBackup> backup)
 
{
 
	for (size_t i = 0; i < backup.size(); i++) {
 
		auto &value = backup[i];
 
		if (value.string.has_value()) {
 
			_global_string_params.SetParam(i, value.string.value());
 
		} else {
src/strings_func.h
Show inline comments
 
@@ -11,13 +11,12 @@
 
#define STRINGS_FUNC_H
 

	
 
#include "strings_type.h"
 
#include "string_type.h"
 
#include "gfx_type.h"
 
#include "core/bitmath_func.hpp"
 
#include "core/span_type.hpp"
 
#include "core/strong_typedef_type.hpp"
 
#include "vehicle_type.h"
 

	
 
/**
 
 * Extract the StringTab from a StringID.
 
 * @param str String identifier
 
@@ -96,13 +95,13 @@ void SetDParamMaxValue(size_t n, T max_v
 
}
 

	
 
void SetDParamStr(size_t n, const char *str);
 
void SetDParamStr(size_t n, const std::string &str);
 
void SetDParamStr(size_t n, std::string &&str);
 

	
 
void CopyInDParam(const span<const StringParameterBackup> backup);
 
void CopyInDParam(const std::span<const StringParameterBackup> backup);
 
void CopyOutDParam(std::vector<StringParameterBackup> &backup, size_t num);
 
bool HaveDParamChanged(const std::vector<StringParameterBackup> &backup);
 

	
 
uint64_t GetDParam(size_t n);
 

	
 
extern TextDirection _current_text_dir; ///< Text direction of the currently selected language
src/strings_internal.h
Show inline comments
 
@@ -9,31 +9,30 @@
 

	
 
#ifndef STRINGS_INTERNAL_H
 
#define STRINGS_INTERNAL_H
 

	
 
#include "strings_func.h"
 
#include "string_func.h"
 
#include "core/span_type.hpp"
 

	
 
/** The data required to format and validate a single parameter of a string. */
 
struct StringParameter {
 
	uint64_t data; ///< The data of the parameter.
 
	const char *string_view; ///< The string value, if it has any.
 
	std::unique_ptr<std::string> string; ///< Copied string value, if it has any.
 
	char32_t type; ///< The #StringControlCode to interpret this data with when it's the first parameter, otherwise '\0'.
 
};
 

	
 
class StringParameters {
 
protected:
 
	StringParameters *parent = nullptr; ///< If not nullptr, this instance references data from this parent instance.
 
	span<StringParameter> parameters = {}; ///< Array with the actual parameters.
 
	std::span<StringParameter> parameters = {}; ///< Array with the actual parameters.
 

	
 
	size_t offset = 0; ///< Current offset in the parameters span.
 
	char32_t next_type = 0; ///< The type of the next data that is retrieved.
 

	
 
	StringParameters(span<StringParameter> parameters = {}) :
 
	StringParameters(std::span<StringParameter> parameters = {}) :
 
		parameters(parameters)
 
	{}
 

	
 
	StringParameter *GetNextParameterPointer();
 

	
 
public:
 
@@ -208,26 +207,26 @@ template <size_t N>
 
class ArrayStringParameters : public StringParameters {
 
	std::array<StringParameter, N> params{}; ///< The actual parameters
 

	
 
public:
 
	ArrayStringParameters()
 
	{
 
		this->parameters = span(params.data(), params.size());
 
		this->parameters = std::span(params.data(), params.size());
 
	}
 

	
 
	ArrayStringParameters(ArrayStringParameters&& other) noexcept
 
	{
 
		*this = std::move(other);
 
	}
 

	
 
	ArrayStringParameters& operator=(ArrayStringParameters &&other) noexcept
 
	{
 
		this->offset = other.offset;
 
		this->next_type = other.next_type;
 
		this->params = std::move(other.params);
 
		this->parameters = span(params.data(), params.size());
 
		this->parameters = std::span(params.data(), params.size());
 
		return *this;
 
	}
 

	
 
	ArrayStringParameters(const ArrayStringParameters &other) = delete;
 
	ArrayStringParameters& operator=(const ArrayStringParameters &other) = delete;
 
};
src/survey.cpp
Show inline comments
 
@@ -247,15 +247,15 @@ void SurveyConfiguration(nlohmann::json 
 
		survey["video_info"] = VideoDriver::GetInstance()->GetInfoString();
 
	}
 
	if (BaseGraphics::GetUsedSet() != nullptr) {
 
		survey["graphics_set"] = fmt::format("{}.{}", BaseGraphics::GetUsedSet()->name, BaseGraphics::GetUsedSet()->version);
 
		const GRFConfig *extra_cfg = BaseGraphics::GetUsedSet()->GetExtraConfig();
 
		if (extra_cfg != nullptr && extra_cfg->num_params > 0) {
 
			survey["graphics_set_parameters"] = span<const uint32_t>(extra_cfg->param.data(), extra_cfg->num_params);
 
			survey["graphics_set_parameters"] = std::span<const uint32_t>(extra_cfg->param.data(), extra_cfg->num_params);
 
		} else {
 
			survey["graphics_set_parameters"] = span<const uint32_t>();
 
			survey["graphics_set_parameters"] = std::span<const uint32_t>();
 
		}
 
	}
 
	if (BaseMusic::GetUsedSet() != nullptr) {
 
		survey["music_set"] = fmt::format("{}.{}", BaseMusic::GetUsedSet()->name, BaseMusic::GetUsedSet()->version);
 
	}
 
	if (BaseSounds::GetUsedSet() != nullptr) {
 
@@ -341,13 +341,13 @@ void SurveyGrfs(nlohmann::json &survey)
 
		if ((c->palette & GRFP_GRF_MASK) == GRFP_GRF_ANY) grf["palette"] = "any";
 

	
 
		if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_UNSET) grf["blitter"] = "unset";
 
		if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_32BPP) grf["blitter"] = "32bpp";
 

	
 
		grf["is_static"] = HasBit(c->flags, GCF_STATIC);
 
		grf["parameters"] = span<const uint32_t>(c->param.data(), c->num_params);
 
		grf["parameters"] = std::span<const uint32_t>(c->param.data(), c->num_params);
 
	}
 
}
 

	
 
/**
 
 * Convert game-script information to JSON.
 
 *
0 comments (0 inline, 0 general)