tbx  0.7.5
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
tbx::Path Class Reference

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.
 
Pathoperator= (const Path &other)
 Assign to another path. More...
 
Pathoperator= (const std::string &name)
 Assign a path to a string. More...
 
Pathoperator= (const char *name)
 Assign a path to a c string. More...
 
Pathset (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...
 
Pathdown (const std::string &child)
 Updates path to the given child. More...
 
Pathup ()
 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 &copyto, unsigned int options=0)
 Copy the object. More...
 
void copy (const std::string &copyto, unsigned int options, void *buffer, unsigned int size)
 Copy the object. More...
 
void move (const std::string &copyto, unsigned int options=0)
 Move a file to a new location. More...
 
void move (const std::string &copyto, 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.
 

Detailed Description

Class to manipulate RISC OS file and directory path names.

Member Enumeration Documentation

◆ CopyOption

Enumeration to options for copy method.

These flags can be combined

Constructor & Destructor Documentation

◆ Path() [1/5]

Path::Path ( const std::string &  name)

Construct a path from the given path string.

Parameters
namestring representing path name

◆ Path() [2/5]

Path::Path ( const char *  name)

Construct a path from the given path string.

Parameters
namestring representing path name

◆ Path() [3/5]

Path::Path ( const Path other)

Copy constructor.

Parameters
otherPath to copy

◆ Path() [4/5]

Path::Path ( const Path other,
const std::string &  child 
)

Construct a path to a child of another path.

Parameters
otherPath for parent directory
childname of the child item in the directory

◆ Path() [5/5]

Path::Path ( const Path other,
const char *  child 
)

Construct a path to a child of another path.

Parameters
otherPath for parent directory
childname of the child item in the directory

Member Function Documentation

◆ attributes() [1/2]

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.

Returns
file attributes of the object

◆ attributes() [2/2]

bool Path::attributes ( int  new_attributes)

Set the attributes of an object.

Parameters
new_attributesnew set of attributes (see PathInfo::Attribute)
Returns
true if successful

◆ begin() [1/2]

Path::Iterator Path::begin ( const std::string &  wild_card)

Create an iterator to search the current directory.

Parameters
wild_cardWildcard to use for search.
Returns
iterator for the directory

◆ begin() [2/2]

Path::Iterator Path::begin ( )

Create an iterator to scan the whole directory.

Returns
iterator for first item in the directory

◆ canonical_equals() [1/2]

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.

Parameters
compare_toPath to compare to
Returns
true if they are the same

◆ canonical_equals() [2/2]

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.

Parameters
compare_toPath to compare to
Returns
true if they are the same

◆ canonicalise()

std::string Path::canonicalise ( const std::string &  path)
static

Static function to provide the canonicalised version of a path name.

Parameters
pathpath to canonicalise
Returns
new path name

◆ child()

Path Path::child ( const std::string &  child) const

Get path object for given child name.

Parameters
childname of child of the current path
Returns
new Path for the child

◆ copy() [1/2]

void Path::copy ( const std::string &  copyto,
unsigned int  options = 0 
)

Copy the object.

Parameters
copytolocation to copy to
optionsbitwise or of flags from CopyOption enum.
Exceptions
OsErrorif the copy fails

◆ copy() [2/2]

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.

Parameters
copytolocation to copy to
optionsbitwise or of flags from CopyOption enum.
bufferbuffer to use
sizesize of buffer to use
Exceptions
OsErrorif the copy fails

◆ create_directory()

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.

Exceptions
OsErrorif directory cannot be created.

◆ create_file()

void Path::create_file ( int  type) const

Create an empty file of the given file type.

Parameters
typefile type for the new file
Exceptions
OsErrorif file failed to created

◆ directory()

bool Path::directory ( ) const

Check if path is a directory on the file system.

Returns
true if the path refers to a directory

◆ down()

Path & Path::down ( const std::string &  child)

Updates path to the given child.

Parameters
childname of child to update path to
Returns
*this

◆ end()

Path::Iterator Path::end ( )

End iterator.

Returns
end iterator for the directory in this path

◆ exists()

bool Path::exists ( ) const

Check if path exists on the file system.

Returns
true if the path exists.

◆ file()

bool Path::file ( ) const

Check if path is a file on the file system.

Returns
true if the path refers to a file

◆ file_type() [1/4]

int Path::file_type ( ) const

Read the file type for this path.

Returns
the file type (or -2 if could not be read)

◆ file_type() [2/4]

bool Path::file_type ( int  type)

Set the file type for this path.

Parameters
typenew file type
Returns
true if file type set successfully

◆ file_type() [3/4]

int Path::file_type ( const std::string &  file_name)
static

Get the file type of the named file.

Parameters
file_namename of file to return type for
Returns
the file type (or -2 if could not be read)

◆ file_type() [4/4]

bool Path::file_type ( const std::string &  file_name,
int  type 
)
static

Set the file type for the named file.

Parameters
file_namepath to file to set type
typenew file type
Returns
true if file type set successfully

◆ image_file()

bool Path::image_file ( ) const

Check if path is a image file system on the file system.

Returns
true if the path refers to a image file system

◆ leaf_name() [1/2]

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.

Parameters
childThe new leaf name part of the path.

◆ leaf_name() [2/2]

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.

Returns
leaf name part or "" string if it can't be determined

◆ load_file()

char * Path::load_file ( int *  length = 0) const

Load this file into a character array.

Parameters
lengthupdated to length of file if specified
Returns
new char[] with contents of file
Exceptions
OsErrorif load failed

◆ modified_time()

UTCTime Path::modified_time ( ) const

Return the modified time from the file in the path.

Returns
modified time of file or UTCTime(0) if file doesn't exist or doesn't have a time.

◆ move() [1/2]

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.

Parameters
copytolocation to move to
optionsbitwise or of flags from CopyOption enum.
Exceptions
OsErrorif the move fails

◆ move() [2/2]

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.

Parameters
copytolocation to move to
optionsbitwise or of flags from CopyOption enum.
bufferbuffer to use
sizesize of buffer to use
Exceptions
OsErrorif the move fails

◆ name()

const std::string& tbx::Path::name ( ) const
inline

Get file name of path.

Returns
file name

◆ operator const char *()

Path::operator const char * ( ) const

Get path as a C string.

Returns
path name as a null terminated C string

◆ operator const std::string &()

Path::operator const std::string & ( ) const

Get path as a string.

Returns
path name as a string

◆ operator=() [1/3]

Path & Path::operator= ( const Path other)

Assign to another path.

Parameters
otherPath to copy
Returns
*this

◆ operator=() [2/3]

Path & Path::operator= ( const std::string &  name)

Assign a path to a string.

Parameters
namepath name as a string

◆ operator=() [3/3]

Path & Path::operator= ( const char *  name)

Assign a path to a c string.

Parameters
namepath name as a c string

◆ parent()

Path Path::parent ( ) const

Get parent of this path.

Returns
new path for the parent

◆ path_info()

bool Path::path_info ( PathInfo info) const

Read the catalogue information for this path.

Parameters
infoPathInfo updated with the information
Returns
true if the path is on the file system

◆ raw_file_type()

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.

Returns
raw file type.

◆ raw_path_info()

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.

Parameters
pathPath referring to a location on a file system
calc_file_typetrue to calculate file type from the returned catalogue information, if false file_type -1 will always be returned.
Returns
true if information read

◆ remove()

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

Exceptions
OsErrorif the object is locked against deletion or is a directory which is not empty or already open.

◆ rename()

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.

Exceptions
OsErrorif it fails

◆ save_file()

void Path::save_file ( const char *  data,
int  length,
int  file_type 
) const

Save an array of characters to a file.

Parameters
datathe array of characters to save
lengththe number of characters to save from the array
file_typefile type to save data as
Exceptions
OsErrorif save fails

◆ set()

Path & Path::set ( const Path other,
const std::string &  child 
)

Set path to a child of another path.

Parameters
otherparent directory
childname of child in the directory
Returns
*this

◆ set_current_directory()

bool Path::set_current_directory ( ) const

Set the OS current directory to this path.

Returns
true if successful

◆ temporary()

Path Path::temporary ( const char *  prefix = 0)
static

Return a Path for a temporary file.

The file will be inside the scrap directory and the leaf name will start with the prefix given (or tbx if there is no prefix).

The file name is checked against other

Parameters
prefixfor leaf name of the path
Returns
Path with temporary file name

◆ up()

Path & Path::up ( )

Updates this path to it's parent.

Returns
*this

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