lsst.afw
g3a5ebb7d8a+28b83bf6a5
Toggle main menu visibility
Loading...
Searching...
No Matches
src
table
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
10
#include "
lsst/afw/table/FieldBase.h
"
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>
56
std::string
FieldBase<T>::getTypeString
() {
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
69
FieldBase<std::string>::FieldBase
(
std::size_t
size) : _size(size) {
70
}
71
72
std::string
FieldBase<std::string>::getTypeString
() {
return
"String"
; }
73
74
std::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
87
void
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
(
96
lsst::pex::exceptions::LengthError
,
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
108
BOOST_PP_SEQ_FOR_EACH
(
INSTANTIATE_FIELD_BASE
,
_
,
109
BOOST_PP_TUPLE_TO_SEQ(
AFW_TABLE_FIELD_TYPE_N
,
AFW_TABLE_FIELD_TYPE_TUPLE
))
110
}
// namespace table
111
}
// namespace afw
112
}
// namespace lsst
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
INSTANTIATE_FIELD_BASE
#define INSTANTIATE_FIELD_BASE(r, data, elem)
Definition
FieldBase.cc:106
FieldBase.h
Flag.h
std::string
std::string::begin
T begin(T... args)
lsst::geom::Angle
lsst::pex::exceptions::LengthError
std::copy
T copy(T... args)
std::string::end
T end(T... args)
std::fill
T fill(T... args)
std::find
T find(T... args)
lsst::afw::table
Definition
table.dox:3
lsst::afw::table::_
_
Definition
BaseColumnView.cc:198
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::afw
Definition
imageAlgorithm.dox:1
lsst
std::string::size
T size(T... args)
std::size_t
lsst::afw::table::FieldBase< Array< U > >::getTypeString
static std::string getTypeString()
Return a string description of the field type.
Definition
FieldBase.cc:63
lsst::afw::table::FieldBase< Array< U > >::FieldBase
FieldBase(size_t size=0)
Construct a FieldBase with the given size.
Definition
FieldBase.h:120
lsst::afw::table::FieldBase< std::string >::Element
char Element
the type of subfields and array elements
Definition
FieldBase.h:227
lsst::afw::table::FieldBase< std::string >::isVariableLength
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array).
Definition
FieldBase.h:262
lsst::afw::table::FieldBase::getTypeString
static std::string getTypeString()
Return a string description of the field type.
Definition
FieldBase.cc:56
lsst::afw::table::FieldBase::getValue
Value getValue(Element const *p, ndarray::Manager::Ptr const &) const
Used to implement BaseRecord::get.
Definition
FieldBase.h:81
lsst::afw::table::FieldBase::FieldBase
FieldBase()=default
lsst::afw::table::FieldBase::setValue
void setValue(Element *p, ndarray::Manager::Ptr const &, Value v) const
Used to implement BaseRecord::set.
Definition
FieldBase.h:84
AFW_TABLE_FIELD_TYPE_N
#define AFW_TABLE_FIELD_TYPE_N
Definition
types.h:38
AFW_TABLE_FIELD_TYPE_TUPLE
#define AFW_TABLE_FIELD_TYPE_TUPLE
Definition
types.h:43
Generated on
for lsst.afw by
1.17.0