util/{Const,Writable}Buffer: add static method FromVoidFloor()
This commit is contained in:
parent
e5c9b4cd75
commit
3e5ce3c92c
@ -124,6 +124,16 @@ struct ConstBuffer {
|
|||||||
return ConstBuffer(nullptr, 0);
|
return ConstBuffer(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast a ConstBuffer<void> to a ConstBuffer<T>, rounding down
|
||||||
|
* to the next multiple of T's size.
|
||||||
|
*/
|
||||||
|
static constexpr ConstBuffer<T> FromVoidFloor(ConstBuffer<void> other) {
|
||||||
|
static_assert(sizeof(T) > 0, "Empty base type");
|
||||||
|
return ConstBuffer<T>(pointer_type(other.data),
|
||||||
|
other.size / sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast a ConstBuffer<void> to a ConstBuffer<T>. A "void"
|
* Cast a ConstBuffer<void> to a ConstBuffer<T>. A "void"
|
||||||
* buffer records its size in bytes, and when casting to "T",
|
* buffer records its size in bytes, and when casting to "T",
|
||||||
@ -134,12 +144,10 @@ struct ConstBuffer {
|
|||||||
constexpr
|
constexpr
|
||||||
#endif
|
#endif
|
||||||
static ConstBuffer<T> FromVoid(ConstBuffer<void> other) {
|
static ConstBuffer<T> FromVoid(ConstBuffer<void> other) {
|
||||||
static_assert(sizeof(T) > 0, "Empty base type");
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert(other.size % sizeof(T) == 0);
|
assert(other.size % sizeof(T) == 0);
|
||||||
#endif
|
#endif
|
||||||
return ConstBuffer<T>(pointer_type(other.data),
|
return FromVoidFloor(other);
|
||||||
other.size / sizeof(T));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ConstBuffer<void> ToVoid() const {
|
constexpr ConstBuffer<void> ToVoid() const {
|
||||||
|
@ -118,6 +118,16 @@ struct WritableBuffer {
|
|||||||
return { nullptr, 0 };
|
return { nullptr, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast a WritableBuffer<void> to a WritableBuffer<T>,
|
||||||
|
* rounding down to the next multiple of T's size.
|
||||||
|
*/
|
||||||
|
static constexpr WritableBuffer<T> FromVoidFloor(WritableBuffer<void> other) {
|
||||||
|
static_assert(sizeof(T) > 0, "Empty base type");
|
||||||
|
return WritableBuffer<T>(pointer_type(other.data),
|
||||||
|
other.size / sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast a WritableBuffer<void> to a WritableBuffer<T>. A "void"
|
* Cast a WritableBuffer<void> to a WritableBuffer<T>. A "void"
|
||||||
* buffer records its size in bytes, and when casting to "T",
|
* buffer records its size in bytes, and when casting to "T",
|
||||||
@ -128,12 +138,10 @@ struct WritableBuffer {
|
|||||||
constexpr
|
constexpr
|
||||||
#endif
|
#endif
|
||||||
static WritableBuffer<T> FromVoid(WritableBuffer<void> other) {
|
static WritableBuffer<T> FromVoid(WritableBuffer<void> other) {
|
||||||
static_assert(sizeof(T) > 0, "Empty base type");
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert(other.size % sizeof(T) == 0);
|
assert(other.size % sizeof(T) == 0);
|
||||||
#endif
|
#endif
|
||||||
return WritableBuffer<T>(pointer_type(other.data),
|
return FromVoidFloor(other);
|
||||||
other.size / sizeof(T));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr WritableBuffer<void> ToVoid() const {
|
constexpr WritableBuffer<void> ToVoid() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user