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" 33 inline int indexCovariance(
int i,
int j) {
return (i < j) ? (i + j * (j + 1) / 2) : (j + i * (i + 1) / 2); }
62 "Constructor disabled (this Field type is not sized).");
78 Reference
getReference(Element *p, ndarray::Manager::Ptr
const &)
const {
return *p; }
81 ConstReference
getConstReference(Element
const *p, ndarray::Manager::Ptr
const &)
const {
return *p; }
84 Value
getValue(Element
const *p, ndarray::Manager::Ptr
const &)
const {
return *p; }
87 void setValue(Element *p, ndarray::Manager::Ptr
const &, Value v)
const { *p = v; }
101 typedef ndarray::Array<U const, 1, 1>
Value;
127 "A non-negative size must be provided when constructing an array field.");
159 if (isVariableLength()) {
160 return reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p)->deep();
162 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
167 if (isVariableLength()) {
168 return reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p)->deep();
170 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
174 Value
getValue(Element
const *p, ndarray::Manager::Ptr
const &
m)
const {
175 if (isVariableLength()) {
176 return *
reinterpret_cast<ndarray::Array<Element, 1, 1>
const *
>(p);
178 return ndarray::external(p, ndarray::makeVector(_size), ndarray::ROW_MAJOR, m);
187 void setValue(Element *p, ndarray::Manager::Ptr
const &,
188 ndarray::Array<Element, 1, 1>
const &value)
const {
189 if (isVariableLength()) {
190 *
reinterpret_cast<ndarray::Array<Element, 1, 1> *
>(p) = value;
192 setValueDeep(p, value);
197 template <
typename Derived>
198 void setValue(Element *p, ndarray::Manager::Ptr
const &,
199 ndarray::ExpressionBase<Derived>
const &value)
const {
200 if (isVariableLength()) {
203 "Assignment to a variable-length array must use a non-const array of the correct type.");
205 setValueDeep(p, value);
209 template <
typename Derived>
210 void setValueDeep(Element *p, ndarray::ExpressionBase<Derived>
const &value)
const {
211 if (value.template getSize<0>() != static_cast<std::size_t>(_size)) {
213 "Incorrect size in array field assignment.");
215 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()) {
298 Value getValue(Element
const *p, ndarray::Manager::Ptr
const &
m)
const;
305 void setValue(Element *p, ndarray::Manager::Ptr
const &,
std::string const &value)
const;
314 #endif // !AFW_TABLE_FieldBase_h_INCLUDED
static FieldBase makeDefault()
Needed to allow Keys to be default-constructed.
Value getValue(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::get.
Field base class default implementation (used for numeric scalars and Angle).
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.
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.
U Element
the type of subfields and array elements
int getSize() const
Return the size of the array (equal to the number of subfield elements), 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)
int getElementCount() const
Return the number of subfield elements (always one for scalars).
bool isVariableLength() const
Return true if the field is variable-length (each record can have a different size array)...
int getElementCount() const
Return the number of subfield elements (equal to the size of the array), or 0 for a variable-length a...
int getSize() const
Return the maximum length of the string, including a null terminator (equal to the number of subfield...
FieldBase(int size=0)
Construct a FieldBase with the given size.
A base class for image defects.
Reference getReference(Element *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (non-const).
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::operator[] (const).
int getElementCount() const
Return the number of subfield elements (equal to the size of the string, including a null terminator)...
int indexCovariance(int i, int j)
Defines the ordering of packed covariance matrices.
Tag types used to declare specialized field types.
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
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)
#define LSST_EXCEPT(type,...)
T Value
the type returned by BaseRecord::get
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::get.
static FieldBase makeDefault()
Needed to allow Keys to be default-constructed.
void setValue(Element *p, ndarray::Manager::Ptr const &, ndarray::ExpressionBase< Derived > const &value) const
Used to implement BaseRecord::set; accepts any ndarray expression.
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).
ConstReference getConstReference(Element const *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (const).
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.
Reference getReference(Element *p, ndarray::Manager::Ptr const &m) const
Used to implement BaseRecord::operator[] (non-const).
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
T & Reference
the type returned by BaseRecord::operator[] (non-const)
static FieldBase makeDefault()
Needed to allow Keys to be default-constructed.