casacore
Loading...
Searching...
No Matches
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
casacore::RecordFieldPtr< T > Class Template Reference

More...

#include <RecordField.h>

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 &)
 
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:
 

Static Private Member Functions

static const T * get_typed_ptr (RecordInterface *record, Int fieldNumber)
 

Private Attributes

RecordInterfaceparent_p
 
Int fieldNumber_p
 

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.

Internally, a RecordFieldPtr stores a Record pointer and field number. Therefore, if the order of fields in a Record is modified, or if the Record is restructured, a RecordFieldPtr is invalidated and should no longer be used.

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

*field = value;
field.define (value);
Int fieldNumber() const
Return the fieldnumber of this field.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.

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

Example

See the example in the Record class.

Motivation

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

Definition at line 110 of file RecordField.h.

Constructor & Destructor Documentation

◆ RecordFieldPtr() [1/3]

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

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

this->isAttached() == False;

◆ RecordFieldPtr() [2/3]

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.

◆ RecordFieldPtr() [3/3]

template<class T >
casacore::RecordFieldPtr< T >::RecordFieldPtr ( RecordInterface record,
const RecordFieldId  
)

Member Function Documentation

◆ attachToRecord() [1/2]

template<class T >
void casacore::RecordFieldPtr< T >::attachToRecord ( RecordInterface record,
const RecordFieldId  
)

◆ attachToRecord() [2/2]

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.

◆ comment()

template<class T >
const String & casacore::RecordFieldPtr< T >::comment ( ) const

Get the comment of this field.

◆ define()

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.

◆ detach()

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

Point to no field in any Record.

◆ fieldNumber()

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

Return the fieldnumber of this field.

Definition at line 159 of file RecordField.h.

References casacore::RecordFieldPtr< T >::fieldNumber_p.

◆ get()

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

◆ get_typed_ptr()

template<class T >
static const T * casacore::RecordFieldPtr< T >::get_typed_ptr ( RecordInterface record,
Int  fieldNumber 
)
staticprivate

◆ isAttached()

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 174 of file RecordField.h.

References casacore::RecordFieldPtr< T >::parent_p.

◆ name()

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

◆ operator*() [1/2]

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;

◆ operator*() [2/2]

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

Definition at line 142 of file RecordField.h.

References casacore::RecordFieldPtr< T >::get().

◆ setComment()

template<class T >
void casacore::RecordFieldPtr< T >::setComment ( const String comment)

Set the comment for this field.

Member Data Documentation

◆ fieldNumber_p

template<class T >
Int casacore::RecordFieldPtr< T >::fieldNumber_p
private

◆ parent_p

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

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