当前位置: 首页>>代码示例>>C++>>正文


C++ serializer::size方法代码示例

本文整理汇总了C++中serializer::size方法的典型用法代码示例。如果您正苦于以下问题:C++ serializer::size方法的具体用法?C++ serializer::size怎么用?C++ serializer::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在serializer的用法示例。


在下文中一共展示了serializer::size方法的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(&current);
  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*)&timestamp[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;
}
开发者ID:ben401,项目名称:OpenEmu,代码行数:52,代码来源:statemanager.cpp


注:本文中的serializer::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。