[OPUS]

Field - OPUS entry field base class


Availability:

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

Constructors:
Field( )
~Field( )

Methods:
operator=( ) field assignment operator
operator==( ) tests for equality between fields
operator%( ) applies differences between fields
clone( ) creates a copy of this object
assign( ) assigns a string to this object
fill( ) fills the field with pad (or indicated) characters
upper( ) upper-cases the field
lower( ) lower-cases the field
id( ) gets the field ID
str( ) gets the string representation of the field (with padding)
ustr( ) gets the string representation of the field (unpadded)
size( ) gets the field width
name( ) gets the field name

Data Members:


 enum PAD { UNDER = '_', DASH = '-', SPACE = ' ',  // allowed pad 
            TAB = '\t'};                           // characters

 static const char FORCEPAD;                       // signals that
                                                   // padding should be
                                                   // used at a position
                                                   // during a % operation

Description

Blackboard entries are composed of any number of Field objects. Each field of an entry has a unique integer ID, a fixed size, and a default pad character. OPUS blackboard polling usually means searching for one or more entries based on equality or wildcarding of fields. Once a match is found to the polling condition, entries are marked as having triggered an event by applying a field "modifier" to a single field in each matching entry using operator%. This prevents other processes, or the same process, from retriggering on the same blackboard entries each time through the polling loop. Once an event is processed, the entries that triggered that event can be updated on the blackboard using another field modifier (often applied to the same field as when the event was triggered).

Derived from

Opus_polymorph

See Also:


Field::Field - The Field constructor.

Synopsis


Field::Field(
             const int id,     // I - field ID
             const int sz,     // I - field width
             const PAD pd)     // I - default pad character

Field::Field(
             const Field& f) // I - field to initialize from

Description

The constructor creates a new Field object with a unique ID, a field width, and pad character. By default, the underscore character is used for padding. The field is padded with the pad character after construction.

Exceptions Thrown

none

Example

  
    Field* f = new Field(0, 5, Field::UNDER); // create new field with ID
                                              // 0, width 5, and underscore
                                              // padding
  


Field::~Field - The Field destructor.

Synopsis


Field::~Field()

Description

This method destroys the object.

Exceptions Thrown

none


Field::operator= - Field assignment operator.

Synopsis


Field& Field::operator=(
                        const Field& rhs) // I - the field to assign from

Description

Given a Field object with the same ID as this object, the field contents of the argument are assigned to this object.

Returns

    A reference to this object.

Exceptions Thrown

Type<Field*> - if the field ID's do not match; Type.arg points to the calling argument


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

Synopsis


Field* Field::clone() const

Description

A new Field object is constructed off the heap and initialized with the contents of this object. The client should delete the new object when it is no longer needed.

Returns

    A pointer to a new Field object initialized with this object.

Exceptions Thrown

none


Field::operator== - Compare the Field object with another.

Synopsis


bool Field::operator==(
                       const Field* ff) // I - field to compare with
                       const

Description

This operator performs an equality comparison between the object and the argument. Two fields are equal if they have the same ID and if their unpadded string representations are identical. This method returns true if the fields are equal, and false if they do not satisfy the equality conditions.

***Note that a pointer to the object with which the comparison is to be made is required, not a reference.

Returns

    true  - if the object meets the equality conditions stated in the

description.

false - if the object and argument are not identical as stated in

the description.

Exceptions Thrown

none

Example

  
    // compare two Field objects
    Field* a = new Field(0, 10);
    Field* b = new Field(0, 10);
  
    if (*a == b) cout << "Fields are equal.";
  


Field::operator% - Apply field modifier to this object.

Synopsis


void Field::operator%(
                      Field* rhs) // I - modifier to compare with

Description

operator% does a character by character comparison between the object and the argument (the modifier) which must be a Field object of the same type and ID. Any character that differs between the two is replaced in the object with the argument's value. Padding is not considered significant unless a special FORCEPAD character is used in the modifier in which case the character in that position in the object is replaced with the pad character.

Returns

    A pointer to this object.

Exceptions Thrown

Bad_val<Field*> - if the argument is null; Bad_val.arg points at the calling argument
Type<Field*> - if the field types or ID's don't match; Type.arg points at the calling argument

Example

  
    Field* f = new Field(0, 8, UNDER);
    Field* g = f->clone;
  
    f->assign("ABCDEFGH");
    g->assign("AB__XYZ!");
  
    *f % g;                  // set *f to "ABCDXYZ_"
  


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

Synopsis


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

Description

This method sets the value of the field equal to the argument. If the string is longer than the field width, only width characters are assigned. If the string is shorter than the field width, the field is padded to width.

Exceptions Thrown

none


Field::fill - Fill field with pad or specified character.

Synopsis


void Field::fill(
                 const char c) // I - fill character or 0 for pad

Description

This method fills the field with the default pad character or the provided character out to the field width.

Exceptions Thrown

none


Field::upper - Change field to all upper case.

Synopsis


void Field::upper()

Description

Each character in the field is converted to uppercase.

Exceptions Thrown

none


Field::lower - Change field to all lower case

Synopsis


void Field::lower()

Description

Each character in the field is changed to lowercase.

Exceptions Thrown

none


Field::id - Get the field ID.

Synopsis


int Field::id() const

Description

This method returns the ID associated with this field.

Returns

    The integer field ID.

Exceptions Thrown

none


Field::size - Get the field width.

Synopsis


int Field::size() const

Description

This method returns the width in characters of the field.

Returns

    The integer field width.

Exceptions Thrown

none


Field::str - Get string representation of the object.

Synopsis


string Field::str() const

Description

This method returns the string value of the field, including pad characters.

Returns

    string containing the value of the field with any padding

Exceptions Thrown

none


Field::ustr - Get string representation of the object (unpadded).

Synopsis


string Field::ustr() const

Description

This method returns the string value of the field string with any padding removed. If the field is nothing but padding, the empty string is returned.

Returns

    a string containing the value of the field, less padding (an

empty string if the field is all padding)

Exceptions Thrown

none


Field::name - Get the name of the field.

Synopsis


string Field::name() const 

Description

This method returns the field name, "FIELD".

Returns

    the string "FIELD"

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