本文整理汇总了C++中serializer::data方法的典型用法代码示例。如果您正苦于以下问题:C++ serializer::data方法的具体用法?C++ serializer::data怎么用?C++ serializer::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类serializer
的用法示例。
在下文中一共展示了serializer::data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
bool StateManager::save(const char *filename, uint8 slot, serializer &s, const char *description) {
//if no state archive exists ...
if(file::exists(filename) == false) {
//try and create one
if(create(filename) == false) return false;
}
//if we cannot load the existing state archive ...
if(load(filename) == false) {
//it's probably an older version, try and create a new one
if(create(filename) == false) return false;
//it still needs to be loaded before we can write to it
if(load(filename) == false) return false;
}
uint8 index = findslot(slot);
if(index == SlotInvalid) {
//create new slot instead of over-writing existing slot
if(info.slotcount >= 255) return false;
index = info.slotcount;
slot = info.slotcount;
}
file fp;
if(fp.open(filename, file::mode_readwrite) == false) return false;
fp.seek(SlotIndex + index);
fp.write(slot);
time_t current = time(0);
tm *ts = localtime(¤t);
char timestamp[32];
sprintf(timestamp, "%.4u-%.2u-%.2u %.2u:%.2u:%.2u",
1900 + ts->tm_year, ts->tm_mon + 1, ts->tm_mday,
ts->tm_hour, ts->tm_min, ts->tm_sec,
(ts->tm_hour < 12 ? "AM" : "PM")
);
fp.seek(DateTimeIndex + index * DateTimeSize);
fp.write((uint8*)×tamp[0], DateTimeSize);
char desc[DescriptionSize];
memset(&desc, 0, DescriptionSize);
strlcpy(desc, description, DescriptionSize);
fp.seek(DescIndex + index * DescriptionSize);
fp.write((uint8*)&desc[0], DescriptionSize);
fp.seek(HeaderSize + index * system.serialize_size);
fp.write(s.data(), s.size());
for(unsigned n = 0; n < system.serialize_size - s.size(); n++) fp.write(0x00);
fp.close();
return true;
}