1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
// static
template <Extractable ...Types>
std::istringstream Parser::extract(StringVect const &keywords, Types &...dest)
{
return extract(one(keywords), std::forward<Types &>(dest) ...);
}
// static
template <Extractable ...Types>
std::istringstream Parser::extract(Lines &&lines, Types &...dest)
{
if (lines)
return extract(*lines.get(), std::forward<Types &>(dest) ...);
std::istringstream in;
in.setstate(std::ios::eofbit);
return in;
}
// static
template <Extractable ...Types>
std::istringstream Parser::extract(LineInfo const &line, Types &...dest)
{
std::istringstream in{ line.tail };
if (not extract(in, std::forward<Types &>(dest) ...))
{
in.setstate(std::ios::failbit);
Err::specification();
}
return in;
}
// static
template <Extractable Type>
std::istringstream Parser::extract(Lines &&lines, Type *dest, size_t size)
{
std::istringstream in;
if (not lines)
{
in.setstate(std::ios::eofbit);
return in;
}
in.str(lines.get()->tail);
for (; size--; ++dest) // fill 'size' elements starting at dest
{
if (not (in >> *dest))
{
in.setstate(std::ios::failbit);
Err::specification();
break;
}
}
return in;
}
// static
template <Extractable Type, Extractable ...Types>
bool Parser::extract(std::istream &in, Type &first, Types &...more)
{
in >> first;
return extract(in, std::forward<Types &>(more)...);
}
inline bool Parser::extract(std::istream &in)
{
return static_cast<bool>(in);
}
// static
template <Extractable Type>
bool Parser::one(StringVect const &base, Type &dest)
{
return static_cast<bool>(extract(one(base), dest));
}
//template <std::floating_point ...Types>
//static bool nonNegative(StringVect const &keywords, Types &...dest)
//{
// return extract(one(keywords)->get(), std::forward<Types &>(dest) ...);
//}
inline bool Parser::nonNegative(StringVect const &base, double &dest)
{
return atLeast(0, base, dest);
}
template <std::integral Type>
bool Parser::nonNegative(StringVect const &base, Type &dest)
{
double tmp;
bool ret = nonNegative(base, tmp);
dest = tmp;
return ret;
}
// static
inline bool Parser::positive(StringVect const &base, double &dest)
{
return atLeast(Globals::WEAK_TOLERANCE, base, dest);
}
inline unsigned Parser::Lines::size() const
{
return d_size;
}
inline Parser::Lines::operator bool() const
{
return d_size != 0;
}
|