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
14template <IExpression LowerBoundT = Expression, IExpression UpperBoundT = Expression>
16public:
17 BoundedExpression() = default;
18
20 {
21 if (other.HasLowerBound())
23 if (other.HasUpperBound())
25 }
26
27 BoundedExpression(const LowerBoundT& lowerBound, const UpperBoundT& upperBound)
28 {
29 SetLowerBound(lowerBound);
30 SetUpperBound(upperBound);
31 }
32
33 [[nodiscard]] auto HasLowerBound() const -> bool
34 {
35 return lowerBound != nullptr;
36 }
37
38 [[nodiscard]] auto HasUpperBound() const -> bool
39 {
40 return upperBound != nullptr;
41 }
42
43 [[nodiscard]] auto GetLowerBound() const -> const LowerBoundT&
44 {
45 assert(HasLowerBound() && "LowerBound is not set.");
46 return *lowerBound;
47 }
48
49 [[nodiscard]] auto GetUpperBound() const -> const UpperBoundT&
50 {
51 assert(HasUpperBound() && "UpperBound is not set.");
52 return *upperBound;
53 }
54
55 template <typename T>
57 void SetLowerBound(const T& expr)
58 {
59 if constexpr (std::is_same_v<T, LowerBoundT>) {
60 lowerBound = std::make_unique<LowerBoundT>(expr);
61 } else {
62 lowerBound = expr.Copy();
63 }
64 }
65
66 template <typename T>
68 void SetUpperBound(const T& expr)
69 {
70 if constexpr (std::is_same_v<T, UpperBoundT>) {
71 upperBound = std::make_unique<UpperBoundT>(expr);
72 } else {
73 upperBound = expr.Copy();
74 }
75 }
76
77private:
80};
81
82} // Oasis
83
84#endif // OAISIS_BOUNDEDEXPRESSION_HPP
Definition BoundedExpression.hpp:15
BoundedExpression(const LowerBoundT &lowerBound, const UpperBoundT &upperBound)
Definition BoundedExpression.hpp:27
auto GetLowerBound() const -> const LowerBoundT &
Definition BoundedExpression.hpp:43
BoundedExpression(const BoundedExpression &other)
Definition BoundedExpression.hpp:19
auto GetUpperBound() const -> const UpperBoundT &
Definition BoundedExpression.hpp:49
auto HasLowerBound() const -> bool
Definition BoundedExpression.hpp:33
void SetLowerBound(const T &expr)
Definition BoundedExpression.hpp:57
auto HasUpperBound() const -> bool
Definition BoundedExpression.hpp:38
void SetUpperBound(const T &expr)
Definition BoundedExpression.hpp:68
An expression.
Definition Expression.hpp:56
Checks if type T is same as any of the provided types in U.
Definition Concepts.hpp:48
T is_same_v
Definition Add.hpp:11