Panda3D
|
The abstract base class for a file or directory within the VirtualFileSystem. More...
#include "virtualFile.h"
Public Member Functions | |
void | close_read_file (istream *stream) const |
Closes a file opened by a previous call to open_read_file(). | |
virtual TypeHandle | force_init_type () |
virtual off_t | get_file_size () const |
Returns the current size on disk (or wherever it is) of the file before it has been opened. | |
virtual off_t | get_file_size (istream *stream) const |
Returns the current size on disk (or wherever it is) of the already-open file. | |
virtual VirtualFileSystem * | get_file_system () const =0 |
virtual Filename | get_filename () const =0 |
const Filename & | get_original_filename () const |
Returns the original filename as it was used to locate this VirtualFile. | |
virtual time_t | get_timestamp () const |
Returns a time_t value that represents the time the file was last modified, to within whatever precision the operating system records this information (on a Windows95 system, for instance, this may only be accurate to within 2 seconds). | |
virtual TypeHandle | get_type () const |
virtual bool | has_file () const |
Returns true if this file exists, false otherwise. | |
virtual bool | is_directory () const |
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise. | |
virtual bool | is_regular_file () const |
Returns true if this file represents a regular file (and read_file() may be called), false otherwise. | |
void | ls (ostream &out=cout) const |
If the file represents a directory, lists its contents. | |
void | ls_all (ostream &out=cout) const |
If the file represents a directory, recursively lists its contents and those of all subdirectories. | |
virtual istream * | open_read_file (bool auto_unwrap) const |
Opens the file for reading. | |
void | output (ostream &out) const |
PT (VirtualFileList) scan_directory() const | |
string | read_file (bool auto_unwrap) const |
Returns the entire contents of the file as a string. | |
bool | read_file (string &result, bool auto_unwrap) const |
Fills up the indicated string with the contents of the file, if it is a regular file. | |
virtual bool | read_file (pvector< unsigned char > &result, bool auto_unwrap) const |
Fills up the indicated pvector with the contents of the file, if it is a regular file. | |
void | set_original_filename (const Filename &filename) |
Stores the original filename that was used to locate this VirtualFile. | |
virtual bool | was_read_successful () const |
Call this method after a reading the istream returned by open_read_file() to completion. | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. | |
static bool | simple_read_file (istream *stream, pvector< unsigned char > &result) |
Fills up the indicated pvector with the contents of the just-opened file. | |
static bool | simple_read_file (istream *stream, pvector< unsigned char > &result, size_t max_bytes) |
As in simple_read_file() with two parameters, above, but only reads up to max_bytes bytes from the file. | |
Protected Member Functions | |
virtual bool | scan_local_directory (VirtualFileList *file_list, const ov_set< string > &mount_points) const |
Fills file_list up with the list of files that are within this directory, excluding those whose basenames are listed in mount_points. | |
Friends | |
class | VirtualFileComposite |
The abstract base class for a file or directory within the VirtualFileSystem.
Definition at line 36 of file virtualFile.h.
void VirtualFile::close_read_file | ( | istream * | stream | ) | const |
Closes a file opened by a previous call to open_read_file().
This really just deletes the istream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.
Definition at line 226 of file virtualFile.cxx.
off_t VirtualFile::get_file_size | ( | ) | const [virtual] |
Returns the current size on disk (or wherever it is) of the file before it has been opened.
Reimplemented in VirtualFileSimple.
Definition at line 193 of file virtualFile.cxx.
Referenced by get_file_size().
off_t VirtualFile::get_file_size | ( | istream * | stream | ) | const [virtual] |
Returns the current size on disk (or wherever it is) of the already-open file.
Pass in the stream that was returned by open_read_file(); some implementations may require this stream to determine the size.
Reimplemented in VirtualFileSimple.
Definition at line 182 of file virtualFile.cxx.
References get_file_size().
const Filename & VirtualFile::get_original_filename | ( | ) | const [inline] |
Returns the original filename as it was used to locate this VirtualFile.
This is usually, but not always, the same string returned by get_filename().
Definition at line 33 of file virtualFile.I.
time_t VirtualFile::get_timestamp | ( | ) | const [virtual] |
Returns a time_t value that represents the time the file was last modified, to within whatever precision the operating system records this information (on a Windows95 system, for instance, this may only be accurate to within 2 seconds).
If the timestamp cannot be determined, either because it is not supported by the operating system or because there is some error (such as file not found), returns 0.
Reimplemented in VirtualFileSimple.
Definition at line 212 of file virtualFile.cxx.
bool VirtualFile::has_file | ( | ) | const [virtual] |
Returns true if this file exists, false otherwise.
Reimplemented in VirtualFileComposite, and VirtualFileSimple.
Definition at line 29 of file virtualFile.cxx.
static void VirtualFile::init_type | ( | ) | [inline, static] |
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Making it inline seems to cause problems in the optimizer.
Reimplemented from TypedReferenceCount.
Reimplemented in VirtualFileComposite, and VirtualFileSimple.
Definition at line 90 of file virtualFile.h.
References TypedReferenceCount::init_type().
Referenced by VirtualFileSimple::init_type(), and VirtualFileComposite::init_type().
bool VirtualFile::is_directory | ( | ) | const [virtual] |
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.
Reimplemented in VirtualFileComposite, and VirtualFileSimple.
Definition at line 40 of file virtualFile.cxx.
Referenced by VirtualFileComposite::add_component(), ls(), and ls_all().
bool VirtualFile::is_regular_file | ( | ) | const [virtual] |
Returns true if this file represents a regular file (and read_file() may be called), false otherwise.
Reimplemented in VirtualFileSimple.
Definition at line 51 of file virtualFile.cxx.
void VirtualFile::ls | ( | ostream & | out = cout | ) | const |
If the file represents a directory, lists its contents.
Definition at line 126 of file virtualFile.cxx.
References Filename::get_basename(), and is_directory().
void VirtualFile::ls_all | ( | ostream & | out = cout | ) | const |
If the file represents a directory, recursively lists its contents and those of all subdirectories.
Definition at line 151 of file virtualFile.cxx.
References is_directory().
istream * VirtualFile::open_read_file | ( | bool | auto_unwrap | ) | const [virtual] |
Opens the file for reading.
Returns a newly allocated istream on success (which you should eventually delete when you are done reading). Returns NULL on failure.
Reimplemented in VirtualFileSimple.
Definition at line 168 of file virtualFile.cxx.
Referenced by VirtualFileSystem::open_read_file().
bool VirtualFile::read_file | ( | pvector< unsigned char > & | result, |
bool | auto_unwrap | ||
) | const [virtual] |
Fills up the indicated pvector with the contents of the file, if it is a regular file.
Returns true on success, false otherwise.
Reimplemented in VirtualFileSimple.
Definition at line 287 of file virtualFile.cxx.
string VirtualFile::read_file | ( | bool | auto_unwrap | ) | const [inline] |
Returns the entire contents of the file as a string.
Definition at line 43 of file virtualFile.I.
Referenced by read_file().
bool VirtualFile::read_file | ( | string & | result, |
bool | auto_unwrap | ||
) | const |
Fills up the indicated string with the contents of the file, if it is a regular file.
Returns true on success, false otherwise.
Definition at line 264 of file virtualFile.cxx.
References read_file().
bool VirtualFile::scan_local_directory | ( | VirtualFileList * | file_list, |
const ov_set< string > & | mount_points | ||
) | const [protected, virtual] |
Fills file_list up with the list of files that are within this directory, excluding those whose basenames are listed in mount_points.
Returns true if successful, false if the file is not a directory or the directory cannot be read.
Reimplemented in VirtualFileComposite, and VirtualFileSimple.
Definition at line 351 of file virtualFile.cxx.
void VirtualFile::set_original_filename | ( | const Filename & | filename | ) | [inline] |
Stores the original filename that was used to locate this VirtualFile.
This is normally called only by the VirtualFileSystem, as it creates each VirtualFile.
Definition at line 58 of file virtualFile.I.
bool VirtualFile::simple_read_file | ( | istream * | stream, |
pvector< unsigned char > & | result, | ||
size_t | max_bytes | ||
) | [static] |
As in simple_read_file() with two parameters, above, but only reads up to max_bytes bytes from the file.
Definition at line 323 of file virtualFile.cxx.
bool VirtualFile::simple_read_file | ( | istream * | in, |
pvector< unsigned char > & | result | ||
) | [static] |
Fills up the indicated pvector with the contents of the just-opened file.
Returns true on success, false otherwise. If the pvector was not empty on entry, the data read from the file will be appended onto it.
Definition at line 300 of file virtualFile.cxx.
Referenced by VirtualFileMount::read_file(), and Multifile::read_subfile().
bool VirtualFile::was_read_successful | ( | ) | const [virtual] |
Call this method after a reading the istream returned by open_read_file() to completion.
If it returns true, the file was read completely and without error; if it returns false, there may have been some errors or a truncated file read. This is particularly likely if the stream is a VirtualFileHTTP.
Definition at line 252 of file virtualFile.cxx.