-
Notifications
You must be signed in to change notification settings - Fork 2
/
Nominal.h
57 lines (42 loc) · 1.6 KB
/
Nominal.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
#ifndef __NOMINAL_H__
#define __NOMINAL_H__
template<class UnitType, class RepType>
class Nominal
{
public:
Nominal(RepType v) : value_(v) {}
bool operator==(const Nominal<UnitType, RepType>& v) const
{ return value_ == v.value_; }
bool operator!=(const Nominal<UnitType, RepType>& v) const
{ return value_ != v.value_; }
const Nominal<UnitType, RepType>& operator=(const Nominal<UnitType,
RepType>& v)
{ value_ = v.value_; return *this; }
RepType value() const
{ return value_; }
protected:
RepType value_;
};
template<class UnitType, class RepType>
class Ordinal : public Nominal<UnitType, RepType>
{
public:
Ordinal(RepType v) : Nominal<UnitType, RepType>(v) {}
bool operator<(const Ordinal<UnitType, RepType>& v) const
{ return Nominal<UnitType, RepType>::value_ < v.value_; }
bool operator<=(const Ordinal<UnitType, RepType>& v) const
{ return Nominal<UnitType, RepType>::value_ <= v.value_; }
bool operator>(const Ordinal<UnitType, RepType>& v) const
{ return Nominal<UnitType, RepType>::value_ > v.value_; }
bool operator>=(const Ordinal<UnitType, RepType>& v) const
{ return Nominal<UnitType, RepType>::value_ >= v.value_; }
Ordinal<UnitType, RepType> operator+(const Ordinal<UnitType,
RepType>& other)
{ return (Nominal<UnitType, RepType>::value_ + other.value_); }
Ordinal<UnitType, RepType> operator/(const Ordinal<UnitType,
RepType>& other)
{ return (Nominal<UnitType, RepType>::value_ / other.value_); }
const Ordinal<UnitType, RepType>& operator++()
{ ++Nominal<UnitType, RepType>::value_; return *this; }
};
#endif // __NOMINAL_H__