class CMyClass : public Dapfor::Common::CDataObject
{
public:
enum
{
FidPrice,
FidQuantity,
FidTime,
FidCity,
};
enum City
{
London = 100,
Paris,
Totonto,
NewYork,
};
public:
CMyClass();
~CMyClass();
double GetPrice() const;
__int64 GetQuantity() const;
long GetTime() const;
long GetCity() const;
void SetPrice(double newPrice);
void SetQuantity(__int64 newQuantity);
void SetTime(long newTime);
void SetCity(long newCity);
private:
double m_Price;
__int64 m_Quantity;
long m_Time;
City m_City;
DF_DECLARE_FIELD_MAP();
DF_DECLARE_SERIALIZABLE_TYPE();
};
Dapfor::Common::CLongEnumFormat::Item cities[] =
{
{CMyClass::London, "London"},
{CMyClass::Paris, "Paris"},
{CMyClass::Totonto, "Totonto"},
{CMyClass::NewYork, "NewYork"},
};
DF_IMPLEMENT_SERIALIZABLE_TYPE(CMyClass)
DF_BEGIN_FIELD_MAP(CMyClass)
DF_DOUBLE_ID(FidPrice, "Price", &CMyClass::GetPrice, &CMyClass::SetPrice, 0)
DF_INT64_ID (FidQuantity, "Quantity", &CMyClass::GetQuantity, &CMyClass::SetQuantity, 0)
DF_LONG_ID (FidTime, "Time", &CMyClass::GetTime, &CMyClass::SetTime, new CCustomLongFormat())
DF_LONG_ID (FidCity, "City", &CMyClass::GetCity, &CMyClass::SetCity, DF_ENUM_FORMAT(cities))
DF_END_FIELD_MAP()
CMyClass::CMyClass()
{
}
CMyClass::~CMyClass()
{
NotifyDelete();
}
long CMyClass::GetCity() const
{
return m_City;
}
double CMyClass::GetPrice() const
{
return m_Price;
}
__int64 CMyClass::GetQuantity() const
{
return m_Quantity;
}
long CMyClass::GetTime() const
{
return m_Time;
}
void CMyClass::SetPrice(double newPrice)
{
m_Price = newPrice;
NotifyUpdate(FidPrice);
}
void CMyClass::SetQuantity(__int64 newQuantity)
{
m_Quantity = newQuantity;
NotifyUpdate(FidQuantity);
}
void CMyClass::SetTime(long newTime)
{
m_Time = newTime;
NotifyUpdate(FidTime);
}
void CMyClass::SetCity(long newCity)
{
m_City = (City)newCity;
NotifyUpdate(FidCity);
}
CSerializer serializer1(CSerializer::Store);
CMyClass object1;
object1.SetCity(CMyClass::London);
object1.SetPrice(123.12);
object1.SetQuantity(1234);
serializer1 << object1.GetSerializationName();
serializer1 << object1;
long size = serializer1.GetSavingSize();
unsigned char* buffer = new unsigned char[size];
serializer1.SaveToBuffer(buffer);
CSerializer serializer2(CSerializer::Restore);
serializer2.LoadFromBuffer(buffer, size);
delete[] buffer;
std::string name;
serializer2 >> name;
CDataObject* object2 = CTypeFactory::CreateObject(name);
serializer2 >> *object2;
ASSERT(object2->GetLong(CMyClass::FidCity) == CMyClass::London);
ASSERT(object2->GetDouble(CMyClass::FidPrice) == 123.12);
ASSERT(object2->GetInt64(CMyClass::FidQuantity) == 1234);
CMyClass* object3 = (CMyClass*)object2;
ASSERT(object3->GetCity() == CMyClass::London);
ASSERT(object3->GetPrice() == 123.12);
ASSERT(object3->GetQuantity() == 1234);