LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
lsst::afw::table::FieldBase< Array< U > > Struct Template Reference

Field base class specialization for arrays. More...

#include <FieldBase.h>

Public Types

typedef ndarray::Array< U const, 1, 1 > Value
 the type returned by BaseRecord::get More...
 
typedef ndarray::ArrayRef< U, 1, 1 > Reference
 the type returned by BaseRecord::operator[] More...
 
typedef ndarray::ArrayRef< U const, 1, 1 > ConstReference
 the type returned by BaseRecord::operator[] (const) More...
 
typedef U Element
 the type of subfields and array elements More...
 

Public Member Functions

 FieldBase (int size=0)
 Construct a FieldBase with the given size. More...
 
 FieldBase (FieldBase const &) noexcept=default
 
 FieldBase (FieldBase &&) noexcept=default
 
FieldBaseoperator= (FieldBase const &) noexcept=default
 
FieldBaseoperator= (FieldBase &&) noexcept=default
 
 ~FieldBase () noexcept=default
 
int getElementCount () const noexcept
 Return the number of subfield elements (equal to the size of the array), or 0 for a variable-length array. More...
 
int getSize () const noexcept
 Return the size of the array (equal to the number of subfield elements), or 0 for a variable-length array. More...
 
bool isVariableLength () const noexcept
 Return true if the field is variable-length (each record can have a different size array). More...
 

Static Public Member Functions

static std::string getTypeString ()
 Return a string description of the field type. More...
 

Protected Member Functions

void stream (std::ostream &os) const
 Defines how Fields are printed. More...
 
Reference getReference (Element *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::operator[] (non-const). More...
 
ConstReference getConstReference (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::operator[] (const). More...
 
Value getValue (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::get. More...
 
void setValue (Element *p, ndarray::Manager::Ptr const &, ndarray::Array< Element, 1, 1 > const &value) const
 Used to implement BaseRecord::set; accepts only non-const arrays of the right type. More...
 
template<typename Derived >
void setValue (Element *p, ndarray::Manager::Ptr const &, ndarray::ExpressionBase< Derived > const &value) const
 Used to implement BaseRecord::set; accepts any ndarray expression. More...
 

Static Protected Member Functions

static FieldBase makeDefault () noexcept
 Needed to allow Keys to be default-constructed. More...
 

Detailed Description

template<typename U>
struct lsst::afw::table::FieldBase< Array< U > >

Field base class specialization for arrays.

The Array tag is used for both fixed-length (same size in every record, accessible via ColumnView) and variable-length arrays; variable-length arrays are initialized with a size of 0. Ideally, we'd use complete different tag classes for those two very different types, but boost::variant and boost::mpl put a limit of 20 on the number of field types, and we're running out. In a future reimplementation of afw::table, we should fix this.

Definition at line 99 of file FieldBase.h.

Member Typedef Documentation

◆ ConstReference

template<typename U >
typedef ndarray::ArrayRef<U const, 1, 1> lsst::afw::table::FieldBase< Array< U > >::ConstReference

the type returned by BaseRecord::operator[] (const)

Definition at line 106 of file FieldBase.h.

◆ Element

template<typename U >
typedef U lsst::afw::table::FieldBase< Array< U > >::Element

the type of subfields and array elements

Definition at line 108 of file FieldBase.h.

◆ Reference

template<typename U >
typedef ndarray::ArrayRef<U, 1, 1> lsst::afw::table::FieldBase< Array< U > >::Reference

the type returned by BaseRecord::operator[]

Definition at line 103 of file FieldBase.h.

◆ Value

template<typename U >
typedef ndarray::Array<U const, 1, 1> lsst::afw::table::FieldBase< Array< U > >::Value

the type returned by BaseRecord::get

Definition at line 100 of file FieldBase.h.

Constructor & Destructor Documentation

◆ FieldBase() [1/3]

template<typename U >
lsst::afw::table::FieldBase< Array< U > >::FieldBase ( int  size = 0)
inline

Construct a FieldBase with the given size.

A size == 0 indicates a variable-length array. Negative sizes are not permitted.

This constructor is implicit with a default so it can be used in the Field constructor (as if it were an int argument) without specializing Field. In other words, it allows one to construct a 25-element array field like this:

Field< Array<float> >("name", "documentation", 25);

...even though the third argument to the Field constructor takes a FieldBase, not an int.

Definition at line 123 of file FieldBase.h.

123  : _size(size) {
124  if (size < 0)
126  "A non-negative size must be provided when constructing an array field.");
127  }
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

◆ FieldBase() [2/3]

template<typename U >
lsst::afw::table::FieldBase< Array< U > >::FieldBase ( FieldBase< Array< U > > const &  )
defaultnoexcept

◆ FieldBase() [3/3]

template<typename U >
lsst::afw::table::FieldBase< Array< U > >::FieldBase ( FieldBase< Array< U > > &&  )
defaultnoexcept

◆ ~FieldBase()

template<typename U >
lsst::afw::table::FieldBase< Array< U > >::~FieldBase ( )
defaultnoexcept

Member Function Documentation

◆ getConstReference()

template<typename U >
ConstReference lsst::afw::table::FieldBase< Array< U > >::getConstReference ( Element const *  p,
ndarray::Manager::Ptr const &  m 
) const
inlineprotected

Used to implement BaseRecord::operator[] (const).

Definition at line 165 of file FieldBase.h.

165  {
166  if (isVariableLength()) {
167  return reinterpret_cast<ndarray::Array<Element, 1, 1> const *>(p)->deep();
168  }
169  return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
170  }
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:147
int m
Definition: SpanSet.cc:49

◆ getElementCount()

template<typename U >
int lsst::afw::table::FieldBase< Array< U > >::getElementCount ( ) const
inlinenoexcept

Return the number of subfield elements (equal to the size of the array), or 0 for a variable-length array.

Definition at line 140 of file FieldBase.h.

140 { return _size; }

◆ getReference()

template<typename U >
Reference lsst::afw::table::FieldBase< Array< U > >::getReference ( Element p,
ndarray::Manager::Ptr const &  m 
) const
inlineprotected

Used to implement BaseRecord::operator[] (non-const).

Definition at line 157 of file FieldBase.h.

157  {
158  if (isVariableLength()) {
159  return reinterpret_cast<ndarray::Array<Element, 1, 1> *>(p)->deep();
160  }
161  return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
162  }
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:147
int m
Definition: SpanSet.cc:49

◆ getSize()

template<typename U >
int lsst::afw::table::FieldBase< Array< U > >::getSize ( ) const
inlinenoexcept

Return the size of the array (equal to the number of subfield elements), or 0 for a variable-length array.

Definition at line 144 of file FieldBase.h.

144 { return _size; }

◆ getTypeString()

template<typename U >
std::string lsst::afw::table::FieldBase< Array< U > >::getTypeString ( )
static

Return a string description of the field type.

Definition at line 63 of file FieldBase.cc.

63  {
64  return (boost::format("Array%s") % TypeTraits<U>::getName()).str();
65 }
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ getValue()

template<typename U >
Value lsst::afw::table::FieldBase< Array< U > >::getValue ( Element const *  p,
ndarray::Manager::Ptr const &  m 
) const
inlineprotected

Used to implement BaseRecord::get.

Definition at line 173 of file FieldBase.h.

173  {
174  if (isVariableLength()) {
175  return *reinterpret_cast<ndarray::Array<Element, 1, 1> const *>(p);
176  }
177  return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
178  }
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:147
int m
Definition: SpanSet.cc:49

◆ isVariableLength()

template<typename U >
bool lsst::afw::table::FieldBase< Array< U > >::isVariableLength ( ) const
inlinenoexcept

Return true if the field is variable-length (each record can have a different size array).

Definition at line 147 of file FieldBase.h.

147 { return _size == 0; }

◆ makeDefault()

template<typename U >
static FieldBase lsst::afw::table::FieldBase< Array< U > >::makeDefault ( )
inlinestaticprotectednoexcept

Needed to allow Keys to be default-constructed.

Definition at line 151 of file FieldBase.h.

151 { return FieldBase(0); }
FieldBase(int size=0)
Construct a FieldBase with the given size.
Definition: FieldBase.h:123

◆ operator=() [1/2]

template<typename U >
FieldBase& lsst::afw::table::FieldBase< Array< U > >::operator= ( FieldBase< Array< U > > const &  )
defaultnoexcept

◆ operator=() [2/2]

template<typename U >
FieldBase& lsst::afw::table::FieldBase< Array< U > >::operator= ( FieldBase< Array< U > > &&  )
defaultnoexcept

◆ setValue() [1/2]

template<typename U >
void lsst::afw::table::FieldBase< Array< U > >::setValue ( Element p,
ndarray::Manager::Ptr const &  ,
ndarray::Array< Element, 1, 1 > const &  value 
) const
inlineprotected

Used to implement BaseRecord::set; accepts only non-const arrays of the right type.

Fixed-length arrays are handled by copying the data from value to p through p + _size. Variable-length arrays are handled by setting p to the address of value, an ndarray, hence a shallow copy (ndarray arrays are reference-counted so this will not leak memory). If you want deep assignment of variable-length data, use operator[] to get a reference and assign to that.

Definition at line 186 of file FieldBase.h.

187  {
188  if (isVariableLength()) {
189  *reinterpret_cast<ndarray::Array<Element, 1, 1> *>(p) = value;
190  } else {
191  setValueDeep(p, value);
192  }
193  }
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:147

◆ setValue() [2/2]

template<typename U >
template<typename Derived >
void lsst::afw::table::FieldBase< Array< U > >::setValue ( Element p,
ndarray::Manager::Ptr const &  ,
ndarray::ExpressionBase< Derived > const &  value 
) const
inlineprotected

Used to implement BaseRecord::set; accepts any ndarray expression.

Definition at line 197 of file FieldBase.h.

198  {
199  if (isVariableLength()) {
200  throw LSST_EXCEPT(
202  "Assignment to a variable-length array must use a non-const array of the correct type.");
203  }
204  setValueDeep(p, value);
205  }
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:147

◆ stream()

template<typename U >
void lsst::afw::table::FieldBase< Array< U > >::stream ( std::ostream os) const
inlineprotected

Defines how Fields are printed.

Definition at line 154 of file FieldBase.h.

154 { os << ", size=" << _size; }

The documentation for this struct was generated from the following files: