#pragma once
#include <memory>
#include <optional>
#include <string>
#include <vector>
struct AppInfo {
};
};
class Error {
public:
message_ = context + ": " + message_;
return *this;
}
const std::string&
message()
const {
return message_; }
std::string
toString()
const {
return message_; }
private:
std::string message_;
};
template<typename T, typename E = Error>
class Result {
public:
static Result
ok(T
value) {
return Result(std::move(
value)); }
bool isOk()
const {
return has_value_; }
bool isErr()
const {
return !has_value_; }
T&
value() {
return value_.value(); }
const T&
value()
const {
return value_.value(); }
E&
error() {
return error_.value(); }
const E&
error()
const {
return error_.value(); }
if (has_value_) return value_.value();
return default_value;
}
template<typename F>
auto map(F func) -> Result<decltype(func(std::declval<T>())), E> {
if (has_value_) {
return Result<decltype(func(std::declval<T>())), E>
::ok(func(value_.value()));
}
return Result<decltype(func(std::declval<T>())), E>
::err(error_.value());
}
template<typename F>
auto flatMap(F func) ->
decltype(func(std::declval<T>())) {
if (has_value_) {
return func(value_.value());
}
return decltype(func(std::declval<T>()))
::err(error_.value());
}
private:
explicit Result(T
value) : has_value_(
true), value_(std::move(
value)) {}
explicit Result(E
error) : has_value_(
false), error_(std::move(
error)) {}
bool has_value_;
std::optional<T> value_;
std::optional<E> error_;
};
template<typename E>
class Result<void, E> {
public:
static Result
ok() {
return Result(
true, std::nullopt); }
static Result
err(E
error) {
return Result(
false, std::move(
error)); }
bool isOk()
const {
return has_value_; }
bool isErr()
const {
return !has_value_; }
E&
error() {
return error_.value(); }
const E&
error()
const {
return error_.value(); }
private:
Result(
bool hv, std::optional<E>
err) : has_value_(hv), error_(std::move(
err)) {}
bool has_value_;
std::optional<E> error_;
};
class NahHost {
public:
static std::unique_ptr<NahHost>
create(
const std::string& root_path);
const std::string&
root()
const {
return root_; }
const std::string& version = "") const;
Result<HostProfile>
loadProfile(
const std::string& name)
const;
const std::string& app_id,
const std::string& version = "",
const std::string& profile = "",
bool enable_trace = false) const;
const CompositionInputs& inputs) const;
private:
explicit NahHost(std::string
root) : root_(std::move(
root)) {}
Result<HostProfile> resolveActiveProfile(const std::string& explicit_name = "") const;
std::string root_;
};
}
std::string toString() const
Error & withContext(const std::string &context)
const std::string & message() const
Result< HostProfile > getActiveHostProfile() const
Get the currently active host profile.
Result< AppInfo > findApplication(const std::string &id, const std::string &version="") const
Find an installed application by ID.
Result< ContractEnvelope > composeContract(const CompositionInputs &inputs) const
Low-level contract composition from explicit inputs.
Result< void > validateProfile(const HostProfile &profile) const
Validate a host profile.
Result< void > setActiveHostProfile(const std::string &name)
Set the active host profile by name.
std::vector< std::string > listProfiles() const
List all available profile names.
Result< HostProfile > loadProfile(const std::string &name) const
Load a specific profile by name.
const std::string & root() const
Get the NAH root path.
Result< ContractEnvelope > getLaunchContract(const std::string &app_id, const std::string &version="", const std::string &profile="", bool enable_trace=false) const
Generate a launch contract for an application.
std::vector< AppInfo > listApplications() const
List all installed applications.
auto map(F func) -> Result< decltype(func(std::declval< T >())), E >
T valueOr(T default_value) const
static Result ok(T value)
static Result err(E error)
auto flatMap(F func) -> decltype(func(std::declval< T >()))
ErrorCode
Error codes for NAH operations.