summaryrefslogtreecommitdiff
path: root/src/common/file_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/file_util.h')
-rw-r--r--src/common/file_util.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h
index b65829291..d0dccdf69 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -6,13 +6,12 @@
6 6
7#include <array> 7#include <array>
8#include <fstream> 8#include <fstream>
9#include <cstddef>
9#include <cstdio> 10#include <cstdio>
10#include <cstring>
11#include <string> 11#include <string>
12#include <vector> 12#include <vector>
13 13
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/string_util.h"
16 15
17// User directory indices for GetUserPath 16// User directory indices for GetUserPath
18enum { 17enum {
@@ -117,9 +116,6 @@ bool SetCurrentDir(const std::string &directory);
117// directory. To be used in "multi-user" mode (that is, installed). 116// directory. To be used in "multi-user" mode (that is, installed).
118const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath=""); 117const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath="");
119 118
120// probably doesn't belong here
121//std::string GetThemeDir(const std::string& theme_name);
122
123// Returns the path to where the sys file are 119// Returns the path to where the sys file are
124std::string GetSysDirectory(); 120std::string GetSysDirectory();
125 121
@@ -182,6 +178,10 @@ public:
182 template <typename T> 178 template <typename T>
183 size_t WriteArray(const T* data, size_t length) 179 size_t WriteArray(const T* data, size_t length)
184 { 180 {
181 static_assert(std::is_standard_layout<T>::value, "Given array does not consist of standard layout objects");
182 // TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here.
183 //static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects");
184
185 if (!IsOpen()) { 185 if (!IsOpen()) {
186 m_good = false; 186 m_good = false;
187 return -1; 187 return -1;
@@ -204,6 +204,12 @@ public:
204 return WriteArray(reinterpret_cast<const char*>(data), length); 204 return WriteArray(reinterpret_cast<const char*>(data), length);
205 } 205 }
206 206
207 template<typename T>
208 size_t WriteObject(const T& object) {
209 static_assert(!std::is_pointer<T>::value, "Given object is a pointer");
210 return WriteArray(&object, 1);
211 }
212
207 bool IsOpen() { return nullptr != m_file; } 213 bool IsOpen() { return nullptr != m_file; }
208 214
209 // m_good is set to false when a read, write or other function fails 215 // m_good is set to false when a read, write or other function fails