Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CascadeDirectory Class Reference

an easy to use directory class More...

#include <cascade/util/CascadeDirectory.h>

Inheritance diagram for CascadeDirectory:

CascadeFSObject CascadeObject List of all members.

Public Types

typedef bool() DirectoryEnumerationCallback (CascadeFSObject *obj, void *pClientData)
typedef bool() DirCopyCallback (u32 inTotal, u32 inComplete, const CascadeString &inCurrentName, void *pClientData)

Public Member Functions

 CascadeDirectory ()
 CascadeDirectory (const char *pName)
virtual ~CascadeDirectory ()
virtual bool Create (mode_t inMode=0666)
virtual bool Delete (bool inRecursive)
virtual bool GetChildCount (u32 &outCount, bool inRecursive, bool inSkipInvisible) const
virtual bool GetChildren (CascadeTemplateArray< CascadeFSObject * > *&outChildren, bool inRecursive, bool inSkipInvisible) const
virtual bool GetMatchingChildCount (CascadeFSObject::Selector &inSelector, bool inRecursive, bool inSkipInvisible, u32 &outCount) const
virtual bool GetMatchingChildren (CascadeFSObject::Selector &inSelector, bool inRecursive, bool inSkipInvisible, CascadeTemplateArray< CascadeFSObject * > *&outChildren) const
virtual bool EnumerateMatchingChildren (CascadeFSObject::Selector &inSelector, bool inRecursive, bool inSkipInvisible, DirectoryEnumerationCallback inCallback, void *inClientData) const
virtual bool SetCWD (void) const
virtual bool CopyTo (CascadeDirectory &inDestination, bool inRecursive, DirCopyCallback *inCallback, void *inClientData, CascadeFile::FileCopyCallback *inFileCallback, void *inFileClientData, FSCopyError &outError)
virtual bool Contains (const CascadeFSObject *inObject, bool &outContains)
virtual bool IsDirectory (void) const

Static Public Member Functions

static CascadeDirectoryGetCWD (void)

Detailed Description

an easy to use directory class

Skip the description

CascadeDirectory is a sub-class of CascadeFSObject, and provides easy to use object-based access to directory operations, most notably getting and setting the current working directory (CWD) and counting and enumerating the contents of a given directory. Directory creation and deletion are also supported.


class CascadeDirectory


Member Typedef Documentation

typedef bool() CascadeDirectory::DirCopyCallback(u32 inTotal, u32 inComplete, const CascadeString &inCurrentName, void *pClientData)
 

callback function for CopyTo method

Create a callback function of this signature to pass to the CopyTo method. Information is provided to calculate the progress of the copy operation, and display the current file or directory name that is being copied.

Return true from your callback to allow the copy to proceed. Return false to cause the copy to stop. (The copy will return a false return value if canceled in this way.)

Parameters:
inTotal the total number of files and directories that are being copied
inComplete the total number of files and directories copied so far
inCurrentName the name of the object being copied now
pClientData client data provided to CopyTo
Returns:
true if copy is to proceed; false if stop requested

typedef bool() CascadeDirectory::DirectoryEnumerationCallback(CascadeFSObject *obj, void *pClientData)
 

callback function for EnumerateMatchingChildren method

Create a callback function of this signature to pass to the EnumerateMatchingChildren method. Each matching child is passed to this function, along with the client data pointer supplied as an argument to EnumerateMatchingChildren.

THE OBJECT POINTER MAY BE NULL. In order to ensure that clients have timely access to aborting the enumeration, the callback will be called with a NULL object pointer if 100 consecutive objects found do not match the selector. Be sure you test for NULL!

The callback should return true if enumeration is to continue. To stop the enumeration, return false.

Parameters:
obj the found object
pClientData the client data pointer
Returns:
true to continue the enumeration, false to cancel.


Constructor & Destructor Documentation

CascadeDirectory::CascadeDirectory  ) 
 

default constructor

Creates a CascadeDirectory object for later use. You must call SetName before this object will be usable for anything.

CascadeDirectory::CascadeDirectory const char *  pName  ) 
 

parameterized constructor

Creates a CascadeDirectory object with the supplied name. Note that the corresponding directory need not exist in the filesystem. You can create one by calling Create().

Parameters:
pName C-string representation of the file name. Names beginning with a "/" are treated as absolute paths, while any other character is treated as a relative path to the current working direcotry.

virtual CascadeDirectory::~CascadeDirectory  )  [virtual]
 

destructor

Destructor


Member Function Documentation

virtual bool CascadeDirectory::Contains const CascadeFSObject inObject,
bool &  outContains
[virtual]
 

is the supplied object contained in this directory?

If the supplied object is contained within this directory, including within a sub-directory of this directory, outContains is set to true. Otherwise, outContains is set to false. The function itself returns false if there is an error, and outContains is not touched.

Parameters:
inObject a CascadeFSObject pointer to check
outContains on successful return, true if this directory contains the object. Untouched if function returns false.
Returns:
true if the function succeeded, regardless of containment.

virtual bool CascadeDirectory::CopyTo CascadeDirectory inDestination,
bool  inRecursive,
DirCopyCallback inCallback,
void *  inClientData,
CascadeFile::FileCopyCallback inFileCallback,
void *  inFileClientData,
FSCopyError outError
[virtual]
 

copy the contents of this directory into destination

Copies the contents of this directory into the destination directory. The destination must exist. If inRecursive is true, then sub-directories are duplicated in the destination as well. If inCallback is provided, it is called to allow progress display.

You may also supply a file callback of the same type taken by CascadeFile::CopyInto. This will allow you to provide more-detailed progress feedback and to interrupt the copying of large files before completion of the current file.

Note:
On failure, some files may have been copied.
Parameters:
inDestination the destination directory. Must exist.
inRecursive whether to include sub-directories
inCallback callback of type DirCopyCallback. May be NULL.
inClientData client data returned to you in your callback. May be NULL.
inFileCallback callback of type FileCopyCallback. May be NULL.
inFileClientData client data returned to you in your file callback. May be NULL.
outError on return, status information of type FSCopyError
Returns:
true if the entire directory was copied. False if failure or canceled.

virtual bool CascadeDirectory::Create mode_t  inMode = 0666  )  [virtual]
 

creates a directory

Creates a directory in the filesystem matching this object's path and name, using the supplied mode.

Parameters:
inMode the mode with which to create the directory. Defaults to 666
Returns:
true if creation succeeded. May fail if the directory (or a file of the same name already exists, or if the name of this object has not been set.
Warning:
Function will fail if all intermediate directories in the path do not exist. This limitation may be addressed in a later version.

virtual bool CascadeDirectory::Delete bool  inRecursive  )  [virtual]
 

deletes the directory from the filesystem

Deletes this directory from the filesystem. If inRecursive is true, the directory and its contents will be deleted. Otherwise, the directory must be empty for this function to succeed. May fail (and return false) if permissions are inadequate, if the specified directory doesn't exist, or if the name of this object has not been set.

Parameters:
inRecursive if true, the directory and its contents will be deleted. Otherwise, the directory must be empty for this function to succeed.
Returns:
true if deletion succeeded. Returns false if permissions are inadequate, if the specified directory doesn't exist, if the directory is non-empty and inRecursive is false, or if the name of this object has not been set.

virtual bool CascadeDirectory::EnumerateMatchingChildren CascadeFSObject::Selector inSelector,
bool  inRecursive,
bool  inSkipInvisible,
DirectoryEnumerationCallback  inCallback,
void *  inClientData
const [virtual]
 

Scans a directory, calling a callback for each match

For each child in this directory which matches a set of criteria, the supplied callback function is called, and a new CascadeFSObject is returned. The callback should return false to abort the enumeration. The client is responsible for deleting the returned object.

Also, in order to ensure that clients can abort the scan in a timely fashion, the callback is called for non-matching items, but in this case, the CascadeFSObject pointer will be NULL. Be sure to check this before using! The inClientData pointer is supplied to the callback function each time it is called, whether or not the item pointer is NULL.

Includes sub-directory contents if inRecursive is true. ".", ".." and any hard links to them are excluded. Symlinked files are considered. Symlinked directories are not traversed if inRecursive is true. If inSkipInvisible is true, files with names beginning with '.' are skipped, and directories with names beginning with '.' are not traversed. Any directory named "resource.frk" is also skipped if inSkipInvisible is true. The criteria are embodied in a selector, supplied to the this function. Some common selectors are supplied with the CascadeFSObject class, or the user may define their own. Returns true if results are valid. Returns true if the enumeration was canceled early by teh callback. Returns false in the event of error. Errors may include insufficient memory to enumerate all children, calling this function on a non-existent directory, or calling this function without setting the name of the CascadeDirectory object.

Parameters:
inSelector a CascadeFSObject::Selector object (actually, a sub-class) to use when determining which children to return
inRecursive pass true to scan sub-directories, or false to only scan the top level
inSkipInvisible pass true to skip files and directories whose names begin with '.'
inCallback a callback function of type DirectoryEnumerationCallback
inClientData a client data pointer which is supplied to the callback
Returns:
true if successful and false if there is a failure (for example, you may have tried to scan a directory that does not exist, or you may not have set the name of this CascadeDirectory object before calling the function. Returns true if aborted by the callback.

virtual bool CascadeDirectory::GetChildCount u32 outCount,
bool  inRecursive,
bool  inSkipInvisible
const [virtual]
 

count children of this directory

Gets the number of contained objects in the directory. Includes sub-directory contents as well, if inRecursive is true. (Note that in the recursive case, a sub-directory with two items in it counts as three children.) outCount may be zero. ".", ".." and any hard links to them are excluded. Linked directories are also skipped if inRecursive is true (to prevent cycles). Items whose names begin

virtual bool CascadeDirectory::GetChildren CascadeTemplateArray< CascadeFSObject * > *&  outChildren,
bool  inRecursive,
bool  inSkipInvisible
const [virtual]
 

returns all children of the directory

Returns an array of CascadeFSObject pointers representing the contained children of this directory. Includes sub-directory contents if inRecursive is true. Allocates the returned objects and the array itself. The caller is responsible for disposing the array and its contents (you must delete each contained CascadeFSObject). ".", ".." and any hard links to them are excluded. Files and directories whose name begins with '.' are excluded if inSkipInvisible is true. Any directory named "resource.frk" is also skipped if inSkipInvisible is true. Symlinked directories are skipped if inRecursive is true (to prevent cycles). Returns true if results are valid. Returns false and leaves outChildren untouched in the event of error. Errors may include insufficient memory to enumerate all children, calling this function on a non-existent directory, or calling this function without setting the name of the directory. Use GetMatchingChildren to be selective about the files you request.

Parameters:
outChildren a reference to a pointer. Declare a local pointer to a CascadeTemplateArray, and pass it in without allocating memory. If this function is successful, that pointer will be changed to point to the newly-created array.
inRecursive pass true for recursive scan, false to scan only first level
inSkipInvisible pass true to skip all files beginning with '.' in their names. If true, directories beginning with '.' are skipped in the recursion.
Returns:
true if successful (and outChildren has been filled in) or false if failure and outChildren is left untouched.

static CascadeDirectory* CascadeDirectory::GetCWD void   )  [static]
 

static function returns current working directory

Static function to create a CascadeDirectory object representing the current working directory.

Returns:
a new CascadeDirectory object representing the current working directory. Caller is responsible for deleting this object. May return NULL if memory allocation fails. Check for NULL before using the returned pointer.

virtual bool CascadeDirectory::GetMatchingChildCount CascadeFSObject::Selector inSelector,
bool  inRecursive,
bool  inSkipInvisible,
u32 outCount
const [virtual]
 

returns a count of child objects matching selector criteria

Returns the number of contained files matching a set of criteria. If inRecursive is true, this count will include the contents of any contained directories. Otherwise, only direct children of this directory are returned. ".", ".." and any hard links to them are excluded. Symlinked files are considered. Symlinked directories are not traversed if inRecursive is true. If inSkipInvisible is true, files with names beginning with '.' are skipped, and directories with names beginning with '.' are not traversed. Any directory named "resource.frk" is also skipped if inSkipInvisible is true. The criteria are embodied in a selector, supplied to the this function. Some common selectors are supplied with the CascadeFSObject class, or the user may define their own.

Parameters:
inSelector a CascadeFSObject::Selector object (actually, a sub-class) to use when determining which children to return
inRecursive pass true to scan sub-directories, or false to only scan the top level
inSkipInvisible pass true to skip files and directories whose names begin with '.'
outCount the supplied u32 is filled with the count of matching children if the function returns true. It is left untouched if the function returns false.
Returns:
true if successful and false if there is a failure (for example, you may have tried to scan a directory that does not exist, or you may not have set the name of this CascadeDirectory object before calling the function

virtual bool CascadeDirectory::GetMatchingChildren CascadeFSObject::Selector inSelector,
bool  inRecursive,
bool  inSkipInvisible,
CascadeTemplateArray< CascadeFSObject * > *&  outChildren
const [virtual]
 

returns an array of matching children

Returns an array of CascadeFSObject pointers representing children of this directory which match a set of criteria. Includes sub- directory contents if inRecursive is true. Allocates the returned objects and the array. The caller is responsible for disposal of these objects and the array itself. ".", ".." and any hard links to them are excluded. Symlinked files are considered. Symlinked directories are not traversed if inRecursive is true. If inSkipInvisible is true, files with names beginning with '.' are skipped, and directories with names beginning with '.' are not traversed. Any directory named "resource.frk" is also skipped if inSkipInvisible is true. The criteria are embodied in a selector, supplied to the this function. Some common selectors are supplied with the CascadeFSObject class, or the user may define their own. Returns true if results are valid. Returns false and leaves outChildren untouched in the event of error. Errors may include insufficient memory to enumerate all children, calling this function on a non-existent directory, or calling this function without setting the name of the CascadeDirectory object.

Parameters:
inSelector a CascadeFSObject::Selector object (actually, a sub-class) to use when determining which children to return
inRecursive pass true to scan sub-directories, or false to only scan the top level
inSkipInvisible pass true to skip files and directories whose names begin with '.'
outChildren a reference to a pointer. Declare a pointer to a CascadeTemplateArray, but do not allocate memory for the pointer. Pass the pointer to this function (don't dereference). Upon successful return, the pointer is changed to point to a new array of matching children. Caller is responsible for disposing the children and the array with delete.
Returns:
true if successful and false if there is a failure (for example, you may have tried to scan a directory that does not exist, or you may not have set the name of this CascadeDirectory object before calling the function

virtual bool CascadeDirectory::IsDirectory void   )  const [inline, virtual]
 

returns true, always

Mandatory override of the pure virtual superclass function.

Returns:
true, always

Implements CascadeFSObject.

virtual bool CascadeDirectory::SetCWD void   )  const [virtual]
 

set this directory to be current working directory

Sets this directory to be the current working directory. Return value indicates success. May fail if the directory does not exist, or if the name has not been set. See also the StSetCWD utility class.

Returns:
true if the CWD was set, or false if not


The documentation for this class was generated from the following file:
Generated on Sun Jul 24 14:27:19 2005 for Cascade Library by  doxygen 1.4.1