Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138461 additions and 70983 deletions
+2 -4
View File
@@ -28,7 +28,7 @@ protected:
SuperArray data; ///< array of arrays of items
/** return first sub-array with free space for new item */
inline SubArray& FirstFreeSubArray()
inline SubArray &FirstFreeSubArray()
{
uint super_size = data.Length();
if (super_size > 0) {
@@ -108,9 +108,7 @@ public:
dmp.WriteValue("num_items", num_items);
for (uint i = 0; i < num_items; i++) {
const T &item = (*this)[i];
char name[32];
seprintf(name, lastof(name), "item[%d]", i);
dmp.WriteStructT(name, &item);
dmp.WriteStructT(fmt::format("item[{}]", i), &item);
}
}
};
+3 -3
View File
@@ -13,14 +13,14 @@
#include "../safeguards.h"
int32 SimpleCountedObject::AddRef()
int32_t SimpleCountedObject::AddRef()
{
return ++m_ref_cnt;
}
int32 SimpleCountedObject::Release()
int32_t SimpleCountedObject::Release()
{
int32 res = --m_ref_cnt;
int32_t res = --m_ref_cnt;
assert(res >= 0);
if (res == 0) {
try {
+3 -9
View File
@@ -125,12 +125,6 @@ public:
return m_pT == nullptr;
}
/** another way how to test for nullptr value */
//inline bool operator == (const CCountedPtr &sp) const {return m_pT == sp.m_pT;}
/** yet another way how to test for nullptr value */
//inline bool operator != (const CCountedPtr &sp) const {return m_pT != sp.m_pT;}
/** assign pointer w/o incrementing ref count */
inline void Attach(Tcls *pT)
{
@@ -202,7 +196,7 @@ template <class T> struct AdaptT {
* @see misc/countedobj.cpp for implementation.
*/
struct SimpleCountedObject {
int32 m_ref_cnt;
int32_t m_ref_cnt;
SimpleCountedObject()
: m_ref_cnt(0)
@@ -211,8 +205,8 @@ struct SimpleCountedObject {
virtual ~SimpleCountedObject()
{}
virtual int32 AddRef();
virtual int32 Release();
virtual int32_t AddRef();
virtual int32_t Release();
virtual void FinalRelease() {};
};
+10 -10
View File
@@ -63,7 +63,7 @@ std::string ValueStr(SignalType t)
std::string TileStr(TileIndex tile)
{
std::stringstream ss;
ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << tile; // 0x%04X
ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << tile.base(); // 0x%04X
ss << " (" << TileX(tile) << ", " << TileY(tile) << ")";
return ss.str();
}
@@ -112,34 +112,34 @@ void DumpTarget::WriteIndent()
}
/** Write 'name = value' with indent and new-line. */
void DumpTarget::WriteValue(const char *name, int value)
void DumpTarget::WriteValue(const std::string &name, int value)
{
WriteIndent();
m_out += std::string(name) + " = " + std::to_string(value) + "\n";
m_out += name + " = " + std::to_string(value) + "\n";
}
/** Write 'name = value' with indent and new-line. */
void DumpTarget::WriteValue(const char *name, const char *value_str)
void DumpTarget::WriteValue(const std::string &name, const std::string &value_str)
{
WriteIndent();
m_out += std::string(name) + " = " + value_str + "\n";
m_out += name + " = " + value_str + "\n";
}
/** Write name & TileIndex to the output. */
void DumpTarget::WriteTile(const char *name, TileIndex tile)
void DumpTarget::WriteTile(const std::string &name, TileIndex tile)
{
WriteIndent();
m_out += std::string(name) + " = " + TileStr(tile) + "\n";
m_out += name + " = " + TileStr(tile) + "\n";
}
/**
* Open new structure (one level deeper than the current one) 'name = {\<LF\>'.
*/
void DumpTarget::BeginStruct(size_t type_id, const char *name, const void *ptr)
void DumpTarget::BeginStruct(size_t type_id, const std::string &name, const void *ptr)
{
/* make composite name */
std::string cur_name = GetCurrentStructName();
if (cur_name.size() > 0) {
if (!cur_name.empty()) {
/* add name delimiter (we use structured names) */
cur_name += ".";
}
@@ -152,7 +152,7 @@ void DumpTarget::BeginStruct(size_t type_id, const char *name, const void *ptr)
m_known_names.insert(KNOWN_NAMES::value_type(KnownStructKey(type_id, ptr), cur_name));
WriteIndent();
m_out += std::string(name) + " = {\n";
m_out += name + " = {\n";
m_indent++;
}
+12 -14
View File
@@ -10,9 +10,7 @@
#ifndef DBG_HELPERS_H
#define DBG_HELPERS_H
#include <map>
#include <stack>
#include <string>
#include "../direction_type.h"
#include "../signal_type.h"
@@ -25,7 +23,7 @@ template <typename T> struct ArrayT;
/** Helper template class that provides C array length and item type */
template <typename T, size_t N> struct ArrayT<T[N]> {
static const size_t length = N;
typedef T item_t;
using Item = T;
};
@@ -34,7 +32,7 @@ template <typename T, size_t N> struct ArrayT<T[N]> {
* or t_unk when index is out of bounds.
*/
template <typename E, typename T>
inline typename ArrayT<T>::item_t ItemAtT(E idx, const T &t, typename ArrayT<T>::item_t t_unk)
inline typename ArrayT<T>::Item ItemAtT(E idx, const T &t, typename ArrayT<T>::Item t_unk)
{
if ((size_t)idx >= ArrayT<T>::length) {
return t_unk;
@@ -48,7 +46,7 @@ inline typename ArrayT<T>::item_t ItemAtT(E idx, const T &t, typename ArrayT<T>:
* or t_unk when index is out of bounds.
*/
template <typename E, typename T>
inline typename ArrayT<T>::item_t ItemAtT(E idx, const T &t, typename ArrayT<T>::item_t t_unk, E idx_inv, typename ArrayT<T>::item_t t_inv)
inline typename ArrayT<T>::Item ItemAtT(E idx, const T &t, typename ArrayT<T>::Item t_unk, E idx_inv, typename ArrayT<T>::Item t_inv)
{
if ((size_t)idx < ArrayT<T>::length) {
return t[idx];
@@ -126,27 +124,27 @@ struct DumpTarget {
: m_indent(0)
{}
static size_t& LastTypeId();
static size_t &LastTypeId();
std::string GetCurrentStructName();
bool FindKnownName(size_t type_id, const void *ptr, std::string &name);
void WriteIndent();
void WriteValue(const char *name, int value);
void WriteValue(const char *name, const char *value_str);
void WriteTile(const char *name, TileIndex t);
void WriteValue(const std::string &name, int value);
void WriteValue(const std::string &name, const std::string &value_str);
void WriteTile(const std::string &name, TileIndex t);
/** Dump given enum value (as a number and as named value) */
template <typename E> void WriteEnumT(const char *name, E e)
template <typename E> void WriteEnumT(const std::string &name, E e)
{
WriteValue(name, ValueStr(e).c_str());
WriteValue(name, ValueStr(e));
}
void BeginStruct(size_t type_id, const char *name, const void *ptr);
void BeginStruct(size_t type_id, const std::string &name, const void *ptr);
void EndStruct();
/** Dump nested object (or only its name if this instance is already known). */
template <typename S> void WriteStructT(const char *name, const S *s)
template <typename S> void WriteStructT(const std::string &name, const S *s)
{
static size_t type_id = ++LastTypeId();
@@ -159,7 +157,7 @@ struct DumpTarget {
if (FindKnownName(type_id, s, known_as)) {
/* We already know this one, no need to dump it. */
std::string known_as_str = std::string("known_as.") + name;
WriteValue(name, known_as_str.c_str());
WriteValue(name, known_as_str);
} else {
/* Still unknown, dump it */
BeginStruct(type_id, name, s);
+9 -9
View File
@@ -10,9 +10,7 @@
#ifndef ENDIAN_BUFFER_HPP
#define ENDIAN_BUFFER_HPP
#include <iterator>
#include <string_view>
#include "../core/span_type.hpp"
#include "../core/bitmath_func.hpp"
#include "../core/overflowsafe_type.hpp"
@@ -54,7 +52,7 @@ public:
if constexpr (std::is_enum_v<T>) {
this->Write(static_cast<std::underlying_type_t<const T>>(data));
} else if constexpr (std::is_base_of_v<StrongTypedefBase, T>) {
this->Write(data.value);
this->Write(data.base());
} else {
this->Write(data);
}
@@ -73,7 +71,8 @@ public:
private:
/** Helper function to write a tuple to the buffer. */
template<class Ttuple, size_t... Tindices>
void WriteTuple(const Ttuple &values, std::index_sequence<Tindices...>) {
void WriteTuple(const Ttuple &values, std::index_sequence<Tindices...>)
{
((*this << std::get<Tindices>(values)), ...);
}
@@ -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; }
@@ -147,7 +146,7 @@ public:
if constexpr (std::is_enum_v<T>) {
data = static_cast<T>(this->Read<std::underlying_type_t<T>>());
} else if constexpr (std::is_base_of_v<StrongTypedefBase, T>) {
data.value = this->Read<decltype(data.value)>();
data = this->Read<typename T::BaseType>();
} else {
data = this->Read<T>();
}
@@ -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 };
@@ -166,7 +165,8 @@ public:
private:
/** Helper function to read a tuple from the buffer. */
template<class Ttuple, size_t... Tindices>
void ReadTuple(Ttuple &values, std::index_sequence<Tindices...>) {
void ReadTuple(Ttuple &values, std::index_sequence<Tindices...>)
{
((*this >> std::get<Tindices>(values)), ...);
}
+4 -4
View File
@@ -39,25 +39,25 @@ protected:
T *data;
/** return reference to the array header (non-const) */
inline ArrayHeader& Hdr()
inline ArrayHeader &Hdr()
{
return *(ArrayHeader*)(((byte*)data) - HeaderSize);
}
/** return reference to the array header (const) */
inline const ArrayHeader& Hdr() const
inline const ArrayHeader &Hdr() const
{
return *(ArrayHeader*)(((byte*)data) - HeaderSize);
}
/** return reference to the block reference counter */
inline uint& RefCnt()
inline uint &RefCnt()
{
return Hdr().reference_count;
}
/** return reference to number of used items */
inline uint& SizeRef()
inline uint &SizeRef()
{
return Hdr().items;
}
+1 -1
View File
@@ -22,7 +22,7 @@ enum OptionDataFlags {
struct OptionData {
byte id; ///< Unique identification of this option data, often the same as #shortname.
char shortname; ///< Short option letter if available, else use \c '\0'.
uint16 flags; ///< Option data flags. @see OptionDataFlags
uint16_t flags; ///< Option data flags. @see OptionDataFlags
const char *longname; ///< Long option name including '-'/'--' prefix, use \c nullptr if not available.
};
+2 -2
View File
@@ -159,7 +159,7 @@ protected:
/** static helper - return hash for the given key modulo number of slots */
inline static int CalcHash(const Tkey &key)
{
uint32 hash = key.CalcHash();
uint32_t hash = key.CalcHash();
hash -= (hash >> 17); // hash * 131071 / 131072
hash -= (hash >> 5); // * 31 / 32
hash &= (1 << Thash_bits) - 1; // modulo slots
@@ -216,7 +216,7 @@ public:
}
/** non-const item search & removal */
Titem_& Pop(const Tkey &key)
Titem_ &Pop(const Tkey &key)
{
Titem_ *item = TryPop(key);
assert(item != nullptr);
-3
View File
@@ -11,10 +11,7 @@
#define LRUCACHE_HPP
#include <utility>
#include <list>
#include <functional>
#include <unordered_map>
#include <stdexcept>
/**
* Size limited cache with a least recently used eviction strategy.