LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lsst::afw::table::Key< T > Class Template Reference

A class used as a handle to a particular field in a table. More...

#include <fwd.h>

Inheritance diagram for lsst::afw::table::Key< T >:
lsst::afw::table::KeyBase< T > lsst::afw::table::FieldBase< T >

Public Member Functions

int getOffset () const
 Return the offset (in bytes) of this field within a record. More...
 
bool isValid () const
 Return true if the key was initialized to valid offset. More...
 
 Key ()
 Default construct a field. More...
 
template<typename OtherT >
bool operator== (Key< OtherT > const &other) const
 Equality comparison. More...
 
template<typename OtherT >
bool operator!= (Key< OtherT > const &other) const
 Equality comparison. More...
 
bool operator== (Key const &other) const
 Equality comparison. More...
 
bool operator!= (Key const &other) const
 Equality comparison. More...
 
- Public Member Functions inherited from lsst::afw::table::FieldBase< T >
int getElementCount () const
 Return the number of subfield elements (always one for scalars). More...
 
 FieldBase ()
 
 FieldBase (int)
 

Private Member Functions

 Key (int offset, FieldBase< T > const &fb=FieldBase< T >())
 

Private Attributes

int _offset
 

Friends

class detail::Access
 
class BaseRecord
 
std::ostream & operator<< (std::ostream &os, Key< T > const &key)
 Stringification. More...
 

Additional Inherited Members

- Public Types inherited from lsst::afw::table::FieldBase< T >
typedef T Value
 the type returned by BaseRecord::get More...
 
typedef T & Reference
 the type returned by BaseRecord::operator[] (non-const) More...
 
typedef T const & ConstReference
 the type returned by BaseRecord::operator[] (const) More...
 
typedef T Element
 the type of subfields (the same as the type itself for scalars) More...
 
- Static Public Member Functions inherited from lsst::afw::table::FieldBase< T >
static std::string getTypeString ()
 Return a string description of the field type. More...
 
- Static Public Attributes inherited from lsst::afw::table::KeyBase< T >
static bool const HAS_NAMED_SUBFIELDS = false
 
- Protected Member Functions inherited from lsst::afw::table::FieldBase< T >
void stream (std::ostream &os) const
 Defines how Fields are printed. More...
 
Reference getReference (Element *p, ndarray::Manager::Ptr const &) const
 Used to implement RecordBase::operator[] (non-const). More...
 
ConstReference getConstReference (Element const *p, ndarray::Manager::Ptr const &) const
 Used to implement RecordBase::operator[] (const). More...
 
Value getValue (Element const *p, ndarray::Manager::Ptr const &) const
 Used to implement RecordBase::get. More...
 
void setValue (Element *p, ndarray::Manager::Ptr const &, Value v) const
 Used to implement RecordBase::set. More...
 
- Static Protected Member Functions inherited from lsst::afw::table::FieldBase< T >
static FieldBase makeDefault ()
 Needed to allow Keys to be default-constructed. More...
 

Detailed Description

template<typename T>
class lsst::afw::table::Key< T >

A class used as a handle to a particular field in a table.

All access to table data ultimately goes through Key objects, which know (via an internal offset) how to address and cast the internal data buffer of a record or table.

Keys can be obtained from a Schema by name:

* schema.find("myfield").key
*

and are also returned when a new field is added. Compound and array keys also provide accessors to retrieve scalar keys to their elements (see the documentation for the KeyBase specializations), even though these element keys do not correspond to a field that exists in any Schema. For example:

* Schema schema;
* Key< Array<float> > arrayKey = schema.addField< Array<float> >("array", "docs for array", 5);
* Key< Point<int> > pointKey = schema.addField< Point<int> >("point", "docs for point");
* Key<float> elementKey = arrayKey[3];
* Key<int> xKey = pointKey.getX();
* PTR(BaseTable) table = BaseTable::make(schema);
* PTR(BaseRecord) record = table.makeRecord();
* assert(&record[arrayKey][3] == &record[elementKey3]);
* assert(record.get(pointKey).getX() == record[xKey]);
*

Key inherits from FieldBase to allow a key for a dynamically-sized field to know its size without needing to specialize Key itself or hold a full Field object.

Definition at line 44 of file fwd.h.

Constructor & Destructor Documentation

template<typename T>
lsst::afw::table::Key< T >::Key ( )
inline

Default construct a field.

The new field will be invalid until a valid Key is assigned to it.

Definition at line 90 of file Key.h.

90 : FieldBase<T>(FieldBase<T>::makeDefault()), _offset(-1) {}
static FieldBase makeDefault()
Needed to allow Keys to be default-constructed.
Definition: FieldBase.h:77
template<typename T>
lsst::afw::table::Key< T >::Key ( int  offset,
FieldBase< T > const &  fb = FieldBase<T>() 
)
inlineexplicitprivate

Definition at line 103 of file Key.h.

104  : FieldBase<T>(fb), _offset(offset) {}

Member Function Documentation

template<typename T>
int lsst::afw::table::Key< T >::getOffset ( ) const
inline

Return the offset (in bytes) of this field within a record.

Definition at line 73 of file Key.h.

73 { return _offset; }
template<typename T>
bool lsst::afw::table::Key< T >::isValid ( ) const
inline

Return true if the key was initialized to valid offset.

This does not guarantee that a key is valid with any particular schema, or even that any schemas still exist in which this key is valid.

A key that is default constructed will always be invalid.

Definition at line 83 of file Key.h.

83 { return _offset >= 0; }
template<typename T>
template<typename OtherT >
bool lsst::afw::table::Key< T >::operator!= ( Key< OtherT > const &  other) const
inline

Equality comparison.

Two keys with different types are never equal. Keys with the same type are equal if they point to the same location in a table, regardless of what Schema they were constructed from (for instance, if a field has a different name in one Schema than another, but is otherwise the same, the two keys will be equal).

Definition at line 64 of file Key.h.

64 { return true; }
template<typename T>
bool lsst::afw::table::Key< T >::operator!= ( Key< T > const &  other) const
inline

Equality comparison.

Two keys with different types are never equal. Keys with the same type are equal if they point to the same location in a table, regardless of what Schema they were constructed from (for instance, if a field has a different name in one Schema than another, but is otherwise the same, the two keys will be equal).

Definition at line 69 of file Key.h.

69 { return !this->operator==(other); }
bool operator==(Key< OtherT > const &other) const
Equality comparison.
Definition: Key.h:63
template<typename T>
template<typename OtherT >
bool lsst::afw::table::Key< T >::operator== ( Key< OtherT > const &  other) const
inline

Equality comparison.

Two keys with different types are never equal. Keys with the same type are equal if they point to the same location in a table, regardless of what Schema they were constructed from (for instance, if a field has a different name in one Schema than another, but is otherwise the same, the two keys will be equal).

Definition at line 63 of file Key.h.

63 { return false; }
template<typename T>
bool lsst::afw::table::Key< T >::operator== ( Key< T > const &  other) const
inline

Equality comparison.

Two keys with different types are never equal. Keys with the same type are equal if they point to the same location in a table, regardless of what Schema they were constructed from (for instance, if a field has a different name in one Schema than another, but is otherwise the same, the two keys will be equal).

Definition at line 66 of file Key.h.

66  {
67  return _offset == other._offset && this->getElementCount() == other.getElementCount();
68  }
int getElementCount() const
Return the number of subfield elements (always one for scalars).
Definition: FieldBase.h:56

Friends And Related Function Documentation

template<typename T>
friend class BaseRecord
friend

Definition at line 101 of file Key.h.

template<typename T>
friend class detail::Access
friend

Definition at line 100 of file Key.h.

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
Key< T > const &  key 
)
friend

Stringification.

Definition at line 93 of file Key.h.

93  {
94  return os << "Key<" << Key<T>::getTypeString() << ">(offset=" << key.getOffset()
95  << ", nElements=" << key.getElementCount() << ")";
96  }
static std::string getTypeString()
Return a string description of the field type.

Member Data Documentation

template<typename T>
int lsst::afw::table::Key< T >::_offset
private

Definition at line 106 of file Key.h.


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