-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.h
85 lines (63 loc) · 1.94 KB
/
State.h
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
85
//============================================================================
// Name : State.h
// Created on : 15.04.2020
// Author : Tokmakov Andrey
// Version : 1.0
// Copyright : Your copyright notice
// Description : State pattern tests
//============================================================================
#ifndef STATE_PATTERN_TESTS__H_
#define STATE_PATTERN_TESTS__H_
#include <iostream>
#include <string>
#include <memory>
namespace State_Pattern_Tests {
class StateContext;
using String = std::string;
using CString = const String&;
class IState {
public:
virtual const String GetName() const noexcept = 0;
virtual void Freeze(std::shared_ptr<StateContext> context) = 0;
virtual void Heat(std::shared_ptr<StateContext> context) = 0;
};
class State : public IState {
private:
String name;
public:
State(CString name);
virtual const String GetName() const noexcept override;
};
class StateContext : public std::enable_shared_from_this<StateContext>{
private:
std::unique_ptr<IState> state;
public:
StateContext(std::unique_ptr<IState> state);
virtual ~StateContext();
public:
void Freeze();
void Heat();
void SetState(std::unique_ptr<IState> state) noexcept;
std::unique_ptr<IState> GetState() noexcept;
};
class SolidState : public State {
public:
SolidState();
virtual void Freeze(std::shared_ptr<StateContext> context);
virtual void Heat(std::shared_ptr<StateContext> context);
};
class LiquidState : public State {
public:
LiquidState();
virtual void Freeze(std::shared_ptr<StateContext> context);
virtual void Heat(std::shared_ptr<StateContext> context);
};
class GasState : public State {
public:
GasState();
virtual void Freeze(std::shared_ptr<StateContext> context);
virtual void Heat(std::shared_ptr<StateContext> context);
};
void Test();
}
#endif /* STATE_PATTERN_TESTS__H_ */