Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
VirtualFileSimple Class Reference

A simple file or directory within the VirtualFileSystem: this maps to exactly one file on one mount point. More...

#include "virtualFileSimple.h"

Inheritance diagram for VirtualFileSimple:
VirtualFile TypedReferenceCount TypedObject ReferenceCount MemoryBase MemoryBase

Public Member Functions

 VirtualFileSimple (VirtualFileMount *mount, const Filename &local_filename, bool implicit_pz_file, int open_flags)
 
virtual bool atomic_compare_and_exchange_contents (std::string &orig_contents, const std::string &old_contents, const std::string &new_contents)
 See Filename::atomic_compare_and_exchange_contents().
 
virtual bool atomic_read_contents (std::string &contents) const
 See Filename::atomic_read_contents().
 
virtual void close_read_file (std::istream *stream) const
 Closes a file opened by a previous call to open_read_file().
 
virtual void close_read_write_file (std::iostream *stream)
 Closes a file opened by a previous call to open_read_write_file().
 
virtual void close_write_file (std::ostream *stream)
 Closes a file opened by a previous call to open_write_file().
 
virtual bool copy_file (VirtualFile *new_file)
 Attempts to copy the contents of this file to the indicated file.
 
virtual bool delete_file ()
 Attempts to delete this file or directory.
 
virtual TypeHandle force_init_type ()
 
virtual std::streamsize get_file_size () const
 Returns the current size on disk (or wherever it is) of the file before it has been opened.
 
virtual std::streamsize get_file_size (std::istream *stream) const
 Returns the current size on disk (or wherever it is) of the already-open file.
 
virtual VirtualFileSystemget_file_system () const
 Returns the VirtualFileSystem this file is associated with.
 
virtual Filename get_filename () const
 Returns the full pathname to this file within the virtual file system.
 
VirtualFileMountget_mount () const
 Returns the VirtualFileMount this file is associated with.
 
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.
 
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.
 
bool is_implicit_pz_file () const
 Returns true if this file is a .pz file that should be implicitly decompressed on load, or false if it is not a .pz file or if it should not be decompressed.
 
virtual bool is_regular_file () const
 Returns true if this file represents a regular file (and read_file() may be called), false otherwise.
 
virtual bool is_writable () const
 Returns true if this file represents a writable regular file (and write_file() may be called), false otherwise.
 
virtual std::ostream * open_append_file ()
 Works like open_write_file(), but the file is opened in append mode.
 
virtual std::iostream * open_read_append_file ()
 Works like open_read_write_file(), but the file is opened in append mode.
 
virtual std::istream * open_read_file (bool auto_unwrap) const
 Opens the file for reading.
 
virtual std::iostream * open_read_write_file (bool truncate)
 Opens the file for writing.
 
virtual std::ostream * open_write_file (bool auto_wrap, bool truncate)
 Opens the file for writing.
 
virtual bool read_file (vector_uchar &result, bool auto_unwrap) const
 Fills up the indicated pvector with the contents of the file, if it is a regular file.
 
virtual bool rename_file (VirtualFile *new_file)
 Attempts to move or rename this file or directory.
 
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.
 
- Public Member Functions inherited from VirtualFile
const Filenameget_original_filename () const
 Returns the original filename as it was used to locate this VirtualFile.
 
void ls (std::ostream &out=std::cout) const
 If the file represents a directory, lists its contents.
 
void ls_all (std::ostream &out=std::cout) const
 If the file represents a directory, recursively lists its contents and those of all subdirectories.
 
void output (std::ostream &out) const
 
std::string read_file (bool auto_unwrap) const
 Returns the entire contents of the file as a string.
 
bool read_file (std::string &result, bool auto_unwrap) const
 Fills up the indicated string with the contents of the file, if it is a regular file.
 
PointerTo< VirtualFileListscan_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.
 
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.
 
bool write_file (const std::string &data, bool auto_wrap)
 Writes the entire contents of the file as a string, if it is writable.
 
- Public Member Functions inherited from TypedReferenceCount
 TypedReferenceCount (const TypedReferenceCount &copy)
 
void operator= (const TypedReferenceCount &copy)
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer.
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer.
 
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.
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from MemoryBase
void operator delete (void *, void *)
 
void operator delete (void *ptr)
 
void operator delete[] (void *, void *)
 
void operator delete[] (void *ptr)
 
void * operator new (size_t size)
 
void * operator new (size_t size, void *ptr)
 
void * operator new[] (size_t size)
 
void * operator new[] (size_t size, void *ptr)
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object.
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack.
 
void ref () const
 Explicitly increments the reference count.
 
bool ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero.
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus.
 
virtual bool unref () const
 Explicitly decrements the reference count.
 
bool unref_if_one () const
 Atomically decreases the reference count of this object if it is one.
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object.
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object.
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from VirtualFile
static TypeHandle get_class_type ()
 
static void init_type ()
 
static bool simple_read_file (std::istream *stream, vector_uchar &result)
 Fills up the indicated pvector with the contents of the just-opened file.
 
static bool simple_read_file (std::istream *stream, vector_uchar &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.
 
- Static Public Member Functions inherited from TypedReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
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 Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 

Additional Inherited Members

- Public Attributes inherited from TypedObject
 get_type
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count.
 

Detailed Description

A simple file or directory within the VirtualFileSystem: this maps to exactly one file on one mount point.

Most directories, and all regular files, are of this kind.

Definition at line 26 of file virtualFileSimple.h.

Constructor & Destructor Documentation

◆ VirtualFileSimple()

VirtualFileSimple::VirtualFileSimple ( VirtualFileMount * mount,
const Filename & local_filename,
bool implicit_pz_file,
int open_flags )
inline

Definition at line 17 of file virtualFileSimple.I.

Member Function Documentation

◆ atomic_compare_and_exchange_contents()

bool VirtualFileSimple::atomic_compare_and_exchange_contents ( std::string & orig_contents,
const std::string & old_contents,
const std::string & new_contents )
virtual

See Filename::atomic_compare_and_exchange_contents().

Reimplemented from VirtualFile.

Definition at line 360 of file virtualFileSimple.cxx.

References VirtualFileMount::atomic_compare_and_exchange_contents().

◆ atomic_read_contents()

bool VirtualFileSimple::atomic_read_contents ( std::string & contents) const
virtual

See Filename::atomic_read_contents().

Reimplemented from VirtualFile.

Definition at line 370 of file virtualFileSimple.cxx.

References VirtualFileMount::atomic_read_contents().

◆ close_read_file()

void VirtualFileSimple::close_read_file ( std::istream * stream) const
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 from VirtualFile.

Definition at line 231 of file virtualFileSimple.cxx.

References VirtualFileMount::close_read_file().

Referenced by copy_file().

◆ close_read_write_file()

void VirtualFileSimple::close_read_write_file ( std::iostream * stream)
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 from VirtualFile.

Definition at line 306 of file virtualFileSimple.cxx.

References VirtualFileMount::close_read_write_file().

◆ close_write_file()

void VirtualFileSimple::close_write_file ( std::ostream * stream)
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 from VirtualFile.

Definition at line 275 of file virtualFileSimple.cxx.

References VirtualFileMount::close_write_file().

◆ copy_file()

bool VirtualFileSimple::copy_file ( VirtualFile * new_file)
virtual

Attempts to copy the contents of this file to the indicated file.

Returns true on success, false on failure.

Reimplemented from VirtualFile.

Definition at line 143 of file virtualFileSimple.cxx.

References close_read_file(), VirtualFile::close_write_file(), VirtualFileMount::copy_file(), VirtualFile::delete_file(), TypedObject::is_of_type(), open_read_file(), and VirtualFile::open_write_file().

Referenced by rename_file().

◆ delete_file()

bool VirtualFileSimple::delete_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 from VirtualFile.

Definition at line 97 of file virtualFileSimple.cxx.

References VirtualFileMount::delete_file().

Referenced by rename_file().

◆ force_init_type()

virtual TypeHandle VirtualFileSimple::force_init_type ( )
inlinevirtual

Reimplemented from VirtualFile.

Definition at line 82 of file virtualFileSimple.h.

◆ get_class_type()

static TypeHandle VirtualFileSimple::get_class_type ( )
inlinestatic

Definition at line 85 of file virtualFileSimple.h.

◆ get_file_size() [1/2]

std::streamsize VirtualFileSimple::get_file_size ( ) const
virtual

Returns the current size on disk (or wherever it is) of the file before it has been opened.

Reimplemented from VirtualFile.

Definition at line 325 of file virtualFileSimple.cxx.

◆ get_file_size() [2/2]

std::streamsize VirtualFileSimple::get_file_size ( std::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 from VirtualFile.

Definition at line 316 of file virtualFileSimple.cxx.

◆ get_file_system()

VirtualFileSystem * VirtualFileSimple::get_file_system ( ) const
virtual

Returns the VirtualFileSystem this file is associated with.

Implements VirtualFile.

Definition at line 30 of file virtualFileSimple.cxx.

References VirtualFileMount::get_file_system().

◆ get_filename()

Filename VirtualFileSimple::get_filename ( ) const
virtual

Returns the full pathname to this file within the virtual file system.

Implements VirtualFile.

Definition at line 38 of file virtualFileSimple.cxx.

References Filename::get_fullpath(), and VirtualFileMount::get_mount_point().

◆ get_mount()

VirtualFileMount * VirtualFileSimple::get_mount ( ) const
inline

Returns the VirtualFileMount this file is associated with.

Definition at line 29 of file virtualFileSimple.I.

◆ get_system_info()

bool VirtualFileSimple::get_system_info ( SubfileInfo & info)
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 from VirtualFile.

Definition at line 352 of file virtualFileSimple.cxx.

References VirtualFileMount::get_system_info().

◆ get_timestamp()

time_t VirtualFileSimple::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 from VirtualFile.

Definition at line 340 of file virtualFileSimple.cxx.

◆ get_type()

virtual TypeHandle VirtualFileSimple::get_type ( ) const
inlinevirtual

Reimplemented from VirtualFile.

Definition at line 79 of file virtualFileSimple.h.

◆ has_file()

bool VirtualFileSimple::has_file ( ) const
virtual

Returns true if this file exists, false otherwise.

Reimplemented from VirtualFile.

Definition at line 60 of file virtualFileSimple.cxx.

◆ init_type()

static void VirtualFileSimple::init_type ( )
inlinestatic

Definition at line 90 of file virtualFileSimple.h.

◆ is_directory()

bool VirtualFileSimple::is_directory ( ) const
virtual

Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.

Reimplemented from VirtualFile.

Definition at line 69 of file virtualFileSimple.cxx.

◆ is_implicit_pz_file()

bool VirtualFileSimple::is_implicit_pz_file ( ) const
inline

Returns true if this file is a .pz file that should be implicitly decompressed on load, or false if it is not a .pz file or if it should not be decompressed.

Definition at line 39 of file virtualFileSimple.I.

◆ is_regular_file()

bool VirtualFileSimple::is_regular_file ( ) const
virtual

Returns true if this file represents a regular file (and read_file() may be called), false otherwise.

Reimplemented from VirtualFile.

Definition at line 78 of file virtualFileSimple.cxx.

Referenced by rename_file().

◆ is_writable()

bool VirtualFileSimple::is_writable ( ) const
virtual

Returns true if this file represents a writable regular file (and write_file() may be called), false otherwise.

Reimplemented from VirtualFile.

Definition at line 87 of file virtualFileSimple.cxx.

References VirtualFileMount::is_writable().

◆ open_append_file()

ostream * VirtualFileSimple::open_append_file ( )
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 from VirtualFile.

Definition at line 264 of file virtualFileSimple.cxx.

References VirtualFileMount::open_append_file().

◆ open_read_append_file()

iostream * VirtualFileSimple::open_read_append_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 from VirtualFile.

Definition at line 295 of file virtualFileSimple.cxx.

References VirtualFileMount::open_read_append_file().

◆ open_read_file()

istream * VirtualFileSimple::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.

If auto_unwrap is true, an explicitly-named .pz/.gz file is automatically decompressed and the decompressed contents are returned. This is different than vfs-implicit-pz, which will automatically decompress a file if the extension .pz is *not* given.

Reimplemented from VirtualFile.

Definition at line 208 of file virtualFileSimple.cxx.

References Filename::get_extension(), and Filename::set_binary().

Referenced by copy_file().

◆ open_read_write_file()

iostream * VirtualFileSimple::open_read_write_file ( bool truncate)
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 from VirtualFile.

Definition at line 285 of file virtualFileSimple.cxx.

References VirtualFileMount::open_read_write_file().

◆ open_write_file()

ostream * VirtualFileSimple::open_write_file ( bool auto_wrap,
bool truncate )
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.

If auto_wrap is true, an explicitly-named .pz file is automatically compressed while writing. If truncate is true, the file is truncated to zero length before writing.

Reimplemented from VirtualFile.

Definition at line 245 of file virtualFileSimple.cxx.

References Filename::get_extension(), VirtualFileMount::open_write_file(), and Filename::set_binary().

◆ read_file()

bool VirtualFileSimple::read_file ( vector_uchar & 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 from VirtualFile.

Definition at line 379 of file virtualFileSimple.cxx.

References Filename::get_extension(), VirtualFileMount::read_file(), and Filename::set_binary().

◆ rename_file()

bool VirtualFileSimple::rename_file ( VirtualFile * new_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 from VirtualFile.

Definition at line 113 of file virtualFileSimple.cxx.

References copy_file(), VirtualFile::delete_file(), delete_file(), VirtualFile::is_directory(), TypedObject::is_of_type(), is_regular_file(), and VirtualFileMount::rename_file().

◆ write_file()

bool VirtualFileSimple::write_file ( const unsigned char * data,
size_t data_size,
bool auto_wrap )
virtual

Writes the indicated data to the file, if it is writable.

Returns true on success, false otherwise.

Reimplemented from VirtualFile.

Definition at line 400 of file virtualFileSimple.cxx.

References Filename::get_extension(), Filename::set_binary(), and VirtualFileMount::write_file().


The documentation for this class was generated from the following files: