LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+bd2ed33bd6,g1470d8bcf6+c6d6eb38e2,g14a832a312+9d12ad093c,g2079a07aa2+86d27d4dc4,g2305ad1205+91a32aca49,g295015adf3+88246b6574,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+c34e8be1fa,g487adcacf7+85dcfbcc36,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ea1711114f,g5a732f18d5+53520f316c,g64a986408d+bd2ed33bd6,g858d7b2824+bd2ed33bd6,g8a8a8dda67+585e252eca,g99cad8db69+016a06b37a,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+b6d7b42999,gc120e1dc64+f745648b3a,gc28159a63d+0e5473021a,gcf0d15dbbd+c34e8be1fa,gdaeeff99f8+f9a426f77a,ge6526c86ff+508d0e0a30,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+8d59551888,gf1cff7945b+bd2ed33bd6,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
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

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

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

void stream (std::ostream &os) const
 Defines how Fields are printed.
 
Reference getReference (Element *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::operator[] (non-const).
 
ConstReference getConstReference (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::operator[] (const).
 
Value getValue (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::get.
 
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.
 
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.
 

Static Protected Member Functions

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

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 this was limited in the original (pre-C++11) implementation and now it would be an API change.

Definition at line 96 of file FieldBase.h.

Member Typedef Documentation

◆ ConstReference

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

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

Definition at line 103 of file FieldBase.h.

◆ Element

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

the type of subfields and array elements

Definition at line 105 of file FieldBase.h.

◆ Reference

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

the type returned by BaseRecord::operator[]

Definition at line 100 of file FieldBase.h.

◆ Value

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

the type returned by BaseRecord::get

Definition at line 97 of file FieldBase.h.

Constructor & Destructor Documentation

◆ FieldBase() [1/3]

template<typename U >
lsst::afw::table::FieldBase< Array< U > >::FieldBase ( size_t 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 120 of file FieldBase.h.

120 : _size(size) {
121 }

◆ 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 159 of file FieldBase.h.

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

◆ getElementCount()

template<typename U >
std::size_t 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 134 of file FieldBase.h.

134{ 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 151 of file FieldBase.h.

151 {
152 if (isVariableLength()) {
153 return reinterpret_cast<ndarray::Array<Element, 1, 1> *>(p)->deep();
154 }
155 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
156 }

◆ getSize()

template<typename U >
std::size_t 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 138 of file FieldBase.h.

138{ 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}

◆ 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 167 of file FieldBase.h.

167 {
168 if (isVariableLength()) {
169 return *reinterpret_cast<ndarray::Array<Element, 1, 1> const *>(p);
170 }
171 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
172 }

◆ 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 141 of file FieldBase.h.

141{ 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 145 of file FieldBase.h.

145{ return FieldBase(0); }
FieldBase(size_t size=0)
Construct a FieldBase with the given size.
Definition FieldBase.h:120

◆ operator=() [1/2]

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

◆ operator=() [2/2]

template<typename U >
FieldBase & lsst::afw::table::FieldBase< Array< U > >::operator= ( FieldBase< Array< U > > const & )
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 180 of file FieldBase.h.

181 {
182 if (isVariableLength()) {
183 *reinterpret_cast<ndarray::Array<Element, 1, 1> *>(p) = value;
184 } else {
185 setValueDeep(p, value);
186 }
187 }

◆ 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 191 of file FieldBase.h.

192 {
193 if (isVariableLength()) {
194 throw LSST_EXCEPT(
196 "Assignment to a variable-length array must use a non-const array of the correct type.");
197 }
198 setValueDeep(p, value);
199 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Reports errors in the logical structure of the program.
Definition Runtime.h:46

◆ 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 148 of file FieldBase.h.

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

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