Belle II Software development
TokenCast< ModuleID_t > Struct Reference

ModuleID_t specialization of TokenCast<T> the decimal point is set to '. More...

#include <ARICHDatabaseTools.h>

Public Member Functions

auto isValidChar (const unsigned char character) const noexcept -> bool
 isValidChar defines characters that are allowed for the convertion
 
auto operator() (const std::string &rToken) const -> ModuleID_t
 operator () converts given token to an integer.
 

Detailed Description

ModuleID_t specialization of TokenCast<T> the decimal point is set to '.

'!

Definition at line 303 of file ARICHDatabaseTools.h.

Member Function Documentation

◆ isValidChar()

auto isValidChar ( const unsigned char  character) const -> bool
inlinenoexcept

isValidChar defines characters that are allowed for the convertion

Parameters
character
Returns
true if its allowed for convertion

Definition at line 309 of file ARICHDatabaseTools.h.

311 {
312 return std::isdigit(character) || ModuleID_t::isValidSector(character);
313 }
static auto isValidSector(const uint8_t sector) noexcept -> bool
isValidSector checks whether a given sector is valid.

◆ operator()()

auto operator() ( const std::string &  rToken) const -> ModuleID_t
inline

operator () converts given token to an integer.

Parameters
rToken
Exceptions
invalid_argumentin case the given string is invalid for convertion
std::out_of_rangeif the given number is smaller/greater than a double.

Definition at line 323 of file ARICHDatabaseTools.h.

324 {
325 const auto begin =
326 std::find_if(rToken.begin(), rToken.end(),
327 [](const char c) { return !std::isspace(c); });
328 const auto end = std::find_if(begin, rToken.end(),
329 [](const char c) { return std::isspace(c); });
330
331 if ((begin + 1 == end) || !std::all_of(begin, end, [this](const char c) {
332 return this->isValidChar(c);
333 }))
334 throw std::invalid_argument("Invalid argiment for module cast, got: '" +
335 rToken + "'!");
336
337 const auto chID = std::stoi(std::string(begin + 1, end));
339 return ModuleID_t(*begin, chID);
340
341 throw std::out_of_range("Module ID out of range. got: '" + rToken + "' !");
342 }
static constexpr auto isValidChannel(const int channel) noexcept -> bool
isValidChannel defines the range of valid channels.
auto isValidChar(const unsigned char character) const noexcept -> bool
isValidChar defines characters that are allowed for the convertion

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