-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeductorBuilder.cpp
50 lines (38 loc) · 1.18 KB
/
DeductorBuilder.cpp
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
44
45
46
47
48
49
50
#include "DeductorBuilder.h"
namespace UKTax
{
namespace Deductors
{
DeductorBuilder* DeductorBuilder::SetRegion(TaxDatabase::UKRegion region)
{
this->region = region;
this->gotRegion = true;
return this;
}
DeductorBuilder* DeductorBuilder::SetStudentLoanPlan(TaxDatabase::StudentLoanPlan plan)
{
this->hasStudentLoan = true;
this->plan = plan;
return this;
}
DeductorBuilder* DeductorBuilder::SetGross(double gross)
{
if (0.0 >= gross)
throw std::exception();
this->gross = gross;
this->gotGross = true;
return this;
}
std::unique_ptr<BaseTaxDeductor> DeductorBuilder::Build()
{
if (!gotGross || 0.0 >= gross || !gotRegion)
throw std::exception("Attempting to build a deductor without required set parameters.");
std::unique_ptr<BaseTaxDeductor> deductor = std::make_unique<NationalInsuranceDeductor>(gross, region);
BaseTaxDeductor* ptr = nullptr;
ptr = deductor->SetNext(new IncomeTaxDeductor(gross, region));
if (hasStudentLoan)
ptr->SetNext(new StudentLoanDeductor(gross, plan));
return std::move(deductor);
}
};
};