casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Member Functions | Private Attributes
casa::RecordFieldPtr< T > Class Template Reference

Access to an individual field in a record. More...

#include <RecordField.h>

Inheritance diagram for casa::RecordFieldPtr< T >:
casa::NoticeTarget

List of all members.

Public Member Functions

 RecordFieldPtr ()
 This object does not point to any field, i.e.
 RecordFieldPtr (RecordInterface &record, Int whichField)
 Attach this field pointer to the given field.
 RecordFieldPtr (RecordInterface &record, const RecordFieldId &)
 RecordFieldPtr (const RecordFieldPtr< T > &other)
 After calling, this and other point to the same field, i.e.
RecordFieldPtr< T > & operator= (const RecordFieldPtr< T > &other)
 ~RecordFieldPtr ()
 
     

void attachToRecord (RecordInterface &record, Int whichField)
 Change our pointer to the supplied field.
void attachToRecord (RecordInterface &record, const RecordFieldId &)
void detach ()
 Point to no field in any Record.
T & operator* ()
 Provide access to the field's value.
const T & operator* () const
const T & get () const
void define (const T &value)
 Store a value in the field using redefinition.
const Stringcomment () const
 Get the comment of this field.
void setComment (const String &comment)
 Set the comment for this field.
Int fieldNumber () const
 Return the fieldnumber of this field.
String name () const
 Return the name of the field.
Bool isAttached () const
 Is this field pointer attached to a valid record? Operations which might cause it to become detached are:

Private Member Functions

virtual void notify (const Notice &message)
 Not important for users - the mechanism by which field pointers are notified when there is a change in the record.

Private Attributes

T * fieldPtr_p
RecordInterfaceparent_p
Int fieldNumber_p

Detailed Description

template<class T>
class casa::RecordFieldPtr< T >

Access to an individual field in a record.

Intended use:

Public interface

Review Status

Reviewed By:
Mark Wieringa
Date Reviewed:
1996/04/15
Test programs:
tRecord

Prerequisite

Etymology

RecordFieldPtr indicates that an object of this type is pointing to a field in a record.

Synopsis

RecordFieldPtr allows access to the fields in a record object. A record object is an object of a class derived from RecordInterface . RecordFieldPtr<T> objects can only be instantiated for types `T' which are valid fields of a record object (e.g. Int, float, String, Record, TableRecord). It can, however, NOT be instantiated for a Table field, because Table fields are accessed indirectly via a TableKeyword object. Table fields have to be accessed directly through the TableRecord interface.

The RecordFieldPtr is pointer-like in the sense that it points to an object that is physically inside of another object (the enclosing record object). Access to the value is obtained via the dereference operator (operator*()) to emphasize the pointer like nature of these classes.
An alternative way to get access to the values is using the functions define and get. Note that in

       RecordFieldPtr<Array<Int> > field (record, fieldNumber);
       Array<Int> value;
       *field = value;
       field.define (value);

the assignment (in line 3) and define (in line 4) are not equivalent. The assignment uses the normal Array assignment, thus it takes the Array conformance rules into account (an assign is only possible when the new array value conforms the current array value or when the current array value is empty). On the other hand, define does not take the current array value into account. Thus an array value can always be redefined.
However, note that if the field is defined with a non-fixed shape in the record description, a value must always conform that shape (in case of assignment as well as in case of define).

RecordFieldPtr is derived from NoticeTarget to get messages from the mother record class when it changes. For example, when the record is destructed, all RecordFieldPtr's pointing to that record will automatically be detached.

Example

See the example in the Record class.

Motivation

RecordFieldPtr provides a fast way to access the data in a record.

Definition at line 118 of file RecordField.h.


Constructor & Destructor Documentation

template<class T>
casa::RecordFieldPtr< T >::RecordFieldPtr ( )

This object does not point to any field, i.e.

this->isAttached() == False;

template<class T>
casa::RecordFieldPtr< T >::RecordFieldPtr ( RecordInterface record,
Int  whichField 
)

Attach this field pointer to the given field.

If it does not exist an exception is thrown.

template<class T>
casa::RecordFieldPtr< T >::RecordFieldPtr ( RecordInterface record,
const RecordFieldId  
)
template<class T>
casa::RecordFieldPtr< T >::RecordFieldPtr ( const RecordFieldPtr< T > &  other)

After calling, this and other point to the same field, i.e.

it uses reference semantics.

template<class T>
casa::RecordFieldPtr< T >::~RecordFieldPtr ( )

     


Member Function Documentation

template<class T>
void casa::RecordFieldPtr< T >::attachToRecord ( RecordInterface record,
Int  whichField 
)

Change our pointer to the supplied field.

If it doesn't exist an exception is thrown.

template<class T>
void casa::RecordFieldPtr< T >::attachToRecord ( RecordInterface record,
const RecordFieldId  
)
template<class T>
const String& casa::RecordFieldPtr< T >::comment ( ) const

Get the comment of this field.

template<class T>
void casa::RecordFieldPtr< T >::define ( const T &  value)

Store a value in the field using redefinition.

Define differs from assignment w.r.t. arrays. For define a variable shaped array is deleted first with the effect that array conformance rules are not applied for them.

template<class T>
void casa::RecordFieldPtr< T >::detach ( )

Point to no field in any Record.

template<class T>
Int casa::RecordFieldPtr< T >::fieldNumber ( ) const [inline]

Return the fieldnumber of this field.

Definition at line 176 of file RecordField.h.

template<class T>
const T& casa::RecordFieldPtr< T >::get ( ) const [inline]

Definition at line 160 of file RecordField.h.

template<class T>
Bool casa::RecordFieldPtr< T >::isAttached ( ) const [inline]

Is this field pointer attached to a valid record? Operations which might cause it to become detached are:

  1. Destruction of the Record
  2. Restructuring of the record.
  3. Explicit call of the detach() member.

Reimplemented from casa::NoticeTarget.

Definition at line 191 of file RecordField.h.

Referenced by casa::RecordFieldPtr< Array< Double > >::isAttached().

template<class T>
String casa::RecordFieldPtr< T >::name ( ) const [inline]

Return the name of the field.

Definition at line 180 of file RecordField.h.

Referenced by casa::ColumnsIndex::copyKeyField().

template<class T>
virtual void casa::RecordFieldPtr< T >::notify ( const Notice message) [private, virtual]

Not important for users - the mechanism by which field pointers are notified when there is a change in the record.

Implements casa::NoticeTarget.

template<class T>
T& casa::RecordFieldPtr< T >::operator* ( )

Provide access to the field's value.


Note: To be sure a const function is called, it is best to use get(); For a non-const object, a non-const function is called, even if used as an rvalue;

template<class T>
const T& casa::RecordFieldPtr< T >::operator* ( ) const [inline]

Definition at line 159 of file RecordField.h.

template<class T>
RecordFieldPtr<T>& casa::RecordFieldPtr< T >::operator= ( const RecordFieldPtr< T > &  other)
template<class T>
void casa::RecordFieldPtr< T >::setComment ( const String comment)

Set the comment for this field.


Member Data Documentation

template<class T>
Int casa::RecordFieldPtr< T >::fieldNumber_p [private]
template<class T>
T* casa::RecordFieldPtr< T >::fieldPtr_p [private]
template<class T>
RecordInterface* casa::RecordFieldPtr< T >::parent_p [private]

Definition at line 196 of file RecordField.h.

Referenced by casa::RecordFieldPtr< Array< Double > >::name().


The documentation for this class was generated from the following file: