mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-14 05:55:13 +01:00
FileUtil: Add a WriteObject method for writing a single, POD-type object.
This commit is contained in:
parent
256bdfb579
commit
279e19732c
@ -181,6 +181,10 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
size_t WriteArray(const T* data, size_t length)
|
size_t WriteArray(const T* data, size_t length)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_standard_layout<T>::value, "Given array does not consist of standard layout objects");
|
||||||
|
// TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here.
|
||||||
|
//static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects");
|
||||||
|
|
||||||
if (!IsOpen()) {
|
if (!IsOpen()) {
|
||||||
m_good = false;
|
m_good = false;
|
||||||
return -1;
|
return -1;
|
||||||
@ -203,6 +207,12 @@ public:
|
|||||||
return WriteArray(reinterpret_cast<const char*>(data), length);
|
return WriteArray(reinterpret_cast<const char*>(data), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
size_t WriteObject(const T& object) {
|
||||||
|
static_assert(!std::is_pointer<T>::value, "Given object is a pointer");
|
||||||
|
return WriteArray(&object, 1);
|
||||||
|
}
|
||||||
|
|
||||||
bool IsOpen() { return nullptr != m_file; }
|
bool IsOpen() { return nullptr != m_file; }
|
||||||
|
|
||||||
// m_good is set to false when a read, write or other function fails
|
// m_good is set to false when a read, write or other function fails
|
||||||
|
Loading…
Reference in New Issue
Block a user