1
0
mirror of https://github.com/Halofreak1990/XFXFramework synced 2024-12-26 13:49:34 +01:00
Tom Lint 742b77c545 Updated project setup
Tidied-up SpriteBatch header- and source file
2014-08-03 22:44:44 +02:00

59 lines
949 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(T const * const 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>();
}