byte_filer Class Reference

#include <byte_filer.h>

Collaboration diagram for byte_filer:

Collaboration graph
[legend]
List of all members.

Public Types

enum  origins { FROM_START, FROM_END, FROM_CURRENT }

Public Member Functions

 byte_filer ()
 constructs an object that doesn't access a file yet.
 byte_filer (const istring &filename, const istring &permissions)
 opens a file "filename" as specified in "permissions".
 byte_filer (const char *filename, const char *permissions)
 synonym for above but takes char pointers.
 byte_filer (bool auto_close, void *opened)
 uses a previously "opened" stdio FILE handle. be careful!
 ~byte_filer ()
bool open (const istring &filename, const istring &permissions)
 opens a file with "filename" and "permissions" as in the constructor.
void close ()
 shuts down the open file, if any.
istring filename () const
 returns the filename that this was opened with.
bool good ()
 returns true if the file seems to be in the appropriate desired state.
size_t length ()
 returns the file's total length, in bytes.
size_t tell ()
 returns the current position within the file, in terms of bytes.
void flush ()
 forces any pending writes to actually be saved to the file.
bool seek (int where, origins origin=FROM_START)
 places the cursor in the file at "where", based on the "origin".
bool eof ()
 returns true if the cursor is at (or after) the end of the file.
int read (byte *buffer, int buffer_size)
 reads "buffer_size" bytes from the file into "buffer".
int write (const byte *buffer, int buffer_size)
 writes "buffer_size" bytes into the file from "buffer".
int read (byte_array &buffer, int desired_size)
 reads "buffer_size" bytes from the file into "buffer".
int write (const byte_array &buffer)
 writes the "buffer" into the file.
int read (istring &buffer, int desired_size)
 read() pulls up to "desired_size" bytes from the file into "buffer".
int write (const istring &buffer, bool add_null=false)
 stores the string in "buffer" into the file at the current position.
int getline (byte *buffer, int desired_size)
 reads a line of text (terminated by a return) into the "buffer".
int getline (byte_array &buffer, int desired_size)
 reads a line of text (terminated by a return) into the "buffer".
int getline (istring &buffer, int desired_size)
 reads a line of text (terminated by a return) into the "buffer".
bool truncate ()
 truncates the file after the current position.
void * file_handle ()
 provides a hook to get at the operating system's file handle.

Static Public Member Functions

static size_t file_size_limit ()
 returns the maximum size that seek and length can support.

Detailed Description

Definition at line 25 of file byte_filer.h.


Member Enumeration Documentation

enum byte_filer::origins

Enumerator:
FROM_START  offset is from the beginning of the file.
FROM_END  offset is from the end of the file.
FROM_CURRENT  offset is from current cursor position.

Definition at line 87 of file byte_filer.h.


Constructor & Destructor Documentation

byte_filer::byte_filer (  ) 

constructs an object that doesn't access a file yet.

use open() to make the object valid.

Definition at line 51 of file byte_filer.cpp.

byte_filer::byte_filer ( const istring filename,
const istring permissions 
)

opens a file "filename" as specified in "permissions".

these are identical to the standard I/O permissions:

a "b" can be added to the end of these to indicate a binary file should be used instead of a text file.

Definition at line 57 of file byte_filer.cpp.

References filename(), and open().

byte_filer::byte_filer ( const char *  filename,
const char *  permissions 
)

synonym for above but takes char pointers.

Definition at line 63 of file byte_filer.cpp.

References open().

byte_filer::byte_filer ( bool  auto_close,
void *  opened 
)

uses a previously "opened" stdio FILE handle. be careful!

the "opened" object must be a valid FILE pointer; void * is used to avoid pulling in the stdio header. this method will not close the file handle if "auto_close" is false.

Definition at line 69 of file byte_filer.cpp.

byte_filer::~byte_filer (  ) 

Definition at line 79 of file byte_filer.cpp.

References close(), and WHACK().


Member Function Documentation

size_t byte_filer::file_size_limit (  )  [static]

returns the maximum size that seek and length can support.

use the huge_file class if you need to exceed the stdio limits.

Definition at line 83 of file byte_filer.cpp.

References BTFL_FILE_TELL_LIMIT.

Referenced by huge_file::length(), huge_file::move_to(), and truncate().

bool byte_filer::open ( const istring filename,
const istring permissions 
)

opens a file with "filename" and "permissions" as in the constructor.

if a different file had already been opened, it is closed.

Definition at line 85 of file byte_filer.cpp.

References close(), filename(), good(), NIL, istring::s(), and istring::t().

Referenced by byte_filer(), grid_processor::reset_data_fields(), and smtp_client::setup_session().

void byte_filer::close (  ) 

shuts down the open file, if any.

open() will have to be invoked before this object can be used again.

Definition at line 106 of file byte_filer.cpp.

References NIL.

Referenced by bitmap::load_from_file(), main(), open(), grid_processor::reset_data_fields(), smtp_client::setup_session(), database_login_info::update_freetds_configuration(), version_ini::write_code(), grid_processor::write_data_fields(), version_ini::write_rc(), and ~byte_filer().

istring byte_filer::filename (  )  const

returns the filename that this was opened with.

Definition at line 81 of file byte_filer.cpp.

Referenced by byte_filer(), huge_file::length(), open(), version_ini::write_assembly(), and write_build_config::write_output_file().

bool byte_filer::good (  ) 

returns true if the file seems to be in the appropriate desired state.

Definition at line 113 of file byte_filer.cpp.

Referenced by file_logger::format_bytes(), huge_file::good(), file_logger::good(), bitmap::load_from_file(), file_logger::log(), file_logger::log_bytes(), main(), open(), bookmark_tree::read_csv_file(), ini_configurator::sections(), tell(), file_logger::truncate(), version_ini::write_code(), write_build_config::write_output_file(), and version_ini::write_rc().

size_t byte_filer::length (  ) 

returns the file's total length, in bytes.

this cannot accurately report a file length if it is file_size_limit() or greater.

Definition at line 150 of file byte_filer.cpp.

References FROM_END, FROM_START, seek(), and tell().

Referenced by huge_file::length(), bitmap::load_from_file(), and main().

size_t byte_filer::tell (  ) 

returns the current position within the file, in terms of bytes.

this is also limited to file_size_limit().

printf(isprintf("failed to tell size, calling it %.0f, and one plus that is %.0f\n", double(BTFL_FILE_TELL_LIMIT), double(long(long(BTFL_FILE_TELL_LIMIT) + 1))).s());

Definition at line 115 of file byte_filer.cpp.

References BTFL_FILE_TELL_LIMIT, and good().

Referenced by length(), file_logger::log(), file_logger::log_bytes(), main(), truncate(), and file_logger::truncate().

void byte_filer::flush (  ) 

forces any pending writes to actually be saved to the file.

Definition at line 175 of file byte_filer.cpp.

Referenced by huge_file::flush(), file_logger::flush(), and truncate().

bool byte_filer::seek ( int  where,
origins  origin = FROM_START 
)

places the cursor in the file at "where", based on the "origin".

note that if the origin is FROM_END, then the offset "where" should be a negative number if you're trying to access the interior of the file; positive offsets indicate places after the actual end of the file.

Definition at line 197 of file byte_filer.cpp.

References FROM_CURRENT, FROM_END, and FROM_START.

Referenced by huge_file::length(), length(), bitmap::load_from_file(), main(), huge_file::move_to(), huge_file::seek(), file_logger::truncate(), and version_ini::write_assembly().

bool byte_filer::eof (  ) 

returns true if the cursor is at (or after) the end of the file.

Definition at line 131 of file byte_filer.cpp.

Referenced by huge_file::eof(), huge_file::length(), manifest_chunk::read_a_string(), grid_processor::reset_data_fields(), smtp_client::setup_session(), and file_logger::truncate().

int byte_filer::read ( byte buffer,
int  buffer_size 
)

reads "buffer_size" bytes from the file into "buffer".

for all of the read and write operations, the number of bytes that is actually processed for the file is returned.

Definition at line 133 of file byte_filer.cpp.

Referenced by huge_file::length(), bitmap::load_from_file(), main(), huge_file::read(), read(), manifest_chunk::read_a_string(), manifest_chunk::read_a_timestamp(), manifest_chunk::read_an_int(), manifest_chunk::read_an_obscured_int(), ini_configurator::sections(), file_logger::truncate(), database_login_info::update_freetds_configuration(), version_ini::write_assembly(), and write_build_config::write_output_file().

int byte_filer::write ( const byte buffer,
int  buffer_size 
)

writes "buffer_size" bytes into the file from "buffer".

Definition at line 136 of file byte_filer.cpp.

Referenced by file_logger::log(), file_logger::log_bytes(), main(), grid_processor::reset_data_fields(), smtp_client::setup_session(), file_logger::truncate(), database_login_info::update_freetds_configuration(), huge_file::write(), write(), version_ini::write_assembly(), grid_processor::write_bogus_row(), version_ini::write_code(), grid_processor::write_fields_for_row(), write_build_config::write_output_file(), and version_ini::write_rc().

int byte_filer::read ( byte_array buffer,
int  desired_size 
)

reads "buffer_size" bytes from the file into "buffer".

Definition at line 139 of file byte_filer.cpp.

References array< contents >::access(), array< contents >::length(), read(), array< contents >::reset(), and array< contents >::zap().

int byte_filer::write ( const byte_array buffer  ) 

writes the "buffer" into the file.

Definition at line 147 of file byte_filer.cpp.

References array< contents >::length(), array< contents >::observe(), and write().

int byte_filer::read ( istring buffer,
int  desired_size 
)

read() pulls up to "desired_size" bytes from the file into "buffer".

since the read() will grab as much data as is available given that it fits in "desired_size". null characters embedded in the file are a bad issue here; some other method must be used to read the file instead (such as the byte_array read above). the "buffer" is shrunk to fit the zero terminator that we automatically add.

Definition at line 159 of file byte_filer.cpp.

References non_negative(), istring::observe(), istring::pad(), read(), and istring::shrink().

int byte_filer::write ( const istring buffer,
bool  add_null = false 
)

stores the string in "buffer" into the file at the current position.

if "add_null" is true, then write() adds a zero terminator to what is written into the file. otherwise just the string's non-null contents are written.

Definition at line 168 of file byte_filer.cpp.

References istring::length(), istring::observe(), and write().

int byte_filer::getline ( byte buffer,
int  desired_size 
)

reads a line of text (terminated by a return) into the "buffer".

Definition at line 211 of file byte_filer.cpp.

Referenced by getline(), main(), bookmark_tree::read_csv_file(), grid_processor::reset_data_fields(), and smtp_client::setup_session().

int byte_filer::getline ( byte_array buffer,
int  desired_size 
)

reads a line of text (terminated by a return) into the "buffer".

Definition at line 218 of file byte_filer.cpp.

References array< contents >::access(), getline(), and array< contents >::reset().

int byte_filer::getline ( istring buffer,
int  desired_size 
)

reads a line of text (terminated by a return) into the "buffer".

Definition at line 224 of file byte_filer.cpp.

References istring::access(), getline(), non_negative(), istring::pad(), and istring::shrink().

bool byte_filer::truncate (  ) 

truncates the file after the current position.

Definition at line 181 of file byte_filer.cpp.

References file_size_limit(), fileno, flush(), and tell().

Referenced by huge_file::truncate(), and version_ini::write_assembly().

void * byte_filer::file_handle (  ) 

provides a hook to get at the operating system's file handle.

this is of the type FILE *, as defined by <stdio.h>.

Definition at line 129 of file byte_filer.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 04:30:39 2008 for HOOPLE Libraries by  doxygen 1.5.1