4 #if !defined(PQXX_HEADER_PRE) 5 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>." 10 #include "pqxx/internal/array-composite.hxx" 11 #include "pqxx/internal/concat.hxx" 28 template<
typename TYPE> constexpr
bool extends_up_to(TYPE
const &)
const 46 throw argument_error{
"Got null value as an inclusive range bound."};
49 [[nodiscard]] constexpr TYPE
const &
get()
const &noexcept {
return m_value; }
55 return not(value < m_value);
62 return not(m_value < value);
81 throw argument_error{
"Got null value as an exclusive range bound."};
84 [[nodiscard]] constexpr TYPE
const &
get()
const &noexcept {
return m_value; }
90 return m_value < value;
97 return value < m_value;
143 return not std::holds_alternative<no_bound>(m_bound);
149 return std::holds_alternative<inclusive_bound<TYPE>>(m_bound);
155 return std::holds_alternative<exclusive_bound<TYPE>>(m_bound);
163 [&
value](
auto const &bound) {
return bound.extends_down_to(
value); },
172 [&
value](
auto const &bound) {
return bound.extends_up_to(
value); },
177 [[nodiscard]] constexpr TYPE
const *
value() const &noexcept
180 [](
auto const &bound) noexcept {
181 using bound_t = std::decay_t<decltype(bound)>;
182 if constexpr (std::is_same_v<bound_t, no_bound>)
183 return static_cast<TYPE
const *
>(
nullptr);
224 m_lower{lower}, m_upper{upper}
227 lower.is_limited() and upper.is_limited() and
228 (*upper.value() < *lower.value()))
229 throw range_error{internal::concat(
230 "Range's lower bound (", *lower.value(),
231 ") is greater than its upper bound (", *upper.value(),
").")};
272 return (m_lower.is_exclusive() or m_upper.is_exclusive()) and
273 m_lower.is_limited() and m_upper.is_limited() and
274 not(*m_lower.value() < *m_upper.value());
281 return m_lower.extends_down_to(value) and m_upper.extends_up_to(value);
291 return (*
this & other) == other;
340 lower.is_limited() and upper.is_limited() and
341 (*upper.value() < *lower.value()))
344 return {lower, upper};
361 return {lower, upper};
375 [[nodiscard]]
static inline zview 388 char *here = begin + s_empty.copy(begin, std::size(s_empty));
398 (
static_cast<char>(value.
lower_bound().is_inclusive() ?
'[' :
'('));
401 if (lower !=
nullptr)
406 if (upper !=
nullptr)
408 if ((end - here) < 2)
411 static_cast<char>(value.
upper_bound().is_inclusive() ?
']' :
')');
419 if (std::size(
text) < 3)
421 bool left_inc{
false};
424 case '[': left_inc =
true;
break;
431 (std::size(
text) != std::size(s_empty)) or
432 (
text[1] !=
'm' and
text[1] !=
'M') or
433 (
text[2] !=
'p' and
text[2] !=
'P') or
434 (
text[3] !=
't' and
text[3] !=
'T') or
435 (
text[4] !=
'y' and
text[4] !=
'Y'))
446 std::size_t index{0};
448 static constexpr std::size_t last{1};
452 std::optional<TYPE> lower, upper;
454 internal::parse_composite_field(index,
text, pos, lower, scan, last);
455 internal::parse_composite_field(index,
text, pos, upper, scan, last);
458 if (pos != std::size(
text))
460 char const closing{
text[pos - 1]};
461 if (closing !=
')' and closing !=
']')
463 bool const right_inc{closing ==
']'};
481 return {lower_bound, upper_bound};
484 [[nodiscard]]
static inline constexpr std::size_t
487 TYPE
const *lower{value.lower_bound().value()},
488 *upper{value.upper_bound().value()};
489 std::size_t
const lsz{
494 return std::size(s_empty) + 1;
496 return 1 + lsz + 1 + usz + 2;
500 static constexpr
zview s_empty{
"empty"_zv};
501 static constexpr
auto s_overrun{
"Not enough space in buffer for range."_zv};
504 static std::string err_bad_input(std::string_view
text)
506 return internal::concat(
"Invalid range input: '",
text,
"'");
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:187
range_bound(no_bound)
Definition: range.hxx:114
range()
Create an empty range.
Definition: range.hxx:239
static char * into_buf(char *begin, char *end, range< TYPE > const &value)
Definition: range.hxx:382
range(range_bound< TYPE > lower, range_bound< TYPE > upper)
Create a range.
Definition: range.hxx:223
zview generic_to_buf(char *begin, char *end, TYPE const &value)
Implement string_traits<TYPE>::to_buf by calling into_buf.
Definition: strconv.hxx:442
bool operator==(range const &rhs) const
Definition: range.hxx:245
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:180
bool operator==(range_bound const &rhs) const
Definition: range.hxx:125
bool contains(TYPE value) const
Does this range encompass value?
Definition: range.hxx:279
static range< TYPE > from_string(std::string_view text)
Definition: range.hxx:417
range operator &(range const &other) const
Intersection of two ranges.
Definition: range.hxx:309
Traits describing a type's "null value," if any.
Definition: strconv.hxx:92
An exclusive boundary value to a pqxx::range.
Definition: range.hxx:74
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
bool extends_down_to(TYPE const &value) const
Would this bound, as a lower bound, include value?
Definition: range.hxx:53
static std::size_t size_buffer(TYPE const &value) noexcept
Estimate how much buffer space is needed to represent value.
range_bound & operator=(range_bound const &)=default
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition: util.hxx:455
Traits class for use in string conversions.
Definition: strconv.hxx:154
bool extends_up_to(TYPE const &value) const
Would this bound, as an upper bound, include value?
Definition: range.hxx:169
range & operator=(range const &)=default
constexpr bool extends_up_to(TYPE const &) const
Definition: range.hxx:28
inclusive_bound(TYPE const &value)
Definition: range.hxx:43
constexpr range_bound< TYPE > const & lower_bound() const &noexcept
Definition: range.hxx:295
bool operator!=(range_bound const &rhs) const
Definition: range.hxx:136
bool extends_down_to(TYPE const &value) const
Would this bound, as a lower bound, include value?
Definition: range.hxx:88
constexpr bool extends_down_to(TYPE const &) const
Definition: range.hxx:24
Nullness traits describing a type which does not have a null value.
Definition: strconv.hxx:114
range_bound(inclusive_bound< TYPE > const &bound)
Definition: range.hxx:116
A C++ equivalent to PostgreSQL's range types.
Definition: range.hxx:215
static zview to_buf(char *begin, char *end, range< TYPE > const &value)
Definition: range.hxx:376
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
static constexpr std::size_t size_buffer(range< TYPE > const &value) noexcept
Definition: range.hxx:485
An inclusive boundary value to a pqxx::range.
Definition: range.hxx:39
constexpr bool is_inclusive() const noexcept
Is this boundary an inclusive one?
Definition: range.hxx:147
bool extends_up_to(TYPE const &value) const
Would this bound, as an upper bound, include value?
Definition: range.hxx:60
bool contains(range< TYPE > const &other) const
Does this range encompass all of other?
Definition: range.hxx:289
bool extends_up_to(TYPE const &value) const
Would this bound, as an upper bound, include value?
Definition: range.hxx:95
A range boundary value.
Definition: range.hxx:109
An unlimited boundary value to a pqxx::range.
Definition: range.hxx:22
bool extends_down_to(TYPE const &value) const
Would this bound, as a lower bound, include value?
Definition: range.hxx:160
bool operator!=(range const &rhs) const
Definition: range.hxx:253
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.
exclusive_bound(TYPE const &value)
Definition: range.hxx:78
Could not convert value to string: not enough buffer space.
Definition: except.hxx:194
constexpr bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:370
bool empty() const
Is this range clearly empty?
Definition: range.hxx:270
constexpr TYPE const * value() const &noexcept
Return bound value, or nullptr if it's not limited.
Definition: range.hxx:177
range_bound(exclusive_bound< TYPE > const &bound)
Definition: range.hxx:118
constexpr range_bound< TYPE > const & upper_bound() const &noexcept
Definition: range.hxx:300
PQXX_PURE glyph_scanner_func * get_glyph_scanner(encoding_group enc)
Definition: encodings.cxx:796
constexpr bool is_exclusive() const noexcept
Is this boundary an exclusive one?
Definition: range.hxx:153
constexpr bool is_limited() const noexcept
Is this a finite bound?
Definition: range.hxx:141