forked from der-freddy/software-engineering-ws15
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.cpp
More file actions
45 lines (39 loc) · 773 Bytes
/
decorator.cpp
File metadata and controls
45 lines (39 loc) · 773 Bytes
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
#include "decorator.hpp"
Decorator::Decorator(std::shared_ptr<UnitConverter> c, std::string unit1,
std::string unit2, double factor):
UnitConverter(unit1, unit2, factor),
m_wrappee(c)
{}
Decorator::Decorator(std::shared_ptr<UnitConverter> c):
UnitConverter(),
m_wrappee(c)
{}
Decorator::~Decorator()
{
m_wrappee.reset();
}
double Decorator::convert(double inValue) const
{
if(m_wrappee != NULL)
return m_wrappee->convert(inValue);
else
return inValue;
}
std::string Decorator::toString() const
{
if(m_wrappee != NULL)
return m_wrappee->toString() + " and ";
else
return "";
}
void Decorator::link(std::shared_ptr<UnitConverter> c)
{
if (c != NULL)
{
m_wrappee = c;
}
else
{
throw std::invalid_argument("");
}
}