Skip to content

Commit 8ae0e71

Browse files
committed
update Exceptions.hpp
1 parent 7db151c commit 8ae0e71

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

.github/workflows/Linux.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ jobs:
9898
- { compiler: { tool: clang, ver: 9 }, std: 23 }
9999
- { compiler: { tool: clang, ver: 10 }, std: 23 }
100100
- { compiler: { tool: clang, ver: 11 }, std: 23 }
101+
- { os: ubuntu-24.04, compiler: { tool: clang, ver: 14 }, std: 20 } # gtest broken for now
102+
- { os: ubuntu-24.04, compiler: { tool: clang, ver: 14 }, std: 23 } # gtest broken for now
103+
- { os: ubuntu-24.04, compiler: { tool: clang, ver: 15 }, std: 20 } # gtest broken for now
104+
- { os: ubuntu-24.04, compiler: { tool: clang, ver: 15 }, std: 23 } # gtest broken for now
105+
- { os: ubuntu-24.04, compiler: { tool: clang, ver: 17 }, std: 23 } # gtest broken for now
101106

102107
runs-on: ${{matrix.os}}
103108
steps:
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <optional>
5+
#include <string>
6+
#include <string_view>
7+
8+
#include "SevenBit/DI/LibraryConfig.hpp"
9+
10+
#include "SevenBit/DI/TypeId.hpp"
11+
12+
namespace sb::di::details
13+
{
14+
template <class T> class ProviderResult
15+
{
16+
public:
17+
enum class Error
18+
{
19+
None,
20+
NotRegistered,
21+
Count
22+
};
23+
24+
private:
25+
T _result;
26+
Error _error;
27+
28+
public:
29+
ProviderResult(T &&result, Error error = Error::None) : _result(std::move(result)), _error(error) {}
30+
ProviderResult(Error error) : _result({}), _error(error) {}
31+
32+
bool isOk() const { return _error == Error::None; }
33+
34+
operator bool() const { return isOk(); };
35+
36+
const T &getResult() const & { return _result; }
37+
T &getResult() & { return _result; }
38+
T &&getResult() && { return std::move(_result); }
39+
40+
const T &operator()() const & { return getResult(); }
41+
T &operator()() & { return getResult(); }
42+
T &&operator()() && { return getResult(); }
43+
44+
Error getError() const { return _error; }
45+
};
46+
} // namespace sb::di::details

Include/SevenBit/DI/Exceptions.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ namespace sb::di
2525

2626
struct EXPORT ServiceRegisterException : InjectorException
2727
{
28-
explicit ServiceRegisterException(TypeId typeId, const std::string &reason);
28+
explicit ServiceRegisterException(TypeId typeId, std::string_view reason);
2929
};
3030

3131
struct EXPORT CannotMoveOutServiceException : InjectorException
3232
{
33-
CannotMoveOutServiceException(TypeId typeId, const std::string &reason);
33+
CannotMoveOutServiceException(TypeId typeId, std::string_view reason);
3434
};
3535

3636
struct EXPORT CannotReleaseServiceException : InjectorException
3737
{
38-
CannotReleaseServiceException(TypeId typeId, const std::string &reason);
38+
CannotReleaseServiceException(TypeId typeId, std::string_view reason);
3939
};
4040

4141
struct EXPORT ServiceNotFoundException : InjectorException
4242
{
43-
ServiceNotFoundException(TypeId typeId, const std::string &reason);
43+
ServiceNotFoundException(TypeId typeId, std::string_view reason);
4444
};
4545

4646
struct EXPORT InvalidServiceException : InjectorException

Include/SevenBit/DI/Impl/Exceptions.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ namespace sb::di
1313

1414
INLINE NullPointerException::NullPointerException(const std::string &why) : InjectorException{why} {}
1515

16-
INLINE ServiceRegisterException::ServiceRegisterException(const TypeId typeId, const std::string &reason)
16+
INLINE ServiceRegisterException::ServiceRegisterException(const TypeId typeId, std::string_view reason)
1717
: InjectorException{details::String::fmt("Cannot register service '{}', reason: {}.", typeId.name(), reason)}
1818
{
1919
}
2020

21-
INLINE ServiceNotFoundException::ServiceNotFoundException(const TypeId typeId, const std::string &reason)
21+
INLINE ServiceNotFoundException::ServiceNotFoundException(const TypeId typeId, std::string_view reason)
2222
: InjectorException{details::String::fmt("Service '{}' was not found, reason: {}.", typeId.name(), reason)}
2323
{
2424
}
2525

26-
INLINE CannotMoveOutServiceException::CannotMoveOutServiceException(const TypeId typeId, const std::string &reason)
26+
INLINE CannotMoveOutServiceException::CannotMoveOutServiceException(const TypeId typeId, std::string_view reason)
2727
: InjectorException{details::String::fmt("Cannot move out service '{}', reason: {}.", typeId.name(), reason)}
2828
{
2929
}
3030

31-
INLINE CannotReleaseServiceException::CannotReleaseServiceException(const TypeId typeId, const std::string &reason)
31+
INLINE CannotReleaseServiceException::CannotReleaseServiceException(const TypeId typeId, std::string_view reason)
3232
: InjectorException{
3333
details::String::fmt("Cannot release ownership of service '{}', reason: {}.", typeId.name(), reason)}
3434
{

0 commit comments

Comments
 (0)