Skip to content

Commit ea424ea

Browse files
committed
refactor meta code
1 parent 59e118d commit ea424ea

18 files changed

+215
-223
lines changed

Include/SevenBit/DI/Details/Factories/ServiceFcnFactory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "SevenBit/DI/LibraryConfig.hpp"
77

88
#include "SevenBit/DI/Details/Helpers/FunctorInjector.hpp"
9+
#include "SevenBit/DI/Details/Meta/Meta.hpp"
910
#include "SevenBit/DI/Details/Services/InPlaceService.hpp"
1011
#include "SevenBit/DI/Details/Services/UniquePtrService.hpp"
11-
#include "SevenBit/DI/Details/Utils/Meta.hpp"
1212
#include "SevenBit/DI/IServiceFactory.hpp"
1313

1414
namespace sb::di::details

Include/SevenBit/DI/Details/Helpers/CtorInjector.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include "SevenBit/DI/LibraryConfig.hpp"
66

7-
#include "SevenBit/DI/Details/Helpers/ServiceCtorArgExtractor.hpp"
8-
#include "SevenBit/DI/Details/Utils/CtorParamsNumber.hpp"
7+
#include "SevenBit/DI/Details/Meta/CtorParamsNumber.hpp"
8+
#include "SevenBit/DI/Details/Meta/ServiceCtorArgExtractor.hpp"
99
#include "SevenBit/DI/ServiceProvider.hpp"
1010

1111
namespace sb::di::details
@@ -19,7 +19,7 @@ namespace sb::di::details
1919

2020
template <class TWrapper> auto makeUnique()
2121
{
22-
return makeUnique<TWrapper>(std::make_index_sequence<ctorParamsNumber<T>()>{});
22+
return makeUnique<TWrapper>(std::make_index_sequence<CtorParamsNumber::value<T>>{});
2323
};
2424

2525
private:

Include/SevenBit/DI/Details/Helpers/FunctorInjector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "SevenBit/DI/LibraryConfig.hpp"
44

5-
#include "SevenBit/DI/Details/Helpers/ServiceGetter.hpp"
5+
#include "SevenBit/DI/Details/Meta/ServiceGetter.hpp"
66

77
namespace sb::di::details
88
{

Include/SevenBit/DI/Details/Utils/CtorParamsNumber.hpp renamed to Include/SevenBit/DI/Details/Meta/CtorParamsNumber.hpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,43 @@
22

33
#include "SevenBit/DI/LibraryConfig.hpp"
44

5-
#include "SevenBit/DI/Details/Utils/Meta.hpp"
5+
#include "SevenBit/DI/Details/Meta/Meta.hpp"
66

77
namespace sb::di::details
88
{
9-
namespace ctorParamsNumberInternals
9+
class CtorParamsNumber
1010
{
11-
template <class T> struct Conv
11+
template <class S>
12+
struct Conv
1213
{
1314
explicit Conv(std::size_t paramNumber) {}
1415

15-
template <class U, class = std::enable_if_t<!IsCopyCtorV<T, U>>> operator U();
16-
template <class U, class = std::enable_if_t<!IsCopyCtorV<T, U>>> operator U &() const;
16+
template <class U, class = std::enable_if_t<!IsCopyCtorV<S, U>>> operator U();
17+
template <class U, class = std::enable_if_t<!IsCopyCtorV<S, U>>> operator U &() const;
1718
};
1819

19-
template <class T, std::size_t... Ns> constexpr auto paramsNumber(std::size_t) -> decltype(T{Conv<T>{Ns}...}, 0)
20+
template <class S, std::size_t... Ns> static constexpr auto paramsNumber(std::size_t) -> decltype(S{Conv<S>{Ns}...}, 0)
2021
{
2122
return sizeof...(Ns);
2223
}
2324

24-
template <class T, std::size_t... Ns> constexpr std::size_t paramsNumber(...)
25+
template <class S, std::size_t... Ns> static constexpr std::size_t paramsNumber(...)
2526
{
2627

2728
if constexpr (sizeof...(Ns) > _7BIT_DI_CTOR_PARAMS_LIMIT)
2829
{
2930
static_assert(
30-
details::notSupportedType<T>,
31+
details::notSupportedType<S>,
3132
"Proper constructor for specified type was not found, reached maximum constructor params number "
3233
"limit, to bump limit define macro _7BIT_DI_CTOR_PARAMS_LIMIT with new value befor including lib");
3334
return 0;
3435
}
3536
else
3637
{
37-
return paramsNumber<T, Ns..., sizeof...(Ns)>(0);
38+
return paramsNumber<S, Ns..., sizeof...(Ns)>(0);
3839
}
3940
}
40-
} // namespace ctorParamsNumberInternals
41-
42-
template <class T> constexpr std::size_t ctorParamsNumber()
43-
{
44-
return ctorParamsNumberInternals::paramsNumber<T>(0);
45-
};
46-
41+
public:
42+
template<class F> static constexpr std::size_t value = paramsNumber<F>(0);
43+
};
4744
} // namespace sb::di::details

Include/SevenBit/DI/Details/Helpers/ServiceCtorArgExtractor.hpp renamed to Include/SevenBit/DI/Details/Meta/ServiceCtorArgExtractor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include "SevenBit/DI/LibraryConfig.hpp"
44

5-
#include "SevenBit/DI/Details/Helpers/ServiceGetter.hpp"
6-
#include "SevenBit/DI/Details/Utils/Meta.hpp"
5+
#include "SevenBit/DI/Details/Meta/ServiceGetter.hpp"
6+
#include "SevenBit/DI/Details/Meta/Meta.hpp"
77

88
namespace sb::di::details
99
{

Include/SevenBit/DI/Details/Helpers/ServiceGetter.hpp renamed to Include/SevenBit/DI/Details/Meta/ServiceGetter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "SevenBit/DI/LibraryConfig.hpp"
77

8-
#include "SevenBit/DI/Details/Utils/Meta.hpp"
8+
#include "SevenBit/DI/Details/Meta/Meta.hpp"
99
#include "SevenBit/DI/ServiceProvider.hpp"
1010

1111
namespace sb::di::details

Include/SevenBit/DI/Details/Utils/Assert.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
#include "SevenBit/DI/LibraryConfig.hpp"
44

5-
#include "SevenBit/DI/Details/Utils/Meta.hpp"
5+
#include "SevenBit/DI/Details/Meta/Meta.hpp"
66

77
namespace sb::di::details
88
{
9-
struct EXPORT Assert
9+
struct Assert
1010
{
1111
template <class Type> static void serviceType()
1212
{

Include/SevenBit/DI/Details/Utils/ContainerUtils.hpp renamed to Include/SevenBit/DI/Details/Utils/Container.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace sb::di::details
88
{
9-
struct ContainerUtils
9+
struct Container
1010
{
1111
template <class ForwardIt, class UnaryPredicate>
1212
static ForwardIt removeIf(ForwardIt first, ForwardIt last, UnaryPredicate &&p)

Include/SevenBit/DI/Details/Utils/StringUtils.hpp renamed to Include/SevenBit/DI/Details/Utils/String.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace sb::di::details
1111
{
12-
struct StringUtils
12+
struct String
1313
{
1414
template <class... Args> static std::string fmt(const std::string_view formatString, Args &&...args)
1515
{

Include/SevenBit/DI/Impl/Exceptions.hpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "SevenBit/DI/LibraryConfig.hpp"
66

7-
#include "SevenBit/DI/Details/Utils/StringUtils.hpp"
7+
#include "SevenBit/DI/Details/Utils/String.hpp"
88
#include "SevenBit/DI/Exceptions.hpp"
99

1010
namespace sb::di
@@ -19,51 +19,48 @@ namespace sb::di
1919
}
2020

2121
INLINE InvalidServiceException::InvalidServiceException(const TypeId typeId)
22-
: InjectorException{details::StringUtils::fmt("Service: '{}' is in not valid state.", typeId.name())}
22+
: InjectorException{details::String::fmt("Service: '{}' is in not valid state.", typeId.name())}
2323
{
2424
}
2525

2626
INLINE CannotReleaseServiceException::CannotReleaseServiceException(const TypeId typeId, std::string_view reason)
27-
: InjectorException{details::StringUtils::fmt("Cannot release ownership of service: '{}', reason: {}.",
28-
typeId.name(), reason)}
27+
: InjectorException{
28+
details::String::fmt("Cannot release ownership of service: '{}', reason: {}.", typeId.name(), reason)}
2929
{
3030
}
3131

3232
INLINE CannotMoveOutServiceException::CannotMoveOutServiceException(const TypeId typeId, std::string_view reason)
33-
: InjectorException{
34-
details::StringUtils::fmt("Cannot move out service: '{}', reason: {}.", typeId.name(), reason)}
33+
: InjectorException{details::String::fmt("Cannot move out service: '{}', reason: {}.", typeId.name(), reason)}
3534
{
3635
}
3736

3837
INLINE ServiceNotFoundException::ServiceNotFoundException(const TypeId typeId, std::string_view reason)
39-
: InjectorException{
40-
details::StringUtils::fmt("Service: '{}' was not found, reason: {}.", typeId.name(), reason)}
38+
: InjectorException{details::String::fmt("Service: '{}' was not found, reason: {}.", typeId.name(), reason)}
4139
{
4240
}
4341

4442
INLINE CircularDependencyException::CircularDependencyException(const TypeId typeId)
4543
: InjectorException{
46-
details::StringUtils::fmt("Circular dependency detected while creating service: '{}'.", typeId.name())}
44+
details::String::fmt("Circular dependency detected while creating service: '{}'.", typeId.name())}
4745
{
4846
}
4947

5048
INLINE ServiceAlreadyRegisteredException::ServiceAlreadyRegisteredException(const TypeId typeId)
51-
: InjectorException{details::StringUtils::fmt("Service: '{}' was already registered.", typeId.name())}
49+
: InjectorException{details::String::fmt("Service: '{}' was already registered.", typeId.name())}
5250
{
5351
}
5452

5553
INLINE ServiceAliasMismatchException::ServiceAliasMismatchException(const TypeId typeId, const TypeId interface,
5654
const bool shouldBeAlias)
57-
: InjectorException{
58-
details::StringUtils::fmt("Service: '{}' should {} alias as other services implementing this "
59-
"interface '{}' that are already registered.",
60-
typeId.name(), (shouldBeAlias ? "be" : "not be"), interface.name())}
55+
: InjectorException{details::String::fmt("Service: '{}' should {} alias as other services implementing this "
56+
"interface '{}' that are already registered.",
57+
typeId.name(), (shouldBeAlias ? "be" : "not be"), interface.name())}
6158
{
6259
}
6360

6461
INLINE ServiceLifeTimeMismatchException::ServiceLifeTimeMismatchException(const TypeId typeId,
6562
const TypeId interface)
66-
: InjectorException{details::StringUtils::fmt(
63+
: InjectorException{details::String::fmt(
6764
"Service: '{}' should have same scope as other services implementing this interface '{}'.", typeId.name(),
6865
interface.name())}
6966
{

Include/SevenBit/DI/OneOrList.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "SevenBit/DI/LibraryConfig.hpp"
88

9-
#include "SevenBit/DI/Details/Utils/Meta.hpp"
9+
#include "SevenBit/DI/Details/Meta/Meta.hpp"
1010

1111
namespace sb::di
1212
{

Include/SevenBit/DI/ServiceCollection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "SevenBit/DI/LibraryConfig.hpp"
99

10-
#include "SevenBit/DI/Details/Utils/ContainerUtils.hpp"
10+
#include "SevenBit/DI/Details/Utils/Container.hpp"
1111
#include "SevenBit/DI/ServiceDescriber.hpp"
1212
#include "SevenBit/DI/ServiceLifeTimes.hpp"
1313
#include "SevenBit/DI/ServiceProvider.hpp"
@@ -348,7 +348,7 @@ namespace sb::di
348348
*/
349349
template <class TPred> std::size_t removeIf(TPred pred)
350350
{
351-
auto it = details::ContainerUtils::removeIf(begin(), end(), std::move(pred));
351+
auto it = details::Container::removeIf(begin(), end(), std::move(pred));
352352
auto r = std::distance(it, end());
353353
removeRange(it, end());
354354
return r;

Tests/Unit/Helpers/ServiceGetterTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "../../Helpers/Classes/Dependencies.hpp"
44
#include "../../Helpers/Mocks/ServiceProviderMock.hpp"
5-
#include <SevenBit/DI/Details/Helpers/ServiceGetter.hpp>
5+
#include <SevenBit/DI/Details/Meta/ServiceGetter.hpp>
66
#include <SevenBit/DI/Details/Services/InPlaceService.hpp>
77
#include <SevenBit/DI/Details/Services/UniquePtrService.hpp>
88

Tests/Unit/Utils/CtorParamsNumberTest.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <gtest/gtest.h>
22

33
#include "../../Helpers/Classes/Complex.hpp"
4-
#include <SevenBit/DI/Details/Utils/CtorParamsNumber.hpp>
4+
#include <SevenBit/DI/Details/Meta/CtorParamsNumber.hpp>
55

66
class CtorParamsNumberTest : public testing::Test
77
{
@@ -51,12 +51,12 @@ struct Ambigious
5151

5252
TEST_F(CtorParamsNumberTest, ShouldGetProperCtorParamsNumber)
5353
{
54-
EXPECT_EQ(sb::di::details::ctorParamsNumber<TestComplexClass1>(), 0);
55-
EXPECT_EQ(sb::di::details::ctorParamsNumber<TestComplexClass2>(), 1);
56-
EXPECT_EQ(sb::di::details::ctorParamsNumber<TestComplexClass3>(), 2);
57-
EXPECT_EQ(sb::di::details::ctorParamsNumber<TestComplexClass4>(), 3);
58-
EXPECT_EQ(sb::di::details::ctorParamsNumber<TestComplexClass5>(), 3);
59-
EXPECT_EQ(sb::di::details::ctorParamsNumber<LotOfParams>(), 13);
60-
EXPECT_EQ(sb::di::details::ctorParamsNumber<LotOfRefs>(), 11);
61-
EXPECT_EQ(sb::di::details::ctorParamsNumber<Ambigious>(), 2);
54+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<TestComplexClass1>, 0);
55+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<TestComplexClass2>, 1);
56+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<TestComplexClass3>, 2);
57+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<TestComplexClass4>, 3);
58+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<TestComplexClass5>, 3);
59+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<LotOfParams>, 13);
60+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<LotOfRefs>, 11);
61+
EXPECT_EQ(sb::di::details::CtorParamsNumber::value<Ambigious>, 2);
6262
}

Tests/Unit/Utils/MetaTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "../../Helpers/Classes/Complex.hpp"
44
#include "../../Helpers/Classes/MultiInherit.hpp"
5-
#include <SevenBit/DI/Details/Utils/Meta.hpp>
5+
#include <SevenBit/DI/Details/Meta/Meta.hpp>
66

77
class MetaTest : public testing::Test
88
{

0 commit comments

Comments
 (0)