-
Notifications
You must be signed in to change notification settings - Fork 0
/
accountlogger.h
43 lines (39 loc) · 959 Bytes
/
accountlogger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef ACCOUNTLOGGER_H
#define ACCOUNTLOGGER_H
#include <string>
namespace AccountLoggerContext
{
using namespace std::literals;
template<typename T> concept bool ACCOUNT_Constraint = requires(T a) {
{ a.balance() } -> double;
{ a.name() } -> std::string;
};
template<typename T> concept bool LOGGER_Constraint = requires(T a) {
{ a.writeLine(""s) } -> T*;
};
template<typename LOGGER> requires
LOGGER_Constraint<LOGGER>
class AccountLoggerObject
{
public:
AccountLoggerObject(LOGGER* loggerObject) : m_logger(loggerObject) {}
template<typename ACCOUNT> requires
ACCOUNT_Constraint<ACCOUNT>
AccountLoggerObject* write(ACCOUNT* accountObject)
{
m_logger->writeLine("Balance of "s +
accountObject->name() +
": "s +
std::to_string(accountObject->balance()));
return this;
}
AccountLoggerObject* writeLine(const std::string& text)
{
m_logger->writeLine(text);
return this;
}
private:
LOGGER* m_logger;
};
}
#endif