WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
expression_type.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <stdint.h>
6
7#include <fmt/base.h>
8
10
11namespace slp {
12
13/// Expression type.
14///
15/// Used for autodiff caching.
16enum class ExpressionType : uint8_t {
17 /// There is no expression.
19 /// The expression is a constant.
21 /// The expression is composed of linear and lower-order operators.
23 /// The expression is composed of quadratic and lower-order operators.
25 /// The expression is composed of nonlinear and lower-order operators.
27};
28
29} // namespace slp
30
31// @cond Suppress Doxygen
32
33/// Formatter for ExpressionType.
34template <>
35struct fmt::formatter<slp::ExpressionType> {
36 /// Parse format string.
37 ///
38 /// @param ctx Format parse context.
39 /// @return Format parse context iterator.
40 constexpr auto parse(fmt::format_parse_context& ctx) {
41 return m_underlying.parse(ctx);
42 }
43
44 /// Formats ExpressionType.
45 ///
46 /// @tparam FmtContext Format context type.
47 /// @param type Expression type.
48 /// @param ctx Format context.
49 /// @return Format context iterator.
50 template <typename FmtContext>
51 constexpr auto format(const slp::ExpressionType& type,
52 FmtContext& ctx) const {
53 using enum slp::ExpressionType;
54
55 switch (type) {
56 case NONE:
57 return m_underlying.format("none", ctx);
58 case CONSTANT:
59 return m_underlying.format("constant", ctx);
60 case LINEAR:
61 return m_underlying.format("linear", ctx);
62 case QUADRATIC:
63 return m_underlying.format("quadratic", ctx);
64 case NONLINEAR:
65 return m_underlying.format("nonlinear", ctx);
66 default:
68 }
69 }
70
71 private:
72 fmt::formatter<const char*> m_underlying;
73};
74
75// @endcond
FMT_INLINE auto format(locale_ref loc, format_string< T... > fmt, T &&... args) -> std::string
Definition format.h:4305
Definition to_underlying.hpp:7
ExpressionType
Expression type.
Definition expression_type.hpp:16
@ CONSTANT
The expression is a constant.
Definition expression_type.hpp:20
@ QUADRATIC
The expression is composed of quadratic and lower-order operators.
Definition expression_type.hpp:24
@ LINEAR
The expression is composed of linear and lower-order operators.
Definition expression_type.hpp:22
@ NONE
There is no expression.
Definition expression_type.hpp:18
@ NONLINEAR
The expression is composed of nonlinear and lower-order operators.
Definition expression_type.hpp:26
void unreachable()
Definition unreachable.hpp:8
@ NONE
No test.
Definition SysIdRoutineLog.hpp:35