BAN: Modify Span constructors to keep constness correctly
This commit is contained in:
parent
cef6999dc7
commit
3572e9794a
|
@ -20,6 +20,10 @@ namespace BAN
|
||||||
public:
|
public:
|
||||||
Span() = default;
|
Span() = default;
|
||||||
Span(T*, size_type);
|
Span(T*, size_type);
|
||||||
|
Span(Span<T>&);
|
||||||
|
template<typename S>
|
||||||
|
requires(is_same_v<T, const S>)
|
||||||
|
Span(const Span<S>&);
|
||||||
|
|
||||||
iterator begin() { return iterator(m_data); }
|
iterator begin() { return iterator(m_data); }
|
||||||
iterator end() { return iterator(m_data + m_size); }
|
iterator end() { return iterator(m_data + m_size); }
|
||||||
|
@ -51,6 +55,22 @@ namespace BAN
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Span<T>::Span(Span& other)
|
||||||
|
: m_data(other.data())
|
||||||
|
, m_size(other.size())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<typename S>
|
||||||
|
requires(is_same_v<T, const S>)
|
||||||
|
Span<T>::Span(const Span<S>& other)
|
||||||
|
: m_data(other.data())
|
||||||
|
, m_size(other.size())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& Span<T>::operator[](size_type index)
|
T& Span<T>::operator[](size_type index)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,8 +21,8 @@ namespace Kernel
|
||||||
const uint8_t* glyph(uint32_t) const;
|
const uint8_t* glyph(uint32_t) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static BAN::ErrorOr<Font> parse_psf1(const BAN::Span<uint8_t>);
|
static BAN::ErrorOr<Font> parse_psf1(BAN::Span<const uint8_t>);
|
||||||
static BAN::ErrorOr<Font> parse_psf2(const BAN::Span<uint8_t>);
|
static BAN::ErrorOr<Font> parse_psf2(BAN::Span<const uint8_t>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAN::HashMap<uint32_t, uint32_t> m_glyph_offsets;
|
BAN::HashMap<uint32_t, uint32_t> m_glyph_offsets;
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace Kernel
|
||||||
BAN::ErrorOr<Font> Font::prefs()
|
BAN::ErrorOr<Font> Font::prefs()
|
||||||
{
|
{
|
||||||
size_t font_data_size = _binary_font_prefs_psf_end - _binary_font_prefs_psf_start;
|
size_t font_data_size = _binary_font_prefs_psf_end - _binary_font_prefs_psf_start;
|
||||||
BAN::Span<uint8_t> font_data(_binary_font_prefs_psf_start, font_data_size);
|
BAN::Span<const uint8_t> font_data(_binary_font_prefs_psf_start, font_data_size);
|
||||||
return parse_psf1(font_data);
|
return parse_psf1(font_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +57,7 @@ namespace Kernel
|
||||||
return BAN::Error::from_c_string("Unsupported font format");
|
return BAN::Error::from_c_string("Unsupported font format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BAN::ErrorOr<Font> Font::parse_psf1(BAN::Span<const uint8_t> font_data)
|
||||||
BAN::ErrorOr<Font> Font::parse_psf1(const BAN::Span<uint8_t> font_data)
|
|
||||||
{
|
{
|
||||||
if (font_data.size() < 4)
|
if (font_data.size() < 4)
|
||||||
return BAN::Error::from_c_string("Font file is too small");
|
return BAN::Error::from_c_string("Font file is too small");
|
||||||
|
@ -139,7 +138,7 @@ namespace Kernel
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<Font> Font::parse_psf2(const BAN::Span<uint8_t> font_data)
|
BAN::ErrorOr<Font> Font::parse_psf2(BAN::Span<const uint8_t> font_data)
|
||||||
{
|
{
|
||||||
struct PSF2Header
|
struct PSF2Header
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace Kernel
|
||||||
BAN::LittleEndian<uint64_t> ending_lba;
|
BAN::LittleEndian<uint64_t> ending_lba;
|
||||||
BAN::LittleEndian<uint64_t> attributes;
|
BAN::LittleEndian<uint64_t> attributes;
|
||||||
BAN::LittleEndian<uint16_t> partition_name[36];
|
BAN::LittleEndian<uint16_t> partition_name[36];
|
||||||
} __attribute__((packed));
|
};
|
||||||
|
|
||||||
static uint32_t crc32_table[256] =
|
static uint32_t crc32_table[256] =
|
||||||
{
|
{
|
||||||
|
@ -167,7 +167,6 @@ namespace Kernel
|
||||||
for (uint32_t i = 0; i < header.partition_entry_count; i++)
|
for (uint32_t i = 0; i < header.partition_entry_count; i++)
|
||||||
{
|
{
|
||||||
const PartitionEntry& entry = *(const PartitionEntry*)(entry_array.data() + header.partition_entry_size * i);
|
const PartitionEntry& entry = *(const PartitionEntry*)(entry_array.data() + header.partition_entry_size * i);
|
||||||
ASSERT((uintptr_t)&entry % 2 == 0);
|
|
||||||
|
|
||||||
char utf8_name[36 * 4 + 1];
|
char utf8_name[36 * 4 + 1];
|
||||||
BAN::UTF8::from_codepoints(entry.partition_name, 36, utf8_name);
|
BAN::UTF8::from_codepoints(entry.partition_name, 36, utf8_name);
|
||||||
|
|
Loading…
Reference in New Issue