NOTE The preferred method for your code to obtain an entity is to be handed an entity from an external source, such as the workspace. This section describes how to use TPathName to obtain entities on your own, though this is not the optimal method.
Obtaining a file
system entity from
a pathname
You can obtain file system entities with TPathName using either absolute or relative paths. When you construct a TPathName with an absolute path, you pass in a pathname and a parser. When you use a relative path, you construct a TPathName using a TDirectory instance, a pathname, and a parser.
The CommonPoint application system does not have a "current" or "working" directory; to use a relative pathname, you must convert it to an absolute pathname, using either TDirectory or TPathName. Relative pathnames can be combined to specify an absolute pathname.
The parser is an instance of a class derived from TPathNameParser. This class defines how to parse a system-dependent pathname. TPathName includes a member function called GetDefaultParser--this function retrieves the parser appropriate to the current system environment. If you do not pass a parser into the TPathName constructor, it retrieves the default parser for you.
NOTE TUnixPathNameParser is the only concrete parser provided in this software release.
This example passes a relative path into TPathName (using the default parser) and retrieves a TFile instance using the GetEntity member function. The myDirectory instance passed into TPathName represents an instance of TDirectory.
THostSpecificPathName myPath = "utilities/wonderprogram/mydocument"; TPathName thePath(myDirectory, myPath); TFile myFile = thePath.GetEntity();
To find the pathname for a specific entity, you construct a TPathName instance, passing in the entity.
This one-line example provides the myFile entity to TPathName and retrieves the corresponding pathname directly from the constructor.
TPathName thePath(myFile);
This short example gets the entity for a path and assumes that the entity is a TFile instance. You can downcast the return value to a TFile by using the `downcast' constructor:
TFile aFile (myPath.GetEntity());
TFile aFile = myPath.GetEntity();