lsst.afw  13.0-98-g5a654715e+2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 "lsst/base.h"
6 #include "lsst/afw/table/fwd.h"
10 
11 namespace lsst {
12 namespace afw {
13 namespace table {
14 
29 class BaseRecord : public daf::base::Citizen {
30 public:
31  // No copying
32  BaseRecord(const BaseRecord&) = delete;
33  BaseRecord& operator=(const BaseRecord&) = delete;
34 
35  // No moving
36  BaseRecord(BaseRecord&&) = delete;
37  BaseRecord& operator=(BaseRecord&&) = delete;
38 
40  typedef BaseTable Table;
41 
44 
47 
50 
52  Schema getSchema() const { return _table->getSchema(); }
53 
55  std::shared_ptr<BaseTable const> getTable() const { return _table; }
56 
64  template <typename T>
65  typename Field<T>::Element* getElement(Key<T> const& key) {
66  if (!key.isValid()) {
67  throw LSST_EXCEPT(
68  pex::exceptions::LogicError,
69  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been setup).");
70  }
71  return reinterpret_cast<typename Field<T>::Element*>(reinterpret_cast<char*>(_data) +
72  key.getOffset());
73  }
74 
82  template <typename T>
83  typename Field<T>::Element const* getElement(Key<T> const& key) const {
84  if (!key.isValid()) {
85  throw LSST_EXCEPT(
86  pex::exceptions::LogicError,
87  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been setup).");
88  }
89  return reinterpret_cast<typename Field<T>::Element const*>(reinterpret_cast<char const*>(_data) +
90  key.getOffset());
91  }
92 
100  template <typename T>
101  typename Field<T>::Reference operator[](Key<T> const& key) {
102  return key.getReference(getElement(key), _manager);
103  }
104 
112  template <typename T>
113  typename Field<T>::ConstReference operator[](Key<T> const& key) const {
114  return key.getConstReference(getElement(key), _manager);
115  }
116 
122  template <typename T>
123  typename Field<T>::Value get(Key<T> const& key) const {
124  return key.getValue(getElement(key), _manager);
125  }
126 
135  template <typename T, typename U>
136  void set(Key<T> const& key, U const& value) {
137  key.setValue(getElement(key), _manager, value);
138  }
139 
143  template <typename T>
144  T get(OutputFunctorKey<T> const& key) const {
145  return key.get(*this);
146  }
147 
151  template <typename T, typename U>
152  void set(InputFunctorKey<T> const& key, U const& value) {
153  return key.set(*this, value);
154  }
155 
156  template <typename Ref>
158  return key.getReference(*this);
159  }
160 
161  template <typename ConstRef>
162  ConstRef operator[](ConstReferenceFunctorKey<ConstRef> const& key) const {
163  return key.getConstReference(*this);
164  }
165 
167  void assign(BaseRecord const& other);
168 
170  void assign(BaseRecord const& other, SchemaMapper const& mapper);
171 
172  ndarray::Manager::Ptr getManager() const { return _manager; }
173 
174  virtual ~BaseRecord() { _table->_destroy(*this); }
175 
176 protected:
178  virtual void _assign(BaseRecord const& other) {}
179 
181  BaseRecord(std::shared_ptr<BaseTable> const& table) : daf::base::Citizen(typeid(this)), _table(table) {
182  table->_initialize(*this);
183  }
184 
185 private:
186  friend class BaseTable;
187  friend class BaseColumnView;
188 
189  // All these are definitely private, not protected - we don't want derived classes mucking with them.
190  void* _data; // pointer to field data
191  std::shared_ptr<BaseTable> _table; // the associated table
192  ndarray::Manager::Ptr _manager; // shared manager for lifetime of _data (like shared_ptr with no pointer)
193 };
194 }
195 }
196 } // namespace lsst::afw::table
197 
198 #endif // !AFW_TABLE_BaseRecord_h_INCLUDED
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Key.h:89
void set(InputFunctorKey< T > const &key, U const &value)
Set a calculated or aggregate field.
Definition: BaseRecord.h:152
Defines the fields and offsets for a table.
Definition: Schema.h:46
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:101
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:113
A custom container class for records, based on std::vector.
Definition: Catalog.h:96
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:46
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied...
Definition: BaseRecord.h:178
ndarray::Manager::Ptr getManager() const
Definition: BaseRecord.h:172
virtual void set(BaseRecord &record, T const &value) const =0
virtual T getReference(BaseRecord &record) const =0
Field< T >::Element const * getElement(Key< T > const &key) const
Return a pointer to the underlying elements of a field (const).
Definition: BaseRecord.h:83
CatalogT< BaseRecord const > ConstCatalog
Template of CatalogT used to hold const records of this type.
Definition: BaseRecord.h:49
BaseTable Table
The associated table class.
Definition: BaseRecord.h:40
Base class for objects that can return a const reference to part of a record, but are not a true Key...
Definition: FunctorKey.h:99
std::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:55
int getOffset() const
Return the offset (in bytes) of this field within a record.
Definition: Key.h:79
Ref operator[](ReferenceFunctorKey< Ref > const &key)
Definition: BaseRecord.h:157
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (const).
Definition: FieldBase.h:76
BaseRecord(std::shared_ptr< BaseTable > const &table)
Construct a record with uninitialized data.
Definition: BaseRecord.h:181
Base class for objects that can set a value on a record, but are not a true Key themselves.
Definition: FunctorKey.h:54
Base class for objects that can return a non-const reference to part of a record, but are not a true ...
Definition: FunctorKey.h:81
Field< T >::Element * getElement(Key< T > const &key)
Return a pointer to the underlying elements of a field (non-const).
Definition: BaseRecord.h:65
Reference getReference(Element *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (non-const).
Definition: FieldBase.h:73
Base class for all records.
Definition: BaseRecord.h:29
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
ConstRef operator[](ConstReferenceFunctorKey< ConstRef > const &key) const
Definition: BaseRecord.h:162
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 set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
Definition: FieldBase.h:82
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:43
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
Schema getSchema() const
Return the Schema that holds this record&#39;s fields and keys.
Definition: BaseRecord.h:52