-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathIceCreamSundae.cpp
84 lines (70 loc) · 2.49 KB
/
IceCreamSundae.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "IceCreamSundae.h"
#include <string>
#include <sstream>
#include <iostream>
#include <ostream>
#include <memory>
using namespace Desserts;
using namespace std;
IceCreamSundae::IceCreamSundae(void) : m_flavor(Flavor::None),
m_toppings(Toppings::None),
m_description() {
wcout << L"Default constructing IceCreamSundae(void)." << endl;
}
IceCreamSundae::IceCreamSundae(Flavor flavor) : m_flavor(flavor),
m_toppings(Toppings::None),
m_description() {
wcout << L"Conversion constructing IceCreamSundae(Flavor)." << endl;
}
IceCreamSundae::IceCreamSundae(Toppings::ToppingsList toppings) :
m_flavor(Flavor::None), m_toppings(toppings), m_description() {
wcout << L"Parameter constructing IceCreamSundae(\
Toppings::ToppingsList)." << endl;
}
IceCreamSundae::IceCreamSundae(const IceCreamSundae& other) :
m_flavor(other.m_flavor), m_toppings(other.m_toppings), m_description() {
wcout << L"Copy constructing IceCreamSundae." << endl;
}
IceCreamSundae& IceCreamSundae::operator=(const IceCreamSundae& other) {
wcout << L"Copy assigning IceCreamSundae." << endl;
m_flavor = other.m_flavor;
m_toppings = other.m_toppings;
return *this;
}
IceCreamSundae::IceCreamSundae(IceCreamSundae&& other) : m_flavor(),
m_toppings(),
m_description() {
wcout << L"Move constructing IceCreamSundae." << endl;
*this = std::move(other);
}
IceCreamSundae& IceCreamSundae::operator=(IceCreamSundae&& other) {
wcout << L"Move assigning IceCreamSundae." << endl;
if (this != &other) {
m_flavor = std::move(other.m_flavor);
m_toppings = std::move(other.m_toppings);
m_description = std::move(other.m_description);
other.m_flavor = Flavor::None;
other.m_toppings = Toppings::None;
other.m_description = std::wstring();
}
return *this;
}
IceCreamSundae::~IceCreamSundae(void) {
wcout << L"Destroying IceCreamSundae." << endl;
}
void IceCreamSundae::AddTopping(Toppings::ToppingsList topping) {
m_toppings = m_toppings | topping;
}
void IceCreamSundae::RemoveTopping(Toppings::ToppingsList topping) {
m_toppings = m_toppings & ~topping;
}
void IceCreamSundae::ChangeFlavor(Flavor flavor) {
m_flavor = flavor;
}
const wchar_t* IceCreamSundae::GetSundaeDescription(void) {
wstringstream str;
str << L"A " << GetFlavorString(m_flavor)
<< L" sundae with the following toppings: " << m_toppings.GetString();
m_description = wstring(str.str());
return m_description.c_str();
}