27 : offset_(0), data_(NULL), data_is_owned_(false), is_writing_(false) {
36 if (!data_is_owned_) {
38 data_is_owned_ =
true;
50 if (!data_is_owned_) {
52 data_is_owned_ =
true;
56 memcpy(&(*data_)[0], data, size);
62 inT64 current_pos = ftell(fp);
64 if (fseek(fp, 0, SEEK_END))
66 end_offset = ftell(fp);
67 if (fseek(fp, current_pos, SEEK_SET))
70 int size = end_offset - current_pos;
72 if (!data_is_owned_) {
74 data_is_owned_ =
true;
77 return static_cast<int>(fread(&(*data_)[0], 1, size, fp)) == size;
83 while (size + 1 < buffer_size && offset_ < data_->size()) {
84 buffer[size++] = (*data_)[offset_++];
85 if ((*data_)[offset_ - 1] ==
'\n')
break;
87 if (size < buffer_size) buffer[size] =
'\0';
88 return size > 0 ? buffer : NULL;
93 int required_size = size *
count;
94 if (required_size <= 0)
return 0;
95 char* char_buffer =
reinterpret_cast<char*
>(buffer);
96 if (data_->
size() - offset_ < required_size)
97 required_size = data_->
size() - offset_;
98 if (required_size > 0 && char_buffer != NULL)
99 memcpy(char_buffer, &(*data_)[offset_], required_size);
100 offset_ += required_size;
101 return required_size / size;
112 if (data_is_owned_)
delete data_;
114 data_is_owned_ =
false;
115 }
else if (!data_is_owned_) {
117 data_is_owned_ =
true;
133 int total = size *
count;
134 if (total <= 0)
return 0;
135 const char* buf =
reinterpret_cast<const char*
>(buffer);
138 for (
int i = 0; i < total; ++i)
void resize_no_init(int size)
int FWrite(const void *buffer, int size, int count)
bool Open(const STRING &filename, FileReader reader)
char * FGets(char *buffer, int buffer_size)
bool CloseWrite(const STRING &filename, FileWriter writer)
bool LoadDataFromFile(const STRING &filename, GenericVector< char > *data)
int FRead(void *buffer, int size, int count)
bool SaveDataToFile(const GenericVector< char > &data, const STRING &filename)
void OpenWrite(GenericVector< char > *data)
bool(* FileReader)(const STRING &filename, GenericVector< char > *data)
bool(* FileWriter)(const GenericVector< char > &data, const STRING &filename)