Panda3D
Public Member Functions | Static Public Member Functions | List of all members
VirtualFileMountSystem Class Reference

Maps an actual OS directory into the VirtualFileSystem. More...

#include "virtualFileMountSystem.h"

Inheritance diagram for VirtualFileMountSystem:
VirtualFileMount TypedReferenceCount TypedObject ReferenceCount MemoryBase MemoryBase

Public Member Functions

 VirtualFileMountSystem (const Filename &physical_filename)
 
virtual bool atomic_compare_and_exchange_contents (const Filename &file, std::string &orig_contents, const std::string &old_contents, const std::string &new_contents)
 See Filename::atomic_compare_and_exchange_contents(). More...
 
virtual bool atomic_read_contents (const Filename &file, std::string &contents) const
 See Filename::atomic_read_contents(). More...
 
virtual bool copy_file (const Filename &orig_filename, const Filename &new_filename)
 Attempts to copy the contents of the indicated file to the indicated file. More...
 
virtual bool create_file (const Filename &file)
 Attempts to create the indicated file within the mount, if it does not already exist. More...
 
virtual bool delete_file (const Filename &file)
 Attempts to delete the indicated file or directory within the mount. More...
 
virtual TypeHandle force_init_type ()
 
virtual std::streamsize get_file_size (const Filename &file, std::istream *stream) const
 Returns the current size on disk (or wherever it is) of the already-open file. More...
 
virtual std::streamsize get_file_size (const Filename &file) const
 Returns the current size on disk (or wherever it is) of the file before it has been opened. More...
 
const Filenameget_physical_filename () const
 Returns the name of the source file on the OS filesystem of the directory or file that is mounted. More...
 
virtual bool get_system_info (const Filename &file, 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 Filename &file) 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 Filename &file) const
 Returns true if the indicated file exists within the mount system. More...
 
virtual bool is_directory (const Filename &file) const
 Returns true if the indicated file exists within the mount system and is a directory. More...
 
virtual bool is_regular_file (const Filename &file) const
 Returns true if the indicated file exists within the mount system and is a regular file. More...
 
virtual bool is_writable (const Filename &file) const
 Returns true if the named file or directory may be written to, false otherwise. More...
 
virtual bool make_directory (const Filename &file)
 Attempts to create the indicated file within the mount, if it does not already exist. More...
 
virtual std::ostream * open_append_file (const Filename &file)
 Works like open_write_file(), but the file is opened in append mode. More...
 
virtual std::iostream * open_read_append_file (const Filename &file)
 Works like open_read_write_file(), but the file is opened in append mode. More...
 
virtual std::istream * open_read_file (const Filename &file) const
 Opens the file for reading, if it exists. More...
 
virtual std::iostream * open_read_write_file (const Filename &file, bool truncate)
 Opens the file for writing. More...
 
virtual std::ostream * open_write_file (const Filename &file, bool truncate)
 Opens the file for writing. More...
 
virtual void output (std::ostream &out) const
 
virtual bool rename_file (const Filename &orig_filename, const Filename &new_filename)
 Attempts to rename the contents of the indicated file to the indicated file. More...
 
virtual bool scan_directory (vector_string &contents, const Filename &dir) const
 Fills the given vector up with the list of filenames that are local to this directory, if the filename is a directory. More...
 
- Public Member Functions inherited from VirtualFileMount
virtual void close_read_file (std::istream *stream) const
 Closes a file opened by a previous call to open_read_file(). More...
 
virtual void close_read_write_file (std::iostream *stream)
 Closes a file opened by a previous call to open_read_write_file(). More...
 
virtual void close_write_file (std::ostream *stream)
 Closes a file opened by a previous call to open_write_file(). More...
 
VirtualFileSystemget_file_system () const
 Returns the file system this mount object is attached to. More...
 
int get_mount_flags () const
 Returns the set of flags passed by the user to the VirtualFileSystem::mount() command. More...
 
const Filenameget_mount_point () const
 Returns the name of the directory within the virtual file system that this mount object is attached to. More...
 
virtual PointerTo< VirtualFilemake_virtual_file (const Filename &local_filename, const Filename &original_filename, bool implicit_pz_file, int open_flags)
 Constructs and returns a new VirtualFile instance that corresponds to the indicated filename within this mount point. More...
 
std::istream * open_read_file (const Filename &file, bool do_uncompress) const
 Opens the file for reading. More...
 
std::ostream * open_write_file (const Filename &file, bool do_compress, bool truncate)
 Opens the file for writing. More...
 
virtual bool read_file (const Filename &file, bool do_uncompress, vector_uchar &result) const
 Fills up the indicated pvector with the contents of the file, if it is a regular file. More...
 
virtual void write (std::ostream &out) const
 
virtual bool write_file (const Filename &file, bool do_compress, const unsigned char *data, size_t data_size)
 Writes the indicated data to the file, if it is a writable file. More...
 
- 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. More...
 
const TypedObjectas_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...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
WeakReferenceListget_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 ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. 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...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 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 Public Member Functions inherited from VirtualFileMount
static TypeHandle get_class_type ()
 
static void init_type ()
 
- 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. More...
 
- 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. More...
 

Detailed Description

Maps an actual OS directory into the VirtualFileSystem.

Definition at line 24 of file virtualFileMountSystem.h.

Member Function Documentation

◆ atomic_compare_and_exchange_contents()

bool VirtualFileMountSystem::atomic_compare_and_exchange_contents ( const Filename file,
std::string &  orig_contents,
const std::string &  old_contents,
const std::string &  new_contents 
)
virtual

◆ atomic_read_contents()

bool VirtualFileMountSystem::atomic_read_contents ( const Filename file,
std::string &  contents 
) const
virtual

◆ copy_file()

bool VirtualFileMountSystem::copy_file ( const Filename orig_filename,
const Filename new_filename 
)
virtual

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

Both filenames will be within the mount. Returns true on success, false on failure. If this returns false, the copy will be performed by explicit read-and-write operations.

Reimplemented from VirtualFileMount.

Definition at line 94 of file virtualFileMountSystem.cxx.

References Filename::copy_to().

◆ create_file()

bool VirtualFileMountSystem::create_file ( const Filename file)
virtual

Attempts to create the indicated file within the mount, if it does not already exist.

Returns true on success (or if the file already exists), or false if it cannot be created.

Reimplemented from VirtualFileMount.

Definition at line 56 of file virtualFileMountSystem.cxx.

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

◆ delete_file()

bool VirtualFileMountSystem::delete_file ( const Filename file)
virtual

Attempts to delete the indicated file or directory within the mount.

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 VirtualFileMount.

Definition at line 69 of file virtualFileMountSystem.cxx.

References Filename::rmdir(), and Filename::unlink().

◆ get_file_size() [1/2]

streamsize VirtualFileMountSystem::get_file_size ( const Filename file,
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.

Implements VirtualFileMount.

Definition at line 302 of file virtualFileMountSystem.cxx.

◆ get_file_size() [2/2]

streamsize VirtualFileMountSystem::get_file_size ( const Filename file) const
virtual

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

Implements VirtualFileMount.

Definition at line 329 of file virtualFileMountSystem.cxx.

References Filename::get_file_size().

◆ get_physical_filename()

const Filename & VirtualFileMountSystem::get_physical_filename ( ) const
inline

Returns the name of the source file on the OS filesystem of the directory or file that is mounted.

Definition at line 28 of file virtualFileMountSystem.I.

◆ get_system_info()

bool VirtualFileMountSystem::get_system_info ( const Filename file,
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 VirtualFileMount.

Definition at line 358 of file virtualFileMountSystem.cxx.

◆ get_timestamp()

time_t VirtualFileMountSystem::get_timestamp ( const Filename file) 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.

Implements VirtualFileMount.

Definition at line 345 of file virtualFileMountSystem.cxx.

References Filename::get_timestamp().

◆ has_file()

bool VirtualFileMountSystem::has_file ( const Filename file) const
virtual

◆ is_directory()

bool VirtualFileMountSystem::is_directory ( const Filename file) const
virtual

Returns true if the indicated file exists within the mount system and is a directory.

Implements VirtualFileMount.

Definition at line 117 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), has_file(), and Filename::is_directory().

◆ is_regular_file()

bool VirtualFileMountSystem::is_regular_file ( const Filename file) const
virtual

Returns true if the indicated file exists within the mount system and is a regular file.

Implements VirtualFileMount.

Definition at line 135 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), has_file(), and Filename::is_regular_file().

◆ is_writable()

bool VirtualFileMountSystem::is_writable ( const Filename file) const
virtual

Returns true if the named file or directory may be written to, false otherwise.

Reimplemented from VirtualFileMount.

Definition at line 153 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), has_file(), and Filename::is_writable().

◆ make_directory()

bool VirtualFileMountSystem::make_directory ( const Filename file)
virtual

Attempts to create the indicated file within the mount, if it does not already exist.

Returns true on success, or false if it cannot be created. If the directory already existed prior to this call, may return either true or false.

Reimplemented from VirtualFileMount.

Definition at line 107 of file virtualFileMountSystem.cxx.

References Filename::mkdir().

◆ open_append_file()

ostream * VirtualFileMountSystem::open_append_file ( const Filename 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 VirtualFileMount.

Definition at line 224 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), and has_file().

◆ open_read_append_file()

iostream * VirtualFileMountSystem::open_read_append_file ( const Filename 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 VirtualFileMount.

Definition at line 276 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), and has_file().

◆ open_read_file()

istream * VirtualFileMountSystem::open_read_file ( const Filename file) const
virtual

Opens the file for reading, if it exists.

Returns a newly allocated istream on success (which you should eventually delete when you are done reading). Returns NULL on failure.

Implements VirtualFileMount.

Definition at line 172 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), and has_file().

◆ open_read_write_file()

iostream * VirtualFileMountSystem::open_read_write_file ( const Filename 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 VirtualFileMount.

Definition at line 250 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), and has_file().

◆ open_write_file()

ostream * VirtualFileMountSystem::open_write_file ( const Filename file,
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.

Reimplemented from VirtualFileMount.

Definition at line 198 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), and has_file().

◆ rename_file()

bool VirtualFileMountSystem::rename_file ( const Filename orig_filename,
const Filename new_filename 
)
virtual

Attempts to rename the contents of the indicated file to the indicated file.

Both filenames will be within the mount. Returns true on success, false on failure. If this returns false, this will be attempted again with a copy-and-delete operation.

Reimplemented from VirtualFileMount.

Definition at line 81 of file virtualFileMountSystem.cxx.

References Filename::rename_to().

◆ scan_directory()

bool VirtualFileMountSystem::scan_directory ( vector_string &  contents,
const Filename dir 
) const
virtual

Fills the given vector up with the list of filenames that are local to this directory, if the filename is a directory.

Returns true if successful, or false if the file is not a directory or cannot be read.

Implements VirtualFileMount.

Definition at line 370 of file virtualFileMountSystem.cxx.

References VirtualFileSystem::get_global_ptr(), has_file(), and Filename::scan_directory().


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