5#include <portals/detail/move_only_function.hpp>
17namespace portals::ui {
25 explicit OptionsRef(T &value) noexcept : value_(&value) {
32 const T &
get() const noexcept {
44template <
class T> OptionsRef<T> opts(T &value)
noexcept {
51template <
class T>
void opts(
const T &&value) =
delete;
74 static std::expected<Arguments, ProcessContextError>
capture(
int argc,
const char *
const *
argv);
78 const
char *const *
argv() const noexcept;
80 std::
size_t size() const noexcept;
85 std::string_view operator[](std::
size_t index) const;
87 std::span<const std::
string>::iterator
begin() const noexcept;
89 std::span<const std::
string>::iterator
end() const noexcept;
92 explicit Arguments(std::shared_ptr<const Data> data) noexcept : data_(std::move(data)) {
95 std::shared_ptr<const Data> data_;
96 friend std::expected<Arguments, ProcessContextError>
args();
107 using Entry = std::pair<std::string, std::string>;
111 static std::expected<Environment, ProcessContextError>
fromEntries(std::span<const Entry> entries);
119 std::size_t
size() const noexcept;
123 bool operator==(const Environment &other) const noexcept;
126 explicit Environment(std::shared_ptr<const Data> data) noexcept : data_(std::move(data)) {
129 std::shared_ptr<const Data> data_;
130 friend std::expected<Environment, ProcessContextError>
environment();
141std::expected<void, ProcessContextError>
initialize(
int argc,
const char *
const *argv);
150std::expected<Arguments, ProcessContextError>
args();
155inline std::expected<Environment, ProcessContextError>
env() {
174 if (!bytes.empty()) {
175 bytes_ = std::make_shared<const std::string>(bytes.data(), bytes.size());
205 const char *
data() const noexcept {
206 return bytes_ ? bytes_->data() :
"";
210 std::size_t
size() const noexcept {
211 return bytes_ ? bytes_->size() : 0;
220 std::string_view
view() const noexcept {
228 std::size_t
find(std::string_view text, std::size_t position = 0) const noexcept {
229 return view().find(text, position);
237 return left.view() == right.view();
245 return left.view() == right;
253 return left.view() == right;
261 return left.view() == (right ? std::string_view(right) : std::string_view{});
269 return stream << text.view();
273 std::shared_ptr<const std::string> bytes_;
277enum class CommandLineErrorCode {
291enum class LaunchDisposition {
303using CommandLineParser =
304 portals::detail::MoveOnlyFunction<std::expected<LaunchAction, CommandLineError>(
const app::Arguments &)>;
314std::expected<LaunchAction, CommandLineError> commandLinePreflight(
int argc,
const char *
const *argv,
315 CommandLineParser &parser)
noexcept;
Immutable owning launch text with allocation-free empty, copy and move operations....
Definition ui_app.hpp:165
LaunchText(const std::string &bytes)
Definition ui_app.hpp:182
LaunchText(const char *bytes)
Definition ui_app.hpp:188
std::size_t find(std::string_view text, std::size_t position=0) const noexcept
Definition ui_app.hpp:228
friend bool operator==(const LaunchText &left, const char *right) noexcept
Definition ui_app.hpp:260
friend bool operator==(const LaunchText &left, const std::string &right) noexcept
Definition ui_app.hpp:252
LaunchText(const LaunchText &other) noexcept=default
std::string_view view() const noexcept
Definition ui_app.hpp:220
const char * data() const noexcept
Definition ui_app.hpp:205
LaunchText & operator=(const LaunchText &other) noexcept=default
LaunchText(LaunchText &&other) noexcept=default
friend std::ostream & operator<<(std::ostream &stream, const LaunchText &text)
Definition ui_app.hpp:268
LaunchText() noexcept=default
Create empty text without allocating.
LaunchText & operator=(LaunchText &&other) noexcept=default
std::size_t size() const noexcept
Definition ui_app.hpp:210
friend bool operator==(const LaunchText &left, const LaunchText &right) noexcept
Definition ui_app.hpp:236
bool empty() const noexcept
Definition ui_app.hpp:215
friend bool operator==(const LaunchText &left, std::string_view right) noexcept
Definition ui_app.hpp:244
OptionsRef(T &value) noexcept
Definition ui_app.hpp:25
OptionsRef(T &&value)=delete
const T & get() const noexcept
Definition ui_app.hpp:32
Immutable owning argument snapshot, including argv[0]; copies share immutable storage.
Definition ui_app.hpp:66
friend std::expected< Arguments, ProcessContextError > args()
static std::expected< Arguments, ProcessContextError > capture(int argc, const char *const *argv)
Opaque immutable storage; no implementation borrow is exposed.
std::size_t size() const noexcept
const char *const * argv() const noexcept
int argc() const noexcept
std::span< conststd::string >::iterator begin() const noexcept
std::span< conststd::string >::iterator end() const noexcept
Immutable owning environment snapshot; missing and empty values remain distinct. Windows names compar...
Definition ui_app.hpp:104
static std::expected< Environment, ProcessContextError > fromEntries(std::span< const Entry > entries)
std::pair< std::string, std::string > Entry
Opaque immutable storage; no process-owned pointers escape.
Definition ui_app.hpp:107
std::expected< std::optional< std::string_view >, ProcessContextError > get(std::string_view name) const noexcept
friend std::expected< Environment, ProcessContextError > environment()
std::size_t size() const noexcept
Read-only process snapshots, independent of a current Scene or Application.
Definition ui_app.hpp:54
ProcessContextError
Process capture failures are separate from widget and parser failures.
Definition ui_app.hpp:57
@ ALREADY_INITIALIZED
Initialization conflicts with the previously published snapshot.
Definition ui_app.hpp:60
@ CAPTURE_FAILED
Process capture or snapshot query failed without changing stored state.
Definition ui_app.hpp:62
@ UNINITIALIZED
No process snapshot has been successfully published.
Definition ui_app.hpp:58
std::expected< Arguments, ProcessContextError > args()
std::expected< Environment, ProcessContextError > environment()
std::expected< Environment, ProcessContextError > env()
Definition ui_app.hpp:155
std::expected< void, ProcessContextError > initialize(int argc, const char *const *argv)
Capture argv and the environment once, before any concurrent foreign environment mutation....
@ CALLBACK_FAILED
A non-allocation exception escaped into a runner callback boundary.
Definition application.hpp:34
@ NO_MEMORY
Allocation failed at a runner exception boundary.
Definition application.hpp:33
@ INVALID_ARGUMENT
Empty task, callback or immutable data owner, or invalid policy.
Definition async.hpp:26
Owning parser diagnostic, safe after the parser's captures retire.
Definition ui_app.hpp:285
std::optional< app::ProcessContextError > processContext
Exact initialization cause, when applicable.
Definition ui_app.hpp:288
CommandLineErrorCode code
Original parser or boundary failure category.
Definition ui_app.hpp:286
LaunchText message
Immutable owning diagnostic; empty fallback and ownership transfers allocate nothing.
Definition ui_app.hpp:287
Successful preflight, optionally printing help/version before any application is created.
Definition ui_app.hpp:297
LaunchText output
Immutable owning help/version text, printed to stdout only for FINISH.
Definition ui_app.hpp:299
LaunchDisposition disposition
Successful preflight decision.
Definition ui_app.hpp:298