mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-17 00:10:03 -04:00
refactor(mmif): allow integral types as offset arguments to as
/span
This commit is contained in:
parent
42a904d4cd
commit
742e6ccca2
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <concepts>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -44,22 +45,27 @@ class mmif : public boost::noncopyable {
|
|||||||
public:
|
public:
|
||||||
virtual ~mmif() = default;
|
virtual ~mmif() = default;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, std::integral U>
|
||||||
T const* as(file_off_t offset = 0) const {
|
T const* as(U offset = 0) const {
|
||||||
return reinterpret_cast<T const*>(
|
return reinterpret_cast<T const*>(
|
||||||
reinterpret_cast<char const*>(this->addr()) + offset);
|
reinterpret_cast<char const*>(this->addr()) + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T = uint8_t>
|
template <typename T = uint8_t, std::integral U>
|
||||||
std::span<T const> span(file_off_t offset, size_t length) const {
|
std::span<T const> span(U offset, size_t length) const {
|
||||||
return std::span(this->as<T>(offset), length);
|
return std::span(this->as<T>(offset), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T = uint8_t>
|
template <typename T = uint8_t, std::integral U>
|
||||||
std::span<T const> span(file_off_t offset = 0) const {
|
std::span<T const> span(U offset) const {
|
||||||
return span<T>(offset, size() - offset);
|
return span<T>(offset, size() - offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T = uint8_t>
|
||||||
|
std::span<T const> span() const {
|
||||||
|
return span<T>(0);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void const* addr() const = 0;
|
virtual void const* addr() const = 0;
|
||||||
virtual size_t size() const = 0;
|
virtual size_t size() const = 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user