Sleipnir C++ API
Loading...
Searching...
No Matches
exit_status.hpp
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <stdint.h>
6
7#include <format>
8#include <utility>
9
10namespace slp {
11
13enum class ExitStatus : int8_t {
15 SUCCESS = 0,
17 CALLBACK_REQUESTED_STOP = 1,
19 TOO_FEW_DOFS = -1,
21 LOCALLY_INFEASIBLE = -2,
24 GLOBALLY_INFEASIBLE = -3,
26 FACTORIZATION_FAILED = -4,
29 LINE_SEARCH_FAILED = -5,
32 FEASIBILITY_RESTORATION_FAILED = -6,
35 NONFINITE_INITIAL_GUESS = -7,
37 DIVERGING_ITERATES = -8,
40 MAX_ITERATIONS_EXCEEDED = -9,
43 TIMEOUT = -10,
44};
45
46} // namespace slp
47
49template <>
50struct std::formatter<slp::ExitStatus> {
55 constexpr auto parse(std::format_parse_context& ctx) {
56 return m_underlying.parse(ctx);
57 }
58
65 template <typename FmtContext>
66 auto format(const slp::ExitStatus& exit_status, FmtContext& ctx) const {
67 using enum slp::ExitStatus;
68
69 switch (exit_status) {
70 case SUCCESS:
71 return m_underlying.format("success", ctx);
72 case CALLBACK_REQUESTED_STOP:
73 return m_underlying.format("callback requested stop", ctx);
74 case TOO_FEW_DOFS:
75 return m_underlying.format("too few degrees of freedom", ctx);
76 case LOCALLY_INFEASIBLE:
77 return m_underlying.format("locally infeasible", ctx);
78 case GLOBALLY_INFEASIBLE:
79 return m_underlying.format("globally infeasible", ctx);
80 case FACTORIZATION_FAILED:
81 return m_underlying.format("factorization failed", ctx);
82 case LINE_SEARCH_FAILED:
83 return m_underlying.format("line search failed", ctx);
84 case FEASIBILITY_RESTORATION_FAILED:
85 return m_underlying.format("feasibility restoration failed", ctx);
86 case NONFINITE_INITIAL_GUESS:
87 return m_underlying.format("nonfinite initial guess", ctx);
88 case DIVERGING_ITERATES:
89 return m_underlying.format("diverging iterates", ctx);
90 case MAX_ITERATIONS_EXCEEDED:
91 return m_underlying.format("max iterations exceeded", ctx);
92 case TIMEOUT:
93 return m_underlying.format("timeout", ctx);
94 default:
95 std::unreachable();
96 }
97 }
98
99 private:
100 std::formatter<const char*> m_underlying;
101};
auto format(const slp::ExitStatus &exit_status, FmtContext &ctx) const
Definition exit_status.hpp:66
constexpr auto parse(std::format_parse_context &ctx)
Definition exit_status.hpp:55