WPILibC++ 2027.0.0-alpha-4
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/// Formatter for ExpressionType.
32template <>
33struct fmt::formatter<slp::ExpressionType> {
34 /// Parse format string.
35 ///
36 /// @param ctx Format parse context.
37 /// @return Format parse context iterator.
38 constexpr auto parse(fmt::format_parse_context& ctx) {
39 return m_underlying.parse(ctx);
40 }
41
42 /// Format ExpressionType.
43 ///
44 /// @tparam FmtContext Format context type.
45 /// @param type Expression type.
46 /// @param ctx Format context.
47 /// @return Format context iterator.
48 template <typename FmtContext>
49 auto format(const slp::ExpressionType& type, FmtContext& ctx) const {
50 using enum slp::ExpressionType;
51
52 switch (type) {
53 case NONE:
54 return m_underlying.format("none", ctx);
55 case CONSTANT:
56 return m_underlying.format("constant", ctx);
57 case LINEAR:
58 return m_underlying.format("linear", ctx);
59 case QUADRATIC:
60 return m_underlying.format("quadratic", ctx);
61 case NONLINEAR:
62 return m_underlying.format("nonlinear", ctx);
63 default:
65 }
66 }
67
68 private:
69 fmt::formatter<const char*> m_underlying;
70};
Definition expression_graph.hpp:11
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
auto format(const slp::ExpressionType &type, FmtContext &ctx) const
Format ExpressionType.
Definition expression_type.hpp:49
constexpr auto parse(fmt::format_parse_context &ctx)
Parse format string.
Definition expression_type.hpp:38