[OPUS]

Extension - A field object that encapsulates the extension portion of a file specification.


Availability:

This class is available for the OPUS Blackboard API. The initial OPUS 2.0 release is described here

Constructors:
Extension( )
~Extension( )

Methods:
operator%( ) override the base class implementation to allow prepend/append and to support FILE_ACTION tasks
clone( ) returns a copy of this object
assign( ) overrides the base class implementation in order to verify the argument
name( ) gets the field name

Data Members:


 static const char PREFIX;        // extension prefix character = '.'

Description

An Extension object stores the file extension portion of the full file specification for a File_entry object. The extension follows, and is separated from, the rootname by the extension prefix character ('.'). The extension prefix character is included as part of the extension object. The maximum number of characters in an extension is 256, and only those characters allowed in a file name by the operating system can be assigned to this object.

Derived from

Field

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 fields.
    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:


Extension::Extension - The Extension constructor.

Synopsis


Extension::Extension(
                     const string& s) // I - string to assign to extension

Extension::Extension(
                     const Extension& abt) // I - object to initialize from

Description

This method constructs a new Extension object and assigns the argument to the object (after validating it). The extension prefix character ('.') must be present for non-empty strings, and the string must not contain characters not permitted in a file name by the operating system. The pad character is specified by File_entry::FILES_PADC.

Exceptions Thrown

Bad_val<string> - if the extension prefix is not present or invalid characters are present; Bad_val.arg contains the calling argument


Extension::~Extension - The Extension destructor.

Synopsis


Extension::~Extension()

Description

This method destroys the object.

Exceptions Thrown

none


Extension::operator% - Apply a field modifier to this object.

Synopsis


void Extension::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

  
    Files_bb fbb;
    File_entry* f_ent = new File_entry("/home/opus/*.dat");
  
    vector<Entry*> results;
    if (fbb.search(f_ent, results)) {
       Extension* mod = new Extension(".trb"); // extension modifier
       for (int i = 0; i < results.size(); i++) {
          Entry* new_file = results[i]->clone();
          Extension*  ex = new Extension;
          new_file->get_field(ex);             // get current extension
          *ex % mod;                           // apply modifier
          new_file->set_field(ex);             // set modified extension
          delete ex;
          fbb.replace(results[i], new_file);   // rename file
          delete results[i];
          delete new_file;
       }
       delete mod;
    }
    delete f_ent;
  


Extension::assign - Assign a string to the object.

Synopsis


void Extension::assign(
                       const string& s) // I - the string to assign

Description

This method overrides the base class implementation in order to check for an extension prefix in non-empty strings. In addition, the string must not contain any character in Os_specific::NON_DIR_BAD_CHARS.

Exceptions Thrown

Bad_val<string> - if the extension prefix is not present or invalid characters are present; Bad_val.arg contains the calling argument


Extension::clone - Create a copy of this object.

Synopsis


Field* Extension::clone() const

Description

This method creates a new Extension 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 to a new Extension object initialized by this object.

Exceptions Thrown

none


Extension::name - Get field name

Synopsis


string Extension::name() const 

Description

This method returns the string name of the field, "EXTENSION".

Returns

    string field name

Exceptions Thrown

none


OPUS API index · STScI Home Page · Search · Topics · Index

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