Simulant
21.12-1275
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
simulant
generic
range_value.h
1
#pragma once
2
3
#include <cstdint>
4
#include <cassert>
5
6
namespace
smlt
{
7
23
template
<
int
min,
int
max,
typename
T=
float
>
24
class
RangeValue
{
25
public
:
26
RangeValue
() =
delete
;
27
RangeValue
(T x):
28
value_(clamp(x)) {}
29
30
RangeValue
(
const
RangeValue
& rhs):
31
value_(rhs.value_) {}
32
33
RangeValue
& operator=(
const
RangeValue
& rhs) {
34
if
(&rhs ==
this
)
return
*
this
;
35
36
value_ = rhs.value_;
37
return
*
this
;
38
}
39
40
operator
T()
const
{
41
return
value_;
42
}
43
44
bool
operator==(
const
RangeValue
& rhs)
const
{
45
return
value_ == rhs.value_;
46
}
47
48
bool
operator!=(
const
RangeValue
& rhs)
const
{
49
return
!(*
this
== rhs);
50
}
51
52
private
:
53
T clamp(T x)
const
{
54
// Debug assertions
55
assert(x >= (T) min);
56
assert(x <= (T) max);
57
58
return
(x < min) ? (T) min:
59
(x > max) ? (T) max : x;
60
}
61
62
T value_ = (T) min;
63
};
64
65
typedef
RangeValue<0, 1>
NormalizedFloat
;
66
typedef
RangeValue<0, 255, uint8_t>
ByteValue
;
67
68
}
smlt
Definition:
animation.cpp:25
smlt::RangeValue
Definition:
range_value.h:24
Generated by
1.8.20