-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split MathObjectTypes into 2 files and make MathObjectType constructo…
…r consteval
- Loading branch information
Showing
127 changed files
with
258 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
|
||
#include "fintamath/core/MathObjectType.hpp" | ||
|
||
namespace fintamath { | ||
|
||
bool isBaseOf(const MathObjectType &toType, const MathObjectType &fromType); | ||
|
||
namespace detail { | ||
|
||
class MathObjectBoundTypes final { | ||
using enum MathObjectType::Id; | ||
|
||
using TypeIdToBoundTypeIdMap = std::unordered_map<size_t, size_t>; | ||
|
||
static TypeIdToBoundTypeIdMap &getMap() { | ||
static TypeIdToBoundTypeIdMap typeIdToBoundTypeIdMap{ | ||
makeTypeIdPair(IMathObject, None), | ||
makeTypeIdPair(IArithmetic, ILiteral), | ||
makeTypeIdPair(IArithmetic, ILiteral), | ||
makeTypeIdPair(IExpression, IComparable), | ||
makeTypeIdPair(IUnaryExpression, IBinaryExpression), | ||
makeTypeIdPair(IBinaryExpression, IPolynomExpression), | ||
makeTypeIdPair(IPolynomExpression, IComparable), | ||
makeTypeIdPair(IComparable, ILiteral), | ||
makeTypeIdPair(INumber, ILiteral), | ||
makeTypeIdPair(IInteger, ILiteral), | ||
makeTypeIdPair(ILiteral, IFunction), | ||
makeTypeIdPair(IConstant, IFunction), | ||
makeTypeIdPair(IFunction, None), | ||
makeTypeIdPair(IOperator, None), | ||
}; | ||
return typeIdToBoundTypeIdMap; | ||
} | ||
|
||
public: | ||
static void bindTypes(const MathObjectType &type, const MathObjectType &boundType) { | ||
getMap().emplace(type.getId(), boundType.getId()); | ||
} | ||
|
||
friend bool fintamath::isBaseOf(const MathObjectType &toType, const MathObjectType &fromType); | ||
|
||
private: | ||
static std::pair<size_t, size_t> makeTypeIdPair(const MathObjectType::Id lhs, const MathObjectType::Id rhs) { | ||
return {static_cast<size_t>(lhs), static_cast<size_t>(rhs)}; | ||
} | ||
}; | ||
|
||
} | ||
|
||
inline bool isBaseOf(const MathObjectType &toType, const MathObjectType &fromType) { | ||
const auto &map = detail::MathObjectBoundTypes::getMap(); | ||
|
||
if (const auto boundaries = map.find(toType.getId()); boundaries != map.end()) { | ||
return fromType.getId() >= boundaries->first && fromType.getId() < boundaries->second; | ||
} | ||
|
||
return toType == fromType; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.