morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::math::WireClampScope Class Reference

Observes whether any Rational had to be clamped while decoding inside this scope. More...

#include <rational.hpp>

Public Member Functions

 WireClampScope () noexcept
 Starts a fresh count, saving any enclosing scope's.
 WireClampScope (const WireClampScope &)=delete
WireClampScope & operator= (const WireClampScope &)=delete
 WireClampScope (WireClampScope &&)=delete
WireClampScope & operator= (WireClampScope &&)=delete
 ~WireClampScope ()
 Folds this scope's count back into the enclosing one.
std::size_t clamped () const noexcept
 How many Rational values were clamped so far in this scope.

Detailed Description

Observes whether any Rational had to be clamped while decoding inside this scope.

Decoding a Rational cannot fail. setWire rebuilds through the canonicalising constructor, which clamps rather than rejects, so {"num":5,"den":0,"dp":2} becomes a perfectly plausible 5/1 and nothing downstream can tell the value was altered.

This makes that observable at the point where it matters – around a decode – without giving Rational an opinion about what should happen next. Whether a clamped value is a protocol violation to reject or a harmless normalisation depends on whether the caller is reading a trusted local value or an untrusted payload off a socket, and only the decoding layer knows which:

if (auto err = glz::read<opts>(action, json)) { ... }
if (clamps.clamped() != 0) {
// reject the payload
}
Observes whether any Rational had to be clamped while decoding inside this scope.
Definition rational.hpp:231
std::size_t clamped() const noexcept
How many Rational values were clamped so far in this scope.
Definition rational.hpp:246

Thread-local and scoped: a decode is synchronous on one thread, and a nested decode must not steal its parent's count.

Definition at line 231 of file rational.hpp.

Constructor & Destructor Documentation

◆ WireClampScope()

morph::math::WireClampScope::WireClampScope ( )
inlinenoexcept

Starts a fresh count, saving any enclosing scope's.

Definition at line 234 of file rational.hpp.

◆ ~WireClampScope()

morph::math::WireClampScope::~WireClampScope ( )
inline

Folds this scope's count back into the enclosing one.

Definition at line 242 of file rational.hpp.

Member Function Documentation

◆ clamped()

std::size_t morph::math::WireClampScope::clamped ( ) const
inlinenodiscardnoexcept

How many Rational values were clamped so far in this scope.

Returns
The clamp count.

Definition at line 246 of file rational.hpp.


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