2 #ifndef AFW_TABLE_FieldBase_h_INCLUDED
3 #define AFW_TABLE_FieldBase_h_INCLUDED
8 #include "boost/mpl/vector.hpp"
9 #include "boost/preprocessor/punctuation/paren.hpp"
61 "Constructor disabled (this Field type is not sized).");
99 using Value = ndarray::Array<const U, 1, 1>;
154 if (isVariableLength()) {
155 return reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p)->deep();
157 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR,
m);
162 if (isVariableLength()) {
163 return reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p)->deep();
165 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR,
m);
170 if (isVariableLength()) {
171 return *
reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p);
173 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR,
m);
183 ndarray::Array<Element, 1, 1>
const &value)
const {
184 if (isVariableLength()) {
185 *
reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p) = value;
187 setValueDeep(p, value);
192 template <
typename Derived>
194 ndarray::ExpressionBase<Derived>
const &value)
const {
195 if (isVariableLength()) {
198 "Assignment to a variable-length array must use a non-const array of the correct type.");
200 setValueDeep(p, value);
204 template <
typename Derived>
205 void setValueDeep(
Element *p, ndarray::ExpressionBase<Derived>
const &value)
const {
206 if (value.template getSize<0>() !=
static_cast<std::size_t>(_size)) {
208 "Incorrect size in array field assignment.");
210 for (
std::size_t i = 0; i < _size; ++i) p[i] = value[i];
275 if (isVariableLength()) {
278 "non-const operator[] not supported for variable-length strings");
286 if (isVariableLength()) {
#define LSST_EXCEPT(type,...)
Tag types used to declare specialized field types.
std::size_t computeCovariancePackedSize(std::size_t size)
Defines the packed size of a covariance matrices.
std::size_t indexCovariance(std::size_t i, std::size_t j)
Defines the ordering of packed covariance matrices.
A base class for image defects.
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.
ndarray::ArrayRef< U, 1, 1 > Reference
the type returned by BaseRecord::operator[]
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 a...
Value getValue(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::get.
void stream(std::ostream &os) const
Defines how Fields are printed.
FieldBase(FieldBase const &) noexcept=default
void setValue(Element *p, ndarray::Manager::Ptr const &, ndarray::ExpressionBase< Derived > const &value) const
Used to implement BaseRecord::set; accepts any ndarray expression.
U Element
the type of subfields and array elements
ndarray::ArrayRef< const U, 1, 1 > ConstReference
the type returned by BaseRecord::operator[] (const)
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array).
FieldBase(FieldBase &&) noexcept=default
Reference getReference(Element *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (non-const).
FieldBase(size_t size=0)
Construct a FieldBase with the given size.
ndarray::Array< const U, 1, 1 > Value
the type returned by BaseRecord::get
static FieldBase makeDefault() noexcept
Needed to allow Keys to be default-constructed.
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (const).
char Element
the type of subfields and array elements
char * Reference
the type returned by BaseRecord::operator[]
const char * ConstReference
the type returned by BaseRecord::operator[] (const)
static FieldBase makeDefault() noexcept
Needed to allow Keys to be default-constructed.
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array).
FieldBase(FieldBase &&) noexcept=default
std::size_t getSize() const noexcept
Return the maximum length of the string, including a null terminator (equal to the number of subfield...
FieldBase(FieldBase const &) noexcept=default
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (const).
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).
Field base class default implementation (used for numeric scalars and lsst::geom::Angle).
const T & ConstReference
the type returned by BaseRecord::operator[] (const)
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (const).
FieldBase(FieldBase const &) noexcept=default
static std::string getTypeString()
Return a string description of the field type.
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::get.
std::size_t getElementCount() const noexcept
Return the number of subfield elements (always one for scalars).
T & Reference
the type returned by BaseRecord::operator[] (non-const)
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
Reference getReference(Element *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (non-const).
static FieldBase makeDefault() noexcept
Needed to allow Keys to be default-constructed.
T Value
the type returned by BaseRecord::get
void stream(std::ostream &os) const
Defines how Fields are printed.
T Element
the type of subfields (the same as the type itself for scalars)
FieldBase(FieldBase &&) noexcept=default