LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Classes | Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
lsst::afw::table::BaseRecord Class Reference

Base class for all records. More...

#include <BaseRecord.h>

Inheritance diagram for lsst::afw::table::BaseRecord:
lsst::afw::detection::PeakRecord lsst::afw::table::ExposureRecord lsst::afw::table::SimpleRecord lsst::afw::table::SourceRecord

Classes

class  ConstructionToken
 

Public Types

using Table = BaseTable
 The associated table class. More...
 
using ColumnView = BaseColumnView
 The associated ColumnView class. More...
 
using Catalog = CatalogT< BaseRecord >
 Template of CatalogT used to hold records of this type. More...
 
using ConstCatalog = CatalogT< const BaseRecord >
 Template of CatalogT used to hold const records of this type. More...
 

Public Member Functions

 BaseRecord (ConstructionToken const &, detail::RecordData &&data)
 Construct a record with uninitialized data. More...
 
 BaseRecord (const BaseRecord &)=delete
 
BaseRecordoperator= (const BaseRecord &)=delete
 
 BaseRecord (BaseRecord &&)=delete
 
BaseRecordoperator= (BaseRecord &&)=delete
 
Schema getSchema () const
 Return the Schema that holds this record's fields and keys. More...
 
std::shared_ptr< BaseTable const > getTable () const
 Return the table this record is associated with. More...
 
template<typename T >
Field< T >::Element * getElement (Key< T > const &key)
 Return a pointer to the underlying elements of a field (non-const). More...
 
template<typename T >
Field< T >::Element const * getElement (Key< T > const &key) const
 Return a pointer to the underlying elements of a field (const). More...
 
template<typename T >
Field< T >::Reference operator[] (Key< T > const &key)
 Return a reference (or reference-like type) to the field's value. More...
 
template<typename T >
Field< T >::ConstReference operator[] (Key< T > const &key) const
 Return a const reference (or const-reference-like type) to the field's value. More...
 
template<typename T >
Field< T >::Value get (Key< T > const &key) const
 Return the value of a field for the given key. More...
 
template<typename T , typename U >
void set (Key< T > const &key, U const &value)
 Set value of a field for the given key. More...
 
template<typename T >
get (OutputFunctorKey< T > const &key) const
 Compute a calculated or aggregate field. More...
 
template<typename T , typename U >
void set (InputFunctorKey< T > const &key, U const &value)
 Set a calculated or aggregate field. More...
 
template<typename Ref >
Ref operator[] (ReferenceFunctorKey< Ref > const &key)
 
template<typename ConstRef >
ConstRef operator[] (ConstReferenceFunctorKey< ConstRef > const &key) const
 
void assign (BaseRecord const &other)
 Copy all field values from other to this, requiring that they have equal schemas. More...
 
void assign (BaseRecord const &other, SchemaMapper const &mapper)
 Copy field values from other to this, using a mapper. More...
 
ndarray::Manager::Ptr getManager () const
 
virtual ~BaseRecord ()
 

Protected Member Functions

virtual void _assign (BaseRecord const &other)
 Called by assign() after transferring fields to allow subclass data members to be copied. More...
 
virtual void _stream (std::ostream &os) const
 Called by operator<<. More...
 

Friends

class BaseTable
 
class BaseColumnView
 
std::ostreamoperator<< (std::ostream &os, BaseRecord const &record)
 Write the record's content out, one field on each line. More...
 

Detailed Description

Base class for all records.

BaseRecord is a polymorphic base class that provides the core record interface: access to fields and links back to the table it is associated with. Field access is provided by the templated get, set, and operator[] member functions. As templates they are nonvirtual and cannot be overridden by subclasses. The implementations for these accessors is in the FieldBase template specializations.

Each subclass of BaseRecord should be paired with a subclass of BaseTable. All record creation goes through a table, as the table allocates the memory used to store a record's fields and holds the Schema instance that defines those fields.

Records are noncopyable, and are hence usually passed by shared_ptr or [const-]reference.

Definition at line 31 of file BaseRecord.h.

Member Typedef Documentation

◆ Catalog

Template of CatalogT used to hold records of this type.

Definition at line 74 of file BaseRecord.h.

◆ ColumnView

The associated ColumnView class.

Definition at line 71 of file BaseRecord.h.

◆ ConstCatalog

Template of CatalogT used to hold const records of this type.

Definition at line 77 of file BaseRecord.h.

◆ Table

The associated table class.

Definition at line 68 of file BaseRecord.h.

Constructor & Destructor Documentation

◆ BaseRecord() [1/3]

lsst::afw::table::BaseRecord::BaseRecord ( ConstructionToken const &  ,
detail::RecordData &&  data 
)

Construct a record with uninitialized data.

Access to this constructor is restricted to BaseTable and BaseRecord subclasses via the ConstructionToken argument, which can only be constructed by BaseTable. This constructor is public so it can still be called by std::make_shared code with access to ConstructionToken.

Definition at line 143 of file BaseRecord.cc.

143  :
144  _data(std::move(data.data)),
145  _table(std::move(data.table)),
146  _manager(std::move(data.manager))
147 {
148  RecordInitializer f = {reinterpret_cast<char *>(_data)};
149  _table->getSchema().forEach(f);
150 }
char * data
Definition: BaseRecord.cc:61
T move(T... args)

◆ BaseRecord() [2/3]

lsst::afw::table::BaseRecord::BaseRecord ( const BaseRecord )
delete

◆ BaseRecord() [3/3]

lsst::afw::table::BaseRecord::BaseRecord ( BaseRecord &&  )
delete

◆ ~BaseRecord()

virtual lsst::afw::table::BaseRecord::~BaseRecord ( )
inlinevirtual

Definition at line 202 of file BaseRecord.h.

202 { _table->_destroy(*this); }

Member Function Documentation

◆ _assign()

virtual void lsst::afw::table::BaseRecord::_assign ( BaseRecord const &  other)
inlineprotectedvirtual

Called by assign() after transferring fields to allow subclass data members to be copied.

Reimplemented in lsst::afw::table::ExposureRecord, and lsst::afw::table::SourceRecord.

Definition at line 209 of file BaseRecord.h.

209 {}

◆ _stream()

void lsst::afw::table::BaseRecord::_stream ( std::ostream os) const
protectedvirtual

Called by operator<<.

Overrides should call the base class implementation and append additional fields on new lines, with the syntax "%(name)s: %(value)s".

Definition at line 152 of file BaseRecord.cc.

152  {
153  getSchema().forEach([&os, this](auto const& item) {
154  os << item.field.getName() << ": " << this->get(item.key) << std::endl;
155  });
156 }
std::ostream * os
Definition: Schema.cc:557
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
Definition: BaseRecord.h:80
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:151
void forEach(F &func) const
Apply a functor to each SchemaItem in the Schema.
Definition: Schema.h:214
T endl(T... args)

◆ assign() [1/2]

void lsst::afw::table::BaseRecord::assign ( BaseRecord const &  other)

Copy all field values from other to this, requiring that they have equal schemas.

Definition at line 122 of file BaseRecord.cc.

122  {
123  if (this->getSchema() != other.getSchema()) {
124  throw LSST_EXCEPT(lsst::pex::exceptions::LogicError, "Unequal schemas in record assignment.");
125  }
126  this->getSchema().forEach(CopyValue(&other, this));
127  this->_assign(other); // let derived classes assign their own stuff
128 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied.
Definition: BaseRecord.h:209
Reports errors in the logical structure of the program.
Definition: Runtime.h:46

◆ assign() [2/2]

void lsst::afw::table::BaseRecord::assign ( BaseRecord const &  other,
SchemaMapper const &  mapper 
)

Copy field values from other to this, using a mapper.

Definition at line 130 of file BaseRecord.cc.

130  {
131  if (!other.getSchema().contains(mapper.getInputSchema())) {
133  "Unequal schemas between input record and mapper.");
134  }
135  if (!this->getSchema().contains(mapper.getOutputSchema())) {
137  "Unequal schemas between output record and mapper.");
138  }
139  mapper.forEach(CopyValue(&other, this)); // use the functor we defined above
140  this->_assign(other); // let derived classes assign their own stuff
141 }
SchemaMapper * mapper
Definition: SchemaMapper.cc:71

◆ get() [1/2]

template<typename T >
Field<T>::Value lsst::afw::table::BaseRecord::get ( Key< T > const &  key) const
inline

Return the value of a field for the given key.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 151 of file BaseRecord.h.

151  {
152  return key.getValue(getElement(key), _manager);
153  }
Field< T >::Element * getElement(Key< T > const &key)
Return a pointer to the underlying elements of a field (non-const).
Definition: BaseRecord.h:93

◆ get() [2/2]

template<typename T >
T lsst::afw::table::BaseRecord::get ( OutputFunctorKey< T > const &  key) const
inline

Compute a calculated or aggregate field.

Definition at line 172 of file BaseRecord.h.

172  {
173  return key.get(*this);
174  }

◆ getElement() [1/2]

template<typename T >
Field<T>::Element* lsst::afw::table::BaseRecord::getElement ( Key< T > const &  key)
inline

Return a pointer to the underlying elements of a field (non-const).

This low-level access is intended mostly for use with serialization; users should generally prefer the safer get(), set() and operator[] member functions.

Definition at line 93 of file BaseRecord.h.

93  {
94  if (!key.isValid()) {
95  throw LSST_EXCEPT(
96  pex::exceptions::LogicError,
97  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been set up).");
98  }
99  return reinterpret_cast<typename Field<T>::Element*>(reinterpret_cast<char*>(_data) +
100  key.getOffset());
101  }
typename FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Definition: Field.h:26

◆ getElement() [2/2]

template<typename T >
Field<T>::Element const* lsst::afw::table::BaseRecord::getElement ( Key< T > const &  key) const
inline

Return a pointer to the underlying elements of a field (const).

This low-level access is intended mostly for use with serialization; users should generally prefer the safer get(), set() and operator[] member functions.

Definition at line 111 of file BaseRecord.h.

111  {
112  if (!key.isValid()) {
113  throw LSST_EXCEPT(
114  pex::exceptions::LogicError,
115  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been set up).");
116  }
117  return reinterpret_cast<typename Field<T>::Element const*>(reinterpret_cast<char const*>(_data) +
118  key.getOffset());
119  }

◆ getManager()

ndarray::Manager::Ptr lsst::afw::table::BaseRecord::getManager ( ) const
inline

Definition at line 200 of file BaseRecord.h.

200 { return _manager; }

◆ getSchema()

Schema lsst::afw::table::BaseRecord::getSchema ( ) const
inline

Return the Schema that holds this record's fields and keys.

Definition at line 80 of file BaseRecord.h.

80 { return _table->getSchema(); }

◆ getTable()

std::shared_ptr<BaseTable const> lsst::afw::table::BaseRecord::getTable ( ) const
inline

Return the table this record is associated with.

Definition at line 83 of file BaseRecord.h.

83 { return _table; }

◆ operator=() [1/2]

BaseRecord& lsst::afw::table::BaseRecord::operator= ( BaseRecord &&  )
delete

◆ operator=() [2/2]

BaseRecord& lsst::afw::table::BaseRecord::operator= ( const BaseRecord )
delete

◆ operator[]() [1/4]

template<typename ConstRef >
ConstRef lsst::afw::table::BaseRecord::operator[] ( ConstReferenceFunctorKey< ConstRef > const &  key) const
inline

Definition at line 190 of file BaseRecord.h.

190  {
191  return key.getConstReference(*this);
192  }

◆ operator[]() [2/4]

template<typename T >
Field<T>::Reference lsst::afw::table::BaseRecord::operator[] ( Key< T > const &  key)
inline

Return a reference (or reference-like type) to the field's value.

Some field types (Point, Moments, Flag, Covariance, and SpherePoint) do not support reference access.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 129 of file BaseRecord.h.

129  {
130  return key.getReference(getElement(key), _manager);
131  }

◆ operator[]() [3/4]

template<typename T >
Field<T>::ConstReference lsst::afw::table::BaseRecord::operator[] ( Key< T > const &  key) const
inline

Return a const reference (or const-reference-like type) to the field's value.

Some field types (Point, Moments, Flag, Covariance, and SpherePoint) do not support reference access.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 141 of file BaseRecord.h.

141  {
142  return key.getConstReference(getElement(key), _manager);
143  }

◆ operator[]() [4/4]

template<typename Ref >
Ref lsst::afw::table::BaseRecord::operator[] ( ReferenceFunctorKey< Ref > const &  key)
inline

Definition at line 185 of file BaseRecord.h.

185  {
186  return key.getReference(*this);
187  }

◆ set() [1/2]

template<typename T , typename U >
void lsst::afw::table::BaseRecord::set ( InputFunctorKey< T > const &  key,
U const &  value 
)
inline

Set a calculated or aggregate field.

Definition at line 180 of file BaseRecord.h.

180  {
181  return key.set(*this, value);
182  }

◆ set() [2/2]

template<typename T , typename U >
void lsst::afw::table::BaseRecord::set ( Key< T > const &  key,
U const &  value 
)
inline

Set value of a field for the given key.

This method has an additional template parameter because some fields accept and convert different types to the stored field type.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 164 of file BaseRecord.h.

164  {
165  key.setValue(getElement(key), _manager, value);
166  }

Friends And Related Function Documentation

◆ BaseColumnView

friend class BaseColumnView
friend

Definition at line 218 of file BaseRecord.h.

◆ BaseTable

friend class BaseTable
friend

Definition at line 217 of file BaseRecord.h.

◆ operator<<

std::ostream& operator<< ( std::ostream os,
BaseRecord const &  record 
)
friend

Write the record's content out, one field on each line.

Definition at line 158 of file BaseRecord.cc.

158  {
159  record._stream(os);
160  return os;
161 }

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