本文整理汇总了C++中IWriteFile类的典型用法代码示例。如果您正苦于以下问题:C++ IWriteFile类的具体用法?C++ IWriteFile怎么用?C++ IWriteFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IWriteFile类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFilename
bool CBinaryFontWriter::onWriteFontFile( const SFontInfo& fontInfo )
{
std::string filename = getFilename() + ".xft";
IWriteFile* writer = device->getFileSystem()->createAndWriteFile(filename.c_str());
writeT(writer, 0xabcdefff);
writeT(writer, (int) FONT_VERSION);
writeT(writer, useAlphaChannel);
writeT(writer, fontInfo.images.size());
std::string imageName;
for (u32 i = 0; i < fontInfo.images.size(); ++i)
{
imageName = getImageName(i);
// write image
writeT(writer, imageName.size());
writer->write(imageName.c_str(), imageName.size());
}
// write charmap
writeT(writer, fontInfo.charMap.size());
for (const std::pair<wchar_t, SFontArea>& chToarea : fontInfo.charMap)
writeT(writer, chToarea);
writer->drop();
return true;
}
示例2: createAndWriteFile
//! Creates a XML Writer from a file.
IXMLWriter* CFileSystem::createXMLWriter(const c8* filename)
{
IWriteFile* file = createAndWriteFile(filename);
IXMLWriter* writer = createXMLWriter(file);
file->drop();
return writer;
}
示例3: writeText
void IXMLWriterTest::writeText()
{
IWriteFile* fWrite = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite);
if (fWrite)
fWrite->drop();
fxml->writeElement("fff", false);
fxml->writeText("text text text");
fxml->writeClosingTag("fff");
if (fxml)
fxml->drop();
IReadFile* fRead = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead);
fxmlR->read();
fxmlR->read();
if (fxmlR->getNodeType() != EXNT_TEXT)
mes.append("\n writeText: element text is not created");
core::stringc strND = core::stringc("text text text");
if (!strND.equalsn(fxmlR->getNodeData(), 14))
mes.append(
"\n writeText: correctly writes text content of the");
if (fxmlR)
fxmlR->drop();
}
示例4: writeXMLHeader
void IXMLWriterTest::writeXMLHeader()
{
IWriteFile* fWrite = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite);
if (fWrite)
fWrite->drop();
fxml->writeXMLHeader();
if (fxml)
fxml->drop();
IReadFile* fRead = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead);
fxmlR->read();
if (fxmlR->getNodeType() != EXNT_UNKNOWN)
mes.append(
"\n writeXMLHeader: does not write the XMLHeader");
if (fxmlR)
fxmlR->drop();
if (fRead)
fRead->drop();
}
示例5: writeClosingTag
void IXMLWriterTest::writeClosingTag()
{
IWriteFile* fWrite = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite);
if (fWrite)
fWrite->drop();
fxml->writeClosingTag("fff");
if (fxml)
fxml->drop();
IReadFile* fRead = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead);
fxmlR->read();
if (fxmlR->getNodeType() != EXNT_ELEMENT_END)
mes.append(
"\n writeClosingTag: Closing tag is not created");
if (fxmlR)
fxmlR->drop();
// TODO create empty closing teg
IWriteFile* fWrite1 = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml1 = IFileSystem::createXMLWriter(fWrite1);
if (fWrite1)
fWrite1->drop();
fxml1->writeClosingTag("");
if (fxml1)
fxml1->drop();
IReadFile* fRead1 = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR1 = IFileSystem::createXMLReader(fRead1);
fxmlR1->read();
if (fxmlR1->getNodeType() != EXNT_ELEMENT_END)
mes.append(
"\n writeClosingTag: emty closing tag is not created");
if (fxmlR1)
fxmlR1->drop();
}
示例6: SaveGame
bool kx::SaveGame()
{
fileSys->changeWorkingDirectoryTo( kxBaseDir );
// kxBaseDir/saves/saveName.kxSave
stringw saveName = saveEditBox->getText();
path filename = "./saves/";
filename += saveName;
filename += ".kxs";
IWriteFile* file = fileSys->createAndWriteFile( filename );
if (!file)
{
std::cout<< "Error: couldn't create save file" << endl;
return false;
}
else
{
IXMLWriter* writer = fileSys->createXMLWriter( file );
if (!writer)
{
std::cout<< "Error: couldn't create XML writer" << std::endl;
return false;
}
else
{
writer->writeXMLHeader();
const wchar_t* saveElement = L"kxSave";
writer->writeElement( saveElement );
writer->writeLineBreak();
IAttributes* attr = fileSys->createEmptyAttributes();
attr->addInt( "activeLevelNum", activeLevel->num );
attr->addInt( "activeLevelProgress", activeLevel->progress );
// add more attrib here...
attr->write( writer );
attr->drop();
writer->writeClosingTag( saveElement );
writer->drop();
file->drop();
messages = ""; // reset
messages += L"Saved ";
messages += saveName;
messages += L".kxs";
messagesNumLines= 1;
return true;
}
}
return false;
}
示例7: writeImageToFile
//! Writes the provided image to disk file
bool CNullDriver::writeImageToFile(IImage* image, const path& filename,u32 param)
{
IWriteFile* file = FileSystem->createAndWriteFile(filename);
if(!file)
return false;
bool result = writeImageToFile(image, file, param);
file->releaseRef();
return result;
}
示例8: createWriteFile
//! Creates a XML Writer from a file.
IXMLWriter* SharedFileSystem::createXMLWriter(
const core::stringc& filename)
{
IWriteFile* file = createWriteFile(filename);
IXMLWriter* writer = irrgame::io::createXMLWriter(file);
if (file)
file->drop();
return writer;
}
示例9: writeComment
void IXMLWriterTest::writeComment()
{
IWriteFile* fWrite = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite);
if (fWrite)
fWrite->drop();
fxml->writeComment(static_cast<const c8*>("bla bla bla"));
if (fxml)
fxml->drop();
IReadFile* fRead = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead);
fxmlR->read();
if (fxmlR->getNodeType() != EXNT_COMMENT)
mes.append("\n writeComment: comment is not created");
if (fxmlR)
fxmlR->drop();
//TODO creates an empty comment
IWriteFile* fWrite1 = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml1 = IFileSystem::createXMLWriter(fWrite1);
if (fWrite1)
fWrite1->drop();
fxml1->writeComment(static_cast<const c8*>(""));
if (fxml1)
fxml1->drop();
IReadFile* fRead1 = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR1 = IFileSystem::createXMLReader(fRead1);
fxmlR1->read();
if (fxmlR1->getNodeType() != EXNT_COMMENT)
mes.append("\n writeComment: empty comment is not created");
if (fxmlR1)
fxmlR1->drop();
}
示例10: writeImageToFile
//! Tests IVideoDriver::writeImageToFile() using IWriteFile
bool writeImageToFile(void)
{
IrrlichtDevice *device = createDevice( EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
if (!device)
return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs
IVideoDriver* driver = device->getVideoDriver();
ISceneManager * smgr = device->getSceneManager();
// Draw a cube background so that we can check that the pixels' alpha is working.
ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
cube->setMaterialFlag(video::EMF_LIGHTING, false);
(void)smgr->addCameraSceneNode();
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
// Test for benign handling of offscreen pixel values as well as onscreen ones.
for(s32 x = -10; x < 170; ++x)
{
s32 y = 120 * x / 160;
driver->drawPixel((u32)x, (u32)y, SColor(255, 255 * x / 640, 255 * (640 - x) / 640, 0));
y = 120 - y;
driver->drawPixel((u32)x, (u32)y, SColor(255 * x / 640, 0, 255, 255));
}
driver->endScene();
bool result = false;
IWriteFile * writtenFile = 0;
IWriteFile * memoryFile = 0;
const char * writtenFilename = 0;
const u32 BUFFER_SIZE = 160 * 120 * 4;
c8 * buffer = 0;
const char * referenceFilename = 0;
video::ECOLOR_FORMAT format;
irr::video::IImage * screenshot = driver->createScreenShot();
if(!screenshot)
{
logTestString("Failed to take screenshot\n");
assert(false);
goto cleanup;
}
format = screenshot->getColorFormat();
if(format != video::ECF_R8G8B8)
{
irr::video::IImage * fixedScreenshot = driver->createImage(video::ECF_R8G8B8, screenshot);
screenshot->drop();
if(!fixedScreenshot)
{
logTestString("Failed to convert screenshot to ECF_A8R8G8B8\n");
assert(false);
goto cleanup;
}
screenshot = fixedScreenshot;
}
buffer = new c8[BUFFER_SIZE];
writtenFilename = "results" DIR_SEP_STRING "Burning's Video-drawPixel.png";
memoryFile = device->getFileSystem()->createMemoryWriteFile(buffer, BUFFER_SIZE, writtenFilename, false);
if(!driver->writeImageToFile(screenshot, memoryFile))
{
logTestString("Failed to write png to memory file\n");
assert(false);
goto cleanup;
}
writtenFile = device->getFileSystem()->createAndWriteFile(memoryFile->getFileName());
if(!writtenFile)
{
logTestString("Can't open %s for writing.\n", writtenFilename);
assert(false);
goto cleanup;
}
if(memoryFile->getPos() != writtenFile->write(buffer, memoryFile->getPos()))
{
logTestString("Error while writing to %s.\n", writtenFilename);
assert(false);
goto cleanup;
}
writtenFile->drop();
writtenFile = 0;
referenceFilename = "media" DIR_SEP_STRING "Burning's Video-drawPixel.png";
if(!binaryCompareFiles(writtenFilename, referenceFilename))
{
logTestString("File written from memory is not the same as the reference file.\n");
assert(false);
goto cleanup;
}
result = true;
//.........这里部分代码省略.........
示例11: PHYSFS_setWriteDir
// ----------------------------------------------------------------------------
void Track::build()
{
IrrlichtDevice* device = Editor::getEditor()->getDevice();
PHYSFS_setWriteDir(Editor::getEditor()->getTrackDir().c_str());
PHYSFS_mkdir(m_file_name.c_str());
path p = Editor::getEditor()->getTrackDir() + m_file_name;
CMeshBuffer<S3DVertex2TCoords>* mb = m_terrain->build(p);
SMesh smesh;
smesh.addMeshBuffer(mb);
for (u32 i = 1; i < m_roads.size(); i++)
{
IRoad* r = m_roads[i];
if (r->getSpline()->getPointNum()>1)
smesh.addMeshBuffer(((Road*)r)->getMeshBuffer());
}
B3DMeshWriter* writer = new B3DMeshWriter(device->getFileSystem());
IWriteFile *file;
file = device->getFileSystem()->createAndWriteFile((p + "/track.b3d").c_str());
writer->writeMesh(file, &smesh);
file->drop();
delete writer;
m_driveline->build(p);
std::ofstream mat;
mat.open((p + "/materials.xml").c_str());
mat << "<materials>\n";
mat << " <material name=\"splatt.png\" graphical-effect=\"splatting\"";
SMaterial m = m_terrain->getMaterial(0);
for (int i = 1; i < 5; i++)
{
mat << " splatting-texture-" << i << "=\"";
mat << Editor::toRelative(m.getTexture(i+1)->getName()).c_str();
mat << "\"";
}
mat << "/>\n";
if (m_gravity_road)
{
for (u32 i = 1; i < m_roads.size(); i++)
{
stringc tex = m_roads[i]->getTexName();
if (tex.size()>0)
{
mat << " <material name=\"";
mat << tex.c_str();
mat << "\" has-gravity=\"yes\" />\n";
}
} // roads
} // gravity road mode
mat <<"</materials>\n";
mat.close();
stringw track;
track += "<track name = \"";
track += m_track_name + L"\"\n";
track += " version = \"5\"\n";
track += " groups = \"made-by-STK-TE\"\n";
track += " designer = \"";
track += m_designer + "\"\n";
track += " music = \"";
track += m_music.c_str();
track += "\"\n";
track += " screenshot = \"screenshot.jpg\"\n";
track += " smooth-normals = \"true\"\n";
track += " reverse = \"Y\"\n>\n";
track += "</track>\n";
PHYSFS_uint64 len = 4 * track.size();
char* dst = new char[len];
#ifdef _WIN32
PHYSFS_utf8FromUcs2((PHYSFS_uint16*)track.c_str(),dst,len);
#else
PHYSFS_utf8FromUcs4((PHYSFS_uint32*)track.c_str(), dst, len);
#endif
FILE* f;
f = fopen((p + "/track.xml").c_str(), "wb");
fwrite(dst, sizeof(char), strlen(dst), f);
fclose(f);
delete[] dst;
std::ofstream scene;
scene.open((p + "/scene.xml").c_str());
scene << "<scene>\n";
scene << " <track model=\"track.b3d\" x=\"0\" y=\"0\" z=\"0\">\n";
exportElements(scene, true);
scene << " </track>\n";
exportElements(scene, false);
//.........这里部分代码省略.........
示例12: main
int main(int argc, char* argv[])
{
if ((argc < 3) ||
((argc==3) && (argv[1][0]=='-')))
{
usage(argv[0]);
return 1;
}
IrrlichtDevice *device = createDevice( video::EDT_NULL,
dimension2d<s32>(800, 600), 32, false, false, false, 0);
device->setWindowCaption(L"Image Converter");
scene::EMESH_WRITER_TYPE type = EMWT_IRR_MESH;
u32 i=1;
bool createTangents=false;
while (argv[i][0]=='-')
{
core::stringc format = argv[i];
if (format.size() > 3)
{
if (format.equalsn("--format=",9))
{
format = format.subString(9,format.size());
if (format=="collada")
type = EMWT_COLLADA;
else if (format=="stl")
type = EMWT_STL;
else if (format=="obj")
type = EMWT_OBJ;
else
type = EMWT_IRR_MESH;
}
else
if (format =="--createTangents")
createTangents=true;
}
else
if (format=="--")
{
++i;
break;
}
++i;
}
const s32 srcmesh = i;
const s32 destmesh = i+1;
--argc;
if ((argc<srcmesh) || (argc<destmesh))
{
std::cerr << "Not enough files given." << std::endl;
usage(argv[0]);
return 1;
}
createTangents = createTangents && (type==EMWT_IRR_MESH);
std::cout << "Converting " << argv[srcmesh] << " to " << argv[destmesh] << std::endl;
IMesh* mesh = device->getSceneManager()->getMesh(argv[srcmesh])->getMesh(0);
if (!mesh)
{
std::cerr << "Could not load " << argv[srcmesh] << std::endl;
return 1;
}
if (createTangents)
{
IMesh* tmp = device->getSceneManager()->getMeshManipulator()->createMeshWithTangents(mesh);
mesh->drop();
mesh=tmp;
}
IMeshWriter* mw = device->getSceneManager()->createMeshWriter(type);
IWriteFile* file = device->getFileSystem()->createAndWriteFile(argv[destmesh]);
mw->writeMesh(file, mesh);
mesh->drop();
file->drop();
mw->drop();
return 0;
}
示例13: writeElement
void IXMLWriterTest::writeElement()
{
IWriteFile* fWrite = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite);
if (fWrite)
fWrite->drop();
fxml->writeElement("fff", true, "attr1", "attrValue1");
if (fxml)
fxml->drop();
IReadFile* fRead = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead);
fxmlR->read();
if (fxmlR->getNodeType() != EXNT_ELEMENT)
mes.append(
"\n writeElement: incorrectly indicates the type of node");
if (fxmlR->getAttributeCount() != 1)
mes.append(
"\n writeElement: correctly returns the number of attributes");
core::stringc strA = core::stringc("attr1");
if (!strA.equalsn(fxmlR->getAttributeName(0), 4))
mes.append(
"\n writeElement: correctly returns the name of attributes");
core::stringc strV = core::stringc("attrValue1");
if (!strV.equalsn(fxmlR->getAttributeValue(0), 10))
mes.append(
"\n writeElement: correctly returns the value of attributes");
if (fxmlR)
fxmlR->drop();
if (fRead)
fRead->drop();
//TODO should not create an element with no name
IWriteFile* fWrite1 = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml1 = IFileSystem::createXMLWriter(fWrite1);
if (fWrite1)
fWrite1->drop();
fxml1->writeElement("", true);
if (fxml1)
fxml1->drop();
IReadFile* fRead1 = IFileSystem::createReadFile(
"assets/io/fileXMLEmpty.xml");
IXMLReader* fxmlR1 = IFileSystem::createXMLReader(fRead1);
fxmlR1->read();
core::stringc strN = core::stringc("");
if (strN.equalsn(fxmlR1->getNodeName(), 1))
mes.append("\n writeElement: node name can not be empty");
if (fxmlR1->getAttributeCount() != 0)
mes.append("\n writeElement: sees non-existent attributes");
if (fxmlR1)
fxmlR1->drop();
if (fRead1)
fRead1->drop();
core::array<core::stringc> atr;
atr.insert(core::stringc("atr1"));
atr.insert(core::stringc("atr2"));
atr.insert(core::stringc("7"));
atr.insert(core::stringc(0));
atr.insert(core::stringc("art5"));
atr.insert(core::stringc("</>"));
atr.insert(core::stringc("art7"));
core::array<core::stringc> atrValue;
atrValue.insert(core::stringc("atrValue1"));
atrValue.insert(core::stringc("atrValue2"));
atrValue.insert(core::stringc("atrValue3"));
atrValue.insert(core::stringc("atrValue4"));
atrValue.insert(core::stringc("atrValue5"));
atrValue.insert(core::stringc("6"));
atrValue.insert(core::stringc(""));
IWriteFile* fWrite3 = IFileSystem::createWriteFile(
"assets/io/fileXMLEmpty.xml");
IXMLWriter* fxml3 = IFileSystem::createXMLWriter(fWrite3);
if (fWrite3)
fWrite3->drop();
fxml3->writeElement("fff", true, atr, atrValue);
if (fxml3)
//.........这里部分代码省略.........