tbx
0.7.5
|
Class to manipulate RISC OS file and directory path names. More...
#include <path.h>
Classes | |
class | Iterator |
Iterator to step through files in a folder. More... | |
Public Types | |
enum | CopyOption { COPY_RECURSE =1, COPY_FORCE =2, COPY_ALLOW_PRINT = 0x100u, COPY_NO_ATTRIBUTES = 0x200u, COPY_STAMP = 0x400u, COPY_STRUCTURE = 0x800u, COPY_NEWER = 0x1000u, COPY_LOOK = 0x4000u } |
Enumeration to options for copy method. More... | |
Public Member Functions | |
Path () | |
Construct an empty path object. | |
Path (const std::string &name) | |
Construct a path from the given path string. More... | |
Path (const char *name) | |
Construct a path from the given path string. More... | |
Path (const Path &other) | |
Copy constructor. More... | |
Path (const Path &other, const std::string &child) | |
Construct a path to a child of another path. More... | |
Path (const Path &other, const char *name) | |
Construct a path to a child of another path. More... | |
virtual | ~Path () |
Path destructor. | |
Path & | operator= (const Path &other) |
Assign to another path. More... | |
Path & | operator= (const std::string &name) |
Assign a path to a string. More... | |
Path & | operator= (const char *name) |
Assign a path to a c string. More... | |
Path & | set (const Path &other, const std::string &child) |
Set path to a child of another path. More... | |
const std::string & | name () const |
Get file name of path. More... | |
operator const std::string & () const | |
Get path as a string. More... | |
operator const char * () const | |
Get path as a C string. More... | |
Path | child (const std::string &child) const |
Get path object for given child name. More... | |
Path | parent () const |
Get parent of this path. More... | |
Path & | down (const std::string &child) |
Updates path to the given child. More... | |
Path & | up () |
Updates this path to it's parent. More... | |
void | leaf_name (const std::string &child) |
Change the leaf name part of the path. More... | |
std::string | leaf_name () const |
Get the leaf name part of the path. More... | |
PathInfo::ObjectType | object_type () const |
Check the File system to determine the type of this object this path refers to. | |
bool | path_info (PathInfo &info) const |
Read the catalogue information for this path. More... | |
bool | raw_path_info (PathInfo &info, bool calc_file_type) const |
Read catalogue information for the given path always returning the raw load/exec address. More... | |
bool | exists () const |
Check if path exists on the file system. More... | |
bool | file () const |
Check if path is a file on the file system. More... | |
bool | directory () const |
Check if path is a directory on the file system. More... | |
bool | image_file () const |
Check if path is a image file system on the file system. More... | |
int | file_type () const |
Read the file type for this path. More... | |
bool | file_type (int type) |
Set the file type for this path. More... | |
int | raw_file_type () const |
Return the file type from the load/exec address. More... | |
int | attributes () const |
Return the objects file attributes. More... | |
bool | attributes (int new_attributes) |
Set the attributes of an object. More... | |
UTCTime | modified_time () const |
Return the modified time from the file in the path. More... | |
void | create_file (int type) const |
Create an empty file of the given file type. More... | |
void | create_directory () const |
Create a directory at the given path. More... | |
void | remove () const |
Remove this file or directory from the file system. More... | |
void | rename (const std::string &new_name) |
Rename file. More... | |
void | copy (const std::string ©to, unsigned int options=0) |
Copy the object. More... | |
void | copy (const std::string ©to, unsigned int options, void *buffer, unsigned int size) |
Copy the object. More... | |
void | move (const std::string ©to, unsigned int options=0) |
Move a file to a new location. More... | |
void | move (const std::string ©to, unsigned int options, void *buffer, unsigned int size) |
Move a file to a new location. More... | |
char * | load_file (int *length=0) const |
Load this file into a character array. More... | |
void | save_file (const char *data, int length, int file_type) const |
Save an array of characters to a file. More... | |
bool | set_current_directory () const |
Set the OS current directory to this path. More... | |
void | canonicalise () |
Canonicalise the path name. | |
bool | canonical_equals (const tbx::Path &compare_to) const |
Compare this path with another to see if their canonical names are the same using a case insensitive compare. More... | |
bool | canonical_equals (const std::string &compare_to) const |
Compare this paths with a string see if their canonical names are the same using a case insensitive compare. More... | |
Path::Iterator | begin (const std::string &wildCard) |
Create an iterator to search the current directory. More... | |
Path::Iterator | begin () |
Create an iterator to scan the whole directory. More... | |
Path::Iterator | end () |
End iterator. More... | |
Static Public Member Functions | |
static int | file_type (const std::string &file_name) |
Get the file type of the named file. More... | |
static bool | file_type (const std::string &file_name, int type) |
Set the file type for the named file. More... | |
static std::string | canonicalise (const std::string &path) |
Static function to provide the canonicalised version of a path name. More... | |
static Path | temporary (const char *prefix=0) |
Return a Path for a temporary file. More... | |
Protected Attributes | |
std::string | _name |
File name this path refers to. | |
Class to manipulate RISC OS file and directory path names.
Enumeration to options for copy method.
These flags can be combined
Path::Path | ( | const std::string & | name | ) |
Construct a path from the given path string.
name | string representing path name |
Path::Path | ( | const char * | name | ) |
Construct a path from the given path string.
name | string representing path name |
Path::Path | ( | const Path & | other, |
const std::string & | child | ||
) |
Construct a path to a child of another path.
other | Path for parent directory |
child | name of the child item in the directory |
Path::Path | ( | const Path & | other, |
const char * | child | ||
) |
Construct a path to a child of another path.
other | Path for parent directory |
child | name of the child item in the directory |
int Path::attributes | ( | ) | const |
Return the objects file attributes.
The lower byte of the attributes are 0 or more of the values in the PathInfo::Attribute enum ored together.
bool Path::attributes | ( | int | new_attributes | ) |
Set the attributes of an object.
new_attributes | new set of attributes (see PathInfo::Attribute) |
Path::Iterator Path::begin | ( | const std::string & | wild_card | ) |
Create an iterator to search the current directory.
wild_card | Wildcard to use for search. |
Path::Iterator Path::begin | ( | ) |
Create an iterator to scan the whole directory.
bool Path::canonical_equals | ( | const tbx::Path & | compare_to | ) | const |
Compare this path with another to see if their canonical names are the same using a case insensitive compare.
compare_to | Path to compare to |
bool Path::canonical_equals | ( | const std::string & | compare_to | ) | const |
Compare this paths with a string see if their canonical names are the same using a case insensitive compare.
compare_to | Path to compare to |
|
static |
Static function to provide the canonicalised version of a path name.
path | path to canonicalise |
Path Path::child | ( | const std::string & | child | ) | const |
Get path object for given child name.
child | name of child of the current path |
void Path::copy | ( | const std::string & | copyto, |
unsigned int | options = 0 |
||
) |
Copy the object.
copyto | location to copy to |
options | bitwise or of flags from CopyOption enum. |
OsError | if the copy fails |
void Path::copy | ( | const std::string & | copyto, |
unsigned int | options, | ||
void * | buffer, | ||
unsigned int | size | ||
) |
Copy the object.
This version uses the given buffer for workspace.
copyto | location to copy to |
options | bitwise or of flags from CopyOption enum. |
buffer | buffer to use |
size | size of buffer to use |
OsError | if the copy fails |
void Path::create_directory | ( | ) | const |
Create a directory at the given path.
If the directory already exists this does nothing and no error is thrown.
OsError | if directory cannot be created. |
void Path::create_file | ( | int | type | ) | const |
Create an empty file of the given file type.
type | file type for the new file |
OsError | if file failed to created |
bool Path::directory | ( | ) | const |
Check if path is a directory on the file system.
Path & Path::down | ( | const std::string & | child | ) |
Updates path to the given child.
child | name of child to update path to |
Path::Iterator Path::end | ( | ) |
End iterator.
bool Path::exists | ( | ) | const |
Check if path exists on the file system.
bool Path::file | ( | ) | const |
Check if path is a file on the file system.
int Path::file_type | ( | ) | const |
Read the file type for this path.
bool Path::file_type | ( | int | type | ) |
Set the file type for this path.
type | new file type |
|
static |
Get the file type of the named file.
file_name | name of file to return type for |
|
static |
Set the file type for the named file.
file_name | path to file to set type |
type | new file type |
bool Path::image_file | ( | ) | const |
Check if path is a image file system on the file system.
void tbx::Path::leaf_name | ( | const std::string & | child | ) |
Change the leaf name part of the path.
The leaf name part is the last path of the path after the directory delimiter.
If a directory delimiter is not found the child is appended to the path.
child | The new leaf name part of the path. |
std::string tbx::Path::leaf_name | ( | ) | const |
Get the leaf name part of the path.
The leaf name part is the last part of the path after the final directory delimiter in the path.
char * Path::load_file | ( | int * | length = 0 | ) | const |
Load this file into a character array.
length | updated to length of file if specified |
OsError | if load failed |
UTCTime Path::modified_time | ( | ) | const |
Return the modified time from the file in the path.
void Path::move | ( | const std::string & | copyto, |
unsigned int | options = 0 |
||
) |
Move a file to a new location.
This moves the file by copying it then deleting the source.
copyto | location to move to |
options | bitwise or of flags from CopyOption enum. |
OsError | if the move fails |
void Path::move | ( | const std::string & | copyto, |
unsigned int | options, | ||
void * | buffer, | ||
unsigned int | size | ||
) |
Move a file to a new location.
This moves the file by copying it then deleting the source.
This version uses the given buffer for workspace.
copyto | location to move to |
options | bitwise or of flags from CopyOption enum. |
buffer | buffer to use |
size | size of buffer to use |
OsError | if the move fails |
|
inline |
Get file name of path.
Path::operator const char * | ( | ) | const |
Get path as a C string.
Path::operator const std::string & | ( | ) | const |
Get path as a string.
Path & Path::operator= | ( | const std::string & | name | ) |
Assign a path to a string.
name | path name as a string |
Path & Path::operator= | ( | const char * | name | ) |
Assign a path to a c string.
name | path name as a c string |
Path Path::parent | ( | ) | const |
Get parent of this path.
bool Path::path_info | ( | PathInfo & | info | ) | const |
Read the catalogue information for this path.
info | PathInfo updated with the information |
int Path::raw_file_type | ( | ) | const |
Return the file type from the load/exec address.
For image FS files it will return the actual file type of the image file whereas file_type returns 0x1000 (directory).
The return value is undefined for directories/applications or files that do not have file types.
bool Path::raw_path_info | ( | PathInfo & | info, |
bool | calc_file_type | ||
) | const |
Read catalogue information for the given path always returning the raw load/exec address.
This can be used to get the actual file type for an ImageFS directory.
path | Path referring to a location on a file system |
calc_file_type | true to calculate file type from the returned catalogue information, if false file_type -1 will always be returned. |
void Path::remove | ( | ) | const |
Remove this file or directory from the file system.
Note: it is not an error if the object does not exist
OsError | if the object is locked against deletion or is a directory which is not empty or already open. |
void Path::rename | ( | const std::string & | new_name | ) |
Rename file.
This is a simple rename that will only work on single objects on the same file system.
OsError | if it fails |
void Path::save_file | ( | const char * | data, |
int | length, | ||
int | file_type | ||
) | const |
Save an array of characters to a file.
data | the array of characters to save |
length | the number of characters to save from the array |
file_type | file type to save data as |
OsError | if save fails |
Set path to a child of another path.
other | parent directory |
child | name of child in the directory |
bool Path::set_current_directory | ( | ) | const |
Set the OS current directory to this path.
|
static |
Path & Path::up | ( | ) |
Updates this path to it's parent.