本文整理汇总了C++中FileIO::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ FileIO::Open方法的具体用法?C++ FileIO::Open怎么用?C++ FileIO::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileIO
的用法示例。
在下文中一共展示了FileIO::Open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveShapshot
// ---------------------------------------------------------------------------
// スナップショット保存
//
bool WinCore::SaveShapshot(const char* filename)
{
LockObj lock(this);
bool docomp = !!(config.flag2 & Config::compresssnapshot);
uint size = devlist.GetStatusSize();
uint8* buf = new uint8[docomp ? size * 129 / 64 + 20 : size];
if (!buf)
return false;
memset(buf, 0, size);
if (devlist.SaveStatus(buf))
{
ulong esize = size * 129 / 64 + 20-4;
if (docomp)
{
if (Z_OK != compress(buf+size+4, &esize, buf, size))
{
delete[] buf;
return false;
}
*(int32*) (buf+size) = -(long)esize;
esize += 4;
}
SnapshotHeader ssh;
memcpy(ssh.id, SNAPSHOT_ID, 16);
ssh.major = ssmajor;
ssh.minor = ssminor;
ssh.datasize = size;
ssh.basicmode = config.basicmode;
ssh.clock = int16(config.clock);
ssh.erambanks = uint16(config.erambanks);
ssh.cpumode = int16(config.cpumode);
ssh.mainsubratio = int16(config.mainsubratio);
ssh.flags = config.flags | (esize < size ? 0x80000000 : 0);
ssh.flag2 = config.flag2;
for (uint i=0; i<2; i++)
ssh.disk[i] = (int8) diskmgr->GetCurrentDisk(i);
FileIO file;
if (file.Open(filename, FileIO::create))
{
file.Write(&ssh, sizeof(ssh));
if (esize < size)
file.Write(buf+size, esize);
else
file.Write(buf, size);
}
}
delete[] buf;
return true;
}
示例2: Import
/**
* Loads a saved board from a file
*
* @param fname
* Name of the file to load
* @return
* True if saved board is found and successfully loaded
*/
bool Board::Import(const string & fname) {
FileIO file;
file.SetFileName(fname);
file.Open();
FILEIO_TABLE table = file.GetTable();
if (table.size() == 9) {
FILEIO_TABLE::iterator tableIt = table.begin();
FILEIO_ROW::iterator rowIt = tableIt->begin();
for (int i = 0; i < 9; ++i) {
for (int j = 0; j < 9; ++j) { // Read a row from the table
m_board[j][i] = atoi(rowIt->c_str());
rowIt++;
}
tableIt++;
rowIt = tableIt->begin();
}
return true;
}
else
return false;
}
示例3: LoadShapshot
// ---------------------------------------------------------------------------
// スナップショット復元
//
bool WinCore::LoadShapshot(const char* filename, const char* diskname)
{
LockObj lock(this);
FileIO file;
if (!file.Open(filename, FileIO::readonly))
return false;
SnapshotHeader ssh;
if (file.Read(&ssh, sizeof(ssh)) != sizeof(ssh))
return false;
if (memcmp(ssh.id, SNAPSHOT_ID, 16))
return false;
if (ssh.major != ssmajor || ssh.minor > ssminor)
return false;
// applyconfig
const uint fl1a = Config::subcpucontrol | Config::fullspeed
| Config::enableopna | Config::enablepcg
| Config::fv15k | Config::cpuburst
| Config::cpuclockmode | Config::digitalpalette
| Config::opnona8 | Config::opnaona8
| Config::enablewait;
const uint fl2a = Config::disableopn44;
config.flags = (config.flags & ~fl1a) | (ssh.flags & fl1a);
config.flag2 = (config.flag2 & ~fl2a) | (ssh.flag2 & fl2a);
config.basicmode = ssh.basicmode;
config.clock = ssh.clock;
config.erambanks = ssh.erambanks;
config.cpumode = ssh.cpumode;
config.mainsubratio = ssh.mainsubratio;
ApplyConfig(&config);
// Reset
PC88::Reset();
// 読み込み
uint8* buf = new uint8[ssh.datasize];
bool r = false;
if (buf)
{
bool read = false;
if (ssh.flags & 0x80000000)
{
int32 csize;
file.Read(&csize, 4);
if (csize < 0)
{
csize = -csize;
uint8* cbuf = new uint8[csize];
if (cbuf)
{
ulong bufsize = ssh.datasize;
file.Read(cbuf, csize);
read = uncompress(buf, &bufsize, cbuf, csize) == Z_OK;
delete[] cbuf;
}
}
}
else
read = file.Read(buf, ssh.datasize) == ssh.datasize;
if (read)
{
r = devlist.LoadStatus(buf);
if (r && diskname)
{
for (uint i=0; i<2; i++)
{
diskmgr->Unmount(i);
diskmgr->Mount(i, diskname, false, ssh.disk[i], false);
}
}
if (!r)
{
statusdisplay.Show(70, 3000, "バージョンが異なります");
PC88::Reset();
}
}
delete[] buf;
}
return r;
}
示例4: setInputs
/**
* liest aus der betreffenden Datei die Gewichte raus,
* falls diese nicht existiert wird eine Datei mit Startwerten erzeugt
*/
void CFunction::setInputs()
{
if(function == STEER)
{
char* dat = "steer.ai";
FileIO* fIO = new FileIO();
if(FUNCTION_NEW || !fIO->Open(dat, FILE_READ_MODE))
{
// printf("\n### make highsteer.ai\n");
fIO->Open(dat, FILE_WRITE_MODE);
fIO->PushHeader("steer");
steer[0] = 0.f;
steer[1] = 4.f;
steer[2] = 0.f;
fIO->PushRecord(steer, sizeof(float)*3);
}
else
{
//printf("\n### read highsteer.ai\n");
fIO->Open(dat, FILE_READ_MODE);
fIO->GotoHeader("steer");
fIO->PopRecord(steer);
}
//Test
/*
printf("steer[0]=%f [1]=%f [2]=%f\n",steer[0],steer[1],steer[2]);
*/
}
if(function == HIGHSTEER)
{
char* dat = "highsteer.ai";
FileIO* fIO = new FileIO();
if(FUNCTION_NEW || !fIO->Open(dat, FILE_READ_MODE))
{
// printf("\n### make highsteer.ai\n");
fIO->Open(dat, FILE_WRITE_MODE);
fIO->PushHeader("highsteerAnd11");
highsteerAnd11[0] = -1.f;
highsteerAnd11[1] = 1.f;
highsteerAnd11[2] = 1.f;
fIO->PushRecord(highsteerAnd11, sizeof(float)*3);
fIO->PushHeader("highsteerAndnot12");
highsteerAndnot12[0] = 0.f;
highsteerAndnot12[1] = 2.f;
highsteerAndnot12[2] = -1.f;
fIO->PushRecord(highsteerAndnot12, sizeof(float)*3);
fIO->PushHeader("highsteerOr21");
highsteerOr21[0] = 0.f;
highsteerOr21[1] = 3.f;
highsteerOr21[2] = 3.f;
fIO->PushRecord(highsteerOr21, sizeof(float)*3);
}
else
{
//printf("\n### read highsteer.ai\n");
fIO->Open(dat, FILE_READ_MODE);
fIO->GotoHeader("highsteerAnd11");
fIO->PopRecord(highsteerAnd11);
fIO->GotoHeader("highsteerAndnot12");
fIO->PopRecord(highsteerAndnot12);
fIO->GotoHeader("highsteerOr21");
fIO->PopRecord(highsteerOr21);
}
//Test
/*
printf("highsteerAnd[0]=%f [1]=%f [2]=%f\n",highsteerAnd11[0],highsteerAnd11[1],highsteerAnd11[2]);
printf("highsteerAndnot[0]=%f [1]=%f [2]=%f\n",highsteerAndnot12[0],highsteerAndnot12[1],highsteerAndnot12[2]);
printf("highsteerOr[0]=%f [1]=%f [2]=%f\n",highsteerOr21[0],highsteerOr21[1],highsteerOr21[2]);
*/
}
if(function == SPEED)
{
char* dat = "speed.ai";
FileIO* fIO = new FileIO();
if(FUNCTION_NEW || !fIO->Open(dat, FILE_READ_MODE))
{
//printf("\n### make speed.ai\n");
fIO->Open(dat, FILE_WRITE_MODE);
fIO->PushHeader("speedAnd11");
speedAnd11[0] = -50.f;
speedAnd11[1] = 10.f;
speedAnd11[2] = 1.f;
fIO->PushRecord(speedAnd11, sizeof(float)*3);
fIO->PushHeader("speedAndnot12");
//.........这里部分代码省略.........