From b304605384391870e40471530307e2b0598c1c0a Mon Sep 17 00:00:00 2001 From: "Vladimir Vashurkin (Alkenso)" Date: Mon, 12 Aug 2019 17:52:14 +0300 Subject: [PATCH] Replaced tabs with spaces. --- include/asenum/asenum.h | 210 ++++++++++++++++++++-------------------- tests/AsEnumTest.cpp | 44 ++++----- 2 files changed, 127 insertions(+), 127 deletions(-) diff --git a/include/asenum/asenum.h b/include/asenum/asenum.h index 27f34ea..34aa000 100644 --- a/include/asenum/asenum.h +++ b/include/asenum/asenum.h @@ -61,8 +61,8 @@ namespace asenum template class AsMap; - template - struct Comparator; + template + struct Comparator; } /** @@ -121,40 +121,40 @@ namespace asenum template bool ifCase(const Handler& handler) const; - /** - @warning Usually ou don't want to use this method. Use safer 'ifCase'. - Force unwraps AsEnum and provides direct access to value that it holds. + /** + @warning Usually ou don't want to use this method. Use safer 'ifCase'. + Force unwraps AsEnum and provides direct access to value that it holds. - @return Const reference to underlying value. - @throws std::invalid_argument exception if 'Case' doesn't correspond to stored case. - */ - template , typename = typename std::enable_if::value>::type> - const R& forceAsCase() const; + @return Const reference to underlying value. + @throws std::invalid_argument exception if 'Case' doesn't correspond to stored case. + */ + template , typename = typename std::enable_if::value>::type> + const R& forceAsCase() const; /** Performs switch-like action allowing to wotk with values of different cases. */ details::AsSwitch> doSwitch() const; - /** - Maps (converts) AsEnum value depends on stored case to type 'T'. - */ + /** + Maps (converts) AsEnum value depends on stored case to type 'T'. + */ template - details::AsMap> doMap() const; + details::AsMap> doMap() const; - /** - Compares two AsEnum instances. Instance meant to be equal if and only if - 1) Underlying enum cases are equal; - 2) Underlying values are equal. - */ - bool operator==(const AsEnum& other) const; + /** + Compares two AsEnum instances. Instance meant to be equal if and only if + 1) Underlying enum cases are equal; + 2) Underlying values are equal. + */ + bool operator==(const AsEnum& other) const; - /** - Compares two AsEnum instances. Instance meant to be equal if and only if - 1) Underlying enum cases are equal; - 2) Underlying values are equal. - */ - bool operator!=(const AsEnum& other) const; + /** + Compares two AsEnum instances. Instance meant to be equal if and only if + 1) Underlying enum cases are equal; + 2) Underlying values are equal. + */ + bool operator!=(const AsEnum& other) const; private: AsEnum(const Enum relatedCase, std::shared_ptr value); @@ -178,11 +178,11 @@ namespace asenum namespace details { - template - constexpr size_t ArraySize(T (&array)[N]) - { - return sizeof(array) / sizeof(array[0]); - } + template + constexpr size_t ArraySize(T (&array)[N]) + { + return sizeof(array) / sizeof(array[0]); + } template struct AsMapResultMaker; @@ -215,12 +215,12 @@ namespace asenum }; - template struct Contains; - template struct Contains { static const bool value = false; }; - template struct Contains { static const bool value = T_type1 == T_type2; }; + template struct Contains; + template struct Contains { static const bool value = false; }; + template struct Contains { static const bool value = T_type1 == T_type2; }; - template - struct Contains { static const bool value = Contains::value || Contains::value; }; + template + struct Contains { static const bool value = Contains::value || Contains::value; }; template @@ -241,9 +241,9 @@ namespace asenum bool m_handled; }; - template - class AsMap - { + template + class AsMap + { static constexpr size_t AllCaseCount = ArraySize(ConcreteAsEnum::AllCases); static constexpr size_t CurrentCaseCount = sizeof...(Types); static constexpr bool IsPreLastCase = AllCaseCount == CurrentCaseCount + 1; @@ -255,28 +255,28 @@ namespace asenum template using UnderlyingType = typename ConcreteAsEnum::template UnderlyingType; - public: - AsMap(const ConcreteAsEnum& asEnum, std::unique_ptr result); - explicit AsMap(const ConcreteAsEnum& asEnum); + public: + AsMap(const ConcreteAsEnum& asEnum, std::unique_ptr result); + explicit AsMap(const ConcreteAsEnum& asEnum); - template > + template > static typename std::enable_if::value, void>::type - ifCaseCall(const ConcreteAsEnum& asEnum, std::unique_ptr& result, const Handler& handler); + ifCaseCall(const ConcreteAsEnum& asEnum, std::unique_ptr& result, const Handler& handler); - template > - static typename std::enable_if::value, void>::type - ifCaseCall(const ConcreteAsEnum& asEnum, std::unique_ptr& result, const Handler& handler); + template > + static typename std::enable_if::value, void>::type + ifCaseCall(const ConcreteAsEnum& asEnum, std::unique_ptr& result, const Handler& handler); - template - T ifDefault(const Handler& handler); + template + T ifDefault(const Handler& handler); template > - R ifCase(const CaseHandler& handler); + R ifCase(const CaseHandler& handler); - private: - std::unique_ptr m_result; - const ConcreteAsEnum& m_asEnum; - }; + private: + std::unique_ptr m_result; + const ConcreteAsEnum& m_asEnum; + }; template struct CaseSet @@ -317,40 +317,40 @@ namespace asenum static_assert(!std::is_same::value, "Type is missing for specified enum value."); }; - template - struct Comparator - { - template - static bool compare(const ConcreteAsEnum& first, const ConcreteAsEnum& second) - { - return first.template forceAsCase() == second.template forceAsCase(); - } + template + struct Comparator + { + template + static bool compare(const ConcreteAsEnum& first, const ConcreteAsEnum& second) + { + return first.template forceAsCase() == second.template forceAsCase(); + } - template <> - static bool compare(const ConcreteAsEnum&, const ConcreteAsEnum&) - { - return true; - } + template <> + static bool compare(const ConcreteAsEnum&, const ConcreteAsEnum&) + { + return true; + } - static bool compare(const ConcreteAsEnum& first, const ConcreteAsEnum& second) - { - if (first.enumCase() != T_Case::Code || second.enumCase() != T_Case::Code) - { - return false; - } + static bool compare(const ConcreteAsEnum& first, const ConcreteAsEnum& second) + { + if (first.enumCase() != T_Case::Code || second.enumCase() != T_Case::Code) + { + return false; + } - return compare(first, second); - } - }; + return compare(first, second); + } + }; - template - struct Comparator - { - static bool compare(const ConcreteAsEnum& first, const ConcreteAsEnum& second) - { - return Comparator::compare(first, second) || Comparator::compare(first, second); - } - }; + template + struct Comparator + { + static bool compare(const ConcreteAsEnum& first, const ConcreteAsEnum& second) + { + return Comparator::compare(first, second) || Comparator::compare(first, second); + } + }; } } @@ -411,12 +411,12 @@ template template ::Enum Case, typename R, typename> const R& asenum::AsEnum::forceAsCase() const { - if (!isCase()) - { - throw std::invalid_argument("Unwrapping case does not correspond to stored case."); - } + if (!isCase()) + { + throw std::invalid_argument("Unwrapping case does not correspond to stored case."); + } - return *reinterpret_cast*>(m_value.get()); + return *reinterpret_cast*>(m_value.get()); } template @@ -429,19 +429,19 @@ template template asenum::details::AsMap::Enum, asenum::AsEnum> asenum::AsEnum::doMap() const { - return details::AsMap>(*this); + return details::AsMap>(*this); } template bool asenum::AsEnum::operator==(const AsEnum& other) const { - return details::Comparator::compare(*this, other); + return details::Comparator::compare(*this, other); } template bool asenum::AsEnum::operator!=(const AsEnum& other) const { - return !(*this == other); + return !(*this == other); } @@ -523,9 +523,9 @@ template typename std::enable_if::value, void>::type asenum::details::AsMap::ifCaseCall(const ConcreteAsEnum& asEnum, std::unique_ptr& result, const Handler& handler) { - asEnum.template ifCase([&] { - result.reset(new T(handler())); - }); + asEnum.template ifCase([&] { + result.reset(new T(handler())); + }); } template @@ -533,28 +533,28 @@ template typename std::enable_if::value, void>::type asenum::details::AsMap::ifCaseCall(const ConcreteAsEnum& asEnum, std::unique_ptr& result, const Handler& handler) { - asEnum.template ifCase([&] (const UT& value) { - result.reset(new T(handler(value))); - }); + asEnum.template ifCase([&] (const UT& value) { + result.reset(new T(handler(value))); + }); } template template T asenum::details::AsMap::ifDefault(const Handler& handler) { - return m_result ? std::move(*m_result) : handler(); + return m_result ? std::move(*m_result) : handler(); } template template R asenum::details::AsMap::ifCase(const CaseHandler& handler) { - static_assert(!Contains::value, "Duplicated map case"); + static_assert(!Contains::value, "Duplicated map case"); - if (!m_result) - { - ifCaseCall(m_asEnum, m_result, handler); - } + if (!m_result) + { + ifCaseCall(m_asEnum, m_result, handler); + } - return ResultMaker::template makeResult(m_asEnum, std::move(m_result)); + return ResultMaker::template makeResult(m_asEnum, std::move(m_result)); } diff --git a/tests/AsEnumTest.cpp b/tests/AsEnumTest.cpp index 75385f5..3236f1a 100644 --- a/tests/AsEnumTest.cpp +++ b/tests/AsEnumTest.cpp @@ -203,30 +203,30 @@ TEST(AsEnum, Map_All_Cases) TEST(AsEnum, ForceAsCase) { - const TestAsEnum value1 = TestAsEnum::create("test"); - // TestEnum::VoidOpt doesn't have 'forceAsEnum' method because associated type is 'void'. - const TestAsEnum value3 = TestAsEnum::create(-100500); - - EXPECT_EQ(value1.forceAsCase(), "test"); - EXPECT_THROW(value1.forceAsCase(), std::invalid_argument); - - EXPECT_THROW(value3.forceAsCase(), std::invalid_argument); - EXPECT_EQ(value3.forceAsCase(), -100500); + const TestAsEnum value1 = TestAsEnum::create("test"); + // TestEnum::VoidOpt doesn't have 'forceAsEnum' method because associated type is 'void'. + const TestAsEnum value3 = TestAsEnum::create(-100500); + + EXPECT_EQ(value1.forceAsCase(), "test"); + EXPECT_THROW(value1.forceAsCase(), std::invalid_argument); + + EXPECT_THROW(value3.forceAsCase(), std::invalid_argument); + EXPECT_EQ(value3.forceAsCase(), -100500); } TEST(AsEnum, Compare) { - const TestAsEnum value1 = TestAsEnum::create("test"); - const TestAsEnum value2 = TestAsEnum::create("test"); - const TestAsEnum value3 = TestAsEnum::create("test2"); - const TestAsEnum value4 = TestAsEnum::create(); - const TestAsEnum value5 = TestAsEnum::create(-100500); - - EXPECT_EQ(value1, value1); - EXPECT_EQ(value1, value2); - EXPECT_NE(value1, value3); - EXPECT_NE(value1, value4); - EXPECT_NE(value1, value5); - - EXPECT_EQ(value4, TestAsEnum::create()); + const TestAsEnum value1 = TestAsEnum::create("test"); + const TestAsEnum value2 = TestAsEnum::create("test"); + const TestAsEnum value3 = TestAsEnum::create("test2"); + const TestAsEnum value4 = TestAsEnum::create(); + const TestAsEnum value5 = TestAsEnum::create(-100500); + + EXPECT_EQ(value1, value1); + EXPECT_EQ(value1, value2); + EXPECT_NE(value1, value3); + EXPECT_NE(value1, value4); + EXPECT_NE(value1, value5); + + EXPECT_EQ(value4, TestAsEnum::create()); }