Skip to content

Commit

Permalink
Remove: replace custom span with std::span
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed Jan 16, 2024
1 parent bb49112 commit fd073a2
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 138 deletions.
2 changes: 1 addition & 1 deletion src/cargotype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/cargotype.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?
Expand Down
1 change: 0 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ add_files(
random_func.hpp
smallstack_type.hpp
container_func.hpp
span_type.hpp
strong_typedef_type.hpp
)
110 changes: 0 additions & 110 deletions src/core/span_type.hpp

This file was deleted.

7 changes: 3 additions & 4 deletions src/misc/endian_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -119,12 +118,12 @@ class EndianBufferWriter {
*/
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; }

Expand Down Expand Up @@ -155,7 +154,7 @@ class EndianBufferReader {
}

template <typename Tvalue>
static Tvalue ToValue(span<const byte> buffer)
static Tvalue ToValue(std::span<const byte> buffer)
{
Tvalue result{};
EndianBufferReader reader{ buffer };
Expand Down
2 changes: 1 addition & 1 deletion src/news_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ struct NewsWindow : Window {
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;
}

Expand Down
7 changes: 3 additions & 4 deletions src/saveload/saveload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/settings_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ 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);
Expand Down
1 change: 1 addition & 0 deletions src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include <numeric>
#include <optional>
#include <set>
#include <span>
#include <stdexcept>
#include <string>
#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion src/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ char *strecpy(char *dst, const char *src, const char *last)
* @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);
Expand Down
3 changes: 1 addition & 2 deletions src/string_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void SetDParamMaxDigits(size_t n, uint count, FontSize size)
* 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];
Expand Down
3 changes: 1 addition & 2 deletions src/strings_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -99,7 +98,7 @@ 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);

Expand Down
9 changes: 4 additions & 5 deletions src/strings_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
{}

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

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

Expand Down
6 changes: 3 additions & 3 deletions src/survey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ void SurveyConfiguration(nlohmann::json &survey)
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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit fd073a2

Please sign in to comment.