Loading [MathJax]/extensions/tex2jax.js
LSST Applications 28.0.0,g04a91732dc+39818242a5,g07dc498a13+fb7087bc2f,g1409bbee79+fb7087bc2f,g1a7e361dbc+fb7087bc2f,g1fd858c14a+9df69a7481,g33399d78f5+cf93122263,g35bb328faa+e55fef2c71,g3bd4b5ce2c+e9a0db2a0e,g3dabb73f91+b2cce74dd5,g424a4f6e28+ee57be4232,g53246c7159+e55fef2c71,g5477a8d5ce+64cdf2f092,g60b5630c4e+ee57be4232,g78460c75b0+8427c4cc8f,g786e29fd12+307f82e6af,g8534526c7b+8e1c6b434f,g89139ef638+fb7087bc2f,g8b49a6ea8e+ee57be4232,g8e3b232dfe+801804d184,g9125e01d80+e55fef2c71,g989de1cb63+fb7087bc2f,g9f33ca652e+f0b312e6e5,gaaedd4e678+fb7087bc2f,gabe3b4be73+9c0c3c7524,gb1101e3267+d435cc4fc1,gb58c049af0+28045f66fd,gca43fec769+e55fef2c71,gce7788e931+f50f89eb98,gcf25f946ba+cf93122263,gd6cbbdb0b4+f6e5445f66,gdd9490a0bf+839504dd15,gde0f65d7ad+9dfeb3589e,ge278dab8ac+b4c2c8faf7,geab183fbe5+ee57be4232,gec3dcf77f0+e7bc33f3ea,gecb8035dfe+1f480bec5e,gf58bf46354+e55fef2c71,gfe7187db8c+5801f20593
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
12
13namespace lsst {
14namespace afw {
15namespace table {
16
32protected:
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
48public:
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
66
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>
129 typename Field<T>::Reference operator[](Key<T> const& key) {
130 return key.getReference(getElement(key), _manager);
131 }
132
140 template <typename T>
141 typename Field<T>::ConstReference operator[](Key<T> const& key) const {
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
207protected:
209 virtual void _assign(BaseRecord const& other) {}
210
213 virtual void _stream(std::ostream& os) const;
214
215
216private:
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
226template <typename RecordT, typename ...Args>
231
232
233} // namespace table
234} // namespace afw
235} // namespace lsst
236
237#endif // !AFW_TABLE_BaseRecord_h_INCLUDED
char * data
Definition BaseRecord.cc:61
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
SchemaMapper * mapper
Basic LSST definitions.
Column-wise view into a sequence of records that have been allocated contiguously.
Base class for all records.
Definition BaseRecord.h:31
Ref operator[](ReferenceFunctorKey< Ref > const &key)
Definition BaseRecord.h:185
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition BaseRecord.h:151
Field< T >::Element * getElement(Key< T > const &key)
Return a pointer to the underlying elements of a field (non-const).
Definition BaseRecord.h:93
void assign(BaseRecord const &other)
Copy all field values from other to this, requiring that they have equal schemas.
ConstRef operator[](ConstReferenceFunctorKey< ConstRef > const &key) const
Definition BaseRecord.h:190
std::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition BaseRecord.h:83
BaseRecord & operator=(BaseRecord &&)=delete
Field< T >::Reference operator[](Key< T > const &key)
Return a reference (or reference-like type) to the field's value.
Definition BaseRecord.h:129
BaseRecord & operator=(const BaseRecord &)=delete
BaseRecord(BaseRecord &&)=delete
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
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
Definition BaseRecord.h:80
ndarray::Manager::Ptr getManager() const
Definition BaseRecord.h:200
void set(InputFunctorKey< T > const &key, U const &value)
Set a calculated or aggregate field.
Definition BaseRecord.h:180
BaseRecord(const BaseRecord &)=delete
BaseRecord(ConstructionToken const &, detail::RecordData &&data)
Construct a record with uninitialized data.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition BaseRecord.h:164
T get(OutputFunctorKey< T > const &key) const
Compute a calculated or aggregate field.
Definition BaseRecord.h:172
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied.
Definition BaseRecord.h:209
friend std::ostream & operator<<(std::ostream &os, BaseRecord const &record)
Write the record's content out, one field on each line.
virtual void _stream(std::ostream &os) const
Called by 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
Base class for all tables.
Definition BaseTable.h:61
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
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
virtual T getConstReference(BaseRecord const &record) const =0
Base class for objects that can set a value on a record, but are not a true Key themselves.
Definition fwd.h:56
virtual void set(BaseRecord &record, T const &value) const =0
A class used as a handle to a particular field in a table.
Definition KeyBase.h:16
std::size_t getOffset() const noexcept
Return the offset (in bytes) of this field within a record.
Definition Key.h:87
bool isValid() const noexcept
Return true if the key was initialized to valid offset.
Definition Key.h:97
Base class for objects that can extract a value from a record, but are not a true Key themselves.
Definition fwd.h:54
virtual T get(BaseRecord const &record) const =0
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
virtual T getReference(BaseRecord &record) const =0
Defines the fields and offsets for a table.
Definition Schema.h:51
A mapping between the keys of two Schemas, used to copy data between them.
Reports errors in the logical structure of the program.
Definition Runtime.h:46
T forward(T... args)
T make_shared(T... args)
const T & ConstReference
the type returned by BaseRecord::operator[] (const)
Definition FieldBase.h:44
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (const).
Definition FieldBase.h:78
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::get.
Definition FieldBase.h:81
T & Reference
the type returned by BaseRecord::operator[] (non-const)
Definition FieldBase.h:43
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
Definition FieldBase.h:84
Reference getReference(Element *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (non-const).
Definition FieldBase.h:75
T Value
the type returned by BaseRecord::get
Definition FieldBase.h:42
typename FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Definition Field.h:26
Helper struct that contains the information passed from BaseTable to BaseRecord at construction.
Definition BaseTable.h:32