11 #ifndef __SIMPLEFILE_H__
12 #define __SIMPLEFILE_H__
69 T*
load(T* target, int64_t& num)
77 bool seek_status=
true;
78 int64_t cur_pos=ftell(
file);
82 if (!fseek(
file, 0, SEEK_END))
84 if ((num=(int64_t) ftell(
file)) != -1)
86 SG_INFO(
"file of size %ld bytes == %ld entries detected\n", num,num/
sizeof(T))
96 if ((fseek(
file,cur_pos, SEEK_SET)) == -1)
101 SG_ERROR(
"filesize autodetection failed\n")
110 target=SG_MALLOC(T, num);
114 size_t num_read=fread((
void*) target,
sizeof(T), num,
file);
115 status=((int64_t) num_read == num);
118 SG_ERROR(
"only %ld of %ld entries read. io error\n", (int64_t) num_read, num)
121 SG_ERROR(
"failed to allocate memory while trying to read %ld entries from file \"s\"\n", (int64_t) num,
filename)
138 bool save(T* target, int64_t num)
146 target=SG_MALLOC(T, num);
150 status=(fwrite((
void*) target,
sizeof(T), num,
file)==
213 virtual const char*
get_name()
const {
return "SimpleFile"; }