LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes | 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...
 
int getElementCount () const
 Return the number of subfield elements (equal to the size of the array). More...
 
int getSize () const
 Return the size of the array (equal to the number of subfield elements). More...
 
bool isVariableLength () const
 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 RecordBase::operator[] (non-const). More...
 
ConstReference getConstReference (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement RecordBase::operator[] (const). More...
 
Value getValue (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement RecordBase::get. More...
 
void setValue (Element *p, ndarray::Manager::Ptr const &, ndarray::Array< Element, 1, 1 > const &value) const
 
template<typename Derived >
void setValue (Element *p, ndarray::Manager::Ptr const &, ndarray::ExpressionBase< Derived > const &value) const
 Used to implement RecordBase::set; accepts any ndarray expression. More...
 

Static Protected Member Functions

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

Private Member Functions

template<typename Derived >
void setValueDeep (Element *p, ndarray::ExpressionBase< Derived > const &value) const
 

Private Attributes

int _size
 

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 negative size. 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 106 of file FieldBase.h.

Member Typedef Documentation

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

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

the type of subfields and array elements

Definition at line 116 of file FieldBase.h.

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

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

Constructor & Destructor Documentation

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

131  : _size(size) {
132  if (size < 0) throw LSST_EXCEPT(
133  lsst::pex::exceptions::LogicError,
134  "A non-negative size must be provided when constructing an array field."
135  );
136  }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46

Member Function Documentation

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

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

Definition at line 167 of file FieldBase.h.

167  {
168  if (isVariableLength()) {
169  return reinterpret_cast< ndarray::Array<Element,1,1> const * >(p)->deep();
170  }
172  }
detail::ExternalInitializer< T, N, Owner > external(T *data, Vector< int, N > const &shape, Vector< int, N > const &strides, Owner const &owner)
Create an expression that initializes an Array with externally allocated memory.
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:148
A multidimensional strided array.
Definition: Array.h:47
tuple m
Definition: lsstimport.py:48
template<typename U >
int lsst::afw::table::FieldBase< Array< U > >::getElementCount ( ) const
inline

Return the number of subfield elements (equal to the size of the array).

Definition at line 142 of file FieldBase.h.

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

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

Definition at line 159 of file FieldBase.h.

159  {
160  if (isVariableLength()) {
161  return reinterpret_cast< ndarray::Array<Element,1,1> * >(p)->deep();
162  }
164  }
detail::ExternalInitializer< T, N, Owner > external(T *data, Vector< int, N > const &shape, Vector< int, N > const &strides, Owner const &owner)
Create an expression that initializes an Array with externally allocated memory.
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:148
A multidimensional strided array.
Definition: Array.h:47
tuple m
Definition: lsstimport.py:48
template<typename U >
int lsst::afw::table::FieldBase< Array< U > >::getSize ( ) const
inline

Return the size of the array (equal to the number of subfield elements).

Definition at line 145 of file FieldBase.h.

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

Return a string description of the field type.

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

Used to implement RecordBase::get.

Definition at line 175 of file FieldBase.h.

175  {
176  if (isVariableLength()) {
177  return *reinterpret_cast< ndarray::Array<Element,1,1> const * >(p);
178  }
180  }
detail::ExternalInitializer< T, N, Owner > external(T *data, Vector< int, N > const &shape, Vector< int, N > const &strides, Owner const &owner)
Create an expression that initializes an Array with externally allocated memory.
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:148
A multidimensional strided array.
Definition: Array.h:47
tuple m
Definition: lsstimport.py:48
template<typename U >
bool lsst::afw::table::FieldBase< Array< U > >::isVariableLength ( ) const
inline

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

Definition at line 148 of file FieldBase.h.

148 { return _size == 0; }
template<typename U >
static FieldBase lsst::afw::table::FieldBase< Array< U > >::makeDefault ( )
inlinestaticprotected

Needed to allow Keys to be default-constructed.

Definition at line 153 of file FieldBase.h.

153 { return FieldBase(0); }
FieldBase(int size=0)
Construct a FieldBase with the given size.
Definition: FieldBase.h:131
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 RecordBase::set; accepts only non-const arrays of the right type, and allows shallow assignment of variable-length arrays (which is the only kind of assignment allowed for variable-length arrays - if you want deep assignment, use operator[] to get a reference and assign to that.

Definition at line 186 of file FieldBase.h.

188  {
189  if (isVariableLength()) {
190  *reinterpret_cast< ndarray::Array<Element,1,1>* >(p) = value;
191  } else {
192  setValueDeep(p, value);
193  }
194  }
void setValueDeep(Element *p, ndarray::ExpressionBase< Derived > const &value) const
Definition: FieldBase.h:213
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:148
A multidimensional strided array.
Definition: Array.h:47
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 RecordBase::set; accepts any ndarray expression.

Definition at line 198 of file FieldBase.h.

200  {
201  if (isVariableLength()) {
202  throw LSST_EXCEPT(
203  lsst::pex::exceptions::LogicError,
204  "Assignment to a variable-length array must use a non-const array of the correct type."
205  );
206  }
207  setValueDeep(p, value);
208  }
void setValueDeep(Element *p, ndarray::ExpressionBase< Derived > const &value) const
Definition: FieldBase.h:213
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:148
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename U >
template<typename Derived >
void lsst::afw::table::FieldBase< Array< U > >::setValueDeep ( Element p,
ndarray::ExpressionBase< Derived > const &  value 
) const
inlineprivate

Definition at line 213 of file FieldBase.h.

213  {
214  if (value.template getSize<0>() != _size) {
215  throw LSST_EXCEPT(
216  lsst::pex::exceptions::LengthError,
217  "Incorrect size in array field assignment."
218  );
219  }
220  for (int i = 0; i < _size; ++i) p[i] = value[i];
221  }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename U >
void lsst::afw::table::FieldBase< Array< U > >::stream ( std::ostream &  os) const
inlineprotected

Defines how Fields are printed.

Definition at line 156 of file FieldBase.h.

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

Member Data Documentation

template<typename U >
int lsst::afw::table::FieldBase< Array< U > >::_size
private

Definition at line 223 of file FieldBase.h.


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