LSSTApplications  19.0.0-14-gb0260a2+1009f50558,20.0.0+089c43b26b,20.0.0+126303c00d,20.0.0+2f3d0e5c40,20.0.0+36ef800059,20.0.0+5efbb753f1,20.0.0+bebc1f60e8,20.0.0+c31f88ab0f,20.0.0+e2e26847c2,20.0.0+f8788d280b,20.0.0-1-g10df615+c10c626ef0,20.0.0-1-g253301a+36ef800059,20.0.0-1-g2b7511a+bebc1f60e8,20.0.0-1-g4d801e7+2364cbef1f,20.0.0-1-g5b95a8c+f41a630bc9,20.0.0-1-g660595b+f45b7d88f4,20.0.0-1-gc96f8cb+4c66cd7cf3,20.0.0-1-gd1c87d7+85c46248f3,20.0.0-1-gedffbd8+f975718b49,20.0.0-13-ge9dc5b3+55648be1db,20.0.0-15-ga86d0f6+bdc7c63f7c,20.0.0-15-gf5872d0+4c66cd7cf3,20.0.0-16-g6fe20a1+a77778c47d,20.0.0-2-g4dae9ad+4c66cd7cf3,20.0.0-2-g7818986+85c46248f3,20.0.0-2-gec03fae+ff10c6d78d,20.0.0-25-g38d2b7ae+bde7f0c6ec,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g6a8623c+55648be1db,20.0.0-3-g750bffe+823a89ab62,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-47-g0830830+f5f993f8be,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-5-gfcebe35+8726ad94da,20.0.0-7-gc818c6e6+aaebb51c78,20.0.0-7-gcda7bf1+2a82aa79eb,20.0.0-9-g61a2a9a3d+14f89e4eca,w.2020.38
LSSTDataManagementBasePackage
BaseRecord.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_BaseRecord_h_INCLUDED
3 #define AFW_TABLE_BaseRecord_h_INCLUDED
4 
5 #include <iosfwd>
6 
7 #include "lsst/base.h"
8 #include "lsst/afw/table/fwd.h"
12 
13 namespace lsst {
14 namespace afw {
15 namespace table {
16 
31 class BaseRecord {
32 protected:
33 
34  // Protected class whose instances must be passed to the public
35  // constructor, providing more fine-grained access control than a
36  // protected constructor would. In particular, this allows make_shared to
37  // be used.
39  private:
40  friend class BaseTable;
41 
42  // A private ctor for this class (and friendship) is necessary to
43  // prevent e.g. BaseRecord({}, ...) calls from code without access
44  // to ConstructionToken.
45  explicit ConstructionToken(int) noexcept {}
46  };
47 
48 public:
49 
58  BaseRecord(ConstructionToken const &, detail::RecordData && data);
59  // No copying
60  BaseRecord(const BaseRecord&) = delete;
61  BaseRecord& operator=(const BaseRecord&) = delete;
62 
63  // No moving
64  BaseRecord(BaseRecord&&) = delete;
66 
68  typedef BaseTable Table;
69 
72 
75 
78 
80  Schema getSchema() const { return _table->getSchema(); }
81 
83  std::shared_ptr<BaseTable const> getTable() const { return _table; }
84 
92  template <typename T>
93  typename Field<T>::Element* getElement(Key<T> const& key) {
94  if (!key.isValid()) {
95  throw LSST_EXCEPT(
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  }
102 
110  template <typename T>
111  typename Field<T>::Element const* getElement(Key<T> const& key) const {
112  if (!key.isValid()) {
113  throw LSST_EXCEPT(
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  }
120 
128  template <typename T>
130  return key.getReference(getElement(key), _manager);
131  }
132 
140  template <typename T>
142  return key.getConstReference(getElement(key), _manager);
143  }
144 
150  template <typename T>
151  typename Field<T>::Value get(Key<T> const& key) const {
152  return key.getValue(getElement(key), _manager);
153  }
154 
163  template <typename T, typename U>
164  void set(Key<T> const& key, U const& value) {
165  key.setValue(getElement(key), _manager, value);
166  }
167 
171  template <typename T>
172  T get(OutputFunctorKey<T> const& key) const {
173  return key.get(*this);
174  }
175 
179  template <typename T, typename U>
180  void set(InputFunctorKey<T> const& key, U const& value) {
181  return key.set(*this, value);
182  }
183 
184  template <typename Ref>
186  return key.getReference(*this);
187  }
188 
189  template <typename ConstRef>
191  return key.getConstReference(*this);
192  }
193 
195  void assign(BaseRecord const& other);
196 
198  void assign(BaseRecord const& other, SchemaMapper const& mapper);
199 
200  ndarray::Manager::Ptr getManager() const { return _manager; }
201 
202  virtual ~BaseRecord() { _table->_destroy(*this); }
203 
205  friend std::ostream& operator<<(std::ostream& os, BaseRecord const& record);
206 
207 protected:
209  virtual void _assign(BaseRecord const& other) {}
210 
213  virtual void _stream(std::ostream& os) const;
214 
215 
216 private:
217  friend class BaseTable;
218  friend class BaseColumnView;
219 
220  // All these are definitely private, not protected - we don't want derived classes mucking with them.
221  void* _data; // pointer to field data
222  std::shared_ptr<BaseTable> _table; // the associated table
223  ndarray::Manager::Ptr _manager; // shared manager for lifetime of _data (like shared_ptr with no pointer)
224 };
225 
226 template <typename RecordT, typename ...Args>
228  return std::make_shared<RecordT>(BaseRecord::ConstructionToken(0), _makeNewRecordData(),
229  std::forward<Args>(args)...);
230 }
231 
232 
233 } // namespace table
234 } // namespace afw
235 } // namespace lsst
236 
237 #endif // !AFW_TABLE_BaseRecord_h_INCLUDED
lsst::afw::table::FieldBase::Reference
T & Reference
the type returned by BaseRecord::operator[] (non-const)
Definition: FieldBase.h:45
std::shared_ptr
STL class.
lsst::meas::algorithms.psfSelectionFromMatchList.args
list args
Definition: psfSelectionFromMatchList.py:27
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::ColumnView
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseRecord.h:71
lsst::afw::table::ConstReferenceFunctorKey
Base class for objects that can return a const reference to part of a record, but are not a true Key.
Definition: FunctorKey.h:109
base.h
lsst::afw::table::InputFunctorKey
Base class for objects that can set a value on a record, but are not a true Key themselves.
Definition: FunctorKey.h:57
lsst::afw::table::BaseRecord::operator[]
ConstRef operator[](ConstReferenceFunctorKey< ConstRef > const &key) const
Definition: BaseRecord.h:190
lsst::afw::table::BaseRecord::~BaseRecord
virtual ~BaseRecord()
Definition: BaseRecord.h:202
lsst::afw::table::BaseRecord::get
T get(OutputFunctorKey< T > const &key) const
Compute a calculated or aggregate field.
Definition: BaseRecord.h:172
lsst::afw::table::BaseRecord::operator=
BaseRecord & operator=(BaseRecord &&)=delete
lsst::afw
Definition: imageAlgorithm.dox:1
fwd.h
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::afw::table::BaseRecord::Catalog
CatalogT< BaseRecord > Catalog
Template of CatalogT used to hold records of this type.
Definition: BaseRecord.h:74
lsst::afw::table::BaseRecord::operator[]
Ref operator[](ReferenceFunctorKey< Ref > const &key)
Definition: BaseRecord.h:185
lsst::afw::table::BaseColumnView
Column-wise view into a sequence of records that have been allocated contiguously.
Definition: BaseColumnView.h:83
lsst::afw::table::BaseRecord::_stream
virtual void _stream(std::ostream &os) const
Called by operator<<.
Definition: BaseRecord.cc:153
lsst::afw::table::detail::RecordData
Helper struct that contains the information passed from BaseTable to BaseRecord at construction.
Definition: BaseTable.h:32
lsst::afw::table::BaseTable
Base class for all tables.
Definition: BaseTable.h:61
lsst::afw::table::OutputFunctorKey
Base class for objects that can extract a value from a record, but are not a true Key themselves.
Definition: FunctorKey.h:40
lsst::afw::table::BaseRecord::getManager
ndarray::Manager::Ptr getManager() const
Definition: BaseRecord.h:200
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
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
lsst::afw::table::BaseRecord::getElement
Field< T >::Element const * getElement(Key< T > const &key) const
Return a pointer to the underlying elements of a field (const).
Definition: BaseRecord.h:111
lsst::afw::table::BaseRecord::BaseRecord
BaseRecord(ConstructionToken const &, detail::RecordData &&data)
Construct a record with uninitialized data.
Definition: BaseRecord.cc:144
FunctorKey.h
std::ostream
STL class.
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::table::BaseRecord
Base class for all records.
Definition: BaseRecord.h:31
lsst::afw::table::BaseRecord::operator[]
Field< T >::ConstReference operator[](Key< T > const &key) const
Return a const reference (or const-reference-like type) to the field's value.
Definition: BaseRecord.h:141
lsst.pex::exceptions::LogicError
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
lsst::afw::table::SchemaMapper
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
lsst::afw::table::Key
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
lsst::afw::table::BaseRecord::ConstCatalog
CatalogT< BaseRecord const > ConstCatalog
Template of CatalogT used to hold const records of this type.
Definition: BaseRecord.h:77
lsst::afw::table::BaseRecord::BaseRecord
BaseRecord(BaseRecord &&)=delete
lsst::afw::table::FieldBase::ConstReference
T const & ConstReference
the type returned by BaseRecord::operator[] (const)
Definition: FieldBase.h:46
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::table::BaseRecord::ConstructionToken
Definition: BaseRecord.h:38
lsst::afw::table::BaseRecord::BaseRecord
BaseRecord(const BaseRecord &)=delete
os
std::ostream * os
Definition: Schema.cc:746
lsst::afw::table::ReferenceFunctorKey
Base class for objects that can return a non-const reference to part of a record, but are not a true ...
Definition: FunctorKey.h:91
lsst::afw::table::BaseRecord::operator<<
friend std::ostream & operator<<(std::ostream &os, BaseRecord const &record)
Write the record's content out, one field on each line.
Definition: BaseRecord.cc:159
lsst::afw::table::BaseRecord::assign
void assign(BaseRecord const &other)
Copy all field values from other to this, requiring that they have equal schemas.
Definition: BaseRecord.cc:123
key
Key< U > key
Definition: Schema.cc:281
lsst::afw::table::BaseRecord::operator=
BaseRecord & operator=(const BaseRecord &)=delete
mapper
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
lsst::afw::table::BaseRecord::operator[]
Field< T >::Reference operator[](Key< T > const &key)
Return a reference (or reference-like type) to the field's value.
Definition: BaseRecord.h:129
BaseTable.h
lsst::afw::table::FieldBase::Value
T Value
the type returned by BaseRecord::get
Definition: FieldBase.h:44
lsst::afw::table::BaseRecord::getTable
std::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:83
lsst::afw::table::BaseRecord::getSchema
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
Definition: BaseRecord.h:80
Schema.h
lsst::afw::table::BaseRecord::set
void set(InputFunctorKey< T > const &key, U const &value)
Set a calculated or aggregate field.
Definition: BaseRecord.h:180
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
lsst::afw::table::BaseTable::constructRecord
std::shared_ptr< RecordT > constructRecord(Args &&...args)
Helper function that must be used by all _makeRecord overrides to actually construct records.
Definition: BaseRecord.h:227
lsst::afw::table::BaseRecord::set
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:164
lsst::afw::table::BaseRecord::Table
BaseTable Table
The associated table class.
Definition: BaseRecord.h:68
lsst::afw::table::CatalogT< BaseRecord >