Realization of Stream class version control in CB

Source: Internet
Author: User

To make a class A stream class, you first define two member functions Savetostream and Loadfromstream for the class, (how to define see "Simplified handling of stream Class I/O") and then consider the version of the stream in both functions. Examples are as follows:

Class tsome{
Private
int num;
Double sum;
Public
void Savetostream (Tstream*stream)
{///function code needs to see "stream Class I/O simplified processing"
Tdataio < int > (0x10001) >> stream;//Storage Version number 1.1
Tdataio < int > (num) >> stream;//storage num
Tdataio < double > (sum) >> stream;//storage sum
}
void Loadfromstream (Tstream*stream)
{
int Ver=tdataio < int > () << stream;//Read version number
if (ver==0x10001) {
Num=tdataio < int > () << stream;//Read num
Sum=tdataio < double > () << stream;//read sum
}else if (ver==0x10002) {
Here to deal with another version ....
}//end If-else
}//end LoadFrom ...
Other code in class ...
};//end class

--------------------------------------------------------------------------------

When a member of a class changes, it is only necessary to record the corresponding change and give an internal version number that provides the read/save code for each build in the I/O function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.