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"
32 inline int indexCovariance(
int i,
int j) {
return (i < j) ? (i + j * (j + 1) / 2) : (j + i * (i + 1) / 2); }
61 "Constructor disabled (this Field type is not sized).");
100 typedef ndarray::Array<U const, 1, 1>
Value;
126 "A non-negative size must be provided when constructing an array field.");
158 if (isVariableLength()) {
159 return reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p)->deep();
161 return ndarray::external(p, ndarray::makeVector(
_size), ndarray::ROW_MAJOR,
m);
166 if (isVariableLength()) {
167 return reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p)->deep();
169 return ndarray::external(p, ndarray::makeVector(
_size), ndarray::ROW_MAJOR,
m);
174 if (isVariableLength()) {
175 return *
reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p);
177 return ndarray::external(p, ndarray::makeVector(
_size), ndarray::ROW_MAJOR,
m);
187 ndarray::Array<Element, 1, 1>
const &value)
const {
188 if (isVariableLength()) {
189 *
reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p) = value;
191 setValueDeep(p, value);
196 template <
typename Derived>
198 ndarray::ExpressionBase<Derived>
const &value)
const {
199 if (isVariableLength()) {
202 "Assignment to a variable-length array must use a non-const array of the correct type.");
204 setValueDeep(p, value);
208 template <
typename Derived>
209 void setValueDeep(
Element *p, ndarray::ExpressionBase<Derived>
const &value)
const {
212 "Incorrect size in array field assignment.");
214 for (
int i = 0; i <
_size; ++i) p[i] = value[i];
279 if (isVariableLength()) {
282 "non-const operator[] not supported for variable-length strings");
290 if (isVariableLength()) {
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Tag types used to declare specialized field types.
Reports attempts to exceed implementation-defined length limits for some classes.
Reports errors in the logical structure of the program.
int computeCovariancePackedSize(int size)
Defines the packed size of a covariance matrices.
int indexCovariance(int i, int j)
Defines the ordering of packed covariance matrices.
A base class for image defects.
table::Key< table::Array< int > > _size
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.
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
ndarray::Array< U const, 1, 1 > Value
the type returned by BaseRecord::get
U Element
the type of subfields and array elements
void setValue(Element *p, ndarray::Manager::Ptr const &, ndarray::ExpressionBase< Derived > const &value) const
Used to implement BaseRecord::set; accepts any ndarray expression.
int getSize() const noexcept
Return the size of the array (equal to the number of subfield elements), or 0 for a variable-length a...
FieldBase(int size=0)
Construct a FieldBase with the given size.
ndarray::ArrayRef< U, 1, 1 > Reference
the type returned by BaseRecord::operator[]
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).
ndarray::ArrayRef< U const, 1, 1 > ConstReference
the type returned by BaseRecord::operator[] (const)
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).
std::string Value
the type returned by BaseRecord::get
char const * ConstReference
the type returned by BaseRecord::operator[] (const)
char Element
the type of subfields and array elements
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
FieldBase(FieldBase const &) noexcept=default
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (const).
int getSize() const noexcept
Return the maximum length of the string, including a null terminator (equal to the number of subfield...
void stream(std::ostream &os) const
Defines how Fields are printed.
char * Reference
the type returned by BaseRecord::operator[]
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).
T & Reference
the type returned by BaseRecord::operator[] (non-const)
T const & 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.
T Element
the type of subfields (the same as the type itself for scalars)
T Value
the type returned by BaseRecord::get
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.
void stream(std::ostream &os) const
Defines how Fields are printed.
int getElementCount() const noexcept
Return the number of subfield elements (always one for scalars).
FieldBase(FieldBase &&) noexcept=default