class CCustomLongFormat : public Dapfor::Common::CFormat
{
public:
CCustomLongFormat();
virtual std::string Format(long val, const Dapfor::Common::CDataObject* pDO) const;
virtual bool Parse(const std::string& str, long& val, const Dapfor::Common::CDataObject* pDO) const;
virtual Dapfor::Common::CFormat* Clone() const;
};
CCustomLongFormat::CCustomLongFormat() : Dapfor::Common::CFormat(Dapfor::Common::Long)
{
}
std::string CCustomLongFormat::Format(long val, const Dapfor::Common::CDataObject* pDO) const
{
switch(val)
{
case 0: return "Zero";
case 1: return "One";
case 2: return "Two";
}
return "";
}
bool CCustomLongFormat::Parse(const std::string& str, long& val, const Dapfor::Common::CDataObject* pDO) const
{
if(str == "Zero")
{
val = 0;
return true;
}
if(str == "One")
{
val = 1;
return true;
}
if(str == "Two")
{
val = 2;
return true;
}
return false;
}
Dapfor::Common::CFormat* CCustomLongFormat::Clone() const
{
return new CCustomLongFormat();
}
DF_BEGIN_FIELD_MAP(CMyClass)
...
DF_LONG_ID (MyFid, "Custom format", &CMyClass::GetMyLong, 0, new CCustomLongFormat())
...
DF_END_FIELD_MAP()