OASIS
Open Algebra Software
Loading...
Searching...
No Matches
BoundedExpression.hpp
Go to the documentation of this file.
1//
2// Created by Matthew McCall on 4/30/24.
3//
4
5#ifndef OAISIS_BOUNDEDEXPRESSION_HPP
6#define OAISIS_BOUNDEDEXPRESSION_HPP
7
8#include <cassert>
9
10#include "Expression.hpp"
11
12namespace Oasis {
13
22template <IExpression LowerBoundT = Expression, IExpression UpperBoundT = Expression>
24public:
25 BoundedExpression() = default;
26
28 {
29 if (other.HasLowerBound())
31 if (other.HasUpperBound())
33 }
34
35 BoundedExpression(const LowerBoundT& lowerBound, const UpperBoundT& upperBound)
36 {
37 SetLowerBound(lowerBound);
38 SetUpperBound(upperBound);
39 }
40
41 [[nodiscard]] auto HasLowerBound() const -> bool
42 {
43 return lowerBound != nullptr;
44 }
45
46 [[nodiscard]] auto HasUpperBound() const -> bool
47 {
48 return upperBound != nullptr;
49 }
50
51 [[nodiscard]] auto GetLowerBound() const -> const LowerBoundT&
52 {
53 assert(HasLowerBound() && "LowerBound is not set.");
54 return *lowerBound;
55 }
56
57 [[nodiscard]] auto GetUpperBound() const -> const UpperBoundT&
58 {
59 assert(HasUpperBound() && "UpperBound is not set.");
60 return *upperBound;
61 }
62
63 template <typename T>
65 void SetLowerBound(const T& expr)
66 {
67 if constexpr (std::is_same_v<T, LowerBoundT>) {
68 lowerBound = std::make_unique<LowerBoundT>(expr);
69 } else {
70 lowerBound = expr.Copy();
71 }
72 }
73
74 template <typename T>
76 void SetUpperBound(const T& expr)
77 {
78 if constexpr (std::is_same_v<T, UpperBoundT>) {
79 upperBound = std::make_unique<UpperBoundT>(expr);
80 } else {
81 upperBound = expr.Copy();
82 }
83 }
84
85private:
88};
89
90} // Oasis
91
92#endif // OAISIS_BOUNDEDEXPRESSION_HPP
A concept base class for both Unary and BoundedBinary expressions.
Definition BoundedExpression.hpp:23
BoundedExpression(const LowerBoundT &lowerBound, const UpperBoundT &upperBound)
Definition BoundedExpression.hpp:35
auto GetLowerBound() const -> const LowerBoundT &
Definition BoundedExpression.hpp:51
BoundedExpression(const BoundedExpression &other)
Definition BoundedExpression.hpp:27
auto GetUpperBound() const -> const UpperBoundT &
Definition BoundedExpression.hpp:57
auto HasLowerBound() const -> bool
Definition BoundedExpression.hpp:41
void SetLowerBound(const T &expr)
Definition BoundedExpression.hpp:65
auto HasUpperBound() const -> bool
Definition BoundedExpression.hpp:46
void SetUpperBound(const T &expr)
Definition BoundedExpression.hpp:76
An expression.
Definition Expression.hpp:62
Checks if type T is same as any of the provided types in U.
Definition Concepts.hpp:51
T is_same_v
Definition Add.hpp:11