Public Member Functions | List of all members
BPath Class Reference

A class representing a file system path. More...

Inherits BFlattenable.

Public Member Functions

 BPath ()
 Creates an uninitialized BPath object. More...
 
 BPath (const BPath &path)
 Creates a copy of the given BPath object. More...
 
 BPath (const entry_ref *ref)
 Creates a BPath object and initializes it to the filesystem entry specified by the passed in entry_ref struct. More...
 
 BPath (const BEntry *entry)
 Creates a BPath object and initializes it to the filesystem entry specified by the passed in BEntry object. More...
 
 BPath (const char *dir, const char *leaf=NULL, bool normalize=false)
 Creates a BPath object and initializes it to the specified path or path and filename combination. More...
 
 BPath (const BDirectory *dir, const char *leaf=NULL, bool normalize=false)
 Creates a BPath object and initializes it to the specified directory and filename combination. More...
 
virtual ~BPath ()
 Destroys the BPath object and frees any associated resources. More...
 
Constructor Helpers
status_t InitCheck () const
 Checks whether or not the object was properly initialized. More...
 
status_t SetTo (const entry_ref *ref)
 Reinitializes the object to the filesystem entry specified by the passed in entry_ref struct. More...
 
status_t SetTo (const BEntry *entry)
 Reinitializes the object to the specified filesystem entry. More...
 
status_t SetTo (const char *path, const char *leaf=NULL, bool normalize=false)
 Reinitializes the object to the passed in path or path and leaf combination. More...
 
status_t SetTo (const BDirectory *dir, const char *leaf=NULL, bool normalize=false)
 Reinitializes the object to the passed in dir and relative path combination. More...
 
void Unset ()
 Returns the object to an uninitialized state. More...
 
Path Manipulation
status_t Append (const char *path, bool normalize=false)
 Appends the passed in relative path to the end of the current path. More...
 
Path Information
const char * Path () const
 Gets the entire path of the object. More...
 
const char * Leaf () const
 Gets the leaf portion of the path. More...
 
status_t GetParent (BPath *path) const
 Initializes path with the parent directory of the BPath object. More...
 
bool IsAbsolute () const
 Gets whether or not the path is absolute or relative. More...
 
Operators
bool operator== (const BPath &item) const
 Performs a simple (string-wise) comparison of paths for equality. More...
 
bool operator== (const char *path) const
 Performs a simple (string-wise) comparison of paths for equality. More...
 
bool operator!= (const BPath &item) const
 Performs a simple (string-wise) comparison of paths for inequality. More...
 
bool operator!= (const char *path) const
 Performs a simple (string-wise) comparison of paths for inequality. More...
 
BPathoperator= (const BPath &item)
 Initializes the object as a copy of item. More...
 
BPathoperator= (const char *path)
 Initializes the object with the passed in path. More...
 
BFlattenable Method Implementations
virtual bool IsFixedSize () const
 Implements BFlattenable::IsFixedSize(). Always returns false. More...
 
virtual type_code TypeCode () const
 Implements BFlattenable::TypeCode(). Always returns B_REF_TYPE. More...
 
virtual ssize_t FlattenedSize () const
 Implements BFlattenable::FlattenedSize(). Gets the size of the flattened entry_ref struct that represents the path in bytes. More...
 
virtual status_t Flatten (void *buffer, ssize_t size) const
 Implements BFlattenable::Flatten(). Converts the path of the object to an entry_ref and writes it into buffer. More...
 
virtual bool AllowsTypeCode (type_code code) const
 Implements BFlattenable::AllowsTypeCode(). Checks if type code is equal to B_REF_TYPE. More...
 
virtual status_t Unflatten (type_code code, const void *buffer, ssize_t size)
 Implements BFlattenable::Unflatten(). Initializes the object with the flattened entry_ref data from the passed in buffer. More...
 
- Public Member Functions inherited from BFlattenable
virtual ~BFlattenable ()
 Destructor. Does nothing. More...
 

Detailed Description

A class representing a file system path.

Since
BeOS R3

Constructor & Destructor Documentation

◆ BPath() [1/6]

BPath::BPath ( )

Creates an uninitialized BPath object.

See also
SetTo()

◆ BPath() [2/6]

BPath::BPath ( const BPath path)

Creates a copy of the given BPath object.

Parameters
paththe object to be copied.
Since
BeOS R3

◆ BPath() [3/6]

BPath::BPath ( const entry_ref ref)

Creates a BPath object and initializes it to the filesystem entry specified by the passed in entry_ref struct.

Parameters
refthe entry_ref to initialize from.
Since
BeOS R5

◆ BPath() [4/6]

BPath::BPath ( const BEntry entry)

Creates a BPath object and initializes it to the filesystem entry specified by the passed in BEntry object.

Parameters
entrythe BEntry object to initialize from.
Since
BeOS R4

◆ BPath() [5/6]

BPath::BPath ( const char *  dir,
const char *  leaf = NULL,
bool  normalize = false 
)

Creates a BPath object and initializes it to the specified path or path and filename combination.

Parameters
dirThe base component of the pathname. May be absolute or relative. If relative, it is based off the current working directory.
leafThe (optional) leaf component of the pathname. Must be relative. The value of leaf is concatenated to the end of dir (a "/" will be added as a separator, if necessary).
normalizeboolean flag used to force normalization; normalization may sometimes occur even if false. The following items require normalization:
  • Relative pathnames (after concatenation; e.g. "boot/ltj")
  • The presence of "." or ".." ("/boot/ltj/../ltj/./gwar")
  • Redundant slashes ("/boot//ltj")
  • A trailing slash ("/boot/ltj/")
Since
BeOS R3

◆ BPath() [6/6]

BPath::BPath ( const BDirectory dir,
const char *  leaf = NULL,
bool  normalize = false 
)

Creates a BPath object and initializes it to the specified directory and filename combination.

Parameters
dirThe directory that provides the base component of the pathname.
leafThe (optional) leaf component of the pathname. Must be relative. The value of leaf is concatenated to the end of dir (a "/" will be added as a separator, if necessary).
normalizeboolean flag used to force normalization; normalization may sometimes occur even if false. The following items require normalization:
  • Relative pathnames (after concatenation; e.g. "boot/ltj")
  • The presence of "." or ".." ("/boot/ltj/../ltj/./gwar")
  • Redundant slashes ("/boot//ltj")
  • A trailing slash ("/boot/ltj/")
Since
BeOS R3

◆ ~BPath()

BPath::~BPath ( )
virtual

Destroys the BPath object and frees any associated resources.

Since
BeOS R3

Member Function Documentation

◆ AllowsTypeCode()

bool BPath::AllowsTypeCode ( type_code  code) const
virtual

Implements BFlattenable::AllowsTypeCode(). Checks if type code is equal to B_REF_TYPE.

Parameters
codeThe type code to test.
Returns
true if code is B_REF_TYPE, false otherwise.
Since
BeOS R3

Reimplemented from BFlattenable.

◆ Append()

status_t BPath::Append ( const char *  path,
bool  normalize = false 
)

Appends the passed in relative path to the end of the current path.

This method fails if the path is absolute or the BPath object is uninitialized.

Parameters
pathRelative pathname to append to current path (may be NULL).
normalizeBoolean flag used to force normalization; normalization may sometimes occur even if false. The following items require normalization:
  • Relative pathnames (after concatenation; e.g. "boot/ltj")
  • The presence of "." or ".." ("/boot/ltj/../ltj/./gwar")
  • Redundant slashes ("/boot//ltj")
  • A trailing slash ("/boot/ltj/")
Returns
A status code.
Return values
B_OKInitialization was successful.
B_BAD_VALUEref was NULL.
B_NAME_TOO_LONGThe pathname was longer than B_PATH_NAME_LENGTH.
Since
BeOS R3

◆ Flatten()

status_t BPath::Flatten ( void *  buffer,
ssize_t  size 
) const
virtual

Implements BFlattenable::Flatten(). Converts the path of the object to an entry_ref and writes it into buffer.

Parameters
bufferThe buffer that the data is to be stored in.
sizeSize of buffer.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUEbuffer was NULL or of insufficient size.
Since
BeOS R3

Implements BFlattenable.

◆ FlattenedSize()

ssize_t BPath::FlattenedSize ( ) const
virtual

Implements BFlattenable::FlattenedSize(). Gets the size of the flattened entry_ref struct that represents the path in bytes.

Returns
The size of the flattened entry_ref struct that represents the path in bytes.
Since
BeOS R3

Implements BFlattenable.

◆ GetParent()

status_t BPath::GetParent ( BPath path) const

Initializes path with the parent directory of the BPath object.

No normalization is performed on the path.

Parameters
pathThe BPath object to be initialized to the parent directory.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUEpath was NULL.
B_ENTRY_NOT_FOUNDThe BPath object represents the root path and thus has no parent.

◆ InitCheck()

status_t BPath::InitCheck ( ) const

Checks whether or not the object was properly initialized.

Returns
B_OK, if the BPath object was properly initialized, an error code otherwise.
Since
BeOS R3

◆ IsAbsolute()

bool BPath::IsAbsolute ( ) const

Gets whether or not the path is absolute or relative.

Warning
This method returns false if the object is initialized.
Returns
true if the path is absolute, false if relative or if the object is uninitialized.

◆ IsFixedSize()

bool BPath::IsFixedSize ( ) const
virtual

Implements BFlattenable::IsFixedSize(). Always returns false.

Returns
false
Since
BeOS R3

Implements BFlattenable.

◆ Leaf()

const char * BPath::Leaf ( ) const

Gets the leaf portion of the path.

The leaf portion of the path is defined to be the string after the last '/'. For the root path ("/") it is an empty string ("").

Returns
The leaf portion of the path or NULL if it is not properly initialized.
Since
BeOS R3

◆ operator!=() [1/2]

bool BPath::operator!= ( const BPath item) const

Performs a simple (string-wise) comparison of paths for inequality.

Warning
No normalization takes place, two uninitialized BPath objects are considered equal.
Parameters
itemthe BPath object to compare.
Returns
true, if the path names are not equal, false otherwise.
Since
BeOS R3

◆ operator!=() [2/2]

bool BPath::operator!= ( const char *  path) const

Performs a simple (string-wise) comparison of paths for inequality.

Warning
No normalization takes place.
Parameters
pathThe path to compare.
Returns
true, if the path names are not equal, false otherwise.
Since
BeOS R3

◆ operator=() [1/2]

BPath & BPath::operator= ( const BPath item)

Initializes the object as a copy of item.

Parameters
itemThe BPath object to copy
Returns
A pointer to the newly initialized BPath object.
Since
BeOS R3

◆ operator=() [2/2]

BPath & BPath::operator= ( const char *  path)

Initializes the object with the passed in path.

Has the same effect as

SetTo(path)
Parameters
paththe path to be assign to this object.
Returns
A pointer to the newly initialized BPath object.
Since
BeOS R3

◆ operator==() [1/2]

bool BPath::operator== ( const BPath item) const

Performs a simple (string-wise) comparison of paths for equality.

Warning
No normalization takes place, two uninitialized BPath objects are considered equal.
Parameters
itemthe BPath object to compare.
Returns
true, if the paths are equal, false otherwise.
Since
BeOS R3

◆ operator==() [2/2]

bool BPath::operator== ( const char *  path) const

Performs a simple (string-wise) comparison of paths for equality.

Warning
No normalization takes place.
Parameters
pathThe path to compare.
Returns
true, if the path names are equal, false otherwise.
Since
BeOS R3

◆ Path()

const char * BPath::Path ( ) const

Gets the entire path of the object.

Returns
The path name of the object, or NULL if it is not properly initialized.
Since
BeOS R3

◆ SetTo() [1/4]

status_t BPath::SetTo ( const entry_ref ref)

Reinitializes the object to the filesystem entry specified by the passed in entry_ref struct.

Parameters
refThe entry_ref to reinitialize the entry from.
Returns
A status code.
Return values
B_OKInitialization was successful.
B_BAD_VALUEref was NULL.
B_NAME_TOO_LONGThe pathname was longer than B_PATH_NAME_LENGTH.
Since
BeOS R5

◆ SetTo() [2/4]

status_t BPath::SetTo ( const BEntry entry)

Reinitializes the object to the specified filesystem entry.

Parameters
entryThe BEntry to reinitialize the entry from.
Returns
A status code.
Return values
B_OKInitialization was successful.
B_BAD_VALUEref was NULL.
B_NAME_TOO_LONGThe pathname was longer than B_PATH_NAME_LENGTH.
Since
BeOS R4

◆ SetTo() [3/4]

status_t BPath::SetTo ( const char *  path,
const char *  leaf = NULL,
bool  normalize = false 
)

Reinitializes the object to the passed in path or path and leaf combination.

Remarks
The following pseudocode is safe:
path.SetTo(path.Path(), "new leaf")
Parameters
pathThe path name to use.
leafThe leaf name to use (may be NULL).
normalizeBoolean flag used to force normalization; normalization may sometimes occur even if false. The following items require normalization:
  • Relative pathnames (after concatenation; e.g. "boot/ltj")
  • The presence of "." or ".." ("/boot/ltj/../ltj/./gwar")
  • Redundant slashes ("/boot//ltj")
  • A trailing slash ("/boot/ltj/")
Returns
A status code.
Return values
B_OKInitialization was successful.
B_BAD_VALUEref was NULL.
B_NAME_TOO_LONGThe pathname was longer than B_PATH_NAME_LENGTH.
Since
BeOS R3

◆ SetTo() [4/4]

status_t BPath::SetTo ( const BDirectory dir,
const char *  path = NULL,
bool  normalize = false 
)

Reinitializes the object to the passed in dir and relative path combination.

Parameters
dirThe directory that provides the base component of the pathname.
paththe relative path name (may be NULL).
normalizeboolean flag used to force normalization; normalization may sometimes occur even if false. The following items require normalization:
  • Relative pathnames (after concatenation; e.g. "boot/ltj")
  • The presence of "." or ".." ("/boot/ltj/../ltj/./gwar")
  • Redundant slashes ("/boot//ltj")
  • A trailing slash ("/boot/ltj/")
Returns
A status code.
Return values
B_OKInitialization was successful.
B_BAD_VALUEref was NULL.
B_NAME_TOO_LONGThe pathname was longer than B_PATH_NAME_LENGTH.
Since
BeOS R3

◆ TypeCode()

type_code BPath::TypeCode ( ) const
virtual

Implements BFlattenable::TypeCode(). Always returns B_REF_TYPE.

Returns
B_REF_TYPE
Since
BeOS R3

Implements BFlattenable.

◆ Unflatten()

status_t BPath::Unflatten ( type_code  code,
const void *  buffer,
ssize_t  size 
)
virtual

Implements BFlattenable::Unflatten(). Initializes the object with the flattened entry_ref data from the passed in buffer.

The type code must be set to B_REF_TYPE.

Parameters
codeThe type code of the flattened data, must be B_REF_TYPE.
bufferA pointer to a buffer containing the flattened data.
sizeThe size of buffer in bytes.
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUEbuffer was NULL or didn't contain an entry_ref.
Since
BeOS R3

Implements BFlattenable.

◆ Unset()

void BPath::Unset ( )

Returns the object to an uninitialized state.

Frees any resources it allocated and marks the object as uninitialized.

Since
BeOS R3