Skip to content

Commit 1c937a7

Browse files
committed
Big 5
1 parent 9a8a3fb commit 1c937a7

File tree

1 file changed

+72
-12
lines changed

1 file changed

+72
-12
lines changed

07_SimpleCppApp/main.cpp

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ class FunctionPreCacher
2626
}
2727
}
2828
}
29+
FunctionPreCacher(FunctionPreCacher&& other) noexcept
30+
{
31+
x = other.x;
32+
count = other.count;
33+
function = other.function;
34+
values = other.values;
35+
36+
other.values = nullptr;
37+
}
2938
FunctionPreCacher(int32_t x, uint32_t count, int32_t(*function)(int32_t))
3039
{
3140
Setup(x, count, function);
@@ -46,17 +55,26 @@ class FunctionPreCacher
4655
return *this;
4756
}
4857

49-
void Setup(int32_t x, uint32_t count, int32_t(*function)(int32_t))
58+
FunctionPreCacher& operator=(FunctionPreCacher&& other) noexcept
5059
{
51-
if (!values)
60+
if (this != &other)
5261
{
53-
this->x = x;
54-
this->count = count;
55-
this->function = function;
62+
this->~FunctionPreCacher();
63+
this->FunctionPreCacher::FunctionPreCacher(std::move(other));
5664
}
65+
66+
return *this;
67+
}
68+
69+
void Setup(int32_t x, uint32_t count, int32_t(*function)(int32_t))
70+
{
71+
Release();
72+
this->x = x;
73+
this->count = count;
74+
this->function = function;
5775
}
5876

59-
void Compute()
77+
FunctionPreCacher& Compute()
6078
{
6179
if (function && count > 0)
6280
{
@@ -70,6 +88,8 @@ class FunctionPreCacher
7088
}
7189
}
7290
}
91+
92+
return *this;
7393
}
7494

7595
void Release()
@@ -97,10 +117,47 @@ class FunctionPreCacher
97117
int32_t(*function)(int32_t x) = nullptr;
98118
};
99119

100-
void PrintPc(const FunctionPreCacher& pc)
120+
class PreCacherContainer
101121
{
102-
pc.Print();
103-
}
122+
public:
123+
PreCacherContainer() = default;
124+
PreCacherContainer(const PreCacherContainer&) = default;
125+
PreCacherContainer(PreCacherContainer&&) noexcept = default;
126+
~PreCacherContainer() = default;
127+
128+
PreCacherContainer& operator=(const PreCacherContainer&) = default;
129+
PreCacherContainer& operator=(PreCacherContainer&&) noexcept = default;
130+
131+
void Print() const
132+
{
133+
std::cout << "Container at " << this << std::endl;
134+
for (int i = 0; i < m_usage; i++)
135+
{
136+
std::cout << "FunctionPreCacher #" << (i + 1) << std::endl;
137+
m_preCachers[i].Print();
138+
}
139+
}
140+
141+
void Append(const FunctionPreCacher& pc)
142+
{
143+
if (m_usage < 8)
144+
{
145+
m_preCachers[m_usage++] = pc;
146+
}
147+
}
148+
149+
void Append(FunctionPreCacher&& pc)
150+
{
151+
if (m_usage < 8)
152+
{
153+
m_preCachers[m_usage++] = std::move(pc);
154+
}
155+
}
156+
157+
private:
158+
FunctionPreCacher m_preCachers[8];
159+
int m_usage = 0;
160+
};
104161

105162
int main()
106163
{
@@ -111,7 +168,10 @@ int main()
111168
std::cout << "Enter the itterations: ";
112169
std::cin >> count;
113170

114-
FunctionPreCacher pc(x, count, &f);
115-
pc.Compute();
116-
PrintPc(pc);
171+
PreCacherContainer cnt;
172+
cnt.Append(std::move(FunctionPreCacher(x, count, &f).Compute()));
173+
cnt.Append(std::move(FunctionPreCacher(x * 2, count, &f).Compute()));
174+
cnt.Append(std::move(FunctionPreCacher(x, count * 2, &f).Compute()));
175+
cnt.Append(std::move(FunctionPreCacher(x * 2, count * 2, &f).Compute()));
176+
cnt.Print();
117177
}

0 commit comments

Comments
 (0)