31 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
36 using namespace basis;
67 double save_posn = _file_pointer;
71 size_t naive_size = _real_file->
length();
72 if (naive_size < _real_file->file_size_limit()) {
75 return double(naive_size);
78 double best_highest = 0.0;
84 #ifdef DEBUG_HUGE_FILE
90 #ifdef DEBUG_HUGE_FILE
94 int bytes_read = _real_file->
read(temp_bytes, 1);
97 #ifdef DEBUG_HUGE_FILE
100 bool at_eof = _real_file->
eof();
101 #ifdef DEBUG_HUGE_FILE
104 if (seek_ret && !at_eof) {
105 #ifdef DEBUG_HUGE_FILE
106 LOG(
"seek worked, incrementing best highest and trying same jump again");
109 best_highest += double(big_jump);
110 _file_pointer += double(big_jump);
112 }
else if (seek_ret && at_eof) {
113 #ifdef DEBUG_HUGE_FILE
114 LOG(
"seek worked but found eof exactly.");
117 best_highest += double(big_jump);
118 _file_pointer += double(big_jump);
123 #ifdef DEBUG_HUGE_FILE
124 LOG(
"seek failed, going back to best highest and trying same jump again");
130 if (worked !=
OKAY) {
134 LOG(
a_sprintf(
"failed to seek back to best highest %.0f on ",
135 best_highest) + _real_file->
name());
144 LOG(
astring(
"failed to seek back to start of file! on ")
145 + _real_file->
name());
158 #ifdef DEBUG_HUGE_FILE
159 LOG(
"got down to smallest big jump, 0!");
165 #ifdef DEBUG_HUGE_FILE
166 LOG(
a_sprintf(
"restraining big jump down to %u.", big_jump));
175 #ifdef DEBUG_HUGE_FILE
176 LOG(
a_sprintf(
"saying file len is %.0f.", best_highest + 1.0));
178 return best_highest + 1.0;
187 #ifdef DEBUG_HUGE_FILE
190 double difference = absolute_posn - _file_pointer;
192 #ifdef DEBUG_HUGE_FILE
193 LOG(
a_sprintf(
"abs_pos=%.0f difference=%.0f old_filepoint=%.0f",
194 absolute_posn, difference, _file_pointer));
197 if (difference < 0.000001) {
198 #ifdef DEBUG_HUGE_FILE
199 LOG(
"difference was minimal, saying we're done.");
208 #ifdef DEBUG_HUGE_FILE
211 bool seek_ret = _real_file->
seek(
int(seek_size),
214 #ifdef DEBUG_HUGE_FILE
215 LOG(
a_sprintf(
"failed to seek %d from current",
int(seek_size)));
219 _file_pointer += seek_size;
220 #ifdef DEBUG_HUGE_FILE
223 difference = absolute_posn - _file_pointer;
224 #ifdef DEBUG_HUGE_FILE
233 #ifdef DEBUG_HUGE_FILE
237 return move_to(_file_pointer + new_position);
244 #ifdef DEBUG_HUGE_FILE
245 LOG(
"into precarious FROM_END case.");
247 double file_len =
length();
248 #ifdef DEBUG_HUGE_FILE
251 _file_pointer = file_len;
257 return move_to(_file_pointer - new_position);
267 int ret = _real_file->
read(to_fill, desired_size);
270 _file_pointer += double(size_read);
279 int ret = _real_file->
write(to_write);
282 _file_pointer += double(size_written);
299 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
306 SYSTEMTIME *st =
new SYSTEMTIME;
309 FILETIME *t =
new FILETIME;
310 SystemTimeToFileTime(st, t);
319 if (ret !=
OKAY) ret;
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
A very common template for a dynamic array of bytes.
Outcomes describe the state of completion for an operation.
Provides file managment services using the standard I/O support.
static size_t file_size_limit()
returns the maximum size that seek and length can support.
int write(const basis::abyte *buffer, int buffer_size)
writes "buffer_size" bytes into the file from "buffer".
@ FROM_START
offset is from the beginning of the file.
@ FROM_CURRENT
offset is from current cursor position.
@ FROM_END
offset is from the end of the file.
bool seek(int where, origins origin=FROM_START)
places the cursor in the file at "where", based on the "origin".
const basis::astring & name() const
returns the file name that the object is operating on.
int read(basis::abyte *buffer, int buffer_size)
reads "buffer_size" bytes from the file into "buffer".
bool eof()
returns true if the cursor is at (or after) the end of the file.
void flush()
forces any pending writes to actually be saved to the file.
size_t length()
returns the file's total length, in bytes.
bool truncate()
truncates the file after the current position.
bool good()
returns true if the file seems to be in the appropriate desired state.
Provides operations commonly needed on file names.
bool exists() const
returns true if the file exists.
double length()
expensive operation accesses the file to find length.
bool truncate()
truncates the file after the current position.
basis::outcome move_to(double absolute_posn)
simpler seek just goes from current location to "absolute_posn".
bool eof() const
reports when the file pointer has reached the end of the file.
basis::outcome seek(double new_position, byte_filer::origins origin=byte_filer::FROM_CURRENT)
move the file pointer to "new_position" if possible.
const basis::astring & name() const
returns the name of the file this operates on.
basis::outcome write(const basis::byte_array &to_write, int &size_written)
stores the array "to_write" into the file.
bool good() const
reports if the file was opened successfully.
void flush()
forces any pending writes to actually be saved to the file.
basis::outcome read(basis::byte_array &to_fill, int desired_size, int &size_read)
reads "desired_size" into "to_fill" if possible.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
type minimum(type a, type b)
maximum returns the greater of two values.
type absolute_value(type a)
Returns a if a is non-negative, and returns -a otherwise.
A platform independent way to obtain the timestamp of a file.
Aids in achievement of platform independence.