83 message_ =
context +
": " + message_;
88 const std::string&
message()
const {
return message_; }
89 std::string
toString()
const {
return message_; }
108template<
typename T,
typename E = Error>
114 bool isOk()
const {
return has_value_; }
115 bool isErr()
const {
return !has_value_; }
118 const T&
value()
const {
return value_.value(); }
120 const E&
error()
const {
return error_.value(); }
123 if (has_value_)
return value_.value();
138 return func(value_.value());
140 return decltype(
func(std::declval<T>()))
::err(error_.value());
145 explicit Result(E
error) : has_value_(false), error_(std::move(
error)) {}
148 std::optional<T> value_;
149 std::optional<E> error_;
158 bool isOk()
const {
return has_value_; }
159 bool isErr()
const {
return !has_value_; }
163 const E&
error()
const {
return error_.value(); }
168 std::optional<E> error_;
210 const std::string&
root()
const {
return root_; }
222 const std::string& version =
"")
const;
248 const std::string& app_id,
249 const std::string& version =
"",
250 const std::string& profile =
"",
251 bool enable_trace =
false)
const;
Error type with code and message.
std::string toString() const
Error & withContext(const std::string &context)
Error(ErrorCode code, std::string message)
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.
static std::unique_ptr< NahHost > create(const std::string &root_path)
Create a NahHost instance for a NAH root directory.
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.
static Result err(E error)
Result type for fallible operations.
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.
Metadata about an installed application.