rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWDirEntry Class Reference
[Internet Basics]

A convenience class that encapsulates parsing and component storage of directory entries typical of those returned from the FTP LIST command. More...

#include <rw/internet/RWDirEntry.h>

List of all members.

Public Types

enum  entryType {
  ftype_directory, ftype_link, ftype_file, ftype_unknown,
  DIRECTORY, LINK, FILE, UNKNOWN
}

Public Member Functions

 RWDirEntry ()
 RWDirEntry (const RWCString &line)
RWCString getData () const
entryType getType () const
RWCString getName () const
int getSize () const
RWTime getTime () const
RWCString getLink () const
bool isValid () const
RWCString getError () const

Friends

std::ostream & operator<< (std::ostream &str, const RWDirEntry &)

Detailed Description

RWDirEntry is a convenience class. It encapsulates parsing and component storage of directory entries typical of those returned from the FTP LIST command. The directory entry format is usually some variation of the UNIX ls long format. RWDirEntry is robust in its ability to make sense of the data passed to it. RWDirEntry expects text similar to the following:

FileType Owner Group Size Date Time Name Link
drwxr-xr-x 3 fred staff 512 Apr 24 16:14 pub
lrwxr-xr-x 1 fred staff 512 Jan 10 1990 data ->/data2
-rw-rw-rw- 1 fred staff 1024 Apr 24 12:23 stuff

If the owner and/or group field is missing, the parsing mechanism provides empty defaults. Data type checks are performed on the fields (for example, Size must be an integer and Time must be in the form XX:XX). If any field fails its format test, the object is set to the invalid state and an error text message is saved. This message is available through the getError() method. If the directory entry parse fails, a copy of the original input string is available through the getData() method.

Examples

 #include <rw/rstream.h>
 #include <rw/cstring.h>
 #include <rw/network/RWWinSockInfo.h>
 #include <rw/internet/RWDirEntry.h>
 
 int
 main()
 {
     RWWinSockInfo info;
 
     RWCString text =
     "lrwxr-xr-x 1 fred staff 512 Jan 10 1990 data -> /data2"
 
     RWDirEntry de = RWDirEntry(text);
 
     cout << de.getName()  << endl;
     cout << de.getTime()  << endl;
     cout << de.getLink()  << endl;
     return 0;
 }

Program Output

 data
 01/10/90 12:00:00
 /data2

Member Enumeration Documentation

Enumerates the possible file types in the file field of an RWDirEntry object.

Enumerator:
ftype_directory 

Entry is a directory.

ftype_link 

Entry is a link.

ftype_file 

Entry is a file.

ftype_unknown 

Entry is an unknown type.

DIRECTORY 
Deprecated:
You can refuse support for this value by defining the macro RW_AVOID_PREPROCESSOR_PROBLEMS.
LINK 
Deprecated:
You can refuse support for this value by defining the macro RW_AVOID_PREPROCESSOR_PROBLEMS.
FILE 
Deprecated:
You can refuse support for this value by defining the macro RW_AVOID_PREPROCESSOR_PROBLEMS.
UNKNOWN 
Deprecated:
You can refuse support for this value by defining the macro RW_AVOID_PREPROCESSOR_PROBLEMS.

Constructor & Destructor Documentation

RWDirEntry::RWDirEntry (  ) 

Constructs a default invalid directory entry.

RWDirEntry::RWDirEntry ( const RWCString line  ) 

Constructs an RWDirEntry object from an RWCString.


Member Function Documentation

RWCString RWDirEntry::getData (  )  const

Returns the raw text that was used to build the object. It is valid to use this method on an object that returns false from the isValid() method. It is useful in the event that the entry text could not be parsed successfully. The RWCString should contain 7-bit US-ASCII data.

RWCString RWDirEntry::getError (  )  const

Returns a text description of the error that was encountered during the directory entry parsing phase. The RWCString should contain 7-bit US-ASCII data.

RWCString RWDirEntry::getLink (  )  const

Returns the link destination if the entry is of type LINK. If the entry is not of type LINK, an empty string is returned. The RWCString should contain 7-bit US-ASCII data.

RWCString RWDirEntry::getName (  )  const

Returns the name of the entry. The RWCString should contain 7-bit US-ASCII data.

int RWDirEntry::getSize (  )  const

Returns the size of the entry.

RWTime RWDirEntry::getTime (  )  const

Returns the time that the file was created.

Typically, files that are at least one year old have only a creation date. For these entries, this method returns 12:00:00. For files less than one year old, the year is typically not specified -- the year is either the current or previous year, depending on the current date. For example, if the current date is 10/15 and the file date is 9/2 (no year), the year of the file is assumed to be the current year. If the current date is 1/4, and the file date is 9/2, the year of the file is assumed to be the previous year.

entryType RWDirEntry::getType (  )  const

Returns the type of the entry.

bool RWDirEntry::isValid (  )  const

Returns true if the entry was parsed successfully. If it was not, the getData() method can be used to retrieve the original text, and the getError() method can be used to return a text description of the parse error.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  str,
const RWDirEntry  
) [friend]

Outputs an RWDirEntry object to an std::ostream in a common format.

Note:
This class does not have an extraction (>>) operator.
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.