LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
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 Template 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

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

Public Member Functions

 FieldBase (int size=-1)
 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
 
int 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...
 
int 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

template<>
struct lsst::afw::table::FieldBase< std::string >

Field base class specialization for strings.

Definition at line 224 of file FieldBase.h.

Member Typedef Documentation

◆ ConstReference

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

Definition at line 231 of file FieldBase.h.

◆ Element

the type of subfields and array elements

Definition at line 233 of file FieldBase.h.

◆ Reference

the type returned by BaseRecord::operator[]

Definition at line 228 of file FieldBase.h.

◆ Value

the type returned by BaseRecord::get

Definition at line 225 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  if (size < 0)
72  "Size must be provided when constructing a string field.");
73 }
Reports attempts to exceed implementation-defined length limits for some classes. ...
Definition: Runtime.h:76
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

◆ 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 289 of file FieldBase.h.

289  {
290  if (isVariableLength()) {
291  return reinterpret_cast<std::string const *>(p)->data();
292  } else {
293  return p;
294  }
295  }
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:268
STL class.
char * data
Definition: BaseRecord.cc:62

◆ getElementCount()

int 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 261 of file FieldBase.h.

261 { 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 278 of file FieldBase.h.

278  {
279  if (isVariableLength()) {
280  // Can't be done until C++17, which allows read/write access to std::string's internal buffer
282  "non-const operator[] not supported for variable-length strings");
283  } else {
284  return p;
285  }
286  }
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:268
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

◆ getSize()

int 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 265 of file FieldBase.h.

265 { return _size; }

◆ getTypeString()

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

Return a string description of the field type.

Definition at line 75 of file FieldBase.cc.

75 { 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 77 of file FieldBase.cc.

77  {
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 }
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:268
STL class.
T find(T... args)
char Element
the type of subfields and array elements
Definition: FieldBase.h:233
int end

◆ 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 268 of file FieldBase.h.

268 { 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 272 of file FieldBase.h.

272 { return FieldBase(0); }
FieldBase(int size=-1)
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 > const &  )
defaultnoexcept

◆ operator=() [2/2]

FieldBase& lsst::afw::table::FieldBase< std::string >::operator= ( FieldBase< std::string > &&  )
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 90 of file FieldBase.cc.

91  {
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 }
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
T copy(T... args)
bool isVariableLength() const noexcept
Return true if the field is variable-length (each record can have a different size array)...
Definition: FieldBase.h:268
Reports attempts to exceed implementation-defined length limits for some classes. ...
Definition: Runtime.h:76
STL class.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
T fill(T... args)

◆ stream()

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

Defines how Fields are printed.

Definition at line 275 of file FieldBase.h.

275 { os << ", size=" << _size; }

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