The name of a file, such as a texture file or an Egg file. More...
#include "filename.h"
Public Types | |
enum | Flags { F_type = 0x0f, F_binary = 0x10, F_text = 0x20, F_pattern = 0x40 } |
enum | Type { T_general = 0x00, T_dso = 0x01, T_executable = 0x02 } |
Public Member Functions | |
Filename (const char *filename) | |
Filename (const std::string &filename) | |
Filename (const std::wstring &filename) | |
Filename (const Filename ©) | |
Filename (std::string &&filename) noexcept | |
Filename (Filename &&from) noexcept | |
Filename () | |
Creates an empty Filename. More... | |
Filename (const Filename &dirname, const Filename &basename) | |
This constructor composes the filename out of a directory part and a basename part. More... | |
bool | __nonzero__ () const |
Returns true if the Filename is valid (not empty), or false if it is an empty string. More... | |
bool | atomic_compare_and_exchange_contents (std::string &orig_contents, const std::string &old_contents, const std::string &new_contents) const |
Uses native file-locking mechanisms to atomically replace the contents of a (small) file with the specified contents, assuming it hasn't changed since the last time the file was read. More... | |
bool | atomic_read_contents (std::string &contents) const |
Uses native file-locking mechanisms to atomically read the contents of a (small) file. More... | |
const char * | c_str () const |
bool | chdir () const |
Changes directory to the specified location. More... | |
int | compare_timestamps (const Filename &other, bool this_missing_is_old=true, bool other_missing_is_old=true) const |
Returns a number less than zero if the file named by this object is older than the given file, zero if they have the same timestamp, or greater than zero if this one is newer. More... | |
int | compare_to (const Filename &other) const |
bool | copy_to (const Filename &other) const |
Copies the file to the indicated new filename, by reading the contents and writing it to the new file. More... | |
bool | empty () const |
bool | exists () const |
Returns true if the filename exists on the disk, false otherwise. More... | |
void | extract_components (vector_string &components) const |
Extracts out the individual directory components of the path into a series of strings. More... | |
int | find_on_searchpath (const DSearchPath &searchpath) |
Performs the reverse of the resolve_filename() operation: assuming that the current filename is fully-specified pathname (i.e. More... | |
time_t | get_access_timestamp () const |
Returns a time_t value that represents the time the file was last accessed, if this information is available. More... | |
std::string | get_basename () const |
Returns the basename part of the filename. More... | |
std::string | get_basename_wo_extension () const |
Returns the basename part of the filename, without the file extension. More... | |
std::string | get_dirname () const |
Returns the directory part of the filename. More... | |
std::string | get_extension () const |
Returns the file extension. More... | |
std::streamsize | get_file_size () const |
Returns the size of the file in bytes, or 0 if there is an error. More... | |
Filename | get_filename_index (int index) const |
If the pattern flag is set for this Filename and the filename string actually includes a sequence of hash marks, then this returns a new Filename with the sequence of hash marks replaced by the indicated index number. More... | |
std::string | get_fullpath () const |
Returns the entire filename: directory, basename, extension. More... | |
std::wstring | get_fullpath_w () const |
Returns the entire filename as a wide-character string. More... | |
std::string | get_fullpath_wo_extension () const |
Returns the full filename–directory and basename parts–except for the extension. More... | |
int | get_hash () const |
Returns a hash code that attempts to be mostly unique for different Filenames. More... | |
std::string | get_hash_to_end () const |
Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end of the filename. More... | |
bool | get_pattern () const |
Returns the flag indicating whether this is a filename pattern. More... | |
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... | |
Type | get_type () const |
Returns the type of the file represented by the filename, as previously set by set_type(). More... | |
bool | has_hash () const |
Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was called), and the filename pattern did include a sequence of hash marks, or false if it was not a filename pattern or did not include hash marks. More... | |
bool | is_binary () const |
Returns true if the Filename has been indicated to represent a binary file via a previous call to set_binary(). More... | |
bool | is_binary_or_text () const |
Returns true either is_binary() or is_text() is true; that is, that the filename has been specified as either binary or text. More... | |
bool | is_directory () const |
Returns true if the filename exists and is a directory name, false otherwise. More... | |
bool | is_executable () const |
Returns true if the filename exists and is executable. More... | |
bool | is_fully_qualified () const |
Returns true if the filename is fully qualified, e.g. More... | |
bool | is_local () const |
Returns true if the filename is local, e.g. More... | |
bool | is_regular_file () const |
Returns true if the filename exists and is the name of a regular file (i.e. More... | |
bool | is_text () const |
Returns true if the Filename has been indicated to represent a text file via a previous call to set_text(). More... | |
bool | is_writable () const |
Returns true if the filename exists and is either a directory or a regular file that can be written to, or false otherwise. More... | |
size_t | length () const |
void | make_absolute () |
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname), and then standardizes it (see standardize()). More... | |
void | make_absolute (const Filename &start_directory) |
Converts the filename to a fully-qualified filename from the root (if it is a relative filename), and then standardizes it (see standardize()). More... | |
bool | make_canonical () |
Converts this filename to a canonical name by replacing the directory part with the fully-qualified directory part. More... | |
bool | make_dir () const |
Creates all the directories in the path to the file specified in the filename, except for the basename itself. More... | |
bool | make_relative_to (Filename directory, bool allow_backups=true) |
Adjusts this filename, which must be a fully-specified pathname beginning with a slash, to make it a relative filename, relative to the fully- specified directory indicated (which must also begin with, and may or may not end with, a slash–a terminating slash is ignored). More... | |
bool | make_true_case () |
On a case-insensitive operating system (e.g. More... | |
bool | mkdir () const |
Creates the directory named by this filename. More... | |
bool | open_append (std::ofstream &stream) const |
Opens the indicated ofstream for writing the file, if possible. More... | |
bool | open_read (std::ifstream &stream) const |
Opens the indicated ifstream for reading the file, if possible. More... | |
bool | open_read_append (std::fstream &stream) const |
Opens the indicated ifstream for reading and writing the file, if possible; writes are appended to the end of the file. More... | |
bool | open_read_write (std::fstream &stream, bool truncate=false) const |
Opens the indicated fstream for read/write access to the file, if possible. More... | |
bool | open_write (std::ofstream &stream, bool truncate=true) const |
Opens the indicated ifstream for writing the file, if possible. More... | |
bool | operator != (const std::string &other) const |
char | operator [] (size_t n) const |
operator const std::string & () const | |
Filename | operator+ (const std::string &other) const |
Returns a new Filename representing the concatenation of the two filenames. More... | |
void | operator+= (const std::string &other) |
Appends the other filename onto the end of this one. More... | |
Filename | operator/ (const Filename &other) const |
Returns a new Filename that is composed of the other filename added to the end of this filename, with an intervening slash added if necessary. More... | |
bool | operator< (const std::string &other) const |
Filename & | operator= (const std::string &filename) |
Filename & | operator= (const std::wstring &filename) |
Filename & | operator= (const char *filename) |
Filename & | operator= (const Filename ©) |
Filename & | operator= (std::string &&filename) noexcept |
Filename & | operator= (Filename &&from) noexcept |
bool | operator== (const std::string &other) const |
void | output (std::ostream &out) const |
bool | rename_to (const Filename &other) const |
Renames the file to the indicated new filename. More... | |
bool | resolve_filename (const DSearchPath &searchpath, const std::string &default_extension=std::string()) |
Searches the given search path for the filename. More... | |
bool | rmdir () const |
The inverse of mkdir(): this removes the directory named by this Filename, if it is in fact a directory. More... | |
bool | scan_directory (vector_string &contents) const |
Attempts to open the named filename as if it were a directory and looks for the non-hidden files within the directory. More... | |
void | set_basename (const std::string &s) |
Replaces the basename part of the filename. More... | |
void | set_basename_wo_extension (const std::string &s) |
Replaces the basename part of the filename, without the file extension. More... | |
void | set_binary () |
Indicates that the filename represents a binary file. More... | |
void | set_dirname (const std::string &s) |
Replaces the directory part of the filename. More... | |
void | set_extension (const std::string &s) |
Replaces the file extension. More... | |
void | set_fullpath (const std::string &s) |
Replaces the entire filename: directory, basename, extension. More... | |
void | set_fullpath_wo_extension (const std::string &s) |
Replaces the full filename–directory and basename parts–except for the extension. More... | |
void | set_hash_to_end (const std::string &s) |
Replaces the part of the filename from the beginning of the hash sequence to the end of the filename. More... | |
void | set_pattern (bool pattern) |
Sets the flag indicating whether this is a filename pattern. More... | |
void | set_text () |
Indicates that the filename represents a text file. More... | |
void | set_type (Type type) |
Sets the type of the file represented by the filename. More... | |
void | standardize () |
Converts the filename to standard form by replacing consecutive slashes with a single slash, removing a trailing slash if present, and backing up over . More... | |
std::string | substr (size_t begin) const |
std::string | substr (size_t begin, size_t end) const |
std::string | to_os_generic () const |
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood on as many platforms as possible. More... | |
std::string | to_os_long_name () const |
This is the opposite of to_os_short_name(): it returns the "long name" of the filename, if the filename exists. More... | |
std::string | to_os_short_name () const |
This works like to_os_generic(), but it returns the "short name" version of the filename, if it exists, or the original filename otherwise. More... | |
std::string | to_os_specific () const |
Converts the filename from our generic Unix-like convention (forward slashes starting with the root at '/') to the corresponding filename in the local operating system (slashes in the appropriate direction, starting with the root at C:\, for instance). More... | |
std::wstring | to_os_specific_w () const |
The wide-string variant on to_os_specific(). More... | |
bool | touch () const |
Updates the modification time of the file to the current time. More... | |
bool | unlink () const |
Permanently deletes the file associated with the filename, if possible. More... | |
Static Public Member Functions | |
static Filename | binary_filename (const Filename &filename) |
static Filename | binary_filename (const std::string &filename) |
static Filename | dso_filename (const std::string &filename) |
static Filename | executable_filename (const std::string &filename) |
static Filename | expand_from (const std::string &user_string, Type type=T_general) |
Returns the same thing as from_os_specific(), but embedded environment variable references (e.g. More... | |
static Filename | from_os_specific (const std::string &os_specific, Type type=T_general) |
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon). More... | |
static Filename | from_os_specific_w (const std::wstring &os_specific, Type type=T_general) |
The wide-string variant of from_os_specific(). More... | |
static TypeHandle | get_class_type () |
static const Filename & | get_common_appdata_directory () |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, common to all users. More... | |
static TextEncoder::Encoding | get_filesystem_encoding () |
Specifies the default encoding to be used for all subsequent Filenames objects. More... | |
static const Filename & | get_home_directory () |
Returns a path to the user's home directory, if such a thing makes sense in the current OS, or to the nearest equivalent. More... | |
static const Filename & | get_temp_directory () |
Returns a path to a system-defined temporary directory. More... | |
static const Filename & | get_user_appdata_directory () |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, specific to the current user. More... | |
static void | init_type () |
static Filename | pattern_filename (const std::string &filename) |
Constructs a filename that represents a sequence of numbered files. More... | |
static void | set_filesystem_encoding (TextEncoder::Encoding encoding) |
Specifies the default encoding to be used for all subsequent Filenames. More... | |
static Filename | temporary (const std::string &dirname, const std::string &prefix, const std::string &suffix=std::string(), Type type=T_general) |
Generates a temporary filename within the indicated directory, using the indicated prefix. More... | |
static Filename | text_filename (const Filename &filename) |
static Filename | text_filename (const std::string &filename) |
The name of a file, such as a texture file or an Egg file.
Stores the full pathname, and includes functions for extracting out the directory prefix part and the file extension and stuff.
A Filename is also aware of the mapping between the Unix-like filename convention we use internally, and the local OS's specific filename convention, and it knows how to perform basic OS-specific I/O, like testing for file existence and searching a searchpath, as well as the best way to open an fstream for reading or writing.
Definition at line 39 of file filename.h.
|
inline |
Creates an empty Filename.
Definition at line 85 of file filename.I.
Referenced by get_common_appdata_directory(), get_home_directory(), get_temp_directory(), get_user_appdata_directory(), operator/(), and temporary().
This constructor composes the filename out of a directory part and a basename part.
It will insert an intervening '/' if necessary.
Definition at line 299 of file filename.cxx.
References get_fullpath().
|
inline |
Returns true if the Filename is valid (not empty), or false if it is an empty string.
This implements the Python equivalent to operator bool. Defining an actual operator bool method for C++ use would work too, but it seems to cause too many ambiguities for the C++ compiler, so we use this Python-only approach instead.
Definition at line 611 of file filename.I.
bool Filename::atomic_compare_and_exchange_contents | ( | std::string & | orig_contents, |
const std::string & | old_contents, | ||
const std::string & | new_contents | ||
) | const |
Uses native file-locking mechanisms to atomically replace the contents of a (small) file with the specified contents, assuming it hasn't changed since the last time the file was read.
This is designed to be similar to AtomicAdjust::compare_and_exchange(). The method writes new_contents to the file, completely replacing the original contents; but only if the original contents exactly matched old_contents. If the file was modified, returns true. If, however, the original contents of the file did not exactly match old_contents, then the file is not modified, and false is returned. In either case, orig_contents is filled with the original contents of the file.
If the file does not exist, it is implicitly created, and its original contents are empty.
If an I/O error occurs on write, some of the file may or may not have been written, and false is returned.
Expressed in pseudo-code, the logic is:
orig_contents = file.read(); if (orig_contents == old_contents) { file.write(new_contents); return true; } return false;
The operation is guaranteed to be atomic only if the only operations that read and write to this file are atomic_compare_and_exchange_contents() and atomic_read_contents().
Definition at line 2642 of file filename.cxx.
References atomic_read_contents(), to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::atomic_compare_and_exchange_contents().
bool Filename::atomic_read_contents | ( | std::string & | contents | ) | const |
Uses native file-locking mechanisms to atomically read the contents of a (small) file.
This is the only way to read a file protected by atomic_compare_and_exchange_contents(), and be confident that the read operation is actually atomic with respect to that method.
If the file does not exist, it is implicitly created, and its contents are empty.
If the file is read successfully, fills its contents in the indicated string, and returns true. If the file cannot be read, returns false.
Definition at line 2780 of file filename.cxx.
References chdir(), get_dirname(), get_fullpath(), get_pattern(), set_dirname(), to_os_specific(), and to_os_specific_w().
Referenced by atomic_compare_and_exchange_contents(), and VirtualFileMountSystem::atomic_read_contents().
bool Filename::chdir | ( | ) | const |
Changes directory to the specified location.
Returns true if successful, false if failure.
Definition at line 2303 of file filename.cxx.
References to_os_specific(), and to_os_specific_w().
Referenced by atomic_read_contents().
int Filename::compare_timestamps | ( | const Filename & | other, |
bool | this_missing_is_old = true , |
||
bool | other_missing_is_old = true |
||
) | const |
Returns a number less than zero if the file named by this object is older than the given file, zero if they have the same timestamp, or greater than zero if this one is newer.
If this_missing_is_old is true, it indicates that a missing file will be treated as if it were older than any other file; otherwise, a missing file will be treated as if it were newer than any other file. Similarly for other_missing_is_old.
Definition at line 1417 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by DestTextureImage::copy_if_stale(), and TextureImage::get_preferred_source().
bool Filename::copy_to | ( | const Filename & | other | ) | const |
Copies the file to the indicated new filename, by reading the contents and writing it to the new file.
Returns true if successful, false on failure. The copy is always binary, regardless of the filename settings.
Definition at line 2438 of file filename.cxx.
References open_read(), open_write(), and unlink().
Referenced by VirtualFileMountSystem::copy_file(), and rename_to().
bool Filename::exists | ( | ) | const |
Returns true if the filename exists on the disk, false otherwise.
If the type is indicated to be executable, this also tests that the file has execute permission.
Definition at line 1267 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by ImageFile::exists(), DSearchPath::find_all_files(), DSearchPath::find_file(), VirtualFileMountSystem::has_file(), CVSCopy::import(), is_executable(), open_read_write(), open_write(), resolve_filename(), temporary(), and ImageFile::unlink().
|
static |
Returns the same thing as from_os_specific(), but embedded environment variable references (e.g.
"$DMODELS/foo.txt") are expanded out. It also automatically elevates the file to its true case if needed.
Definition at line 407 of file filename.cxx.
References ExecutionEnvironment::expand_string(), from_os_specific(), and make_true_case().
Referenced by ConfigVariableFilename::get_word().
void Filename::extract_components | ( | vector_string & | components | ) | const |
Extracts out the individual directory components of the path into a series of strings.
get_basename() will be the last component stored in the vector. Note that no distinction is made by this method between a leading slash and no leading slash, but you can call is_local() to differentiate the two cases.
Definition at line 872 of file filename.cxx.
int Filename::find_on_searchpath | ( | const DSearchPath & | searchpath | ) |
Performs the reverse of the resolve_filename() operation: assuming that the current filename is fully-specified pathname (i.e.
beginning with '/'), look on the indicated search path for a directory under which the file can be found. When found, adjust the Filename to be relative to the indicated directory name.
Returns the index of the directory on the searchpath at which the file was found, or -1 if it was not found.
Definition at line 1689 of file filename.cxx.
References DSearchPath::get_num_directories.
|
static |
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
Use this function to create a Filename from an externally-given filename string. Use to_os_specific() again later to reconvert it back to the local operating system's conventions.
This function will do the right thing even if the filename is partially local conventions and partially Panda conventions; e.g. some backslashes and some forward slashes.
Definition at line 328 of file filename.cxx.
Referenced by DSearchPath::append_path(), PandaIOSystem::ComparePaths(), MaxToEggConverter::convert(), PandaIOSystem::Exists(), expand_from(), from_os_specific_w(), ConfigDeclaration::get_filename_value(), get_home_directory(), PandaIOSystem::Open(), ProgramBase::parse_command_line(), and temporary().
|
static |
The wide-string variant of from_os_specific().
Returns a new Filename, converted from an os-specific wide-character string.
Definition at line 394 of file filename.cxx.
References from_os_specific(), get_filesystem_encoding(), TextEncoder::get_text, TextEncoder::set_encoding(), and TextEncoder::set_wtext().
Referenced by MaxToEggConverter::convert(), get_common_appdata_directory(), get_home_directory(), get_temp_directory(), get_user_appdata_directory(), and make_true_case().
time_t Filename::get_access_timestamp | ( | ) | const |
Returns a time_t value that represents the time the file was last accessed, if this information is available.
See also get_timestamp(), which returns the last modification time.
Definition at line 1525 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
|
inline |
Returns the basename part of the filename.
This is everything in the filename after the rightmost slash, including any extensions.
Definition at line 367 of file filename.I.
Referenced by ConfigVariableFilename::get_basename(), PT(), STBasicTerrain::setup_terrain(), and FfmpegVideoCursor::start_thread().
|
inline |
Returns the basename part of the filename, without the file extension.
Definition at line 386 of file filename.I.
Referenced by MayaToEggConverter::convert_file(), ConfigVariableFilename::get_basename_wo_extension(), ProgramBase::get_exec_command(), EggTexture::is_equivalent_to(), EggTexture::sorts_less_than(), and ProgramBase::write_man_page().
|
static |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, common to all users.
Definition at line 645 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), Filename(), from_os_specific_w(), AtomicAdjustDummyImpl::get_ptr(), is_directory(), make_canonical(), set_basename(), and set_dirname().
|
inline |
Returns the directory part of the filename.
This is everything in the filename up to, but not including the rightmost slash.
Definition at line 358 of file filename.I.
Referenced by atomic_read_contents(), MaxToEggConverter::convert(), FltHeader::convert_path(), ConfigVariableFilename::get_dirname(), ConfigDeclaration::get_filename_value(), EggTexture::is_equivalent_to(), FilenameUnifier::make_canonical(), make_dir(), rename_to(), FilenameUnifier::set_txa_filename(), STBasicTerrain::setup_terrain(), and EggTexture::sorts_less_than().
|
inline |
Returns the file extension.
This is everything after the rightmost dot, if there is one, or the empty string if there is not.
Definition at line 400 of file filename.I.
Referenced by CPT(), ConfigVariableFilename::get_extension(), EggTexture::is_equivalent_to(), is_executable(), VirtualFileSimple::open_read_file(), VirtualFileSimple::open_write_file(), PT(), VirtualFileSimple::read_file(), resolve_filename(), EggTexture::sorts_less_than(), XFile::write(), and MayaApi::write().
std::streamsize Filename::get_file_size | ( | ) | const |
Returns the size of the file in bytes, or 0 if there is an error.
Definition at line 1551 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::get_file_size().
Filename Filename::get_filename_index | ( | int | index | ) | const |
If the pattern flag is set for this Filename and the filename string actually includes a sequence of hash marks, then this returns a new Filename with the sequence of hash marks replaced by the indicated index number.
If the pattern flag is not set for this Filename or it does not contain a sequence of hash marks, this quietly returns the original filename.
Definition at line 836 of file filename.cxx.
References set_fullpath(), and set_pattern().
Referenced by compare_timestamps(), exists(), get_access_timestamp(), get_file_size(), get_timestamp(), is_directory(), is_executable(), is_regular_file(), and is_writable().
|
inlinestatic |
Specifies the default encoding to be used for all subsequent Filenames objects.
See set_filesystem_encoding().
Definition at line 639 of file filename.I.
Referenced by from_os_specific_w(), get_fullpath_w(), scan_directory(), to_os_long_name(), to_os_short_name(), and to_os_specific_w().
|
inline |
Returns the entire filename: directory, basename, extension.
This is the same thing returned by the string typecast operator.
Definition at line 338 of file filename.I.
Referenced by atomic_read_contents(), Filename(), VirtualFileSimple::get_filename(), ConfigVariableFilename::get_fullpath(), get_fullpath_w(), make_canonical(), make_dir(), make_relative_to(), to_os_specific(), and URLSpec::URLSpec().
|
inline |
Returns the entire filename as a wide-character string.
Definition at line 346 of file filename.I.
References get_filesystem_encoding(), get_fullpath(), TextEncoder::get_wtext(), TextEncoder::set_encoding(), and TextEncoder::set_text.
Referenced by make_true_case().
|
inline |
Returns the full filename–directory and basename parts–except for the extension.
Definition at line 377 of file filename.I.
Referenced by ConfigVariableFilename::get_fullpath_wo_extension().
int Filename::get_hash | ( | ) | const |
Returns a hash code that attempts to be mostly unique for different Filenames.
Definition at line 2582 of file filename.cxx.
|
inline |
Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end of the filename.
Definition at line 540 of file filename.I.
|
static |
Returns a path to the user's home directory, if such a thing makes sense in the current OS, or to the nearest equivalent.
This may or may not be directly writable by the application.
Definition at line 474 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), Filename(), from_os_specific(), from_os_specific_w(), AtomicAdjustDummyImpl::get_ptr(), is_directory(), and make_canonical().
Referenced by get_user_appdata_directory().
|
inline |
Returns the flag indicating whether this is a filename pattern.
See set_pattern().
Definition at line 519 of file filename.I.
Referenced by atomic_read_contents(), make_dir(), make_true_case(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), rename_to(), scan_directory(), set_pattern(), to_os_generic(), to_os_long_name(), to_os_short_name(), to_os_specific(), touch(), and unlink().
|
static |
Returns a path to a system-defined temporary directory.
Definition at line 539 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), Filename(), from_os_specific_w(), AtomicAdjustDummyImpl::get_ptr(), is_directory(), make_canonical(), set_basename(), and set_dirname().
Referenced by temporary().
time_t Filename::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).
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.
Definition at line 1497 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::get_timestamp().
|
inline |
Returns the type of the file represented by the filename, as previously set by set_type().
Definition at line 485 of file filename.I.
Referenced by to_os_specific().
|
static |
Returns a path to a system-defined directory appropriate for creating a subdirectory for storing application-specific data, specific to the current user.
Definition at line 589 of file filename.cxx.
References AtomicAdjustDummyImpl::compare_and_exchange_ptr(), Filename(), from_os_specific_w(), get_home_directory(), AtomicAdjustDummyImpl::get_ptr(), is_directory(), make_canonical(), set_basename(), and set_dirname().
|
inline |
Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was called), and the filename pattern did include a sequence of hash marks, or false if it was not a filename pattern or did not include hash marks.
If this is true, then get_filename_index() will return a different filename each time.
Definition at line 531 of file filename.I.
|
inline |
Returns true if the Filename has been indicated to represent a binary file via a previous call to set_binary().
It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called.
Definition at line 435 of file filename.I.
|
inline |
Returns true either is_binary() or is_text() is true; that is, that the filename has been specified as either binary or text.
If this is false, the filename has not been specified.
Definition at line 445 of file filename.I.
Referenced by open_append(), open_read(), open_read_append(), open_read_write(), and open_write().
bool Filename::is_directory | ( | ) | const |
Returns true if the filename exists and is a directory name, false otherwise.
Definition at line 1359 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by get_common_appdata_directory(), get_home_directory(), get_temp_directory(), get_user_appdata_directory(), and VirtualFileMountSystem::is_directory().
bool Filename::is_executable | ( | ) | const |
Returns true if the filename exists and is executable.
Definition at line 1387 of file filename.cxx.
References exists(), get_extension(), get_filename_index(), and to_os_specific().
|
inline |
Returns true if the filename is fully qualified, e.g.
begins with a slash. This is almost, but not quite, the same thing as !is_local(). It's not exactly the same because a special case is made for filenames that begin with a single dot followed by a slash–these are considered to be fully qualified (they are explicitly relative to the current directory, and do not refer to a filename on a search path somewhere).
Definition at line 562 of file filename.I.
Referenced by DSearchPath::find_all_files(), and DSearchPath::find_file().
|
inline |
Returns true if the filename is local, e.g.
does not begin with a slash, or false if the filename is fully specified from the root.
Definition at line 549 of file filename.I.
Referenced by DSearchPath::find_all_files(), VirtualFileSystem::find_all_files(), VirtualFileSystem::find_file(), DSearchPath::find_file(), PathReplace::full_convert_path(), make_absolute(), GlobPattern::matches_file(), resolve_filename(), and PathReplace::store_path().
bool Filename::is_regular_file | ( | ) | const |
Returns true if the filename exists and is the name of a regular file (i.e.
not a directory or device), false otherwise.
Definition at line 1297 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::is_regular_file().
|
inline |
Returns true if the Filename has been indicated to represent a text file via a previous call to set_text().
It is possible that neither is_binary() nor is_text() will be true, if neither set_binary() nor set_text() was ever called.
Definition at line 456 of file filename.I.
Referenced by VirtualFileMount::make_virtual_file(), open_append(), open_read(), open_read_append(), open_read_write(), and open_write().
bool Filename::is_writable | ( | ) | const |
Returns true if the filename exists and is either a directory or a regular file that can be written to, or false otherwise.
Definition at line 1327 of file filename.cxx.
References get_filename_index(), to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::is_writable().
void Filename::make_absolute | ( | ) |
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname), and then standardizes it (see standardize()).
This is sometimes a little problematic, since it may convert the file to its 'true' absolute pathname, which could be an ugly NFS-named file, irrespective of symbolic links (e.g. /.automount/dimbo/root/usr2/fit/people/drose instead of /fit/people/drose); besides being ugly, filenames like this may not be consistent across multiple different platforms.
Definition at line 968 of file filename.cxx.
References is_local(), and standardize().
Referenced by BamCacheRecord::add_dependent_file(), PathReplace::full_convert_path(), FilenameUnifier::get_bam_filename(), and PathReplace::store_path().
void Filename::make_absolute | ( | const Filename & | start_directory | ) |
Converts the filename to a fully-qualified filename from the root (if it is a relative filename), and then standardizes it (see standardize()).
This flavor accepts a specific starting directory that the filename is known to be relative to.
Definition at line 983 of file filename.cxx.
References is_local(), and standardize().
bool Filename::make_canonical | ( | ) |
Converts this filename to a canonical name by replacing the directory part with the fully-qualified directory part.
This is done by changing to that directory and calling getcwd().
This has the effect of (a) converting relative paths to absolute paths (but see make_absolute() if this is the only effect you want), and (b) always resolving a given directory name to the same string, even if different symbolic links are traversed, and (c) changing nice symbolic-link paths like fit/people/drose to ugly NFS automounter names like hosts/dimbo/usr2/fit/people/drose. This can be troubling, but sometimes this is exactly what you want, particularly if you're about to call make_relative_to() between two filenames.
The return value is true if successful, or false on failure (usually because the directory name does not exist or cannot be chdir'ed into).
Definition at line 1011 of file filename.cxx.
References get_fullpath(), and make_true_case().
Referenced by PandaIOSystem::ComparePaths(), get_common_appdata_directory(), get_home_directory(), get_temp_directory(), get_user_appdata_directory(), and FilenameUnifier::make_canonical().
bool Filename::make_dir | ( | ) | const |
Creates all the directories in the path to the file specified in the filename, except for the basename itself.
This assumes that the Filename contains the name of a file, not a directory name; it ensures that the directory containing the file exists.
However, if the filename ends in a slash, it assumes the Filename represents the name of a directory, and creates all the paths.
Definition at line 2484 of file filename.cxx.
References get_dirname(), get_fullpath(), get_pattern(), mkdir(), to_os_specific(), and to_os_specific_w().
bool Filename::make_relative_to | ( | Filename | directory, |
bool | allow_backups = true |
||
) |
Adjusts this filename, which must be a fully-specified pathname beginning with a slash, to make it a relative filename, relative to the fully- specified directory indicated (which must also begin with, and may or may not end with, a slash–a terminating slash is ignored).
This only performs a string comparsion, so it may be wise to call make_canonical() on both filenames before calling make_relative_to().
If allow_backups is false, the filename will only be adjusted to be made relative if it is already somewhere within or below the indicated directory. If allow_backups is true, it will be adjusted in all cases, even if this requires putting a series of .. characters before the filename –unless it would have to back all the way up to the root.
Returns true if the file was adjusted, false if it was not.
Definition at line 1640 of file filename.cxx.
References get_fullpath(), and standardize().
Referenced by FilenameUnifier::make_bam_filename(), FilenameUnifier::make_egg_filename(), and FilenameUnifier::make_user_filename().
bool Filename::make_true_case | ( | ) |
On a case-insensitive operating system (e.g.
Windows), this method looks up the file in the file system and resets the Filename to represent the actual case of the file as it exists on the disk. The return value is true if the file exists and the conversion can be made, or false if there is some error.
On a case-sensitive operating system, this method does nothing and always returns true.
An empty filename is considered to exist in this case.
Definition at line 1053 of file filename.cxx.
References from_os_specific_w(), get_fullpath_w(), get_pattern(), and to_os_specific_w().
Referenced by expand_from(), ConfigDeclaration::get_filename_value(), VirtualFileMountSystem::has_file(), and make_canonical().
bool Filename::mkdir | ( | ) | const |
Creates the directory named by this filename.
Unlike make_dir(), this assumes that the Filename contains the directory name itself. Also, parent directories are not automatically created; this function fails if any parent directory is missing.
Definition at line 2540 of file filename.cxx.
References to_os_specific(), and to_os_specific_w().
Referenced by make_dir(), and VirtualFileMountSystem::make_directory().
bool Filename::open_append | ( | std::ofstream & | stream | ) | const |
Opens the indicated ofstream for writing the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
Definition at line 1945 of file filename.cxx.
References get_pattern(), is_binary_or_text(), is_text(), to_os_specific(), and to_os_specific_w().
Referenced by touch().
bool Filename::open_read | ( | std::ifstream & | stream | ) | const |
Opens the indicated ifstream for reading the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
Definition at line 1863 of file filename.cxx.
References get_pattern(), is_binary_or_text(), is_text(), to_os_specific(), and to_os_specific_w().
Referenced by copy_to(), QtessInputFile::read(), and FltTexture::read_attr_data().
bool Filename::open_read_append | ( | std::fstream & | stream | ) | const |
Opens the indicated ifstream for reading and writing the file, if possible; writes are appended to the end of the file.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
Definition at line 2019 of file filename.cxx.
References get_pattern(), is_binary_or_text(), is_text(), to_os_specific(), and to_os_specific_w().
bool Filename::open_read_write | ( | std::fstream & | stream, |
bool | truncate = false |
||
) | const |
Opens the indicated fstream for read/write access to the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read_write() without first calling one of set_text() or set_binary().
Definition at line 1977 of file filename.cxx.
References exists(), get_pattern(), is_binary_or_text(), is_text(), to_os_specific(), to_os_specific_w(), and touch().
bool Filename::open_write | ( | std::ofstream & | stream, |
bool | truncate = true |
||
) | const |
Opens the indicated ifstream for writing the file, if possible.
Returns true if successful, false otherwise. This requires the setting of the set_text()/set_binary() flags to open the file appropriately as indicated; it is an error to call open_read() without first calling one of set_text() or set_binary().
If truncate is true, the file is truncated to zero length upon opening it, if it already exists. Otherwise, the file is kept at its original length.
Definition at line 1899 of file filename.cxx.
References exists(), get_pattern(), is_binary_or_text(), is_text(), to_os_specific(), and to_os_specific_w().
Referenced by copy_to(), VirtualFileMountSystem::create_file(), XFile::write(), PfmFile::write(), DCFile::write(), and FltHeader::write_flt().
|
inline |
Returns a new Filename representing the concatenation of the two filenames.
Definition at line 318 of file filename.I.
|
inline |
Appends the other filename onto the end of this one.
This does not introduce an intervening slash, but see the Filename constructor that takes two parameters.
Definition at line 307 of file filename.I.
Returns a new Filename that is composed of the other filename added to the end of this filename, with an intervening slash added if necessary.
Definition at line 329 of file filename.I.
References Filename().
|
inlinestatic |
Constructs a filename that represents a sequence of numbered files.
See set_pattern().
Definition at line 160 of file filename.I.
References set_pattern().
bool Filename::rename_to | ( | const Filename & | other | ) | const |
Renames the file to the indicated new filename.
If the new filename is in a different directory, this will perform a move. Returns true if successful, false on failure.
Definition at line 2339 of file filename.cxx.
References copy_to(), get_dirname(), get_pattern(), set_binary(), temporary(), to_os_specific(), to_os_specific_w(), and unlink().
Referenced by VirtualFileMountSystem::rename_file().
bool Filename::resolve_filename | ( | const DSearchPath & | searchpath, |
const std::string & | default_extension = std::string() |
||
) |
Searches the given search path for the filename.
If it is found, updates the filename to the full pathname found and returns true; otherwise, returns false.
Definition at line 1581 of file filename.cxx.
References exists(), DSearchPath::find_file(), get_extension(), is_local(), and set_extension().
Referenced by LoaderFileTypePandatool::resolve_filename().
bool Filename::rmdir | ( | ) | const |
The inverse of mkdir(): this removes the directory named by this Filename, if it is in fact a directory.
Definition at line 2557 of file filename.cxx.
References to_os_specific(), and to_os_specific_w().
Referenced by VirtualFileMountSystem::delete_file().
bool Filename::scan_directory | ( | vector_string & | contents | ) | const |
Attempts to open the named filename as if it were a directory and looks for the non-hidden files within the directory.
Fills the given vector up with the sorted list of filenames that are local to this directory.
It is the user's responsibility to ensure that the contents vector is empty before making this call; otherwise, the new files will be appended to it.
Returns true on success, false if the directory could not be read for some reason.
Definition at line 1718 of file filename.cxx.
References get_filesystem_encoding(), get_pattern(), TextEncoder::get_text, TextEncoder::set_encoding(), TextEncoder::set_wtext(), and to_os_specific_w().
Referenced by CVSSourceDirectory::scan(), and VirtualFileMountSystem::scan_directory().
void Filename::set_basename | ( | const std::string & | s | ) |
Replaces the basename part of the filename.
This is everything in the filename after the rightmost slash, including any extensions.
Definition at line 754 of file filename.cxx.
Referenced by get_common_appdata_directory(), get_temp_directory(), and get_user_appdata_directory().
void Filename::set_basename_wo_extension | ( | const std::string & | s | ) |
Replaces the basename part of the filename, without the file extension.
Definition at line 783 of file filename.cxx.
|
inline |
Indicates that the filename represents a binary file.
This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS.
Definition at line 414 of file filename.I.
Referenced by VirtualFileMountSystem::create_file(), VirtualFileMount::make_virtual_file(), DatagramInputFile::open(), DatagramOutputFile::open(), IffInputFile::open_read(), VirtualFileSimple::open_read_file(), VirtualFileSimple::open_write_file(), VirtualFileSimple::read_file(), FltHeader::read_flt(), rename_to(), set_type(), XFile::write(), and FltHeader::write_flt().
void Filename::set_dirname | ( | const std::string & | s | ) |
Replaces the directory part of the filename.
This is everything in the filename up to, but not including the rightmost slash.
Definition at line 704 of file filename.cxx.
Referenced by atomic_read_contents(), get_common_appdata_directory(), get_temp_directory(), get_user_appdata_directory(), and FilenameUnifier::make_canonical().
void Filename::set_extension | ( | const std::string & | s | ) |
Replaces the file extension.
This is everything after the rightmost dot, if there is one, or the empty string if there is not.
Definition at line 804 of file filename.cxx.
Referenced by PfmBba::process_pfm(), and resolve_filename().
|
inlinestatic |
Specifies the default encoding to be used for all subsequent Filenames.
This is used to represent wide-character (Unicode) filenames internally. On non-Windows-based systems, the encoded filename is also passed to the underlying operating system.
Definition at line 630 of file filename.I.
void Filename::set_fullpath | ( | const std::string & | s | ) |
Replaces the entire filename: directory, basename, extension.
This can also be achieved with the assignment operator.
Definition at line 695 of file filename.cxx.
Referenced by get_filename_index().
void Filename::set_fullpath_wo_extension | ( | const std::string & | s | ) |
Replaces the full filename–directory and basename parts–except for the extension.
Definition at line 766 of file filename.cxx.
void Filename::set_hash_to_end | ( | const std::string & | s | ) |
Replaces the part of the filename from the beginning of the hash sequence to the end of the filename.
Definition at line 856 of file filename.cxx.
|
inline |
Sets the flag indicating whether this is a filename pattern.
When this is true, the filename is understood to be a placeholder for a numbered sequence of filename, such as an image sequence. In this case, a sequence of one or more hash characters ("#") should appear in the filename string; these characters will be filled in with the corresponding number (or more) of digits representing the sequence number. Sequence numbers always begin counting at 0.
When this is true, methods like has_hash() and get_hash_to_end() and get_filename_index() may be called. Methods like is_exists() will implicitly test for existance of filename sequence 0.
Definition at line 503 of file filename.I.
References get_pattern().
Referenced by get_filename_index(), and pattern_filename().
|
inline |
Indicates that the filename represents a text file.
This is primarily relevant to the read_file() and write_file() methods, so they can set the appropriate flags to the OS.
Definition at line 424 of file filename.I.
Referenced by MultiplexStream::add_file(), load_prc_file(), VirtualFileMount::make_virtual_file(), parse_vrml(), DXFFile::process(), PfmBba::process_pfm(), XFile::read(), DCFile::read(), EggData::read(), DCFile::write(), write_private_key(), and write_public_keys().
|
inline |
Sets the type of the file represented by the filename.
This is useful for to_os_specific(), resolve_filename(), test_existence(), and all such real- world access functions. It helps the Filename know how to map the internal filename to the OS-specific filename (for instance, maybe executables should have an .exe extension).
Definition at line 468 of file filename.I.
References set_binary().
Referenced by temporary().
void Filename::standardize | ( | ) |
Converts the filename to standard form by replacing consecutive slashes with a single slash, removing a trailing slash if present, and backing up over .
. sequences within the filename where possible.
Definition at line 900 of file filename.cxx.
Referenced by make_absolute(), make_relative_to(), and to_os_specific().
|
static |
Generates a temporary filename within the indicated directory, using the indicated prefix.
If the directory is empty, a system-defined directory is chosen instead.
The generated filename did not exist when the Filename checked, but since it does not specifically create the file, it is possible that another process could simultaneously create a file by the same name.
Definition at line 424 of file filename.cxx.
References exists(), Filename(), from_os_specific(), get_temp_directory(), and set_type().
Referenced by BamCache::flush_index(), and rename_to().
string Filename::to_os_generic | ( | ) | const |
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood on as many platforms as possible.
Since Windows can usually understand a forward-slash-delimited filename, this means it does the same thing as to_os_specific(), but it uses forward slashes instead of backslashes.
This method has a pretty limited use; it should generally be used for writing file references to a file that might be read on any operating system.
Definition at line 1182 of file filename.cxx.
References get_pattern().
Referenced by FltExternalReference::apply_converted_filenames(), FltTexture::apply_converted_filenames(), MayaApi::read(), MayaShaderColorDef::reset_maya_texture(), FltExternalReference::set_ref_filename(), FltTexture::set_texture_filename(), and MayaApi::write().
string Filename::to_os_long_name | ( | ) | const |
This is the opposite of to_os_short_name(): it returns the "long name" of the filename, if the filename exists.
On non-Windows platforms, this returns the same thing as to_os_specific().
Definition at line 1236 of file filename.cxx.
References get_filesystem_encoding(), get_pattern(), TextEncoder::get_text, TextEncoder::set_encoding(), TextEncoder::set_wtext(), to_os_specific(), and to_os_specific_w().
string Filename::to_os_short_name | ( | ) | const |
This works like to_os_generic(), but it returns the "short name" version of the filename, if it exists, or the original filename otherwise.
On Windows platforms, this returns the 8.3 filename version of the given filename, if the file exists, and the same thing as to_os_specific() otherwise. On non-Windows platforms, this always returns the same thing as to_os_specific().
Definition at line 1202 of file filename.cxx.
References get_filesystem_encoding(), get_pattern(), TextEncoder::get_text, TextEncoder::set_encoding(), TextEncoder::set_wtext(), to_os_specific(), and to_os_specific_w().
string Filename::to_os_specific | ( | ) | const |
Converts the filename from our generic Unix-like convention (forward slashes starting with the root at '/') to the corresponding filename in the local operating system (slashes in the appropriate direction, starting with the root at C:\, for instance).
Returns the string representing the converted filename, but does not change the Filename itself.
See also from_os_specific().
Definition at line 1123 of file filename.cxx.
References get_fullpath(), get_pattern(), get_type(), and standardize().
Referenced by atomic_compare_and_exchange_contents(), atomic_read_contents(), chdir(), compare_timestamps(), exists(), get_access_timestamp(), get_file_size(), get_timestamp(), is_directory(), is_executable(), is_regular_file(), is_writable(), make_dir(), mkdir(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), print_xml_to_file(), MayaApi::read(), rename_to(), CVSSourceTree::restore_cwd(), rmdir(), STTree::STTree(), CVSSourceTree::temp_chdir(), to_os_long_name(), to_os_short_name(), to_os_specific_w(), touch(), unlink(), and MayaApi::write().
wstring Filename::to_os_specific_w | ( | ) | const |
The wide-string variant on to_os_specific().
Definition at line 1163 of file filename.cxx.
References get_filesystem_encoding(), TextEncoder::get_wtext(), TextEncoder::set_encoding(), TextEncoder::set_text, and to_os_specific().
Referenced by atomic_compare_and_exchange_contents(), atomic_read_contents(), chdir(), compare_timestamps(), exists(), get_access_timestamp(), get_file_size(), get_timestamp(), is_directory(), is_regular_file(), is_writable(), make_dir(), make_true_case(), mkdir(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), rename_to(), rmdir(), scan_directory(), to_os_long_name(), to_os_short_name(), touch(), and unlink().
bool Filename::touch | ( | ) | const |
Updates the modification time of the file to the current time.
If the file does not already exist, it will be created. Returns true if successful, false if there is an error.
Definition at line 2225 of file filename.cxx.
References get_pattern(), open_append(), to_os_specific(), and to_os_specific_w().
Referenced by open_read_write().
bool Filename::unlink | ( | ) | const |
Permanently deletes the file associated with the filename, if possible.
Returns true if successful, false if failure (for instance, because the file did not exist, or because permissions were inadequate).
Definition at line 2319 of file filename.cxx.
References get_pattern(), to_os_specific(), and to_os_specific_w().
Referenced by copy_to(), VirtualFileMountSystem::delete_file(), and rename_to().