From 1610c0cbf3bc3d3ac444c0c70043b2c0acf6e9ec Mon Sep 17 00:00:00 2001 From: fintarin Date: Mon, 8 Apr 2024 14:59:53 +0400 Subject: [PATCH] 1 --- include/fintamath/config/Config.hpp | 2 +- include/fintamath/core/Converter.hpp | 4 ++-- include/fintamath/core/MultiMethod.hpp | 18 +++++++++--------- include/fintamath/core/None.hpp | 2 +- include/fintamath/core/Parser.hpp | 12 ++++++------ include/fintamath/core/Tokenizer.hpp | 4 ++-- .../exceptions/InvalidInputException.hpp | 10 +++++----- .../exceptions/UndefinedException.hpp | 10 +++++----- src/fintamath/config/Config.cpp | 2 +- src/fintamath/config/ConverterConfig.cpp | 2 +- src/fintamath/config/ConverterConfig.hpp | 2 +- src/fintamath/config/ExpressionConfig.cpp | 2 +- src/fintamath/config/ExpressionConfig.hpp | 2 +- src/fintamath/config/PrecisionConfig.cpp | 2 +- src/fintamath/config/PrecisionConfig.hpp | 2 +- src/fintamath/config/TypeConfig.cpp | 2 +- src/fintamath/config/TypeConfig.hpp | 2 +- src/fintamath/core/Converter.cpp | 2 +- src/fintamath/core/Tokenizer.cpp | 4 ++-- 19 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/fintamath/config/Config.hpp b/include/fintamath/config/Config.hpp index a08956ab2..facaaf253 100644 --- a/include/fintamath/config/Config.hpp +++ b/include/fintamath/config/Config.hpp @@ -3,7 +3,7 @@ namespace fintamath::detail { struct Config final { - Config(); + Config() noexcept; }; } diff --git a/include/fintamath/core/Converter.hpp b/include/fintamath/core/Converter.hpp index 000e94554..a8729acc2 100644 --- a/include/fintamath/core/Converter.hpp +++ b/include/fintamath/core/Converter.hpp @@ -19,7 +19,7 @@ class Converter final { using ConverterMultiMethod = MultiMethod(const IMathObject &, const IMathObject &)>; public: - static std::unique_ptr convert(const IMathObject &to, const IMathObject &from) { + static std::unique_ptr convert(const IMathObject &to, const IMathObject &from) noexcept { return getConverter()(to, from); } @@ -33,7 +33,7 @@ class Converter final { } private: - static ConverterMultiMethod &getConverter(); + static ConverterMultiMethod &getConverter() noexcept; }; } diff --git a/include/fintamath/core/MultiMethod.hpp b/include/fintamath/core/MultiMethod.hpp index f067eaf77..ba4f7a55b 100644 --- a/include/fintamath/core/MultiMethod.hpp +++ b/include/fintamath/core/MultiMethod.hpp @@ -25,14 +25,6 @@ class MultiMethod final { using IdToCallbackMap = std::unordered_map>; public: - template - requires(sizeof...(Args) == sizeof...(ArgsBase)) - void add(const auto &func) { - idToCallbackMap[CallbackId(Args::getClassStatic()...)] = [func](const ArgsBase &...args) { - return func(cast(args)...); - }; - } - template requires(sizeof...(Args) == sizeof...(ArgsBase)) Res operator()(Args &&...args) const { @@ -45,10 +37,18 @@ class MultiMethod final { template requires(sizeof...(Args) == sizeof...(ArgsBase)) - bool contains(const Args &...args) const { + bool contains(const Args &...args) const noexcept { return idToCallbackMap.contains(CallbackId(args.getClass()...)); } + template + requires(sizeof...(Args) == sizeof...(ArgsBase)) + void add(const auto &func) noexcept { + idToCallbackMap[CallbackId(Args::getClassStatic()...)] = [func](const ArgsBase &...args) { + return func(cast(args)...); + }; + } + private: IdToCallbackMap idToCallbackMap; }; diff --git a/include/fintamath/core/None.hpp b/include/fintamath/core/None.hpp index b644f485f..b009c241f 100644 --- a/include/fintamath/core/None.hpp +++ b/include/fintamath/core/None.hpp @@ -5,7 +5,7 @@ namespace fintamath { struct None { - static constexpr MathObjectClass getClassStatic() { + static constexpr MathObjectClass getClassStatic() noexcept { return nullptr; } }; diff --git a/include/fintamath/core/Parser.hpp b/include/fintamath/core/Parser.hpp index f1fc3d6e9..35bceacfe 100644 --- a/include/fintamath/core/Parser.hpp +++ b/include/fintamath/core/Parser.hpp @@ -43,7 +43,7 @@ class Parser final { using GeneratorConstructorVector = std::vector; public: - Generator parse(std::string str) const { + Generator parse(std::string str) const noexcept { if (const auto stringToConstructors = stringToConstructorsMap.find(str); stringToConstructors != stringToConstructorsMap.end()) { for (const auto &constructor : stringToConstructors->second) { co_yield constructor(); @@ -57,7 +57,7 @@ class Parser final { } } - std::optional parseFirst(std::string str) const { + std::optional parseFirst(std::string str) const noexcept { auto gener = parse(std::move(str)); if (auto iter = gener.begin(); iter != gener.end()) { @@ -69,7 +69,7 @@ class Parser final { template requires(!std::is_abstract_v && !StringConstructable && EmptyConstructable) - void registerType() { + void registerType() noexcept { static const std::string name = Type{}.toString(); stringToConstructorsMap[name].emplace_back([]() -> Return { @@ -81,7 +81,7 @@ class Parser final { template requires(!std::is_abstract_v && StringConstructable) - void registerType() { + void registerType() noexcept { generatorConstructors.emplace_back([](std::string str) -> Generator { try { co_yield std::make_unique(std::move(str)); @@ -94,7 +94,7 @@ class Parser final { template requires(std::is_abstract_v) - void registerType() { + void registerType() noexcept { generatorConstructors.emplace_back([](std::string str) -> Generator { for (auto &value : Type::parse(std::move(str))) { co_yield std::move(value); @@ -103,7 +103,7 @@ class Parser final { } template - void registerType() const { + void registerType() const noexcept { // No object of this type can be constructed } diff --git a/include/fintamath/core/Tokenizer.hpp b/include/fintamath/core/Tokenizer.hpp index f2f3dc44b..38f604e65 100644 --- a/include/fintamath/core/Tokenizer.hpp +++ b/include/fintamath/core/Tokenizer.hpp @@ -12,7 +12,7 @@ class Tokenizer final { public: static TokenVector tokenize(std::string str); - static void registerToken(const Token &token); + static void registerToken(const Token &token) noexcept; private: static bool appendToken(TokenVector &tokens, Token &token, bool shouldSplit = false); @@ -23,7 +23,7 @@ class Tokenizer final { static bool isSpace(char ch); - static TokenVector &getRegisteredTokens(); + static TokenVector &getRegisteredTokens() noexcept; }; } diff --git a/include/fintamath/exceptions/InvalidInputException.hpp b/include/fintamath/exceptions/InvalidInputException.hpp index de2f10aba..2fb93e578 100644 --- a/include/fintamath/exceptions/InvalidInputException.hpp +++ b/include/fintamath/exceptions/InvalidInputException.hpp @@ -10,9 +10,9 @@ namespace fintamath { class InvalidInputException : public Exception { public: - InvalidInputException() = default; + InvalidInputException() noexcept = default; - explicit InvalidInputException(const std::string &input) { + explicit InvalidInputException(const std::string &input) noexcept { content += ": " + input; } @@ -26,7 +26,7 @@ class InvalidInputException : public Exception { class InvalidInputFunctionException final : public InvalidInputException { public: - explicit InvalidInputFunctionException(const std::string &func, const std::vector &argVect) { + explicit InvalidInputFunctionException(const std::string &func, const std::vector &argVect) noexcept { content += ": " + func + "("; if (!argVect.empty()) { @@ -47,7 +47,7 @@ class InvalidInputFunctionException final : public InvalidInputException { class InvalidInputBinaryOperatorException final : public InvalidInputException { public: - explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { + explicit InvalidInputBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) noexcept { content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; } }; @@ -60,7 +60,7 @@ class InvalidInputUnaryOperatorException final : public InvalidInputException { }; public: - explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { + explicit InvalidInputUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) noexcept { switch (type) { case Type::Prefix: content += ": " + oper + "(" + rhs + ")"; diff --git a/include/fintamath/exceptions/UndefinedException.hpp b/include/fintamath/exceptions/UndefinedException.hpp index 56ab666db..213fb16ea 100644 --- a/include/fintamath/exceptions/UndefinedException.hpp +++ b/include/fintamath/exceptions/UndefinedException.hpp @@ -10,9 +10,9 @@ namespace fintamath { class UndefinedException : public Exception { public: - UndefinedException() = default; + UndefinedException() noexcept = default; - explicit UndefinedException(const std::string &input) { + explicit UndefinedException(const std::string &input) noexcept { content += ": " + input; } @@ -26,7 +26,7 @@ class UndefinedException : public Exception { class UndefinedFunctionException final : public UndefinedException { public: - explicit UndefinedFunctionException(const std::string &func, const std::vector &argVect) { + explicit UndefinedFunctionException(const std::string &func, const std::vector &argVect) noexcept { content += ": " + func + "("; if (!argVect.empty()) { @@ -47,7 +47,7 @@ class UndefinedFunctionException final : public UndefinedException { class UndefinedBinaryOperatorException final : public UndefinedException { public: - explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) { + explicit UndefinedBinaryOperatorException(const std::string &oper, const std::string &lhs, const std::string &rhs) noexcept { content += ": (" + lhs + ")" + oper + "(" + rhs + ")"; } }; @@ -60,7 +60,7 @@ class UndefinedUnaryOperatorException final : public UndefinedException { }; public: - explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) { + explicit UndefinedUnaryOperatorException(const std::string &oper, const std::string &rhs, const Type type) noexcept { switch (type) { case Type::Prefix: content += ": " + oper + "(" + rhs + ")"; diff --git a/src/fintamath/config/Config.cpp b/src/fintamath/config/Config.cpp index 9dab57d4e..7da731330 100644 --- a/src/fintamath/config/Config.cpp +++ b/src/fintamath/config/Config.cpp @@ -7,7 +7,7 @@ namespace fintamath::detail { -Config::Config() { +Config::Config() noexcept { [[maybe_unused]] static const TypeConfig typeConfig; [[maybe_unused]] static const PrecisionConfig precisionConfig; [[maybe_unused]] static const ConverterConfig converterConfig; diff --git a/src/fintamath/config/ConverterConfig.cpp b/src/fintamath/config/ConverterConfig.cpp index 3e14d7fba..ccab62bea 100644 --- a/src/fintamath/config/ConverterConfig.cpp +++ b/src/fintamath/config/ConverterConfig.cpp @@ -10,7 +10,7 @@ namespace fintamath::detail { -ConverterConfig::ConverterConfig() { +ConverterConfig::ConverterConfig() noexcept { Converter::add([](const Integer & /*type*/, const Integer &value) { return Integer(value).clone(); }); diff --git a/src/fintamath/config/ConverterConfig.hpp b/src/fintamath/config/ConverterConfig.hpp index 2977f3815..34a7e57cb 100644 --- a/src/fintamath/config/ConverterConfig.hpp +++ b/src/fintamath/config/ConverterConfig.hpp @@ -3,7 +3,7 @@ namespace fintamath::detail { struct ConverterConfig final { - ConverterConfig(); + ConverterConfig() noexcept; }; } diff --git a/src/fintamath/config/ExpressionConfig.cpp b/src/fintamath/config/ExpressionConfig.cpp index 6474b7b2e..1beb1174d 100644 --- a/src/fintamath/config/ExpressionConfig.cpp +++ b/src/fintamath/config/ExpressionConfig.cpp @@ -100,7 +100,7 @@ namespace fintamath::detail { -ExpressionConfig::ExpressionConfig() { +ExpressionConfig::ExpressionConfig() noexcept { Expression::registerExpressionConstructor([](ArgumentPtrVector &&args) { return AddExpr(std::move(args)).clone(); }); diff --git a/src/fintamath/config/ExpressionConfig.hpp b/src/fintamath/config/ExpressionConfig.hpp index f188f01fd..b584c808a 100644 --- a/src/fintamath/config/ExpressionConfig.hpp +++ b/src/fintamath/config/ExpressionConfig.hpp @@ -3,7 +3,7 @@ namespace fintamath::detail { struct ExpressionConfig final { - ExpressionConfig(); + ExpressionConfig() noexcept; }; } diff --git a/src/fintamath/config/PrecisionConfig.cpp b/src/fintamath/config/PrecisionConfig.cpp index a787376da..d1c17409b 100644 --- a/src/fintamath/config/PrecisionConfig.cpp +++ b/src/fintamath/config/PrecisionConfig.cpp @@ -4,7 +4,7 @@ namespace fintamath::detail { -PrecisionConfig::PrecisionConfig() { +PrecisionConfig::PrecisionConfig() noexcept { constexpr unsigned defaultPrecision = 20; Real::setPrecision(defaultPrecision); } diff --git a/src/fintamath/config/PrecisionConfig.hpp b/src/fintamath/config/PrecisionConfig.hpp index c5ef5a16b..c56c0885d 100644 --- a/src/fintamath/config/PrecisionConfig.hpp +++ b/src/fintamath/config/PrecisionConfig.hpp @@ -3,7 +3,7 @@ namespace fintamath::detail { struct PrecisionConfig final { - PrecisionConfig(); + PrecisionConfig() noexcept; }; } diff --git a/src/fintamath/config/TypeConfig.cpp b/src/fintamath/config/TypeConfig.cpp index 9eb41b920..5b2055ea9 100644 --- a/src/fintamath/config/TypeConfig.cpp +++ b/src/fintamath/config/TypeConfig.cpp @@ -121,7 +121,7 @@ namespace fintamath::detail { -TypeConfig::TypeConfig() { +TypeConfig::TypeConfig() noexcept { IMathObject::registerType(); IMathObject::registerType(); IMathObject::registerType(); diff --git a/src/fintamath/config/TypeConfig.hpp b/src/fintamath/config/TypeConfig.hpp index 2dbaf37b8..cbc0b74e5 100644 --- a/src/fintamath/config/TypeConfig.hpp +++ b/src/fintamath/config/TypeConfig.hpp @@ -3,7 +3,7 @@ namespace fintamath::detail { struct TypeConfig final { - TypeConfig(); + TypeConfig() noexcept; }; } diff --git a/src/fintamath/core/Converter.cpp b/src/fintamath/core/Converter.cpp index 526d81840..5a5e01eb2 100644 --- a/src/fintamath/core/Converter.cpp +++ b/src/fintamath/core/Converter.cpp @@ -4,7 +4,7 @@ namespace fintamath::detail { -Converter::ConverterMultiMethod &Converter::getConverter() { +Converter::ConverterMultiMethod &Converter::getConverter() noexcept { static ConverterMultiMethod converter; return converter; } diff --git a/src/fintamath/core/Tokenizer.cpp b/src/fintamath/core/Tokenizer.cpp index 0f208c099..f8884ea69 100644 --- a/src/fintamath/core/Tokenizer.cpp +++ b/src/fintamath/core/Tokenizer.cpp @@ -36,7 +36,7 @@ TokenVector Tokenizer::tokenize(std::string str) { return tokens; } -void Tokenizer::registerToken(const Token &token) { +void Tokenizer::registerToken(const Token &token) noexcept { auto &tokens = getRegisteredTokens(); tokens.insert(std::ranges::upper_bound(tokens, token, [](const Token &lhs, const Token &rhs) { return lhs.size() > rhs.size(); @@ -98,7 +98,7 @@ bool Tokenizer::isSpace(const char ch) { return ch == ' '; } -TokenVector &Tokenizer::getRegisteredTokens() { +TokenVector &Tokenizer::getRegisteredTokens() noexcept { static TokenVector registeredTokens; return registeredTokens; }