Originally Posted by
Elysia
I don't understand what you're trying to do, or how. You might want to elaborate on that and show some prototype code.
your wish is my command
Code:
template<class T>
class NullableColumnValue
{
public:
NullableColumnValue() : m_isnull(true) { }
NullableColumnValue(const T& t) : m_T(t), m_isnull(false) { }
NullableColumnValue(const NullableColumnValue& rhs) : m_T(rhs.m_T), m_isnull(rhs.m_isnull) { }
~NullableColumnValue() { }
void Value(const T& t) { m_T = t; m_isnull = false; }
void Value(const NullableColumnValue<T>& t) { m_T = t.m_t; m_isnull = t.m_isnull; }
T& Value(void) { if (!m_isnull) return m_T; else throw NullableColumnException("Column value is null."); }
const T& Value(void) const { if (m_isnull) throw NullableColumnException("Column value is null."); else return m_T; }
bool IsNull(void) const { return m_isnull; }
NullableColumnValue& operator = (const T& t) { m_T = t; m_isnull = false; return *this; }
NullableColumnValue& operator = (const NullableColumnValue<T>& t) { m_T = t.m_T; m_isnull = t.false; return *this; }
bool operator == (const NullableColumnValue<T>& t)
{
if (t.m_isnull && m_isnull) return true;
if (t.m_isnull && !m_isnull) return false;
if (!t.m_isnull && m_isnull) return false;
return (t.m_T == m_T);
}
bool operator == (const T& t)
{
if (m_isnull) return false;
return (t == m_T);
}
// the solution I'll probably end up using
T& operator () () { if (!m_isnull) return m_T; else throw NullableColumnException("Column value is null."); }
const T& operator () () const { if (!m_isnull) return m_T; else throw NullableColumnException("Column value is null."); }
// the original idea
operator T () { if (!m_isnull) return m_T; else throw NullableColumnException("Column value is null."); }
operator bool (void) const { if (m_isnull) return false; else return true; }
static NullableColumnValue<T> NullValue(void) { return NullableColumnValue<T>(); }
private:
T m_T;
bool m_isnull;
};