LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+11,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+9,19.0.0-21-g2644856+11,19.0.0-22-gc5dc5b1+6,19.0.0-23-gdc29a50+3,19.0.0-24-g923e380+11,19.0.0-25-g6c8df7140,19.0.0-28-g9b887e2,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+10,19.0.0-3-g9c54d0d+10,19.0.0-3-gca68e65+6,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+9,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+11,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+11,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+11,19.0.0-4-ge404a01+10,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+11,19.0.0-6-gbaebbfb+10,19.0.0-60-gafafd468+11,19.0.0-67-g3ab1e6e,19.0.0-7-g039c0b5+9,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+11,19.0.0-8-g3a3ce09+6,19.0.0-9-g463f923+10,w.2020.21
LSSTDataManagementBasePackage
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

typedef BaseTable Table
 The associated table class. More...
 
typedef BaseColumnView ColumnView
 The associated ColumnView class. More...
 
typedef CatalogT< BaseRecordCatalog
 Template of CatalogT used to hold records of this type. More...
 
typedef CatalogT< BaseRecord const > ConstCatalog
 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 144 of file BaseRecord.cc.

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

◆ 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 153 of file BaseRecord.cc.

153  {
154  getSchema().forEach([&os, this](auto const& item) {
155  os << item.field.getName() << ": " << this->get(item.key) << std::endl;
156  });
157 }

◆ 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 123 of file BaseRecord.cc.

123  {
124  if (this->getSchema() != other.getSchema()) {
125  throw LSST_EXCEPT(lsst::pex::exceptions::LogicError, "Unequal schemas in record assignment.");
126  }
127  this->getSchema().forEach(CopyValue(&other, this));
128  this->_assign(other); // let derived classes assign their own stuff
129 }

◆ 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 131 of file BaseRecord.cc.

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

◆ 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  }

◆ 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  }

◆ 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 159 of file BaseRecord.cc.

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

The documentation for this class was generated from the following files:
std::move
T move(T... args)
lsst::afw::table::BaseRecord::get
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:151
lsst::afw::table::BaseRecord::getElement
Field< T >::Element * getElement(Key< T > const &key)
Return a pointer to the underlying elements of a field (non-const).
Definition: BaseRecord.h:93
lsst::afw::table::Schema::forEach
void forEach(F &&func) const
Apply a functor to each SchemaItem in the Schema.
Definition: Schema.h:212
data
char * data
Definition: BaseRecord.cc:62
lsst::afw::table::BaseRecord::_assign
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied.
Definition: BaseRecord.h:209
astshim.fitsChanContinued.contains
def contains(self, name)
Definition: fitsChanContinued.py:127
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::pex::exceptions::LogicError
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
os
std::ostream * os
Definition: Schema.cc:746
std::endl
T endl(T... args)
key
Key< U > key
Definition: Schema.cc:281
mapper
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
lsst::afw::table::BaseRecord::getSchema
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
Definition: BaseRecord.h:80
lsst::afw::table::Field::Element
FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Definition: Field.h:26