Panda3D
|
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 string &filename="") | |
Filename (const wstring &filename) | |
Filename (const Filename ©) | |
Filename (const Filename &dirname, const Filename &basename) | |
This constructor composes the filename out of a directory part and a basename part. | |
Filename (const char *filename) | |
bool | __nonzero__ () const |
Returns true if the Filename is valid (not empty), or false if it is an empty string. | |
bool | atomic_compare_and_exchange_contents (string &orig_contents, const string &old_contents, const 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. | |
bool | atomic_read_contents (string &contents) const |
Uses native file-locking mechanisms to atomically read the contents of a (small) file. | |
const char * | c_str () const |
bool | chdir () const |
Changes directory to the specified location. | |
int | compare_timestamps (const Filename &other, bool this_missing_is_old=true, bool other_missing_is_old=true) const |
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. | |
bool | empty () const |
bool | exists () const |
void | extract_components (vector_string &components) const |
int | find_on_searchpath (const DSearchPath &searchpath) |
time_t | get_access_timestamp () const |
string | get_basename () const |
Returns the basename part of the filename. | |
string | get_basename_wo_extension () const |
Returns the basename part of the filename, without the file extension. | |
string | get_dirname () const |
Returns the directory part of the filename. | |
string | get_extension () const |
Returns the file extension. | |
off_t | get_file_size () const |
Filename | get_filename_index (int index) const |
string | get_fullpath () const |
Returns the entire filename: directory, basename, extension. | |
wstring | get_fullpath_w () const |
Returns the entire filename as a wide-character string. | |
string | get_fullpath_wo_extension () const |
Returns the full filename--directory and basename parts--except for the extension. | |
int | get_hash () const |
Returns a hash code that attempts to be mostly unique for different Filenames. | |
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. | |
bool | get_pattern () const |
Returns the flag indicating whether this is a filename pattern. | |
time_t | get_timestamp () const |
Type | get_type () const |
Returns the type of the file represented by the filename, as previously set by set_type(). | |
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. | |
bool | is_binary () const |
Returns true if the Filename has been indicated to represent a binary file via a previous call to set_binary(). | |
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. | |
bool | is_directory () const |
bool | is_executable () const |
bool | is_fully_qualified () const |
Returns true if the filename is fully qualified, e.g. | |
bool | is_local () const |
Returns true if the filename is local, e.g. | |
bool | is_regular_file () const |
bool | is_text () const |
Returns true if the Filename has been indicated to represent a text file via a previous call to set_text(). | |
bool | is_writable () const |
size_t | length () const |
void | make_absolute () |
void | make_absolute (const Filename &start_directory) |
bool | make_canonical () |
bool | make_dir () const |
Creates all the directories in the path to the file specified in the filename, except for the basename itself. | |
bool | make_relative_to (Filename directory, bool allow_backups=true) |
bool | make_true_case () |
bool | mkdir () const |
Creates the directory named by this filename. | |
bool | open_append (ofstream &stream) const |
Opens the indicated ofstream for writing the file, if possible. | |
bool | open_read (ifstream &stream) const |
Opens the indicated ifstream for reading the file, if possible. | |
bool | open_read_append (fstream &stream) const |
Opens the indicated ifstream for reading and writing the file, if possible; writes are appended to the end of the file. | |
bool | open_read_write (fstream &stream, bool truncate=false) const |
Opens the indicated fstream for read/write access to the file, if possible. | |
bool | open_write (ofstream &stream, bool truncate=true) const |
Opens the indicated ifstream for writing the file, if possible. | |
operator const string & () const | |
bool | operator!= (const string &other) const |
Filename | operator+ (const string &other) const |
Returns a new Filename representing the concatenation of the two filenames. | |
void | operator+= (const string &other) |
Appends the other filename onto the end of this one. | |
bool | operator< (const string &other) const |
Filename & | operator= (const string &filename) |
Filename & | operator= (const char *filename) |
Filename & | operator= (const wstring &filename) |
Filename & | operator= (const Filename ©) |
bool | operator== (const string &other) const |
char | operator[] (int n) const |
void | output (ostream &out) const |
bool | rename_to (const Filename &other) const |
Renames the file to the indicated new filename. | |
bool | resolve_filename (const DSearchPath &searchpath, const string &default_extension=string()) |
bool | rmdir () const |
The inverse of mkdir(): this removes the directory named by this Filename, if it is in fact a directory. | |
bool | scan_directory (vector_string &contents) const |
void | set_basename (const string &s) |
void | set_basename_wo_extension (const string &s) |
void | set_binary () |
Indicates that the filename represents a binary file. | |
void | set_dirname (const string &s) |
void | set_extension (const string &s) |
void | set_fullpath (const string &s) |
void | set_fullpath_wo_extension (const string &s) |
void | set_hash_to_end (const string &s) |
void | set_pattern (bool pattern) |
Sets the flag indicating whether this is a filename pattern. | |
void | set_text () |
Indicates that the filename represents a text file. | |
void | set_type (Type type) |
Sets the type of the file represented by the filename. | |
void | standardize () |
string | substr (size_t begin, size_t end=string::npos) const |
string | to_os_generic () const |
string | to_os_long_name () const |
string | to_os_short_name () const |
string | to_os_specific () const |
wstring | to_os_specific_w () const |
bool | touch () const |
Updates the modification time of the file to the current time. | |
bool | unlink () const |
Permanently deletes the file associated with the filename, if possible. | |
Static Public Member Functions | |
static Filename | binary_filename (const Filename &filename) |
static Filename | binary_filename (const string &filename) |
static Filename | dso_filename (const string &filename) |
static Filename | executable_filename (const string &filename) |
static Filename | expand_from (const string &user_string, Type type=T_general) |
static Filename | from_os_specific (const 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). | |
static Filename | from_os_specific_w (const wstring &os_specific, Type type=T_general) |
static TypeHandle | get_class_type () |
static const Filename & | get_common_appdata_directory () |
static TextEncoder::Encoding | get_filesystem_encoding () |
Specifies the default encoding to be used for all subsequent Filenames objects. | |
static const Filename & | get_home_directory () |
static const Filename & | get_temp_directory () |
static const Filename & | get_user_appdata_directory () |
static void | init_type () |
static Filename | pattern_filename (const string &filename) |
Constructs a filename that represents a sequence of numbered files. | |
static void | set_filesystem_encoding (TextEncoder::Encoding encoding) |
Specifies the default encoding to be used for all subsequent Filenames. | |
static Filename | temporary (const string &dirname, const string &prefix, const string &suffix=string(), Type type=T_general) |
static Filename | text_filename (const Filename &filename) |
static Filename | text_filename (const string &filename) |
Protected Member Functions | |
size_t | get_common_prefix (const string &other) const |
Returns the length of the longest common initial substring of this string and the other one that ends in a slash. | |
void | locate_basename () |
After the string has been reassigned, search for the slash marking the beginning of the basename, and set _dirname_end and _basename_start correctly. | |
void | locate_extension () |
Once the end of the directory prefix has been found, and _dirname_end and _basename_start are set correctly, search for the dot marking the beginning of the extension, and set _basename_end and _extension_start correctly. | |
void | locate_hash () |
Identifies the part of the filename that contains the sequence of hash marks, if any. | |
bool | r_make_canonical (const Filename &cwd) |
The recursive implementation of make_canonical(). | |
Static Protected Member Functions | |
static int | count_slashes (const string &str) |
Returns the number of non-consecutive slashes in the indicated string, not counting a terminal slash. | |
Protected Attributes | |
size_t | _basename_end |
size_t | _basename_start |
size_t | _dirname_end |
size_t | _extension_start |
string | _filename |
int | _flags |
size_t | _hash_end |
size_t | _hash_start |
Static Protected Attributes | |
static AtomicAdjust::Pointer | _common_appdata_directory |
static TextEncoder::Encoding | _filesystem_encoding = TextEncoder::E_utf8 |
static AtomicAdjust::Pointer | _home_directory |
static AtomicAdjust::Pointer | _temp_directory |
static AtomicAdjust::Pointer | _user_appdata_directory |
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 44 of file filename.h.
This constructor composes the filename out of a directory part and a basename part.
It will insert an intervening '/' if necessary.
Definition at line 293 of file filename.cxx.
References get_fullpath().
bool Filename::__nonzero__ | ( | ) | const [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 662 of file filename.I.
bool Filename::atomic_compare_and_exchange_contents | ( | string & | orig_contents, |
const string & | old_contents, | ||
const 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 2931 of file filename.cxx.
Referenced by VirtualFileMountSystem::atomic_compare_and_exchange_contents().
bool Filename::atomic_read_contents | ( | 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 3070 of file filename.cxx.
Referenced by VirtualFileMountSystem::atomic_read_contents().
bool Filename::chdir | ( | ) | const |
Changes directory to the specified location.
Returns true if successful, false if failure.
Definition at line 2560 of file filename.cxx.
Referenced by r_make_canonical().
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 2705 of file filename.cxx.
References open_read(), open_write(), and unlink().
Referenced by VirtualFileMountSystem::copy_file(), and rename_to().
int Filename::count_slashes | ( | const string & | str | ) | [static, protected] |
Returns the number of non-consecutive slashes in the indicated string, not counting a terminal slash.
Definition at line 3312 of file filename.cxx.
Filename Filename::from_os_specific | ( | const string & | os_specific, |
Filename::Type | type = T_general |
||
) | [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 352 of file filename.cxx.
References set_type().
Referenced by SpeedTreeNode::add_from_stf(), DSearchPath::append_path(), WithOutputFile::check_last_arg(), PandaIOSystem::ComparePaths(), MaxToEggConverter::convert(), ProgramBase::dispatch_filename(), ProgramBase::dispatch_search_path(), PandaIOSystem::Exists(), FltTexture::extract_record(), FltExternalReference::extract_record(), XFileMaterial::fill_material(), ExecutionEnvironment::get_cwd(), AudioManager::get_dls_pathname(), VirtualFileSystem::get_global_ptr(), PfmTrans::handle_args(), PfmBba::handle_args(), EggTextureCards::handle_args(), SomethingToEgg::handle_args(), EggReader::handle_args(), EggMultiFilter::handle_args(), CVSCopy::handle_args(), RocketRenderInterface::LoadTexture(), PandaIOSystem::Open(), PandaFramework::open_framework(), ProgramBase::parse_command_line(), and ConfigPageManager::reload_implicit_pages().
string Filename::get_basename | ( | ) | const [inline] |
Returns the basename part of the filename.
This is everything in the filename after the rightmost slash, including any extensions.
Definition at line 356 of file filename.I.
Referenced by AssimpLoader::build_graph(), ColladaLoader::build_graph(), EggCharacterCollection::check_errors(), CVSCopy::cvs_add(), Texture::do_read_one(), Texture::do_reload_ram_image(), Texture::do_write_datagram_header(), BamCache::flush_index(), PathReplace::full_convert_path(), ConfigVariableFilename::get_basename(), EggReader::handle_args(), CVSCopy::import(), VirtualFile::ls(), EggCharacterFilter::post_command_line(), PfmTrans::process_pfm(), EggFile::read_egg(), CVSSourceTree::scan(), STBasicTerrain::setup_terrain(), PathReplace::store_path(), and TextureReference::update_egg().
string Filename::get_basename_wo_extension | ( | ) | const [inline] |
Returns the basename part of the filename, without the file extension.
Definition at line 380 of file filename.I.
Referenced by XFileToEggConverter::convert_file(), SoftToEggConverter::convert_file(), MayaToEggConverter::convert_file(), Texture::do_read_dds_file(), Texture::do_read_one(), TextureReference::from_egg(), ConfigVariableFilename::get_basename_wo_extension(), ProgramBase::get_exec_command(), EggTexture::is_equivalent_to(), Texture::load_related(), PfmTrans::process_pfm(), EggGroupNode::r_load_externals(), ProgramBase::show_usage(), EggTexture::sorts_less_than(), ParametricCurveCollection::write_egg(), and ParametricCurve::write_egg().
size_t Filename::get_common_prefix | ( | const string & | other | ) | const [protected] |
Returns the length of the longest common initial substring of this string and the other one that ends in a slash.
This is the lowest directory common to both filenames.
Definition at line 3288 of file filename.cxx.
string Filename::get_dirname | ( | ) | const [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 344 of file filename.I.
Referenced by SpeedTreeNode::add_from_stf(), MaxToEggConverter::convert(), FltHeader::convert_path(), SoftToEggConverter::convert_soft(), CVSCopy::cvs_add(), Texture::do_write_datagram_header(), ConfigVariableFilename::get_dirname(), SomethingToEgg::handle_args(), EggWriter::handle_args(), EggReader::handle_args(), EggMultiFilter::handle_args(), EggFilter::handle_args(), EggTexture::is_equivalent_to(), FilenameUnifier::make_canonical(), make_dir(), Texture::make_this_from_bam(), SomethingToEgg::post_command_line(), PaletteGroup::prepare(), r_make_canonical(), EggFile::read_egg(), rename_to(), Multifile::repack(), FilenameUnifier::set_txa_filename(), STBasicTerrain::setup_terrain(), EggTexture::sorts_less_than(), and SpeedTreeNode::InstanceList::write_datagram().
string Filename::get_extension | ( | ) | const [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 397 of file filename.I.
Referenced by WithOutputFile::check_last_arg(), ConfigVariableFilename::get_extension(), WithOutputFile::get_output(), SomethingToEgg::handle_args(), EggTexture::is_equivalent_to(), VirtualFileSimple::open_read_file(), VirtualFileSimple::open_write_file(), PaletteGroup::prepare(), VirtualFileSimple::read_file(), VirtualFileSystem::resolve_filename(), EggTexture::sorts_less_than(), XFile::write(), MayaApi::write(), VirtualFileSimple::write_file(), and FltHeader::write_flt().
TextEncoder::Encoding Filename::get_filesystem_encoding | ( | ) | [inline, static] |
Specifies the default encoding to be used for all subsequent Filenames objects.
See set_filesystem_encoding().
Definition at line 698 of file filename.I.
Referenced by get_fullpath_w().
string Filename::get_fullpath | ( | ) | const [inline] |
Returns the entire filename: directory, basename, extension.
This is the same thing returned by the string typecast operator.
Definition at line 318 of file filename.I.
Referenced by MayaPview::doIt(), Filename(), VirtualFileSimple::get_filename(), ConfigVariableFilename::get_fullpath(), get_fullpath_w(), CVSCopy::import(), make_dir(), r_make_canonical(), VirtualFileSystem::scan_mount_points(), and SpeedTreeNode::InstanceList::write_datagram().
wstring Filename::get_fullpath_w | ( | ) | const [inline] |
Returns the entire filename as a wide-character string.
Definition at line 329 of file filename.I.
References get_filesystem_encoding(), get_fullpath(), TextEncoder::get_wtext(), TextEncoder::set_encoding(), and TextEncoder::set_text().
string Filename::get_fullpath_wo_extension | ( | ) | const [inline] |
Returns the full filename--directory and basename parts--except for the extension.
Definition at line 368 of file filename.I.
Referenced by ConfigVariableFilename::get_fullpath_wo_extension(), and ImageFile::set_filename().
int Filename::get_hash | ( | ) | const |
Returns a hash code that attempts to be mostly unique for different Filenames.
Definition at line 2860 of file filename.cxx.
string Filename::get_hash_to_end | ( | ) | const [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 572 of file filename.I.
bool Filename::get_pattern | ( | ) | const [inline] |
Returns the flag indicating whether this is a filename pattern.
See set_pattern().
Definition at line 544 of file filename.I.
Referenced by locate_hash(), make_dir(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), rename_to(), set_pattern(), touch(), and unlink().
Filename::Type Filename::get_type | ( | ) | const [inline] |
Returns the type of the file represented by the filename, as previously set by set_type().
Definition at line 503 of file filename.I.
bool Filename::has_hash | ( | ) | const [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 560 of file filename.I.
Referenced by Texture::do_read(), and Texture::do_write().
bool Filename::is_binary | ( | ) | const [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 441 of file filename.I.
Referenced by Multifile::compare_subfile().
bool Filename::is_binary_or_text | ( | ) | const [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 454 of file filename.I.
Referenced by Multifile::add_subfile(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), and Multifile::update_subfile().
bool Filename::is_fully_qualified | ( | ) | const [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 602 of file filename.I.
Referenced by VirtualFileSystem::find_all_files(), DSearchPath::find_all_files(), DSearchPath::find_file(), PathReplace::full_convert_path(), PathReplace::match_path(), and EggData::resolve_egg_filename().
bool Filename::is_local | ( | ) | const [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 584 of file filename.I.
Referenced by VirtualFileSystem::find_all_files(), DSearchPath::find_all_files(), DSearchPath::find_file(), EggGroupNode::force_filenames(), PathReplace::full_convert_path(), EggGroupNode::has_absolute_pathnames(), PathReplace::match_path(), VirtualFileSystem::resolve_filename(), VirtualFileSystem::scan_mount_points(), BamCache::store(), and PathReplace::store_path().
bool Filename::is_text | ( | ) | const [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 468 of file filename.I.
Referenced by Multifile::add_subfile(), Multifile::compare_subfile(), open_append(), open_read(), open_read_append(), open_read_write(), open_write(), and Multifile::update_subfile().
void Filename::locate_basename | ( | ) | [protected] |
After the string has been reassigned, search for the slash marking the beginning of the basename, and set _dirname_end and _basename_start correctly.
Definition at line 3161 of file filename.cxx.
Referenced by operator+=().
void Filename::locate_extension | ( | ) | [protected] |
Once the end of the directory prefix has been found, and _dirname_end and _basename_start are set correctly, search for the dot marking the beginning of the extension, and set _basename_end and _extension_start correctly.
Definition at line 3215 of file filename.cxx.
Referenced by operator+=().
void Filename::locate_hash | ( | ) | [protected] |
Identifies the part of the filename that contains the sequence of hash marks, if any.
Definition at line 3252 of file filename.cxx.
References get_pattern().
Referenced by operator+=(), and set_pattern().
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 2755 of file filename.cxx.
References get_dirname(), get_fullpath(), get_pattern(), and mkdir().
Referenced by WithOutputFile::get_output(), Extractor::step(), ImageFile::write(), EggFile::write_egg(), and EggMultiFilter::write_eggs().
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 2814 of file filename.cxx.
Referenced by make_dir(), and VirtualFileMountSystem::make_directory().
bool Filename::open_append | ( | 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 2126 of file filename.cxx.
References get_pattern(), is_binary_or_text(), and is_text().
Referenced by MultiplexStream::add_file(), VirtualFileMountSystem::open_append_file(), and touch().
bool Filename::open_read | ( | 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 2028 of file filename.cxx.
References get_pattern(), is_binary_or_text(), and is_text().
Referenced by Multifile::compare_subfile(), CVSCopy::copy_binary_file(), DatagramOutputFile::copy_datagram(), copy_to(), EggMultiFilter::handle_args(), VirtualFileMountSystem::open_read_file(), QtessInputFile::read(), FltTexture::read_attr_data(), ConfigPageManager::reload_implicit_pages(), Extractor::set_multifile(), and CVSCopy::verify_binary_file().
bool Filename::open_read_append | ( | 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 2221 of file filename.cxx.
References get_pattern(), is_binary_or_text(), and is_text().
Referenced by VirtualFileMountSystem::open_read_append_file().
bool Filename::open_read_write | ( | 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 2168 of file filename.cxx.
References get_pattern(), is_binary_or_text(), is_text(), and touch().
Referenced by Multifile::open_read_write(), and VirtualFileMountSystem::open_read_write_file().
bool Filename::open_write | ( | 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 2070 of file filename.cxx.
References get_pattern(), is_binary_or_text(), and is_text().
Referenced by Notify::config_initialized(), CVSCopy::copy_binary_file(), copy_to(), VirtualFileMountSystem::create_file(), WithOutputFile::get_output(), Multifile::open_write(), VirtualFileMountSystem::open_write_file(), PfmBba::process_pfm(), Multifile::repack(), DatagramInputFile::save_datagram(), Extractor::step(), XFile::write(), PfmFile::write(), DCFile::write(), FltTexture::write_attr_data(), ParametricCurveCollection::write_egg(), ParametricCurve::write_egg(), and FltHeader::write_flt().
Filename Filename::operator+ | ( | const string & | other | ) | const [inline] |
Returns a new Filename representing the concatenation of the two filenames.
Definition at line 303 of file filename.I.
void Filename::operator+= | ( | const string & | other | ) | [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 289 of file filename.I.
References locate_basename(), locate_extension(), and locate_hash().
Filename Filename::pattern_filename | ( | const string & | filename | ) | [inline, static] |
Constructs a filename that represents a sequence of numbered files.
See set_pattern().
Definition at line 146 of file filename.I.
References set_pattern().
Referenced by Texture::do_read(), and Texture::do_write().
bool Filename::r_make_canonical | ( | const Filename & | cwd | ) | [protected] |
The recursive implementation of make_canonical().
Definition at line 3346 of file filename.cxx.
References chdir(), ExecutionEnvironment::get_cwd(), get_dirname(), get_fullpath(), and r_make_canonical().
Referenced by r_make_canonical().
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 2602 of file filename.cxx.
References copy_to(), get_dirname(), get_pattern(), set_binary(), and unlink().
Referenced by VirtualFileMountSystem::rename_file(), and Multifile::repack().
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 2833 of file filename.cxx.
Referenced by VirtualFileMountSystem::delete_file().
void Filename::set_binary | ( | ) | [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 Multifile::add_subfile(), Multifile::compare_subfile(), CVSCopy::copy_binary_file(), VirtualFileMountSystem::create_file(), Multifile::extract_subfile(), WithOutputFile::get_output(), DatagramOutputFile::open(), DatagramInputFile::open(), IffInputFile::open_read(), Multifile::open_read(), VirtualFileSimple::open_read_file(), Multifile::open_read_write(), Multifile::open_write(), VirtualFileSimple::open_write_file(), VirtualFileSimple::read_file(), FltHeader::read_flt(), ConfigPageManager::reload_implicit_pages(), rename_to(), Multifile::repack(), DatagramInputFile::save_datagram(), set_type(), Extractor::step(), BamCache::store(), Multifile::update_subfile(), CVSCopy::verify_binary_file(), XFile::write(), FltTexture::write_attr_data(), VirtualFileSimple::write_file(), and FltHeader::write_flt().
void Filename::set_filesystem_encoding | ( | TextEncoder::Encoding | encoding | ) | [inline, static] |
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 686 of file filename.I.
void Filename::set_pattern | ( | bool | pattern | ) | [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 526 of file filename.I.
References get_pattern(), and locate_hash().
Referenced by pattern_filename().
void Filename::set_text | ( | ) | [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 427 of file filename.I.
Referenced by MultiplexStream::add_file(), Multifile::compare_subfile(), Notify::config_initialized(), WithOutputFile::get_output(), DXFFile::process(), PfmBba::process_pfm(), XFile::read(), EggData::read(), DCFile::read(), ConfigPageManager::reload_implicit_pages(), DCFile::write(), ParametricCurveCollection::write_egg(), ParametricCurve::write_egg(), and EggData::write_egg().
void Filename::set_type | ( | Filename::Type | type | ) | [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 484 of file filename.I.
References set_binary().
Referenced by from_os_specific().
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 2479 of file filename.cxx.
References get_pattern(), and open_append().
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 2579 of file filename.cxx.
References get_pattern().
Referenced by CVSCopy::copy_binary_file(), copy_to(), VirtualFileMountSystem::delete_file(), MayaPview::doIt(), Palettizer::read_stale_eggs(), rename_to(), Multifile::repack(), ImageFile::unlink(), PaletteImage::update_filename(), ImageFile::write(), and TemporaryFile::~TemporaryFile().