1
0
mirror of https://github.com/Halofreak1990/XFXFramework synced 2024-12-26 13:49:34 +01:00
Tom Lint 245a1b1034 Updated System::Nullable
Replaced sourceRectangle parameter with Nullable
2013-06-01 16:04:30 +02:00

54 lines
869 B
C++

namespace System
{
// Represents an object whose underlying type is a value type that can also be assigned null like a reference type.
template <typename T>
class Nullable
{
private:
T* data;
public:
static const Nullable<T> Null;
Nullable()
: data(null)
{
}
Nullable(const T& newData)
: data(const_cast<T*>(&newData))
{
}
Nullable(const Nullable<T> &obj)
: data(obj.data)
{
}
bool HasValue() const { return (data != null); }
T getValue() const { return *data; }
operator T() const { return *data; }
Nullable<T>& operator =(const T * newVal)
{
data = newVal;
return *this;
}
Nullable<T>& operator =(const Nullable<T>& right)
{
if (right == *this)
goto end;
*data = *right.data;
end:
return *this;
}
};
template <typename T>
const Nullable<T> Nullable<T>::Null = Nullable<T>();
}