casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::RecordFieldPtr< T > Class Template Reference

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

#include <RecordField.h>

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

Public Member Functions

 RecordFieldPtr ()
 This object does not point to any field, i.e. More...
 
 RecordFieldPtr (RecordInterface &record, Int whichField)
 Attach this field pointer to the given field. More...
 
 RecordFieldPtr (RecordInterface &record, const RecordFieldId &)
 
 RecordFieldPtr (const RecordFieldPtr< T > &other)
 After calling, this and other point to the same field, i.e. More...
 
RecordFieldPtr< T > & operator= (const RecordFieldPtr< T > &other)
 
 ~RecordFieldPtr ()
 
void attachToRecord (RecordInterface &record, Int whichField)
 Change our pointer to the supplied field. More...
 
void attachToRecord (RecordInterface &record, const RecordFieldId &)
 
void detach ()
 Point to no field in any Record. More...
 
T & operator* ()
 Provide access to the field's value. More...
 
const T & operator* () const
 
const T & get () const
 
void define (const T &value)
 Store a value in the field using redefinition. More...
 
const Stringcomment () const
 Get the comment of this field. More...
 
void setComment (const String &comment)
 Set the comment for this field. More...
 
Int fieldNumber () const
 Return the fieldnumber of this field. More...
 
String name () const
 Return the name of the field. More...
 
Bool isAttached () const
 Is this field pointer attached to a valid record? Operations which might cause it to become detached are: More...
 
- Public Member Functions inherited from casacore::NoticeTarget
virtual ~NoticeTarget ()
 Destructs this NoticeTarget. More...
 
Bool isValid () const
 Returns a boolean value telling whether this NoticeTarget is still "valid". More...
 
Bool isAttached () const
 Returns a boolean value telling whether this NoticeTarget is still attached to a NoticeSource or not. More...
 
void invalidate ()
 Makes the current NoticeTarget "invalid". More...
 

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. More...
 

Private Attributes

T * fieldPtr_p
 
RecordInterfaceparent_p
 
Int fieldNumber_p
 

Additional Inherited Members

- Protected Member Functions inherited from casacore::NoticeTarget
 NoticeTarget ()
 Creates an unlinked, "invalid" NoticeTarget. More...
 
 NoticeTarget (NoticeSource *v)
 Creates a "valid" NoticeTarget linked to the specified NoticeSource. More...
 
 NoticeTarget (NoticeSource &v)
 
 NoticeTarget (NoticeTarget &other)
 Creates a "valid" NoticeTarget linked to the same NoticeSource as the other NoticeTarget. More...
 
 NoticeTarget (NoticeTarget *other)
 
void unlink ()
 Unlinks this NoticeTarget from its NoticeSource. More...
 
void link (const NoticeTarget &other)
 Links this NoticeTarget to the same NoticeSource as the other NoticeTarget. More...
 
void link (const NoticeTarget *other)
 
Link< NoticeTarget * > * next ()
 Retrieves the next NoticeTarget in the target list of the associated NoticeSource. More...
 
const Link< NoticeTarget * > * next () const
 
void attach (NoticeSource *v)
 Adds this NoticeTarget to the target list in the specified NoticeSource, so that it will receive all notices sent out by that NoticeSource. More...
 
void attach (NoticeSource &v)
 
- Protected Attributes inherited from casacore::NoticeTarget
Link< NoticeTarget * > * ilink
 
NoticeSourcecontainer
 
Bool valid
 

Detailed Description

template<class T>
class casacore::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>
casacore::RecordFieldPtr< T >::RecordFieldPtr ( )

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

this->isAttached() == False;

template<class T>
casacore::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>
casacore::RecordFieldPtr< T >::RecordFieldPtr ( RecordInterface record,
const RecordFieldId  
)
template<class T>
casacore::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>
casacore::RecordFieldPtr< T >::~RecordFieldPtr ( )

Member Function Documentation

template<class T>
void casacore::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 casacore::RecordFieldPtr< T >::attachToRecord ( RecordInterface record,
const RecordFieldId  
)
template<class T>
const String& casacore::RecordFieldPtr< T >::comment ( ) const

Get the comment of this field.

template<class T>
void casacore::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 casacore::RecordFieldPtr< T >::detach ( )

Point to no field in any Record.

template<class T>
Int casacore::RecordFieldPtr< T >::fieldNumber ( ) const
inline

Return the fieldnumber of this field.

Definition at line 176 of file RecordField.h.

template<class T>
const T& casacore::RecordFieldPtr< T >::get ( ) const
inline

Definition at line 160 of file RecordField.h.

template<class T>
Bool casacore::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.

Definition at line 191 of file RecordField.h.

template<class T>
String casacore::RecordFieldPtr< T >::name ( ) const
inline

Return the name of the field.

Definition at line 180 of file RecordField.h.

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

template<class T>
virtual void casacore::RecordFieldPtr< T >::notify ( const Notice message)
privatevirtual

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

Implements casacore::NoticeTarget.

template<class T>
T& casacore::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& casacore::RecordFieldPtr< T >::operator* ( ) const
inline

Definition at line 159 of file RecordField.h.

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

Set the comment for this field.

Member Data Documentation

template<class T>
Int casacore::RecordFieldPtr< T >::fieldNumber_p
private
template<class T>
T* casacore::RecordFieldPtr< T >::fieldPtr_p
private
template<class T>
RecordInterface* casacore::RecordFieldPtr< T >::parent_p
private

Definition at line 196 of file RecordField.h.

Referenced by casacore::RecordFieldPtr< casacore::String >::name().


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