LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
FieldBase.cc
Go to the documentation of this file.
1// -*- lsst-c++ -*-
2
3#include <cstdint>
4#include <limits>
5
6#include "boost/format.hpp"
7#include "boost/preprocessor/seq/for_each.hpp"
8#include "boost/preprocessor/tuple/to_seq.hpp"
9
11#include "lsst/afw/table/Flag.h"
12
13namespace lsst {
14namespace afw {
15namespace table {
16
17namespace {
18
19template <typename T>
20struct TypeTraits;
21
22template <>
23struct TypeTraits<std::uint8_t> {
24 static char const *getName() { return "B"; }
25};
26template <>
27struct TypeTraits<std::uint16_t> {
28 static char const *getName() { return "U"; }
29};
30template <>
31struct TypeTraits<std::int32_t> {
32 static char const *getName() { return "I"; }
33};
34template <>
35struct TypeTraits<std::int64_t> {
36 static char const *getName() { return "L"; }
37};
38template <>
39struct TypeTraits<float> {
40 static char const *getName() { return "F"; }
41};
42template <>
43struct TypeTraits<double> {
44 static char const *getName() { return "D"; }
45};
46template <>
47struct TypeTraits<lsst::geom::Angle> {
48 static char const *getName() { return "Angle"; }
49};
50
51} // namespace
52
53//----- POD scalars -----------------------------------------------------------------------------------------
54
55template <typename T>
57 return TypeTraits<T>::getName();
58}
59
60//----- POD array -------------------------------------------------------------------------------------------
61
62template <typename U>
63std::string FieldBase<Array<U> >::getTypeString() {
64 return (boost::format("Array%s") % TypeTraits<U>::getName()).str();
65}
66
67//----- String ----------------------------------------------------------------------------------------------
68
70}
71
73
74std::string FieldBase<std::string>::getValue(Element const *p, ndarray::Manager::Ptr const &m) const {
75 if (isVariableLength()) {
76 // p is a pointer to a std::string; return a copy
77 return std::string(*reinterpret_cast<std::string const *>(p));
78 } else {
79 // p is a char * that is null-terminated only if the string has fewer than _size chars;
80 // return a copy as a std::string
81 Element const *end = p + _size;
82 end = std::find(p, end, 0);
83 return std::string(p, end);
84 }
85}
86
87void FieldBase<std::string>::setValue(Element *p, ndarray::Manager::Ptr const &,
88 std::string const &value) const {
89 if (isVariableLength()) {
90 // p is a pointer to a std::string; replace its contents with a copy of `value`
91 *reinterpret_cast<std::string *>(p) = value;
92 } else {
93 // copy the contents of `value` to p through p + _size, null extra characters, if any
94 if (value.size() > _size) {
95 throw LSST_EXCEPT(
97 (boost::format("String (%d) is too large for field (%d).") % value.size() % _size).str());
98 }
99 std::copy(value.begin(), value.end(), p);
100 std::fill(p + value.size(), p + _size, char(0)); // null extra characters, if any
101 }
102}
103
104//----- Explicit instantiation ------------------------------------------------------------------------------
105
106#define INSTANTIATE_FIELD_BASE(r, data, elem) template struct FieldBase<elem>;
107
110} // namespace table
111} // namespace afw
112} // namespace lsst
int end
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
#define INSTANTIATE_FIELD_BASE(r, data, elem)
Definition: FieldBase.cc:106
int m
Definition: SpanSet.cc:48
T begin(T... args)
A class representing an angle.
Definition: Angle.h:128
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
T copy(T... args)
T end(T... args)
T fill(T... args)
T find(T... args)
BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_COLUMNVIEW_SCALAR, _, BOOST_PP_TUPLE_TO_SEQ(AFW_TABLE_SCALAR_FIELD_TYPE_N, AFW_TABLE_SCALAR_FIELD_TYPE_TUPLE)) BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_COLUMNVIEW_ARRAY
STL namespace.
T size(T... args)
char Element
the type of subfields and array elements
Definition: FieldBase.h:227
Field base class default implementation (used for numeric scalars and lsst::geom::Angle).
Definition: FieldBase.h:41
static std::string getTypeString()
Return a string description of the field type.
Definition: FieldBase.cc:56
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::get.
Definition: FieldBase.h:81
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
Definition: FieldBase.h:84
#define AFW_TABLE_FIELD_TYPE_N
Definition: types.h:38
#define AFW_TABLE_FIELD_TYPE_TUPLE
Definition: types.h:43