LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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 
13 namespace lsst {
14 namespace afw {
15 namespace table {
16 
17 namespace {
18 
19 template <typename T>
20 struct TypeTraits;
21 
22 template <>
23 struct TypeTraits<std::uint8_t> {
24  static char const *getName() { return "B"; }
25 };
26 template <>
27 struct TypeTraits<std::uint16_t> {
28  static char const *getName() { return "U"; }
29 };
30 template <>
31 struct TypeTraits<std::int32_t> {
32  static char const *getName() { return "I"; }
33 };
34 template <>
35 struct TypeTraits<std::int64_t> {
36  static char const *getName() { return "L"; }
37 };
38 template <>
39 struct TypeTraits<float> {
40  static char const *getName() { return "F"; }
41 };
42 template <>
43 struct TypeTraits<double> {
44  static char const *getName() { return "D"; }
45 };
46 template <>
47 struct TypeTraits<lsst::geom::Angle> {
48  static char const *getName() { return "Angle"; }
49 };
50 
51 } // namespace
52 
53 //----- POD scalars -----------------------------------------------------------------------------------------
54 
55 template <typename T>
57  return TypeTraits<T>::getName();
58 }
59 
60 //----- POD array -------------------------------------------------------------------------------------------
61 
62 template <typename U>
63 std::string FieldBase<Array<U> >::getTypeString() {
64  return (boost::format("Array%s") % TypeTraits<U>::getName()).str();
65 }
66 
67 //----- String ----------------------------------------------------------------------------------------------
68 
70  if (size < 0)
72  "Size must be provided when constructing a string field.");
73 }
74 
76 
77 std::string FieldBase<std::string>::getValue(Element const *p, ndarray::Manager::Ptr const &m) const {
78  if (isVariableLength()) {
79  // p is a pointer to a std::string; return a copy
80  return std::string(*reinterpret_cast<std::string const *>(p));
81  } else {
82  // p is a char * that is null-terminated only if the string has fewer than _size chars;
83  // return a copy as a std::string
84  Element const *end = p + _size;
85  end = std::find(p, end, 0);
86  return std::string(p, end);
87  }
88 }
89 
90 void FieldBase<std::string>::setValue(Element *p, ndarray::Manager::Ptr const &,
91  std::string const &value) const {
92  if (isVariableLength()) {
93  // p is a pointer to a std::string; replace its contents with a copy of `value`
94  *reinterpret_cast<std::string *>(p) = value;
95  } else {
96  // copy the contents of `value` to p through p + _size, null extra characters, if any
97  if (value.size() > std::size_t(_size)) {
98  throw LSST_EXCEPT(
100  (boost::format("String (%d) is too large for field (%d).") % value.size() % _size).str());
101  }
102  std::copy(value.begin(), value.end(), p);
103  std::fill(p + value.size(), p + _size, char(0)); // null extra characters, if any
104  }
105 }
106 
107 //----- Explicit instantiation ------------------------------------------------------------------------------
108 
109 #define INSTANTIATE_FIELD_BASE(r, data, elem) template struct FieldBase<elem>;
110 
112  BOOST_PP_TUPLE_TO_SEQ(AFW_TABLE_FIELD_TYPE_N, AFW_TABLE_FIELD_TYPE_TUPLE))
113 } // namespace table
114 } // namespace afw
115 } // namespace lsst
lsst::afw::table::FieldBase::FieldBase
FieldBase()=default
std::string
STL class.
lsst::afw::table::FieldBase::setValue
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
Definition: FieldBase.h:86
std::find
T find(T... args)
std::string::size
T size(T... args)
lsst::afw
Definition: imageAlgorithm.dox:1
lsst.pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
end
int end
Definition: BoundedField.cc:105
std::fill
T fill(T... args)
_size
table::Key< table::Array< int > > _size
Definition: PsfexPsf.cc:364
lsst.pex::exceptions::LengthError
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
lsst::afw::table::_
_
Definition: BaseColumnView.cc:188
std::copy
T copy(T... args)
AFW_TABLE_FIELD_TYPE_TUPLE
#define AFW_TABLE_FIELD_TYPE_TUPLE
Definition: types.h:44
lsst::afw::table::BOOST_PP_SEQ_FOR_EACH
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
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::table::FieldBase
Field base class default implementation (used for numeric scalars and lsst::geom::Angle).
Definition: FieldBase.h:43
lsst::afw::table::FieldBase< std::string >::Element
char Element
the type of subfields and array elements
Definition: FieldBase.h:233
lsst::afw::table::FieldBase::getTypeString
static std::string getTypeString()
Return a string description of the field type.
Definition: FieldBase.cc:56
std::string::begin
T begin(T... args)
std
STL namespace.
lsst::geom::Angle
A class representing an angle.
Definition: Angle.h:127
lsst::afw::table::FieldBase::getValue
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::get.
Definition: FieldBase.h:83
std::size_t
std::string::end
T end(T... args)
INSTANTIATE_FIELD_BASE
#define INSTANTIATE_FIELD_BASE(r, data, elem)
Definition: FieldBase.cc:109
FieldBase.h
AFW_TABLE_FIELD_TYPE_N
#define AFW_TABLE_FIELD_TYPE_N
Definition: types.h:39
m
int m
Definition: SpanSet.cc:49
Flag.h