[OPUS]

Dangle - A field object that encapsulates the dangle 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:
Dangle( )
~Dangle( )

Methods:
operator%( ) overrides 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;     // Dangle prefix character = '_'

Description

A Dangle object stores the dangle portion of the full file specification for a File_entry object. The dangle is attached to the end of the extension and includes a dangle prefix character ('_'). A file specification cannot include a dangle unless an extension also is defined. The maximum dangle length is 256 characters and those characters not permitted in a file name by the operating system can not be assigned to the 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:


Dangle::Dangle - The Dangle constructor.

Synopsis


Dangle::Dangle(
               const string& s) // I - string to assign to dangle

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

Description

This method constructs a new Dangle object and assigns the argument to the object (after validating it). The dangle prefix character must be included 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 dangle prefix is not present or invalid characters are present; Bad_val.arg contains the calling argument


Dangle::~Dangle - The Dangle destructor.

Synopsis


Dangle::~Dangle()

Description

This method destroys the object.

Exceptions Thrown

none


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

Synopsis


void Dangle::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)) {
       Dangle* mod = new Dangle("_proc")   ; // dangle modifier
       for (int i = 0; i < results.size(); i++) {
          Entry* new_file = results[i]->clone();
          Dangle*  dg = new Dangle;
          new_file->get_field(dg);           // get current dangle
          *dg % mod;                         // apply modifier
          new_file->set_field(dg);           // set modified dangle
          delete dg;
          fbb.replace(results[i], new_file); // rename file
          delete results[i];
          delete new_file;
       }
       delete mod;
    }
    delete f_ent;
  


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

Synopsis


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

Description

This method overrides the base class implementation in order to check for a dangle 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 dangle prefix is not present or invalid characters are present; Bad_val.arg contains the calling argument


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

Synopsis


Field* Dangle::clone() const

Description

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

Exceptions Thrown

none


Dangle::name - Get field name

Synopsis


string Dangle::name() const 

Description

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

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