Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
aria::binding::Navigator Class Reference

#include <navigation.hpp>

Public Types

using RouteParams = std::unordered_map<std::string, std::string>
 Param map captured from a route pattern (e.g. {id}).
using RouteFactory = std::function<std::shared_ptr<ViewModel>(const RouteParams&)>

Public Member Functions

 Navigator ()=default
 ~Navigator ()
 Navigator (const Navigator &)=delete
Navigatoroperator= (const Navigator &)=delete
template<typename VM, typename... Args>
requires std::derived_from<VM, ViewModel>
std::shared_ptr< VM > push (Args &&... args)
template<typename VM, typename... Args>
requires std::derived_from<VM, ViewModel>
std::shared_ptr< VM > replace (Args &&... args)
void push (std::shared_ptr< ViewModel > vm, Presentation kind=Presentation::Push)
 Push (Presentation::Push).
void replace (std::shared_ptr< ViewModel > vm)
 Replace the topmost entry (in place).
template<typename R, typename VM, typename... Args>
requires std::derived_from<VM, ViewModel>
std::shared_future< std::optional< R > > push_for_result (Args &&... args)
 N-2: push a child entry that will eventually return a typed result R to the caller.
template<typename R>
std::shared_future< std::optional< R > > push_for_result (std::shared_ptr< ViewModel > vm, Presentation kind=Presentation::Push)
template<typename R>
bool dismiss_with (R result)
 N-2: dismiss the topmost entry with a typed result.
bool pop ()
 Pop the topmost entry.
bool dismiss_modal ()
 N-1: dismiss the topmost MODAL entry.
void pop_to_root ()
 Pop until only one Push entry remains.
void clear ()
bool empty () const noexcept
std::size_t size () const noexcept
std::shared_ptr< ViewModelat (std::size_t i) const
aria::async::CancellationToken top_token () const
 Topmost entry's cancellation token.
Presentation top_presentation () const
 Topmost entry's presentation kind.
void register_route (std::string pattern, RouteFactory factory)
 Register a route pattern.
bool route (std::string_view path, RouteOptions opts={})
 Resolve path against registered patterns.

Public Attributes

Property< std::shared_ptr< ViewModel > > current {nullptr}
 Topmost entry's VM, or nullptr if the stack is empty.
Property< std::size_t > depth {0}
 Total stack depth (modals included).

Member Typedef Documentation

◆ RouteParams

using aria::binding::Navigator::RouteParams = std::unordered_map<std::string, std::string>

Param map captured from a route pattern (e.g. {id}).

◆ RouteFactory

using aria::binding::Navigator::RouteFactory = std::function<std::shared_ptr<ViewModel>(const RouteParams&)>

Constructor & Destructor Documentation

◆ Navigator() [1/2]

aria::binding::Navigator::Navigator ( )
default

◆ ~Navigator()

aria::binding::Navigator::~Navigator ( )
inline

◆ Navigator() [2/2]

aria::binding::Navigator::Navigator ( const Navigator & )
delete

Member Function Documentation

◆ operator=()

Navigator & aria::binding::Navigator::operator= ( const Navigator & )
delete

◆ push() [1/2]

template<typename VM, typename... Args>
requires std::derived_from<VM, ViewModel>
std::shared_ptr< VM > aria::binding::Navigator::push ( Args &&... args)
inline

◆ replace() [1/2]

template<typename VM, typename... Args>
requires std::derived_from<VM, ViewModel>
std::shared_ptr< VM > aria::binding::Navigator::replace ( Args &&... args)
inline

◆ push() [2/2]

void aria::binding::Navigator::push ( std::shared_ptr< ViewModel > vm,
Presentation kind = Presentation::Push )
inline

Push (Presentation::Push).

Activates the new entry and deactivates the previous topmost.

◆ replace() [2/2]

void aria::binding::Navigator::replace ( std::shared_ptr< ViewModel > vm)
inline

Replace the topmost entry (in place).

The previous entry is deactivated, its cancellation fires, and any pending push_for_result resolves with std::nullopt.

◆ push_for_result() [1/2]

template<typename R, typename VM, typename... Args>
requires std::derived_from<VM, ViewModel>
std::shared_future< std::optional< R > > aria::binding::Navigator::push_for_result ( Args &&... args)
inlinenodiscard

N-2: push a child entry that will eventually return a typed result R to the caller.

The returned shared_future resolves when the child calls Navigator::dismiss_with<R>(result) or is popped without a value (resolves to std::nullopt).

◆ push_for_result() [2/2]

template<typename R>
std::shared_future< std::optional< R > > aria::binding::Navigator::push_for_result ( std::shared_ptr< ViewModel > vm,
Presentation kind = Presentation::Push )
inlinenodiscard

◆ dismiss_with()

template<typename R>
bool aria::binding::Navigator::dismiss_with ( R result)
inline

N-2: dismiss the topmost entry with a typed result.

Equivalent to pop() but propagates result to the awaiting future. If the topmost entry was not created via push_for_result<R> the result is discarded (matches Android setResult on a non-result-launched activity).

◆ pop()

bool aria::binding::Navigator::pop ( )
inline

Pop the topmost entry.

Returns false if the stack is empty. Any pending push_for_result resolves with std::nullopt.

◆ dismiss_modal()

bool aria::binding::Navigator::dismiss_modal ( )
inline

N-1: dismiss the topmost MODAL entry.

Returns false if the topmost is not a modal.

◆ pop_to_root()

void aria::binding::Navigator::pop_to_root ( )
inline

Pop until only one Push entry remains.

Modals are popped first, then Push entries; the deepest Push entry is preserved.

◆ clear()

void aria::binding::Navigator::clear ( )
inline

◆ empty()

bool aria::binding::Navigator::empty ( ) const
inlinenodiscardnoexcept

◆ size()

std::size_t aria::binding::Navigator::size ( ) const
inlinenodiscardnoexcept

◆ at()

std::shared_ptr< ViewModel > aria::binding::Navigator::at ( std::size_t i) const
inlinenodiscard

◆ top_token()

aria::async::CancellationToken aria::binding::Navigator::top_token ( ) const
inlinenodiscard

Topmost entry's cancellation token.

Throws if the stack is empty – callers normally take the token immediately after push and stash it.

◆ top_presentation()

Presentation aria::binding::Navigator::top_presentation ( ) const
inlinenodiscard

Topmost entry's presentation kind.

◆ register_route()

void aria::binding::Navigator::register_route ( std::string pattern,
RouteFactory factory )
inline

Register a route pattern.

Pattern segments enclosed in {...} capture into RouteParams; everything else is matched literally. Example: "users/{id}" matches "users/42" -> {id: "42"}.

◆ route()

bool aria::binding::Navigator::route ( std::string_view path,
RouteOptions opts = {} )
inline

Resolve path against registered patterns.

Returns false if no pattern matches; in that case the navigator is unchanged. Otherwise applies the action prescribed by opts.

Member Data Documentation

◆ current

Property<std::shared_ptr<ViewModel> > aria::binding::Navigator::current {nullptr}

Topmost entry's VM, or nullptr if the stack is empty.

◆ depth

Property<std::size_t> aria::binding::Navigator::depth {0}

Total stack depth (modals included).


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