LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
lsst::afw::table::FieldBase< std::string > Struct Reference

Field base class specialization for strings. More...

#include <FieldBase.h>

Inheritance diagram for lsst::afw::table::FieldBase< std::string >:
lsst::afw::table::Key< std::string >

Public Types

using Value = std::string
 the type returned by BaseRecord::get More...
 
using Reference = char *
 the type returned by BaseRecord::operator[] More...
 
using ConstReference = const char *
 the type returned by BaseRecord::operator[] (const) More...
 
using Element = char
 the type of subfields and array elements More...
 

Public Member Functions

 FieldBase (std::size_t size=std::numeric_limits< size_t >::max())
 Construct a FieldBase with the given size. More...
 
 FieldBase (FieldBase const &) noexcept=default
 
 FieldBase (FieldBase &&) noexcept=default
 
FieldBaseoperator= (FieldBase const &) noexcept=default
 
FieldBaseoperator= (FieldBase &&) noexcept=default
 
 ~FieldBase () noexcept=default
 
std::size_t getElementCount () const noexcept
 Return the number of subfield elements (equal to the size of the string, including a null terminator), or 0 for a variable-length string. More...
 
std::size_t getSize () const noexcept
 Return the maximum length of the string, including a null terminator (equal to the number of subfield elements), or 0 for a variable-length string. More...
 
bool isVariableLength () const noexcept
 Return true if the field is variable-length (each record can have a different size array). More...
 

Static Public Member Functions

static std::string getTypeString ()
 Return a string description of the field type. More...
 

Protected Member Functions

void stream (std::ostream &os) const
 Defines how Fields are printed. More...
 
Reference getReference (Element *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::operator[] (non-const). More...
 
ConstReference getConstReference (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::operator[] (const). More...
 
Value getValue (Element const *p, ndarray::Manager::Ptr const &m) const
 Used to implement BaseRecord::get. More...
 
void setValue (Element *p, ndarray::Manager::Ptr const &, std::string const &value) const
 Used to implement BaseRecord::set Fixed-lengths strings are handled by copying the data into p through p + _size, nulling extra characters, if any. More...
 

Static Protected Member Functions

static FieldBase makeDefault () noexcept
 Needed to allow Keys to be default-constructed. More...
 

Detailed Description

Field base class specialization for strings.

Definition at line 218 of file FieldBase.h.

Member Typedef Documentation

◆ ConstReference

the type returned by BaseRecord::operator[] (const)

Definition at line 225 of file FieldBase.h.

◆ Element

the type of subfields and array elements

Definition at line 227 of file FieldBase.h.

◆ Reference

the type returned by BaseRecord::operator[]

Definition at line 222 of file FieldBase.h.

◆ Value

the type returned by BaseRecord::get

Definition at line 219 of file FieldBase.h.

Constructor & Destructor Documentation

◆ FieldBase() [1/3]

Construct a FieldBase with the given size.

A size == 0 indicates a variable-length string. Negative sizes are not permitted.

This constructor is implicit and has an invalid default so it can be used in the Field constructor (as if it were an int argument) without specializing Field. In other words, it allows one to construct a 25-character string field like this:

Field< std::string >("name", "documentation", 25);

...even though the third argument to the Field constructor takes a FieldBase, not an int.

Definition at line 69 of file FieldBase.cc.

69  : _size(size) {
70 }

◆ FieldBase() [2/3]

◆ FieldBase() [3/3]

◆ ~FieldBase()

Member Function Documentation

◆ getConstReference()

ConstReference lsst::afw::table::FieldBase< std::string >::getConstReference ( Element const *  p,
ndarray::Manager::Ptr const &  m 
) const
inlineprotected

Used to implement BaseRecord::operator[] (const).

Definition at line 283 of file FieldBase.h.

283  {
284  if (isVariableLength()) {
285  return reinterpret_cast<std::string const *>(p)->data();
286  } else {
287  return p;
288  }
289  }
char * data
Definition: BaseRecord.cc:61
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array).
Definition: FieldBase.h:262

◆ getElementCount()

std::size_t lsst::afw::table::FieldBase< std::string >::getElementCount ( ) const
inlinenoexcept

Return the number of subfield elements (equal to the size of the string, including a null terminator), or 0 for a variable-length string.

Definition at line 255 of file FieldBase.h.

255 { return _size; }

◆ getReference()

Reference lsst::afw::table::FieldBase< std::string >::getReference ( Element p,
ndarray::Manager::Ptr const &  m 
) const
inlineprotected

Used to implement BaseRecord::operator[] (non-const).

Definition at line 272 of file FieldBase.h.

272  {
273  if (isVariableLength()) {
274  // Can't be done until C++17, which allows read/write access to std::string's internal buffer
276  "non-const operator[] not supported for variable-length strings");
277  } else {
278  return p;
279  }
280  }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Reports errors in the logical structure of the program.
Definition: Runtime.h:46

◆ getSize()

std::size_t lsst::afw::table::FieldBase< std::string >::getSize ( ) const
inlinenoexcept

Return the maximum length of the string, including a null terminator (equal to the number of subfield elements), or 0 for a variable-length string.

Definition at line 259 of file FieldBase.h.

259 { return _size; }

◆ getTypeString()

std::string lsst::afw::table::FieldBase< std::string >::getTypeString ( )
static

Return a string description of the field type.

Definition at line 72 of file FieldBase.cc.

72 { return "String"; }

◆ getValue()

std::string lsst::afw::table::FieldBase< std::string >::getValue ( Element const *  p,
ndarray::Manager::Ptr const &  m 
) const
protected

Used to implement BaseRecord::get.

Definition at line 74 of file FieldBase.cc.

74  {
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 }
int end
T find(T... args)
char Element
the type of subfields and array elements
Definition: FieldBase.h:227

◆ isVariableLength()

bool lsst::afw::table::FieldBase< std::string >::isVariableLength ( ) const
inlinenoexcept

Return true if the field is variable-length (each record can have a different size array).

Definition at line 262 of file FieldBase.h.

262 { return _size == 0; }

◆ makeDefault()

static FieldBase lsst::afw::table::FieldBase< std::string >::makeDefault ( )
inlinestaticprotectednoexcept

Needed to allow Keys to be default-constructed.

Definition at line 266 of file FieldBase.h.

266 { return FieldBase(0); }
FieldBase(std::size_t size=std::numeric_limits< size_t >::max())
Construct a FieldBase with the given size.
Definition: FieldBase.cc:69

◆ operator=() [1/2]

FieldBase& lsst::afw::table::FieldBase< std::string >::operator= ( FieldBase< std::string > &&  )
defaultnoexcept

◆ operator=() [2/2]

FieldBase& lsst::afw::table::FieldBase< std::string >::operator= ( FieldBase< std::string > const &  )
defaultnoexcept

◆ setValue()

void lsst::afw::table::FieldBase< std::string >::setValue ( Element p,
ndarray::Manager::Ptr const &  ,
std::string const &  value 
) const
protected

Used to implement BaseRecord::set Fixed-lengths strings are handled by copying the data into p through p + _size, nulling extra characters, if any.

The data is only null-terminated if value.size() < _size. Variable-length strings are handled by setting p to the address of a std::string that is a copy of value

Definition at line 87 of file FieldBase.cc.

88  {
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 }
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
T copy(T... args)
T fill(T... args)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ stream()

void lsst::afw::table::FieldBase< std::string >::stream ( std::ostream os) const
inlineprotected

Defines how Fields are printed.

Definition at line 269 of file FieldBase.h.

269 { os << ", size=" << _size; }
std::ostream * os
Definition: Schema.cc:557

The documentation for this struct was generated from the following files: