io/Reader: add method ReadT()
This commit is contained in:
parent
b81cac3305
commit
496184b1bc
|
@ -5,6 +5,7 @@
|
||||||
#define READER_HXX
|
#define READER_HXX
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface that can read bytes from a stream until the stream
|
* An interface that can read bytes from a stream until the stream
|
||||||
|
@ -26,6 +27,13 @@ public:
|
||||||
*/
|
*/
|
||||||
[[gnu::nonnull]]
|
[[gnu::nonnull]]
|
||||||
virtual std::size_t Read(void *data, std::size_t size) = 0;
|
virtual std::size_t Read(void *data, std::size_t size) = 0;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
requires std::is_standard_layout_v<T> && std::is_trivially_copyable_v<T>
|
||||||
|
void ReadT(T &dest) {
|
||||||
|
// TODO check return value
|
||||||
|
Read(&dest, sizeof(dest));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue