11 #ifndef __SIMPLEFILE_H__
12 #define __SIMPLEFILE_H__
71 T*
load(T* target, int64_t& num)
79 bool seek_status=
true;
80 int64_t cur_pos=ftell(
file);
84 if (!fseek(
file, 0, SEEK_END))
86 if ((num=(int64_t) ftell(
file)) != -1)
88 SG_INFO(
"file of size %ld bytes == %ld entries detected\n", num,num/
sizeof(T))
98 if ((fseek(
file,cur_pos, SEEK_SET)) == -1)
103 SG_ERROR(
"filesize autodetection failed\n")
112 target=SG_MALLOC(T, num);
116 size_t num_read=fread((
void*) target,
sizeof(T), num,
file);
117 status=((int64_t) num_read == num);
120 SG_ERROR(
"only %ld of %ld entries read. io error\n", (int64_t) num_read, num)
123 SG_ERROR(
"failed to allocate memory while trying to read %ld entries from file \"s\"\n", (int64_t) num,
filename)
140 bool save(T* target, int64_t num)
148 target=SG_MALLOC(T, num);
152 status=(fwrite((
void*) target,
sizeof(T), num,
file)==
215 virtual const char*
get_name()
const {
return "SimpleFile"; }
virtual const char * get_name() const
Template class SimpleFile to read and write from files.
void set_line_buffer_size(int32_t bufsize)
Class SGObject is the base class of all shogun objects.
bool save(T *target, int64_t num)
void get_buffered_line(char *line, uint64_t len)
CSimpleFile(char *fname, FILE *f)
all of classes and functions are contained in the shogun namespace
T * load(T *target, int64_t &num)
#define SG_UNSTABLE(func,...)