-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeasePlan.h
97 lines (79 loc) · 2.06 KB
/
LeasePlan.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
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "BaseLib/Collection/ISet.h"
#include"BaseLib/Export.h"
namespace BaseLib { namespace Policy {
enum class DLL_STATE LeasePlanKind : short
{
RENEW_ON_ACCESS = 1,
RENEW_ON_WRITE = 2,
RENEW_ON_READ = 3,
NO_RENEW = 4
};
/**
* Automatic renew or terminate LeasePlan policy upon update of cached objects
*
* TODO: Is Kind logical in a lease? Other kinds? Periodic, indefinite, fixed, subscription?
*/
class DLL_STATE LeasePlan
: protected Collection::ISet<LeasePlanKind>
{
public:
LeasePlan(LeasePlanKind kind)
: Collection::ISet<LeasePlanKind>(kind)
{ }
LeasePlan(std::set<LeasePlanKind> kinds)
: Collection::ISet<LeasePlanKind>(kinds)
{ }
virtual ~LeasePlan()
{ }
bool IsRenewOnAccess() const
{
return this->contains(LeasePlanKind::RENEW_ON_ACCESS);
}
bool IsRenewOnWrite() const
{
return this->contains(LeasePlanKind::RENEW_ON_WRITE);
}
bool IsRenewOnRead() const
{
return this->contains(LeasePlanKind::RENEW_ON_READ);
}
bool IsNoRenew() const
{
return this->contains(LeasePlanKind::NO_RENEW);
}
// --------------------------------------------
// Static constructors
// --------------------------------------------
static LeasePlan NoRenew()
{
return LeasePlan(LeasePlanKind::NO_RENEW);
}
static LeasePlan RenewOnAccess()
{
return LeasePlan(LeasePlanKind::RENEW_ON_ACCESS);
}
static LeasePlan RenewOnWrite()
{
return LeasePlan(LeasePlanKind::RENEW_ON_WRITE);
}
static LeasePlan RenewOnRead()
{
return LeasePlan(LeasePlanKind::RENEW_ON_READ);
}
friend std::ostream& operator<<(std::ostream &ostr, const LeasePlanKind &kind)
{
ostr << (int)kind;
return ostr;
}
friend std::ostream& operator<<(std::ostream &ostr, const LeasePlan &leasePlan)
{
ostr << "LeasePlan: ";
for(const auto &kind : leasePlan)
{
ostr << (int)kind;
}
return ostr;
}
};
}}