lsst.afw  14.0-58-g91bfccb15
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 
32 public:
33  // No copying
34  BaseRecord(const BaseRecord&) = delete;
35  BaseRecord& operator=(const BaseRecord&) = delete;
36 
37  // No moving
38  BaseRecord(BaseRecord&&) = delete;
39  BaseRecord& operator=(BaseRecord&&) = delete;
40 
42  typedef BaseTable Table;
43 
46 
49 
52 
54  Schema getSchema() const { return _table->getSchema(); }
55 
57  std::shared_ptr<BaseTable const> getTable() const { return _table; }
58 
66  template <typename T>
67  typename Field<T>::Element* getElement(Key<T> const& key) {
68  if (!key.isValid()) {
69  throw LSST_EXCEPT(
71  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been setup).");
72  }
73  return reinterpret_cast<typename Field<T>::Element*>(reinterpret_cast<char*>(_data) +
74  key.getOffset());
75  }
76 
84  template <typename T>
85  typename Field<T>::Element const* getElement(Key<T> const& key) const {
86  if (!key.isValid()) {
87  throw LSST_EXCEPT(
89  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been setup).");
90  }
91  return reinterpret_cast<typename Field<T>::Element const*>(reinterpret_cast<char const*>(_data) +
92  key.getOffset());
93  }
94 
102  template <typename T>
103  typename Field<T>::Reference operator[](Key<T> const& key) {
104  return key.getReference(getElement(key), _manager);
105  }
106 
114  template <typename T>
115  typename Field<T>::ConstReference operator[](Key<T> const& key) const {
116  return key.getConstReference(getElement(key), _manager);
117  }
118 
124  template <typename T>
125  typename Field<T>::Value get(Key<T> const& key) const {
126  return key.getValue(getElement(key), _manager);
127  }
128 
137  template <typename T, typename U>
138  void set(Key<T> const& key, U const& value) {
139  key.setValue(getElement(key), _manager, value);
140  }
141 
145  template <typename T>
146  T get(OutputFunctorKey<T> const& key) const {
147  return key.get(*this);
148  }
149 
153  template <typename T, typename U>
154  void set(InputFunctorKey<T> const& key, U const& value) {
155  return key.set(*this, value);
156  }
157 
158  template <typename Ref>
160  return key.getReference(*this);
161  }
162 
163  template <typename ConstRef>
164  ConstRef operator[](ConstReferenceFunctorKey<ConstRef> const& key) const {
165  return key.getConstReference(*this);
166  }
167 
169  void assign(BaseRecord const& other);
170 
172  void assign(BaseRecord const& other, SchemaMapper const& mapper);
173 
174  ndarray::Manager::Ptr getManager() const { return _manager; }
175 
176  virtual ~BaseRecord() { _table->_destroy(*this); }
177 
179  friend std::ostream & operator<<(std::ostream & os, BaseRecord const & record);
180 
181 protected:
183  virtual void _assign(BaseRecord const& other) {}
184 
187  virtual void _stream(std::ostream & os) const;
188 
190  BaseRecord(std::shared_ptr<BaseTable> const& table) : daf::base::Citizen(typeid(this)), _table(table) {
191  table->_initialize(*this);
192  }
193 
194 private:
195  friend class BaseTable;
196  friend class BaseColumnView;
197 
198  // All these are definitely private, not protected - we don't want derived classes mucking with them.
199  void* _data; // pointer to field data
200  std::shared_ptr<BaseTable> _table; // the associated table
201  ndarray::Manager::Ptr _manager; // shared manager for lifetime of _data (like shared_ptr with no pointer)
202 };
203 }
204 }
205 } // namespace lsst::afw::table
206 
207 #endif // !AFW_TABLE_BaseRecord_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:47
Base class for objects that can extract a value from a record, but are not a true Key themselves...
Definition: FunctorKey.h:40
Column-wise view into a sequence of records that have been allocated contiguously.
Field< T >::Reference operator[](Key< T > const &key)
Return a reference (or reference-like type) to the field&#39;s value.
Definition: BaseRecord.h:103
friend std::ostream & operator<<(std::ostream &os, BaseRecord const &record)
Write the record&#39;s content out, one field on each line.
int getOffset() const
Return the offset (in bytes) of this field within a record.
Definition: Key.h:79
Field< T >::ConstReference operator[](Key< T > const &key) const
Return a const reference (or const-reference-like type) to the field&#39;s value.
Definition: BaseRecord.h:115
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
CatalogT< BaseRecord > Catalog
Template of CatalogT used to hold records of this type.
Definition: BaseRecord.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:183
ConstRef operator[](ConstReferenceFunctorKey< ConstRef > const &key) const
Definition: BaseRecord.h:164
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Key.h:89
virtual T getReference(BaseRecord &record) const =0
ndarray::Manager::Ptr getManager() const
Definition: BaseRecord.h:174
CatalogT< BaseRecord const > ConstCatalog
Template of CatalogT used to hold const records of this type.
Definition: BaseRecord.h:51
A base class for image defects.
Reference getReference(Element *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (non-const).
Definition: FieldBase.h:78
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (const).
Definition: FieldBase.h:81
BaseTable Table
The associated table class.
Definition: BaseRecord.h:42
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
Ref operator[](ReferenceFunctorKey< Ref > const &key)
Definition: BaseRecord.h:159
Field< T >::Element const * getElement(Key< T > const &key) const
Return a pointer to the underlying elements of a field (const).
Definition: BaseRecord.h:85
Schema getSchema() const
Return the Schema that holds this record&#39;s fields and keys.
Definition: BaseRecord.h:54
BaseRecord(std::shared_ptr< BaseTable > const &table)
Construct a record with uninitialized data.
Definition: BaseRecord.h:190
Base class for objects that can set a value on a record, but are not a true Key themselves.
Definition: FunctorKey.h:57
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
Field< T >::Element * getElement(Key< T > const &key)
Return a pointer to the underlying elements of a field (non-const).
Definition: BaseRecord.h:67
std::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:57
#define LSST_EXCEPT(type,...)
Base class for all records.
Definition: BaseRecord.h:31
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
T Value
the type returned by BaseRecord::get
Definition: FieldBase.h:45
Citizen(const std::type_info &)
virtual T getConstReference(BaseRecord const &record) const =0
FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Definition: Field.h:26
void assign(BaseRecord const &other)
Copy all field values from other to this, requiring that they have equal schemas. ...
T const & ConstReference
the type returned by BaseRecord::operator[] (const)
Definition: FieldBase.h:47
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseRecord.h:45
STL class.
BaseRecord & operator=(const BaseRecord &)=delete
BaseRecord(const BaseRecord &)=delete
T & Reference
the type returned by BaseRecord::operator[] (non-const)
Definition: FieldBase.h:46
Base class for all tables.
Definition: BaseTable.h:44
virtual void _stream(std::ostream &os) const
Called by operator<<.