Public Types | |
enum | Mode { Store, Restore } |
Working mode. More... | |
Public Member Functions | |
CSerializer (Mode mode) | |
Constructor. | |
CSerializer (const CSerializer &serializer) | |
Copy constructor. | |
~CSerializer () | |
Destructor. | |
bool | Write (void *buf, int len) |
Writes bytes to the serializer. | |
bool | Read (void *buf, int len) |
Reads bytes from the serializer. | |
int | SaveToBuffer (void *buffer) const |
Copies serialized data to a binary buffer. | |
void | LoadFromBuffer (const void *buffer, int size) |
Loads data from a binary buffer. | |
int | GetSavingSize () const |
Gets the size of the buffer needed to copy serialized data. | |
Mode | GetMode () const |
Gets a mode. | |
void | Clear () |
Clears all serialized data. | |
CSerializer & | operator= (const CSerializer &serializer) |
Copy an operator. | |
Insertion operators | |
CSerializer & | operator<< (char v) |
Writes char-type value to the serializer. | |
CSerializer & | operator<< (unsigned char v) |
Writes unsigned char-type value to the serializer. | |
CSerializer & | operator<< (short v) |
Writes short-type value to the serializer. | |
CSerializer & | operator<< (unsigned short v) |
Writes unsigned short-type value to the serializer. | |
CSerializer & | operator<< (long v) |
Writes long-type value to the serializer. | |
CSerializer & | operator<< (unsigned long v) |
Writes unsigned long-type value to the serializer. | |
CSerializer & | operator<< (int v) |
Writes int-type value to the serializer. | |
CSerializer & | operator<< (unsigned int v) |
Writes unsigned int-type value to the serializer. | |
CSerializer & | operator<< (int64 v) |
Writes __int64-type value to the serializer. | |
CSerializer & | operator<< (float v) |
Writes float-type value to the serializer. | |
CSerializer & | operator<< (double v) |
Writes double-type value to the serializer. | |
CSerializer & | operator<< (bool v) |
Writes bool-type value to the serializer. | |
CSerializer & | operator<< (const CString &v) |
Writes MFC string - type value to the serializer. | |
CSerializer & | operator<< (const TString &v) |
Writes STL string - type value to the serializer. | |
CSerializer & | operator<< (const CValue &v) |
Writes an object of CValue class to the serializer. | |
CSerializer & | operator<< (const CDataObject &v) |
Writes CDataObject instance to the serializer. | |
CSerializer & | operator<< (const CFormat &v) |
Writes an object of CFormat class to the serializer. | |
Extraction operators | |
CSerializer & | operator>> (char &v) |
Reads char-type value from the serializer. | |
CSerializer & | operator>> (unsigned char &v) |
Reads unsigned char-type value from the serializer. | |
CSerializer & | operator>> (short &v) |
Reads short-type value from the serializer. | |
CSerializer & | operator>> (unsigned short &v) |
Reads unsigned short-type value from the serializer. | |
CSerializer & | operator>> (long &v) |
Reads long-type value from the serializer. | |
CSerializer & | operator>> (unsigned long &v) |
Reads unsigned long-type value from the serializer. | |
CSerializer & | operator>> (int &v) |
Reads int-type value from the serializer. | |
CSerializer & | operator>> (unsigned int &v) |
Reads unsigned int-type value from the serializer. | |
CSerializer & | operator>> (int64 &v) |
Reads __int64-type value from the serializer. | |
CSerializer & | operator>> (float &v) |
Reads float-type value from the serializer. | |
CSerializer & | operator>> (double &v) |
Reads double-type value from the serializer. | |
CSerializer & | operator>> (bool &v) |
Reads bool-type value from the serializer. | |
CSerializer & | operator>> (CString &v) |
Reads MFC string - type value from the serializer. | |
CSerializer & | operator>> (TString &v) |
Reads STL string - type value from the serializer. | |
CSerializer & | operator>> (CValue &v) |
Reads an object of CValue class from the serializer. | |
CSerializer & | operator>> (CDataObject &v) |
Reads CDataObject instance from the serializer. | |
CSerializer & | operator>> (CFormat &v) |
Reads an object of CFormat class from the serializer. | |
Classes | |
struct | BadVersionException |
Thrown when an object tries to restore itself from the archive with a version greater than the maximum supported. More... | |
struct | NotSupportedException |
Thrown when an object doesn't support serialization. More... | |
struct | SerializationException |
Base class for serialization exceptions. More... |
//For serialization an object should implement pairs of Get- and Set- methods. //MyClass.h file //This is a declaration of class, an instance of which can be serialized and deserialized to/from the binary form. //The class has pairs of Set- and Get- methods that can be called by their identifiers. Also it has a default constructor. class CMyClass : public Dapfor::Common::CDataObject { public: //It is better to use enumerations instead of long numeric values... //The grid can use the same identifiers to display values returned by //functions of the class. enum { FidPrice, FidQuantity, FidTime, FidCity, }; //Some cities... enum City { London = 100, Paris, Totonto, NewYork, }; public: CMyClass(); ~CMyClass(); //Get- methods double GetPrice() const; __int64 GetQuantity() const; long GetTime() const; long GetCity() const; //Set- methods void SetPrice(double newPrice); void SetQuantity(__int64 newQuantity); void SetTime(long newTime); void SetCity(long newCity); private: //Private fields double m_Price; __int64 m_Quantity; long m_Time; City m_City; //Fieldmap declaration. DF_DECLARE_FIELD_MAP(); //Serializable type declaration. DF_DECLARE_SERIALIZABLE_TYPE(); }; //MyClass.cpp file // Enum format strings Dapfor::Common::CLongEnumFormat::Item cities[] = { {CMyClass::London, "London"}, {CMyClass::Paris, "Paris"}, {CMyClass::Totonto, "Totonto"}, {CMyClass::NewYork, "NewYork"}, }; // Declaration of a field map. // To put an object of CMyClass class into the grid, it is necessary to declare a table enabling calls of specified functions by identifiers. // Each data field should have a pair of Set and Get- functions. 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() { } //Virtual destructor CMyClass::~CMyClass() { //Object ends the life cycle. 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); } //How to serialize and deserialize a data object: //Create a serializer to store a data object CSerializer serializer1(CSerializer::Store); //Our data object CMyClass object1; object1.SetCity(CMyClass::London); object1.SetPrice(123.12); object1.SetQuantity(1234); //Serialize the name of the class serializer1 << object1.GetSerializationName(); //Serialize the data object itself serializer1 << object1; //Copy data to the binary buffer long size = serializer1.GetSavingSize(); unsigned char* buffer = new unsigned char[size]; serializer1.SaveToBuffer(buffer); //Create a new serializer CSerializer serializer2(CSerializer::Restore); //Load data from the buffer serializer2.LoadFromBuffer(buffer, size); delete[] buffer; //Restore the class name std::string name; serializer2 >> name; //Try to create a new data object CDataObject* object2 = CTypeFactory::CreateObject(name); //Deserialise the object itself serializer2 >> *object2; //The object is created and deserialized. //To access to the data object without casting we can use field identifiers ASSERT(object2->GetLong(CMyClass::FidCity) == CMyClass::London); ASSERT(object2->GetDouble(CMyClass::FidPrice) == 123.12); ASSERT(object2->GetInt64(CMyClass::FidQuantity) == 1234); //There is another way to call methods: We can cast the type to the CMyClass. //If RTTI is enabled, we can use dynamic_cast<> operator. CMyClass* object3 = (CMyClass*)object2; ASSERT(object3->GetCity() == CMyClass::London); ASSERT(object3->GetPrice() == 123.12); ASSERT(object3->GetQuantity() == 1234);
enum Mode |
CSerializer | ( | Mode | mode | ) |
Constructor.
[in] | mode | Serialization mode |
CSerializer | ( | const CSerializer & | serializer | ) |
Copy constructor.
[in] | serializer | Reference to the serializer to be copied. |
bool Write | ( | void * | buf, | |
int | len | |||
) |
Writes bytes to the serializer.
[in] | buf | Pointer to the buffer. |
[in] | len | Length of the buffer |
SerializationException |
CSerializer & operator<< | ( | char | v | ) |
Writes char-type value to the serializer.
[in] | v | Char type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | unsigned char | v | ) |
Writes unsigned char-type value to the serializer.
[in] | v | Unsigned char type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | short | v | ) |
Writes short-type value to the serializer.
[in] | v | Short type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | unsigned short | v | ) |
Writes unsigned short-type value to the serializer.
[in] | v | Unsigned short type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | long | v | ) |
Writes long-type value to the serializer.
[in] | v | Long type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | unsigned long | v | ) |
Writes unsigned long-type value to the serializer.
[in] | v | Unsigned long type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | int | v | ) |
Writes int-type value to the serializer.
[in] | v | Int type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | unsigned int | v | ) |
Writes unsigned int-type value to the serializer.
[in] | v | Unsigned int type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | int64 | v | ) |
Writes __int64-type value to the serializer.
[in] | v | __int64 type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | float | v | ) |
Writes float-type value to the serializer.
[in] | v | Float type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | double | v | ) |
Writes double-type value to the serializer.
[in] | v | Double type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | bool | v | ) |
Writes bool-type value to the serializer.
[in] | v | Bool type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | const CString & | v | ) |
Writes MFC string - type value to the serializer.
[in] | v | MFC string type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | const TString & | v | ) |
Writes STL string - type value to the serializer.
[in] | v | STL string type value to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | const CValue & | v | ) |
Writes an object of CValue class to the serializer.
[in] | v | Object of CValue type to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | const CDataObject & | v | ) |
Writes CDataObject instance to the serializer.
[in] | v | CDataObject to be serialized to the serializer. |
SerializationException |
CSerializer & operator<< | ( | const CFormat & | v | ) |
Writes an object of CFormat class to the serializer.
[in] | v | CFormat to be serialized to the serializer. |
SerializationException |
bool Read | ( | void * | buf, | |
int | len | |||
) |
Reads bytes from the serializer.
[in] | buf | Pointer to the buffer to which the data is copied. |
[in] | len | Length of the buffer |
SerializationException |
CSerializer & operator>> | ( | char & | v | ) |
Reads char-type value from the serializer.
[in] | v | Char type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | unsigned char & | v | ) |
Reads unsigned char-type value from the serializer.
[in] | v | Unsigned char type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | short & | v | ) |
Reads short-type value from the serializer.
[in] | v | Short type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | unsigned short & | v | ) |
Reads unsigned short-type value from the serializer.
[in] | v | Unsigned short type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | long & | v | ) |
Reads long-type value from the serializer.
[in] | v | Long type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | unsigned long & | v | ) |
Reads unsigned long-type value from the serializer.
[in] | v | Unsigned long type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | int & | v | ) |
Reads int-type value from the serializer.
[in] | v | Int type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | unsigned int & | v | ) |
Reads unsigned int-type value from the serializer.
[in] | v | Unsigned int type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | int64 & | v | ) |
Reads __int64-type value from the serializer.
[in] | v | __int64 type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | float & | v | ) |
Reads float-type value from the serializer.
[in] | v | Float type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | double & | v | ) |
Reads double-type value from the serializer.
[in] | v | Double type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | bool & | v | ) |
Reads bool-type value from the serializer.
[in] | v | Bool type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | CString & | v | ) |
Reads MFC string - type value from the serializer.
[in] | v | string type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | TString & | v | ) |
Reads STL string - type value from the serializer.
[in] | v | string type value that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | CValue & | v | ) |
Reads an object of CValue class from the serializer.
[in] | v | CValue type object that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | CDataObject & | v | ) |
Reads CDataObject instance from the serializer.
[in] | v | CDataObject that is read from the serializer. |
SerializationException |
CSerializer & operator>> | ( | CFormat & | v | ) |
Reads an object of CFormat class from the serializer.
[in] | v | CFormat type object that is read from the serializer. |
SerializationException |
int SaveToBuffer | ( | void * | buffer | ) | const |
Copies serialized data to a binary buffer.
[in] | buffer | Pointer to the buffer where serialized data is copied. |
SerializationException |
void LoadFromBuffer | ( | const void * | buffer, | |
int | maxSize | |||
) |
Loads data from a binary buffer.
[in] | buffer | Pointer to the buffer from which serialized data is copied. |
[in] | maxSize | Size of the buffer. |
SerializationException |
int GetSavingSize | ( | ) | const |
Gets the size of the buffer needed to copy serialized data.
CSerializer::Mode GetMode | ( | ) | const |
Gets a mode.
CSerializer & operator= | ( | const CSerializer & | serializer | ) |
Copy an operator.
[in] | serializer | Reference to the serializer to be copied. |
Copyright Dapfor 2007-2009 | Generated on Wed Jul 7 03:24:43 2010 for MFCGrid by 1.5.5 |