Listing 1
class Field
{
/// \name Construction
private:
this(char[] name, char[] value)
in
{
assert(null !== name);
assert(null !== value);
}
body
{
m_name = name;
m_value = value;
}
/// \name Attributes
public:
char[] name()
{
return m_name;
}
char[] value()
{
return m_value;
}
Record record()
{
return m_record;
}
/// \name Comparison
public:
int opCmp(Object rhs)
{
Field f = cast(Field)(rhs);
if(null === f)
{
throw new InvalidTypeException("Attempt to compare a Field
with an instance of another type");
}
return opCmp(f);
}
public:
int opCmp(Field rhs)
{
int res;
if(this === rhs)
{
res = 0;
}
else
{
res = std.string.cmp(m_name, rhs.m_name);
if(0 == res)
{
res = std.string.cmp(m_value, rhs.m_value);
}
}
return res;
}
// Members
private:
char[] m_name;
char[] m_value;
Record m_record;
}