#include <PhxTemplates.h>
Public Member Functions | |
| ValueType (T val) | |
| bool | operator== (const ValueType< TypeName, T > &rhs) const |
| bool | operator!= (const ValueType< TypeName, T > &rhs) const |
| bool | operator< (const ValueType< TypeName, T > &rhs) const |
| bool | operator<= (const ValueType< TypeName, T > &rhs) const |
| bool | operator> (const ValueType< TypeName, T > &rhs) const |
| bool | operator>= (const ValueType< TypeName, T > &rhs) const |
|
const ValueType< TypeName, T > & | operator= (const ValueType< TypeName, T > &rhs) |
| T | value () const |
| void | value (T v) |
The purpose of this class is to provide additional type safety and impose additional restrictions on the use of primitive types. Rather than simply typedef'ing types from primitives (like int or double), we encapsulate them in a class. This prevents accidental type conversions. The primary purpose of this class is to serve as a base for more complicated, safe value types.
Standard value types are characterized as types which represent quantities that are == comparable and assignable. Examples include Kilograms, AircraftSerialNumber. Examples of types that are NOT value types include Aircraft, Timer. While it is true that one _could_ define =/== for a Timer and Aircraft class, the semantics are specific to how that class was implemented -- it isn't clear from looking at either class _exactly_ when two instances are equal. Value types, however, encapsulating just one value with a specific meaning make it clear exactly when two objects will compare as equal.
class KilogramsClass; typedef ValueType<KilogramsClass, double> Kilograms;
The default constructor sets the internal value to 0. Clearly this means that any type for which a statement of the form: T t(0); is not legal will not work as a type for this class.
1.4.2