![]() |
Simulant
21.12-1292
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
|
#include <range_value.h>
Public Member Functions | |
RangeValue (T x) | |
RangeValue (const RangeValue &rhs) | |
RangeValue & | operator= (const RangeValue &rhs) |
operator T () const | |
bool | operator== (const RangeValue &rhs) const |
bool | operator!= (const RangeValue &rhs) const |
Lots of methods have arguments which must be clamped to a range. Using a 'float' or 'int' doesn't convey that via the API, and it means every method must do its own clamping. This template class allows you to specify a range (and type) for arguments and automatically clamps to the range. e.g.
void set_some_value(RangeValue<0, 1> value);
or
void set_some_byte(RangeValue<0, 255, uint8_t> value);
Now it's clear what the value should be.