-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHistory.h
81 lines (65 loc) · 1.5 KB
/
History.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
#ifndef BaseLib_Policy_History_h_IsIncluded
#define BaseLib_Policy_History_h_IsIncluded
#include"BaseLib/Templates/BaseTypes.h"
#include"BaseLib/Policy/Lifespan.h"
#include"BaseLib/Export.h"
namespace BaseLib { namespace Policy
{
namespace HistoryKind
{
enum Type
{
KEEP_LAST,
KEEP_ALL
};
}
class DLL_STATE History
: public Templates::ComparableImmutableType<int>
{
private:
History(HistoryKind::Type kind, int depth, Lifespan lifespan)
: Templates::ComparableImmutableType<int>(depth)
, kind_(kind)
, lifespan_(lifespan)
{ }
public:
History()
: Templates::ComparableImmutableType<int>(1)
, kind_(HistoryKind::KEEP_LAST)
, lifespan_(Lifespan::Infinite())
{ }
HistoryKind::Type Kind() const
{
return kind_;
}
Lifespan Lifetime() const
{
return lifespan_;
}
int Depth() const
{
return this->Clone();
}
bool IsKeepAll() const
{
return kind_ == HistoryKind::KEEP_ALL;
}
bool IsKeepLast() const
{
return kind_ == HistoryKind::KEEP_LAST;
}
public:
static History KeepAll(Lifespan lifespan = Lifespan::Infinite())
{
return History(HistoryKind::KEEP_ALL, std::numeric_limits<int>::max(), lifespan);
}
static History KeepLast(int depth, Lifespan lifespan = Lifespan::Infinite())
{
return History(HistoryKind::KEEP_LAST, depth, lifespan);
}
private:
HistoryKind::Type kind_;
Lifespan lifespan_;
};
}}
#endif