FuncSketch
Loading...
Searching...
No Matches
expression.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <variant>
23
24#include <fmt/base.h>
25
28#include "func_sketch/expressions/expression_decl.h" // IWYU pragma: keep
32
33namespace func_sketch::expressions {
34
42public:
46
52 explicit Expression(ConstantExpression expression)
53 : expression_(expression) {}
54
60 explicit Expression(ParameterExpression expression)
61 : expression_(expression) {}
62
68 explicit Expression(UnaryExpression expression) : expression_(expression) {}
69
75 explicit Expression(BinaryExpression expression)
76 : expression_(expression) {}
77
84 : expression_(expression) {}
85
92 template <typename T>
93 [[nodiscard]] const T& as() const {
94 return std::get<T>(expression_);
95 }
96
102 [[nodiscard]] const VariantType& as_variant() const { return expression_; }
103
104private:
107};
108
109} // namespace func_sketch::expressions
110
115template <>
116struct fmt::formatter<func_sketch::expressions::Expression>
117 : fmt::formatter<string_view> {
126 format_context& context) const -> format_context::iterator;
127};
128
133template <>
134struct fmt::formatter<func_sketch::expressions::Expression*>
135 : fmt::formatter<string_view> {
144 format_context& context) const -> format_context::iterator;
145};
Definition of BinaryExpression structure.
Expression(ParameterExpression expression)
Constructor.
Definition expression.h:60
Expression(ConstantExpression expression)
Constructor.
Definition expression.h:52
Expression(UnaryExpression expression)
Constructor.
Definition expression.h:68
Expression(FunctionCallExpression expression)
Constructor.
Definition expression.h:83
const T & as() const
Get as a type.
Definition expression.h:93
VariantType expression_
Expression.
Definition expression.h:106
Expression(BinaryExpression expression)
Constructor.
Definition expression.h:75
const VariantType & as_variant() const
Get the expression as variant.
Definition expression.h:102
std::variant< ConstantExpression, ParameterExpression, UnaryExpression, BinaryExpression, FunctionCallExpression > VariantType
Type of the variant of expressions.
Definition expression.h:44
Definition of ConstantExpression structure.
Declaration of Expression class.
Definition of FunctionCallExpression structure.
Definition of ParameterExpression structure.
auto format(const func_sketch::expressions::Expression &value, format_context &context) const -> format_context::iterator
Format a value.
auto format(const func_sketch::expressions::Expression *value, format_context &context) const -> format_context::iterator
Format a value.
Definition of UnaryExpression structure.