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"
12 #include "lsst/base.h"
13 #include "lsst/pex/exceptions.h"
33 inline int indexCovariance(
int i,
int j) {
return (i < j) ? (i + j * (j + 1) / 2) : (j + i * (i + 1) / 2); }
61 throw LSST_EXCEPT(lsst::pex::exceptions::LogicError,
62 "Constructor disabled (this Field type is not sized).");
70 void stream(std::ostream &os)
const {}
96 typedef ndarray::Array<U const, 1, 1>
Value;
121 throw LSST_EXCEPT(lsst::pex::exceptions::LogicError,
122 "A non-negative size must be provided when constructing an array field.");
144 void stream(std::ostream &os)
const { os <<
", size=" << _size; }
148 if (isVariableLength()) {
149 return reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p)->deep();
151 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
156 if (isVariableLength()) {
157 return reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p)->deep();
159 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
164 if (isVariableLength()) {
165 return *
reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p);
167 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
177 ndarray::Array<Element, 1, 1>
const &value)
const {
178 if (isVariableLength()) {
179 *
reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p) = value;
181 setValueDeep(p, value);
186 template <
typename Derived>
188 ndarray::ExpressionBase<Derived>
const &value)
const {
189 if (isVariableLength()) {
191 lsst::pex::exceptions::LogicError,
192 "Assignment to a variable-length array must use a non-const array of the correct type.");
194 setValueDeep(p, value);
198 template <
typename Derived>
199 void setValueDeep(
Element *p, ndarray::ExpressionBase<Derived>
const &value)
const {
200 if (value.template getSize<0>() != static_cast<std::size_t>(_size)) {
201 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
202 "Incorrect size in array field assignment.");
204 for (
int i = 0; i < _size; ++i) p[i] = value[i];
258 void stream(std::ostream &os)
const { os <<
", size=" << _size; }
262 if (isVariableLength()) {
264 throw LSST_EXCEPT(lsst::pex::exceptions::LogicError,
265 "non-const operator[] not supported for variable-length strings");
273 if (isVariableLength()) {
274 return reinterpret_cast<std::string
const *
>(p)->data();
288 void setValue(
Element *p, ndarray::Manager::Ptr
const &, std::string
const &value)
const;
297 #endif // !AFW_TABLE_FieldBase_h_INCLUDED
Value getValue(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::get.
static FieldBase makeDefault()
Needed to allow Keys to be default-constructed.
Field base class default implementation (used for numeric scalars and Angle).
int getElementCount() const
Return the number of subfield elements (equal to the size of the string, including a null terminator)...
int getSize() const
Return the size of the array (equal to the number of subfield elements), or 0 for a variable-length a...
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.
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 getElementCount() const
Return the number of subfield elements (equal to the size of the array), or 0 for a variable-length a...
void stream(std::ostream &os) const
Defines how Fields are printed.
ndarray::ArrayRef< U, 1, 1 > Reference
the type returned by BaseRecord::operator[]
char const * ConstReference
the type returned by BaseRecord::operator[] (const)
int computeCovariancePackedSize(int size)
Defines the packed size of a covariance matrices.
ndarray::ArrayRef< U const, 1, 1 > ConstReference
the type returned by BaseRecord::operator[] (const)
FieldBase(int size=0)
Construct a FieldBase with the given size.
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (const).
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (const).
int getElementCount() const
Return the number of subfield elements (always one for scalars).
int indexCovariance(int i, int j)
Defines the ordering of packed covariance matrices.
int getSize() const
Return the maximum length of the string, including a null terminator (equal to the number of subfield...
Tag types used to declare specialized field types.
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
void stream(std::ostream &os) const
Defines how Fields are printed.
ndarray::Array< U const, 1, 1 > Value
the type returned by BaseRecord::get
T Element
the type of subfields (the same as the type itself for scalars)
Reference getReference(Element *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (non-const).
void stream(std::ostream &os) const
Defines how Fields are printed.
T Value
the type returned by BaseRecord::get
static FieldBase makeDefault()
Needed to allow Keys to be default-constructed.
Reference getReference(Element *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (non-const).
char * Reference
the type returned by BaseRecord::operator[]
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
std::string Value
the type returned by BaseRecord::get
T const & ConstReference
the type returned by BaseRecord::operator[] (const)
char Element
the type of subfields and array elements
Reference getReference(Element *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (non-const).
T & Reference
the type returned by BaseRecord::operator[] (non-const)
static FieldBase makeDefault()
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).
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::get.
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
static std::string getTypeString()
Return a string description of the field type.