Changeset - r28492:0d3d4fd5e362
[Not reviewed]
master
1 14 0
Patric Stout - 3 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
 
@@ -158,7 +158,7 @@ SpriteID CargoSpec::GetCargoIcon() const
 

	
 
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)
src/cargotype.h
Show inline comments
 
@@ -16,7 +16,6 @@
 
#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;
 
@@ -190,7 +189,7 @@ 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?
src/core/CMakeLists.txt
Show inline comments
 
@@ -25,6 +25,5 @@ add_files(
 
    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
 
@@ -11,7 +11,6 @@
 
#define ENDIAN_BUFFER_HPP
 

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

	
 
@@ -119,12 +118,12 @@ private:
 
 */
 
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; }
 

	
 
@@ -155,7 +154,7 @@ public:
 
	}
 

	
 
	template <typename Tvalue>
 
	static Tvalue ToValue(span<const byte> buffer)
 
	static Tvalue ToValue(std::span<const byte> buffer)
 
	{
 
		Tvalue result{};
 
		EndianBufferReader reader{ buffer };
src/news_gui.cpp
Show inline comments
 
@@ -586,7 +586,7 @@ private:
 
	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;
 
	}
 

	
src/saveload/saveload.h
Show inline comments
 
@@ -13,7 +13,6 @@
 
#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
 
@@ -480,13 +479,13 @@ struct 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 {
src/settings_internal.h
Show inline comments
 
@@ -360,7 +360,7 @@ static constexpr const SettingDesc *GetS
 
	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);
src/stdafx.h
Show inline comments
 
@@ -70,6 +70,7 @@
 
#include <numeric>
 
#include <optional>
 
#include <set>
 
#include <span>
 
#include <stdexcept>
 
#include <string>
 
#include <type_traits>
src/string.cpp
Show inline comments
 
@@ -85,7 +85,7 @@ char *strecpy(char *dst, const char *src
 
 * @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);
src/string_func.h
Show inline comments
 
@@ -15,12 +15,11 @@
 
#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);
src/strings.cpp
Show inline comments
 
@@ -155,7 +155,7 @@ 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];
src/strings_func.h
Show inline comments
 
@@ -14,7 +14,6 @@
 
#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"
 

	
 
@@ -99,7 +98,7 @@ void SetDParamStr(size_t n, const char *
 
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);
 

	
src/strings_internal.h
Show inline comments
 
@@ -12,7 +12,6 @@
 

	
 
#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 {
 
@@ -25,12 +24,12 @@ struct StringParameter {
 
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)
 
	{}
 

	
 
@@ -211,7 +210,7 @@ class ArrayStringParameters : public Str
 
public:
 
	ArrayStringParameters()
 
	{
 
		this->parameters = span(params.data(), params.size());
 
		this->parameters = std::span(params.data(), params.size());
 
	}
 

	
 
	ArrayStringParameters(ArrayStringParameters&& other) noexcept
 
@@ -224,7 +223,7 @@ public:
 
		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;
 
	}
 

	
src/survey.cpp
Show inline comments
 
@@ -250,9 +250,9 @@ void SurveyConfiguration(nlohmann::json 
 
		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) {
 
@@ -344,7 +344,7 @@ void SurveyGrfs(nlohmann::json &survey)
 
		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);
 
	}
 
}
 

	
0 comments (0 inline, 0 general)