Panda3D
|
The abstract base class for a file or directory within the VirtualFileSystem. More...
#include "virtualFile.h"
Public Member Functions | |
virtual bool | atomic_compare_and_exchange_contents (string &orig_contents, const string &old_contents, const string &new_contents) |
See Filename::atomic_compare_and_exchange_contents(). More... | |
virtual bool | atomic_read_contents (string &contents) const |
See Filename::atomic_read_contents(). More... | |
virtual void | close_read_file (istream *stream) const |
Closes a file opened by a previous call to open_read_file(). More... | |
virtual void | close_read_write_file (iostream *stream) |
Closes a file opened by a previous call to open_read_write_file(). More... | |
virtual void | close_write_file (ostream *stream) |
Closes a file opened by a previous call to open_write_file(). More... | |
virtual bool | copy_file (VirtualFile *new_file) |
Attempts to copy the contents of this file to the indicated file. More... | |
virtual bool | delete_file () |
Attempts to delete this file or directory. More... | |
virtual TypeHandle | force_init_type () |
virtual streamsize | get_file_size (istream *stream) const |
Returns the current size on disk (or wherever it is) of the already-open file. More... | |
virtual streamsize | get_file_size () const |
Returns the current size on disk (or wherever it is) of the file before it has been opened. More... | |
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. More... | |
virtual bool | get_system_info (SubfileInfo &info) |
Populates the SubfileInfo structure with the data representing where the file actually resides on disk, if this is knowable. More... | |
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). More... | |
virtual TypeHandle | get_type () const |
virtual bool | has_file () const |
Returns true if this file exists, false otherwise. More... | |
virtual bool | is_directory () const |
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise. More... | |
virtual bool | is_regular_file () const |
Returns true if this file represents a regular file (and read_file() may be called), false otherwise. More... | |
virtual bool | is_writable () const |
Returns true if this file may be written to, which implies write_file() may be called (unless it is a directory instead of a regular file). More... | |
void | ls (ostream &out=cout) const |
If the file represents a directory, lists its contents. More... | |
void | ls_all (ostream &out=cout) const |
If the file represents a directory, recursively lists its contents and those of all subdirectories. More... | |
virtual ostream * | open_append_file () |
Works like open_write_file(), but the file is opened in append mode. More... | |
virtual iostream * | open_read_append_file () |
Works like open_read_write_file(), but the file is opened in append mode. More... | |
virtual istream * | open_read_file (bool auto_unwrap) const |
Opens the file for reading. More... | |
virtual iostream * | open_read_write_file (bool truncate) |
Opens the file for writing. More... | |
virtual ostream * | open_write_file (bool auto_wrap, bool truncate) |
Opens the file for writing. More... | |
void | output (ostream &out) const |
string | read_file (bool auto_unwrap) const |
Returns the entire contents of the file as a string. More... | |
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. More... | |
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. More... | |
virtual bool | rename_file (VirtualFile *new_file) |
Attempts to move or rename this file or directory. More... | |
PointerTo< VirtualFileList > | scan_directory () const |
If the file represents a directory (that is, is_directory() returns true), this returns the list of files within the directory at the current time. More... | |
void | set_original_filename (const Filename &filename) |
Stores the original filename that was used to locate this VirtualFile. More... | |
virtual bool | was_read_successful () const |
Call this method after a reading the istream returned by open_read_file() to completion. More... | |
bool | write_file (const string &data, bool auto_wrap) |
Writes the entire contents of the file as a string, if it is writable. More... | |
virtual bool | write_file (const unsigned char *data, size_t data_size, bool auto_wrap) |
Writes the indicated data to the file, if it is writable. More... | |
![]() | |
TypedReferenceCount (const TypedReferenceCount ©) | |
void | operator= (const TypedReferenceCount ©) |
![]() | |
TypedObject (const TypedObject ©) | |
TypedObject * | as_typed_object () |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
const TypedObject * | as_typed_object () const |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
int | get_best_parent_from_Set (const std::set< int > &) const |
int | get_type_index () const |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More... | |
bool | is_exact_type (TypeHandle handle) const |
Returns true if the current object is the indicated type exactly. More... | |
bool | is_of_type (TypeHandle handle) const |
Returns true if the current object is or derives from the indicated type. More... | |
void | operator= (const TypedObject ©) |
![]() | |
int | get_ref_count () const |
Returns the current reference count. More... | |
WeakReferenceList * | get_weak_list () const |
Returns the WeakReferenceList associated with this ReferenceCount object. More... | |
bool | has_weak_list () const |
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More... | |
void | local_object () |
This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More... | |
void | ref () const |
Explicitly increments the reference count. More... | |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | test_ref_count_nonzero () const |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
virtual bool | unref () const |
Explicitly decrements the reference count. More... | |
void | weak_ref (WeakPointerToVoid *ptv) |
Adds the indicated PointerToVoid as a weak reference to this object. More... | |
void | weak_unref (WeakPointerToVoid *ptv) |
Removes the indicated PointerToVoid as a weak reference to this object. More... | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
static bool | simple_read_file (istream *stream, pvector< unsigned char > &result) |
Fills up the indicated pvector with the contents of the just-opened file. More... | |
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. More... | |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
![]() | |
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. More... | |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
Friends | |
class | VirtualFileComposite |
The abstract base class for a file or directory within the VirtualFileSystem.
Definition at line 37 of file virtualFile.h.
|
virtual |
See Filename::atomic_compare_and_exchange_contents().
Reimplemented in VirtualFileSimple.
Definition at line 406 of file virtualFile.cxx.
References atomic_read_contents().
Referenced by get_system_info().
|
virtual |
See Filename::atomic_read_contents().
Reimplemented in VirtualFileSimple.
Definition at line 418 of file virtualFile.cxx.
References read_file().
Referenced by atomic_compare_and_exchange_contents().
|
virtual |
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.
Reimplemented in VirtualFileSimple.
Definition at line 242 of file virtualFile.cxx.
References was_read_successful().
Referenced by open_read_file().
|
virtual |
Closes a file opened by a previous call to open_read_write_file().
This really just deletes the iostream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.
Reimplemented in VirtualFileSimple.
Definition at line 337 of file virtualFile.cxx.
References get_file_size().
Referenced by open_read_append_file().
|
virtual |
Closes a file opened by a previous call to open_write_file().
This really just deletes the ostream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.
Reimplemented in VirtualFileSimple.
Definition at line 297 of file virtualFile.cxx.
References open_read_write_file().
Referenced by VirtualFileSimple::copy_file(), and open_append_file().
|
virtual |
Attempts to copy the contents of this file to the indicated file.
Returns true on success, false on failure.
Reimplemented in VirtualFileSimple.
Definition at line 111 of file virtualFile.cxx.
References scan_directory().
Referenced by rename_file().
|
virtual |
Attempts to delete this file or directory.
This can remove a single file or an empty directory. It will not remove a nonempty directory. Returns true on success, false on failure.
Reimplemented in VirtualFileSimple.
Definition at line 77 of file virtualFile.cxx.
References rename_file().
Referenced by VirtualFileSimple::copy_file(), is_writable(), BamCache::list_index(), and VirtualFileSimple::rename_file().
|
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 351 of file virtualFile.cxx.
References get_file_size().
Referenced by FmodAudioSound::get_finished_event().
|
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 362 of file virtualFile.cxx.
References get_timestamp().
Referenced by close_read_write_file(), and get_file_size().
|
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.
References read_file().
Referenced by VirtualFileSystem::parse_option().
|
virtual |
Populates the SubfileInfo structure with the data representing where the file actually resides on disk, if this is knowable.
Returns true if the file might reside on disk, and the info is populated, or false if it does not (or it is not known where the file resides), in which case the info is meaningless.
Reimplemented in VirtualFileSimple.
Definition at line 396 of file virtualFile.cxx.
References atomic_compare_and_exchange_contents().
Referenced by get_timestamp().
|
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 381 of file virtualFile.cxx.
References get_system_info().
Referenced by get_file_size().
|
virtual |
Returns true if this file exists, false otherwise.
Reimplemented in VirtualFileSimple, and VirtualFileComposite.
Definition at line 30 of file virtualFile.cxx.
References is_directory().
|
virtual |
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.
Reimplemented in VirtualFileSimple, and VirtualFileComposite.
Definition at line 41 of file virtualFile.cxx.
References is_regular_file().
Referenced by VirtualFileComposite::add_component(), has_file(), ls(), ls_all(), VirtualFileSystem::parse_option(), VirtualFileSimple::rename_file(), and simple_read_file().
|
virtual |
Returns true if this file represents a regular file (and read_file() may be called), false otherwise.
Reimplemented in VirtualFileSimple.
Definition at line 52 of file virtualFile.cxx.
References is_writable().
Referenced by is_directory().
|
virtual |
Returns true if this file may be written to, which implies write_file() may be called (unless it is a directory instead of a regular file).
Reimplemented in VirtualFileSimple.
Definition at line 64 of file virtualFile.cxx.
References delete_file().
Referenced by is_regular_file().
void VirtualFile::ls | ( | ostream & | out = cout | ) | const |
If the file represents a directory, lists its contents.
Definition at line 186 of file virtualFile.cxx.
References Filename::get_basename(), is_directory(), ls_all(), and scan_directory().
Referenced by scan_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 211 of file virtualFile.cxx.
References is_directory(), and open_read_file().
Referenced by ls().
|
virtual |
Works like open_write_file(), but the file is opened in append mode.
Like open_write_file, the returned pointer should eventually be passed to close_write_file().
Reimplemented in VirtualFileSimple.
Definition at line 283 of file virtualFile.cxx.
References close_write_file().
Referenced by VirtualFileSystem::open_append_file(), and open_write_file().
|
virtual |
Works like open_read_write_file(), but the file is opened in append mode.
Like open_read_write_file, the returned pointer should eventually be passed to close_read_write_file().
Reimplemented in VirtualFileSimple.
Definition at line 323 of file virtualFile.cxx.
References close_read_write_file().
Referenced by VirtualFileSystem::open_read_append_file(), and open_read_write_file().
|
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 228 of file virtualFile.cxx.
References close_read_file().
Referenced by FmodAudioSound::get_finished_event(), ls_all(), and VirtualFileSystem::open_read_file().
|
virtual |
Opens the file for writing.
Returns a newly allocated iostream on success (which you should eventually delete when you are done writing). Returns NULL on failure.
Reimplemented in VirtualFileSimple.
Definition at line 310 of file virtualFile.cxx.
References open_read_append_file().
Referenced by close_write_file(), and VirtualFileSystem::open_read_write_file().
|
virtual |
Opens the file for writing.
Returns a newly allocated ostream on success (which you should eventually delete when you are done writing). Returns NULL on failure.
Reimplemented in VirtualFileSimple.
Definition at line 270 of file virtualFile.cxx.
References open_append_file().
Referenced by VirtualFileSimple::copy_file(), VirtualFileSystem::open_write_file(), and was_read_successful().
|
inline |
Returns the entire contents of the file as a string.
Definition at line 43 of file virtualFile.I.
References write_file().
Referenced by atomic_read_contents(), get_original_filename(), and 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 430 of file virtualFile.cxx.
References read_file().
|
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 453 of file virtualFile.cxx.
References write_file().
|
virtual |
Attempts to move or rename this file or directory.
If the original file is an ordinary file, it will quietly replace any already-existing file in the new filename (but not a directory). If the original file is a directory, the new filename must not already exist.
If the file is a directory, the new filename must be within the same mount point. If the file is an ordinary file, the new filename may be anywhere; but if it is not within the same mount point then the rename operation is automatically performed as a two-step copy-and-delete operation.
Reimplemented in VirtualFileSimple.
Definition at line 99 of file virtualFile.cxx.
References copy_file().
Referenced by delete_file().
PointerTo< VirtualFileList > VirtualFile::scan_directory | ( | ) | const |
If the file represents a directory (that is, is_directory() returns true), this returns the list of files within the directory at the current time.
Returns NULL if the file is not a directory or if the directory cannot be read.
Definition at line 125 of file virtualFile.cxx.
References ordered_vector< Key, Compare, Vector >::begin(), ordered_vector< Key, Compare, Vector >::end(), VirtualFileSystem::get_file(), ls(), VirtualFileSystem::scan_mount_points(), and ov_set< Key, Compare, Vector >::sort().
Referenced by copy_file(), VirtualFileSystem::is_regular_file(), ls(), and simple_read_file().
|
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 69 of file virtualFile.I.
Referenced by VirtualFileSystem::parse_option(), and write_file().
|
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 477 of file virtualFile.cxx.
Referenced by VirtualFileMount::read_file(), Multifile::read_subfile(), and write_file().
|
static |
As in simple_read_file() with two parameters, above, but only reads up to max_bytes bytes from the file.
Definition at line 500 of file virtualFile.cxx.
References is_directory(), Filename::make_relative_to(), and scan_directory().
|
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 257 of file virtualFile.cxx.
References open_write_file().
Referenced by close_read_file().
|
inline |
Writes the entire contents of the file as a string, if it is writable.
Definition at line 56 of file virtualFile.I.
References set_original_filename().
Referenced by read_file().
|
virtual |
Writes the indicated data to the file, if it is writable.
Returns true on success, false otherwise.
Reimplemented in VirtualFileSimple.
Definition at line 464 of file virtualFile.cxx.
References simple_read_file().