-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathControl04.cpp
More file actions
59 lines (45 loc) · 1.69 KB
/
Control04.cpp
File metadata and controls
59 lines (45 loc) · 1.69 KB
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
// ===========================================================================
// Control.cpp - Pimpl Idiom with separate header file
// ===========================================================================
#include <iostream>
#include <string>
#include <memory>
#include "ControlPimpl.h"
#include "Control.h"
namespace PimplVariantWithSeparateHeaderFile {
// ===========================================================
// main class methods
// default c'tor
Control::Control() : m_pimpl(std::make_unique<ControlPimpl>()) {}
Control::~Control() = default; // due to 'can't delete an incomplete type'
// move semantics - using default behaviour
Control::Control(Control&&) noexcept = default;
Control& Control::operator=(Control&&) noexcept = default;
// copy semantics - using (automatically generated) public copy constructor of ControlPimpl
Control::Control(const Control& op) : m_pimpl{ new ControlPimpl(*op.m_pimpl) } {}
Control& Control::operator=(const Control& op) {
if (this != &op) {
m_pimpl = std::unique_ptr<ControlPimpl>(new ControlPimpl(*op.m_pimpl));
}
return *this;
}
// remaining member functions
void Control::setText(const std::string& text)
{
m_pimpl->setText(text);
}
void Control::resize(const int width, const int height)
{
m_pimpl->resize(width, height);
}
void Control::show()
{
m_pimpl->show();
}
void Control::hide() {
m_pimpl->hide();
}
}
// ===========================================================================
// End-of-File
// ===========================================================================