Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMDir Class Reference

Directory listing object. More...

#include <PLMDir.hpp>

Inheritance diagram for PLMDir:

Inheritance graph
[legend]
List of all members.

Public Methods

 PLMDir (const char *path=0)
virtual bool Open (const char *source)
virtual const char * Name () const
virtual u32 NbFiles () const
virtual void Update ()
virtual PLMResFileOpenFile (const char *name) const
virtual bool CopyFile (const char *name, const char *path) const
void GoUp ()
void GoRoot ()
void GoCWD ()
bool IsEmpty () const
bool IsRoot () const
u32 NbSubdirs () const
void PrintInfo () const
virtual PLMResFileOpenFile (const iterator &it) const=0
iterator Begin () const
iterator End () const
siterator SBegin () const
siterator SEnd () const
virtual void Sort (int how)

Protected Methods

virtual const char * FileName (u32 i) const
virtual u32 FileSize (u32 i) const
virtual time_t FileDate (u32 i) const
virtual bool FileAccess (u32 i, u32 perm_flags) const
virtual bool IsFileHidden (u32 i) const
virtual bool IsFile (u32 i) const
virtual bool IsFileLink (u32 i) const
virtual bool IsFileDir (u32 i) const
virtual int CompareFunc (const PLMSortableItem *f1, const PLMSortableItem *f2) const
virtual PLMSortableItemGetItem (u32 i) const
u32 SortedIndex (u32 i) const
u32 IterIndex (const iterator &it) const

Detailed Description

Directory listing object.

The object state is based on a path string, not the current directory. It holds a list of all entries in this directory. It is possible to update the list, to change the path, and to access the list content through iterators (normal or sorted). Note that under Linux, invalid links are ignored (not listed).

Use:

  • use ChangePath() and Go*() methods to get the list of another directory (internal directory list is then automatically updated, no need to call Update() immediately after a change),
  • to get all the entries in the current path, you just have to use an iterator. You can sort all entries before (with Sort()) and then use a s(orted)iterator.
Example: PLMDir dir; // default = application's current working directory.

sort entries by decreasing sizes, with directories first dir.Sort (PLM::SORT_DIRS | PLM::SORT_SIZE | PLM::SORT_REVERSE);

PLMDir::siterator it = m_path.SBegin ();

print file names and sizes (not the directories and the hidden files) for (; it.IsNotEnd(); it.Next()) // or ++it { if (! it.IsHidden () && ! it.IsDir()) cout << "- " << it.Name () << "\t\t" << it.Size () << endl; }

Important: note that all the modifications done to a PLMDir object by ChangePath() and Go*(), never modify the current working directory of the application. Use PLMFileUtils methods to get/modify global settings (with PLMFileUtils::GetCWD()).


Constructor & Destructor Documentation

PLMDir::PLMDir const char *    path = 0
 

Create a new object and initialize it to path or to current application working directory if NULL.


Member Function Documentation

virtual bool PLMDir::Open const char *    source [virtual]
 

Change current path and update the list.

Parameters:
source  new directory to read, can be absolute or relative to current one.
Returns:
false on error (can't enter or read path).

Implements PLMFileProvider.

const char * PLMDir::Name   [inline, virtual]
 

Get the complete name (absolute path) of the current directory.

Implements PLMFileProvider.

u32 PLMDir::NbFiles   [inline, virtual]
 

Return the total number of entries (files and subdirectories, including .

and ..).

Implements PLMFileProvider.

virtual void PLMDir::Update   [virtual]
 

Force the source to update its content list.

Items are automatically sorted if Sort() has already been called.

Reimplemented from PLMFileProvider.

virtual PLMResFile* PLMDir::OpenFile const char *    name const [virtual]
 

Try to open the file (in read-only mode) named name (may contain a relative path).

Returns:
a valid file pointer (that must be deleted after use) on success, or NULL on error.

Implements PLMFileProvider.

virtual bool PLMDir::CopyFile const char *    name,
const char *    path
const [virtual]
 

Copy the file named name from the source, into a standard file.

Parameters:
name  the name of the file in the source
path  the directory to create the copied file. It can contain a file name too, in this case, the file uses that name.
Returns:
true on success.

Implements PLMFileProvider.

void PLMDir::GoUp  
 

Change current path to parent directory.

void PLMDir::GoRoot  
 

Change current path to root directory (of current drive on windows).

void PLMDir::GoCWD  
 

Change current path to the application's current working directory.

bool PLMDir::IsEmpty  
 

Check if current directory is empty (no file other than '.' and '..').

bool PLMDir::IsRoot   [inline]
 

Check if current directory is the root directory (of current drive under win32).

u32 PLMDir::NbSubdirs   [inline]
 

Get the number of subdirectories (not files) in the current directory (including '.' and '..').

void PLMDir::PrintInfo   [virtual]
 

Print some informations on current log.

Implements PLMFileProvider.

const char * PLMDir::FileName u32    i const [inline, protected, virtual]
 

Get the name (read-only) of the file at index i (from an iterator).

Implements PLMFileProvider.

u32 PLMDir::FileSize u32    i const [inline, protected, virtual]
 

Get the total size in bytes of the file at index i (from an iterator).

Implements PLMFileProvider.

time_t PLMDir::FileDate u32    i const [inline, protected, virtual]
 

Get the date of the file at index i (from an iterator).

Implements PLMFileProvider.

bool PLMDir::FileAccess u32    i,
u32    perm_flags
const [inline, protected, virtual]
 

Get the access mode of the file at index i (from an iterator).

Implements PLMFileProvider.

bool PLMDir::IsFileHidden u32    i const [inline, protected, virtual]
 

Check if the file at index i (from an iterator) is hidden.

Implements PLMFileProvider.

bool PLMDir::IsFile u32    i const [inline, protected, virtual]
 

Check if the element at index i (from an iterator) is a standard file (not a link or a folder).

Implements PLMFileProvider.

bool PLMDir::IsFileLink u32    i const [inline, protected, virtual]
 

Check if the element at index i (from an iterator) is a link (false under win32).

Implements PLMFileProvider.

bool PLMDir::IsFileDir u32    i const [inline, protected, virtual]
 

Check if the element at index i (from an iterator) is a directory.

Implements PLMFileProvider.

virtual int PLMDir::CompareFunc const PLMSortableItem   f1,
const PLMSortableItem   f2
const [protected, virtual]
 

Determine order between two items.

Returns:
  • if f1 = f2, return 0
  • if f1 < f2, a negative value
  • if f1 > f2, a positive value

Implements PLMFileProvider.

virtual PLMSortableItem* PLMDir::GetItem u32    i const [inline, protected, virtual]
 

Get the real internalindex of the i-th sorted element.

Implements PLMFileProvider.

virtual PLMResFile* PLMFileProvider::OpenFile const iterator &    it const [pure virtual, inherited]
 

Try to open the file (in read-only mode) pointed by the iterator it.

Returns:
a valid file pointer (that must be deleted after use) on success, or NULL on error.

iterator PLMFileProvider::Begin   const [inline, inherited]
 

Get an interator pointing on the first element of the current list.

iterator PLMFileProvider::End   const [inline, inherited]
 

Get an interator pointing just after the last element of the current list.

Usually to be compared with another iterator to find the end. Call iterator.Last() to get an iterator on the last element.

siterator PLMFileProvider::SBegin   const [inline, inherited]
 

Get a 'sorted' iterator pointing on the first item of the sorted list.

The sorted iterator will run through the list in the order set by the last call to Sort().

siterator PLMFileProvider::SEnd   const [inline, inherited]
 

Get a 'sorted' iterator pointing just after the last item of the sorted list.

Usually to be compared with another iterator to find the end. Call siterator.Last() to get an iterator on the last element.

virtual void PLMFileProvider::Sort int    how [virtual, inherited]
 

Change the order of the list.

Use PLM::SortFlags constants to select an order. Only one of SORT_NAME/SIZE/DATE/EXT can be selected and OR-ed with the other flags REVERSE, CASE and/or DIRS. Later calls to Open() and Update() will automatically use the same settings. Note that only SortedIterators will parse the list in the right order, standard iterators always use the native order (SORT_NONE). After a call to Sort(), any existing s(orted)iterator are not valid anymore, you should get a new one.

u32 PLMFileProvider::SortedIndex u32    i const [inline, protected, inherited]
 

Get the "real" internal index of the i-th sorted element (from an iterator).

u32 PLMFileProvider::IterIndex const iterator &    it const [inline, protected, inherited]
 

Get the internal index of the iterator.


The documentation for this class was generated from the following file:
  • PLMDir.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:38 2004.