This class is available for the OPUS Blackboard API. The initial OPUS 2.0 release is described here
Constructors:
Directory( ) | |
~Directory( ) |
Methods:
clone( ) | returns a copy of this object |
operator%( ) | overrides the base class implementation to allow prepend/append and to support FILE_ACTION tasks |
assign( ) | overrides the base class implementation in order to verify and assign the argument |
pop( ) | sets the object value to be the parent directory of the current value |
push( ) | sets the object value to be a subdirectory of the current value |
name( ) | gets the field name |
Description
A Directory object stores the path portion of the full file specification for a File_entry object. The maximum directory length is 256 characters and those characters not permitted in a file path by the operating system can not be assigned to the object.
Derived from
Example
#include <iostream> #include "file_entry.h" #include "directory.h" #include "rootname.h" #include "extension.h" #include "dangle.h" using namespace std; // The following example demonstrates parsing of a full file // specification using a File_entry object and its Field's. int main(int argc, char* argv[]) { // assign file spec. File_entry* fe = new File_entry("/home/opus/data_file.dat_done"); cout << "File specification: " << fe->str() << endl; Field* f = new Directory; fe->get_field(f); // get path cout << "Directory is: " << f->ustr() << endl; delete f; f = new Rootname; fe->get_field(f); // get path cout << "Rootname is: " << f->ustr() << endl; delete f; f = new Extension; fe->get_field(f); // get path cout << "Extension is: " << f->ustr() << endl; delete f; f = new Dangle; fe->get_field(f); // get path cout << "Dangle is: " << f->ustr() << endl; delete f; delete fe; return 0; }
See Also:
Directory::Directory - The Directory constructor.
Synopsis
Directory::Directory( const string& s) // I - string containing path spec. Directory::Directory( const Directory& abt) // I - object to initialize from
Description
This method constructs a new Directory object, and assigns it to the path indicated in the calling argument. The argument is validated and must not contain characters not permitted in a path specification by the operating system. An empty string argument is interpreted as the current working directory.
Exceptions Thrown
Bad_val<string> | - if the string does not appear to be a directory specification or invalid characters are present; Bad_val.arg contains the calling argument |
Io_error<int> | - if a problem occurs determining the current working directory; Io_error.arg contains the value of errno |
Directory::~Directory - The Directory destructor.
Synopsis
Directory::~Directory()
Description
This method destroys the object.
Exceptions Thrown
Directory::operator% - Apply a field modifier to this object.
Synopsis
void Directory::operator%( Field* d) // I - object to compare against
Description
operator% does a character by character comparison between the string representation of this object and that of the argument. Any character that differs between the two is replaced in this object with the character in the argument. Padding is not considered significant unless the special Field::FORCEPAD character is used in the argument to force the replacement of the character at that position with the pad character. If the wildcard character, File_entry::DIFF_WILDCARD, is present as the first or last character in the argument's string value, it expands to the entire unpadded contents of this object's string representation at that position, and this object is assigned the resulting concatenation. If the argument string contains an Opus_env::FILE_ACTION_INDICATOR character, a File_action exception is thrown so that the desired task can be performed.
Returns
A pointer to this object.
Exceptions Thrown
Type<Field*> | - if the object types do not match; Type.arg points to the calling argument |
Bad_val<Field*> | - if the wildcard character is in the wrong place; Bad_val.arg points to the calling argument |
File_action<string> | - if a file action command should be executed; File_action.arg contains the FILE_ACTION Command object label as posted on the command blackboard |
Example
Directory* mod = new Directory("*/done/"); Directory* dir = new Directory("/home/opus/data/"); // apply differences *dir % mod; // dir now contains "/home/opus/data/done/"
Directory::assign - Assign a string to the object.
Synopsis
void Directory::assign( const string& s) // I - the string to assign
Description
This method overrides the base class implementation in order to check the calling argument syntax. An empty string is translated to the current working directory, leading/trailing spaces are trimmed, and a trailing '/' is appended to directory specificiation (in Unix) if it is not present. The string argument must not contain any characters in Os_specific::DIR_BAD_CHARS.
Exceptions Thrown
Bad_val<string> | - if the string does not appear to be a directory specification or invalid characters are present; Bad_val.arg contains the calling argument |
Io_error<int> | - if a problem occurs determining the current working directory; Io_error.arg contains the value of errno |
Example
Directory d; d.assign("/tmp"); // assigns "/tmp/" to field string
Directory::clone - Create a copy of this object.
Synopsis
Field* Directory::clone() const
Description
This method creates a new Directory object, initialized by this object, off the heap and returns a pointer to the new object. The client should delete the returned object when it is no longer needed.
Returns
A pointer the new Directory object initialized by this object.
Exceptions Thrown
Directory::pop - Pop last directory off object path specification.
Synopsis
void Directory::pop()
Description
The Directory object is modified to point to the parent directory of its current value. If there is no parent directory, an exception is thrown.
Exceptions Thrown
Bad_val<string> | - if the string does not appear to be a directory specification or invalid characters are present; Bad_val.arg contains the calling argument |
Io_error<int> | - if a problem occurs determining the current working directory; Io_error.arg contains the value of errno |
Not_ready<string> | - if directory has no parent; Not_ready.arg contains the object string representation |
Bad_val<string> | - if unable to pop directory off the object value; Bad_val.arg contains the object string representation |
Example
Directory* d = new Directory("/home/bubba"); d.pop(); // directory is now "/home"
Directory::push - Append subdirectory to current object path specification.
Synopsis
void Directory::push( const string& sub) // I - subdirectory to append
Description
The Directory object is modified to point to the indicated subdirectory(ies), relative to its current value. The indicated subdirectory(ies) need not exist on the file system.
Exceptions Thrown
Bad_val<string> | - if the string does not appear to be a directory specification or invalid characters are present; Bad_val.arg contains the calling argument |
Io_error<int> | - if a problem occurs determining the current working directory; Io_error.arg contains the value of errno |
Bad_val<string> | - if argument is the null string; Bad_val.arg contains the null string |
Example
string sub("bubba"); Directory* d = new Directory("/home/bubba"); d.push(sub); // directory is now "/home/bubba"
Directory::name - Get the field name
Synopsis
string Directory::name() const
Description
This method returns the name of the field, "DIRECTORY".
Returns
string field name
Exceptions Thrown
Copyright © 1997-2000 The Association of Universities for
Research in Astronomy, Inc. All Rights Reserved.
For more information, contact opushelp@stsci.edu
Last modified: 25 April 2000