-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCount.h
66 lines (51 loc) · 1.23 KB
/
Count.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
#pragma once
#include"BaseLib/Templates/BaseTypes.h"
#include"BaseLib/Export.h"
namespace BaseLib {
template <typename T>
class CountType : public Templates::ComparableMutableType<T>
{
public:
CountType()
: Templates::ComparableMutableType<T>()
{ }
CountType(T count)
: Templates::ComparableMutableType<T>(count)
{ }
virtual ~CountType()
{ }
T Number() const
{
return this->delegate();
}
bool IsZero() const
{
return this->delegate() == 0;
}
// ---------------------------------------
// Factory functions
// ---------------------------------------
static CountType<T> Infinite()
{
return CountType<T>(std::numeric_limits<T>::max());
}
static CountType<T> Create(T count)
{
return CountType<T>(count);
}
static CountType<T> Zero()
{
return CountType<T>();
}
// ---------------------------------------
// print out
// ---------------------------------------
friend std::ostream& operator<<(std::ostream& ostr, const CountType<T>& count)
{
ostr << count.delegate();
return ostr;
}
};
typedef CountType<int> Count;
typedef CountType<int64> CountInt64;
}