LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 "lsst/base.h"
6 #include "lsst/afw/table/fwd.h"
10 
11 namespace lsst { namespace afw { namespace table {
12 
28 #ifndef SWIG // swig complains about these not being %shared_ptr, and it doesn't need to know about them
29  : public daf::base::Citizen,
30  private boost::noncopyable
31 #endif
32 {
33 public:
34 
36  typedef BaseTable Table;
37 
40 
43 
46 
48  Schema getSchema() const { return _table->getSchema(); }
49 
51  CONST_PTR(BaseTable) getTable() const { return _table; }
52 
60  template <typename T>
61  typename Field<T>::Element * getElement(Key<T> const & key) {
62  if (!key.isValid()) {
63  throw LSST_EXCEPT(
64  pex::exceptions::LogicError,
65  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been setup)."
66  );
67  }
68  return reinterpret_cast<typename Field<T>::Element*>(
69  reinterpret_cast<char*>(_data) + key.getOffset()
70  );
71  }
72 
80  template <typename T>
81  typename Field<T>::Element const * getElement(Key<T> const & key) const {
82  if (!key.isValid()) {
83  throw LSST_EXCEPT(
84  pex::exceptions::LogicError,
85  "Key is not valid (if this is a SourceRecord, make sure slot aliases have been setup)."
86  );
87  }
88  return reinterpret_cast<typename Field<T>::Element const *>(
89  reinterpret_cast<char const *>(_data) + key.getOffset()
90  );
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 
140 #ifndef SWIG
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 
168 #endif // !SWIG
169 
171  void assign(BaseRecord const & other);
172 
174  void assign(BaseRecord const & other, SchemaMapper const & mapper);
175 
177 
178  virtual ~BaseRecord() { _table->_destroy(*this); }
179 
180 protected:
181 
183  virtual void _assign(BaseRecord const & other) {}
184 
186  BaseRecord(PTR(BaseTable) const & table) : daf::base::Citizen(typeid(this)), _table(table) {
187  table->_initialize(*this);
188  }
189 
190 private:
191 
192  friend class BaseTable;
193  friend class BaseColumnView;
194 
195  // All these are definitely private, not protected - we don't want derived classes mucking with them.
196  void * _data; // pointer to field data
197  PTR(BaseTable) _table; // the associated table
198  ndarray::Manager::Ptr _manager; // shared manager for lifetime of _data (like shared_ptr with no pointer)
199 };
200 
201 }}} // namespace lsst::afw::table
202 
203 #endif // !AFW_TABLE_BaseRecord_h_INCLUDED
CatalogT< BaseRecord > Catalog
Template of CatalogT used to hold records of this type.
Definition: BaseRecord.h:42
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
Defines the fields and offsets for a table.
Definition: Schema.h:46
Ref operator[](ReferenceFunctorKey< Ref > const &key)
Definition: BaseRecord.h:159
Schema getSchema() const
Return the Schema that holds this record&#39;s fields and keys.
Definition: BaseRecord.h:48
Column-wise view into a sequence of records that have been allocated contiguously.
int getOffset() const
Return the offset (in bytes) of this field within a record.
Definition: Key.h:73
BaseTable Table
The associated table class.
Definition: BaseRecord.h:36
#define PTR(...)
Definition: base.h:41
ndarray::Manager::Ptr getManager() const
Definition: BaseRecord.h:176
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
boost::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:51
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied...
Definition: BaseRecord.h:183
#define CONST_PTR(...)
Definition: base.h:47
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
virtual T getReference(BaseRecord &record) const =0
bool isValid() const
Return true if the key was initialized to valid offset.
Definition: Key.h:83
void _initialize(BaseRecord &record)
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement RecordBase::set.
Definition: FieldBase.h:92
T const & ConstReference
the type returned by BaseRecord::operator[] (const)
Definition: FieldBase.h:52
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
boost::intrusive_ptr< Manager > Ptr
Definition: Manager.h:42
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement RecordBase::operator[] (const).
Definition: FieldBase.h:86
boost::shared_ptr< BaseTable > _table
Definition: BaseRecord.h:197
FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Definition: Field.h:25
CatalogT< BaseRecord const > ConstCatalog
Template of CatalogT used to hold const records of this type.
Definition: BaseRecord.h:45
Field< T >::Element const * getElement(Key< T > const &key) const
Return a pointer to the underlying elements of a field (const).
Definition: BaseRecord.h:81
T Value
the type returned by BaseRecord::get
Definition: FieldBase.h:50
virtual T getConstReference(BaseRecord const &record) const =0
ConstRef operator[](ConstReferenceFunctorKey< ConstRef > const &key) const
Definition: BaseRecord.h:164
void assign(BaseRecord const &other)
Copy all field values from other to this, requiring that they have equal schemas. ...
Field< T >::Element * getElement(Key< T > const &key)
Return a pointer to the underlying elements of a field (non-const).
Definition: BaseRecord.h:61
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Base class for all records.
Definition: BaseRecord.h:27
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
void set(InputFunctorKey< T > const &key, U const &value)
Set a calculated or aggregate field.
Definition: BaseRecord.h:154
Citizen(const std::type_info &)
Definition: Citizen.cc:173
T & Reference
the type returned by BaseRecord::operator[] (non-const)
Definition: FieldBase.h:51
ndarray::Manager::Ptr _manager
Definition: BaseRecord.h:198
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseRecord.h:39
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
Reference getReference(Element *p, ndarray::Manager::Ptr const &) const
Used to implement RecordBase::operator[] (non-const).
Definition: FieldBase.h:83
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
virtual void set(BaseRecord &record, T const &value) const =0
BaseRecord(boost::shared_ptr< BaseTable > const &table)
Construct a record with uninitialized data.
Definition: BaseRecord.h:186
Base class for all tables.
Definition: BaseTable.h:44