morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::forms::SectionSet< Model, Sections > Class Template Reference

Drives N independently editable action drafts on one screen. More...

#include <sections.hpp>

Public Member Functions

 SectionSet (::morph::bridge::BridgeHandler< Model > &handler, std::function< void(std::exception_ptr)> onError=nullptr)
 Constructs a section set dispatching through handler.
 SectionSet (const SectionSet &)=delete
SectionSet & operator= (const SectionSet &)=delete
 SectionSet (SectionSet &&)=delete
SectionSet & operator= (SectionSet &&)=delete
 ~SectionSet ()
 Stops every callback this set installed from being delivered.
template<auto FieldPtr>
void set (::morph::bridge::detail::MemberPointerTraits< decltype(FieldPtr)>::ValueType value)
 Sets one field of its section's draft, dispatching that section if the draft is now ready.
template<typename A>
void reset ()
 Clears one section's draft back to a default-constructed action.
template<typename A>
A draft () const
 Snapshots one section's current draft.
std::optional< std::string > resolved (std::string_view path) const
 Looks up a value captured from a section's submitted draft or result.

Detailed Description

template<typename Model, typename... Sections>
class morph::forms::SectionSet< Model, Sections >

Drives N independently editable action drafts on one screen.

Each section accumulates its own draft through set<> and dispatches through the handler as soon as ActionValidator<A>::ready accepts it. There is no active section and no sequence: a field belonging to any declared section may be set at any time, in any order. This is the whole difference from morph::flows::FlowSession, which throws on a field outside its current step.

A ready section re-fires on every subsequent set<>. There is no latch and no coalescing, matching FlowSession; a caller that wants one request per pause debounces on its own side, where it knows what a pause means.

Template Parameters
ModelThe model the handler is bound to.
SectionsOne or more Section<Action, Title, Binds...> types.

Definition at line 133 of file sections.hpp.

Constructor & Destructor Documentation

◆ SectionSet()

template<typename Model, typename... Sections>
morph::forms::SectionSet< Model, Sections >::SectionSet ( ::morph::bridge::BridgeHandler< Model > & handler,
std::function< void(std::exception_ptr)> onError = nullptr )
inlineexplicit

Constructs a section set dispatching through handler.

Parameters
handlerHandler every section dispatches through. Must outlive this SectionSet, which belongs to the handler's owner: it is built, used and destroyed there, and the handler's guiExec delivers its continuations there.
onErrorOptional callback invoked when a section's dispatch fails. When absent, the error is logged via morph::log::logError. Stored and invoked for this object's whole lifetime, so anything the callable refers to must outlive it.

Definition at line 149 of file sections.hpp.

◆ ~SectionSet()

template<typename Model, typename... Sections>
morph::forms::SectionSet< Model, Sections >::~SectionSet ( )
inline

Stops every callback this set installed from being delivered.

There is nothing to detach: a section's continuations are owned by the in-flight dispatch, not held in a map this object could remove itself from. _callbacks gates each one on a token it checks before touching this, so a completion resolving after this object is gone finds the token stopped and returns without dereferencing anything.

requestStop() is called explicitly rather than left to the member's own destruction, even though _callbacks is declared last: members are destroyed only after the destructor body runs, so a body that later grew a call pumping an event loop would otherwise deliver into a half-dead object. The body does not do that today; stopping first keeps it correct if one is ever added.

Destroyed on the handler's owner, where its continuations run, so the check a continuation makes and this destructor cannot interleave.

Definition at line 175 of file sections.hpp.

Member Function Documentation

◆ set()

template<typename Model, typename... Sections>
template<auto FieldPtr>
void morph::forms::SectionSet< Model, Sections >::set ( ::morph::bridge::detail::MemberPointerTraits< decltype(FieldPtr)>::ValueType value)
inline

Sets one field of its section's draft, dispatching that section if the draft is now ready.

Unlike FlowSession::set<> this imposes no ordering: the field's action need only be one of the declared sections. On the handler's owner.

Template Parameters
FieldPtrPointer-to-data-member of a declared section's action struct.
Parameters
valueNew value for the field.

Definition at line 188 of file sections.hpp.

◆ reset()

template<typename Model, typename... Sections>
template<typename A>
void morph::forms::SectionSet< Model, Sections >::reset ( )
inline

Clears one section's draft back to a default-constructed action.

Touches no other section and dispatches nothing. Values already captured from a previous successful dispatch stay in resolved(): they describe what the model was told, which resetting an editor does not undo.

Template Parameters
AThe section's action type.

Definition at line 206 of file sections.hpp.

◆ draft()

template<typename Model, typename... Sections>
template<typename A>
A morph::forms::SectionSet< Model, Sections >::draft ( ) const
inlinenodiscard

Snapshots one section's current draft.

A copy, not a reference into live state. On the handler's owner.

Template Parameters
AThe section's action type.
Returns
The draft as it stands.

Definition at line 219 of file sections.hpp.

◆ resolved()

template<typename Model, typename... Sections>
std::optional< std::string > morph::forms::SectionSet< Model, Sections >::resolved ( std::string_view path) const
inlinenodiscard

Looks up a value captured from a section's submitted draft or result.

Parameters
path"<ActionTypeId>.<field>", matching a section's declared Bind::path().
Returns
The field's JSON-encoded value, or std::nullopt if path was never captured — the section never fired successfully, or has no such field.

Definition at line 231 of file sections.hpp.


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