コード例 #1
0
			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();

			}
コード例 #2
0
			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();
			}
コード例 #3
0
			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();

			}
コード例 #4
0
			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();
			}
コード例 #5
0
ファイル: kxGameSaveLoad.cpp プロジェクト: robcmills/kyuplex
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;
}
コード例 #6
0
	bool CSLevel::savePrefab(CSObject* obj, stringc filename)
	{
		CS_LOG(CSLOGTYPE::CSL_DEBUG, "Saving prefab to file %s", filename.c_str());

		CS_CHECK_BOOL(obj, CSLOGTYPE::CSL_WARNING, "Warning unable to save prefab. obj is not valid");

		_chdir(getApplication()->getDirectory("PrefabDirectory").c_str());

		IXMLWriter* writer = getDevice()->getFileSystem()->createXMLWriter(filename);
		if (!writer) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to create prefab file %s", filename.c_str()); return false; }

		writer->writeXMLHeader();

		stringw name("CSOBJECT");
		writer->writeElement(name.c_str(), false, L"TYPE", stringw(obj->getInfo()->getName()).c_str());
		writer->writeLineBreak();

		IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver());
		SAttributeReadWriteOptions options;
		obj->serializeAttributes(attr, &options);

		if (attr->getAttributeCount() != 0)
		{
			attr->write(writer);
			writer->writeLineBreak();
		}

		attr->drop();

		writer->writeClosingTag(name.c_str());
		writer->writeLineBreak();
		writer->writeLineBreak();

		writer->drop();
		return true;
	}
コード例 #7
0
ファイル: CGWIC_Cell.cpp プロジェクト: matrixsmaster/GWIC
void CGWIC_Cell::SaveObjectStates()
{
	path filenm = GWIC_CELLSTORE_DIR;
	filenm += GetCellFileSuffix();
	filenm += ".xml";
	IXMLWriter* xml = graphics->getFileSystem()->createXMLWriter(filenm);
	if (!xml) {
		std::cerr << "SaveObjectStates(): can't create writer to " << filenm.c_str() << std::endl;
		return;
	}
	xml->writeXMLHeader();
	CIrrStrParser pos,rot,scl;
	stringw vs;
	for (u32 i=0; i<objects.size(); i++) {
		vs = objects[i]->GetFileName();
		xml->writeElement(L"object",false,L"file",vs.c_str());
		xml->writeLineBreak();
		pos += objects[i]->GetPos();
		rot += objects[i]->GetRot();
		scl += objects[i]->GetScale();
		xml->writeElement(L"position",true,
				L"pos",pos.GetBuff().c_str(),
				L"rot",rot.GetBuff().c_str(),
				L"scale",scl.GetBuff().c_str());
		xml->writeLineBreak();
		xml->writeElement(L"options",true,
				L"physical",((objects[i]->GetPhysical())?(L"1"):(L"0")),
				L"enabled",((objects[i]->GetEnabled())?(L"1"):(L"0")));
		xml->writeLineBreak();
		pos = rot = scl = L"";
		xml->writeClosingTag(L"object");
		xml->writeLineBreak();
	}
	xml->drop();
}
コード例 #8
0
	// save the level objects to disk file
	bool CSLevel::saveToDisk(stringc filename)
	{
		// log this event
		CS_LOG(CSLOGTYPE::CSL_DEBUG, "Saving game data - %s", filename.c_str());

		// creat ethe xml writer
		IXMLWriter* writer = getDevice()->getFileSystem()->createXMLWriter(filename);
		if (!writer) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to create save file %s", filename.c_str()); return false; }

		// write the xml header
		writer->writeXMLHeader();

		vector3df pos(0, 0, 0);
		vector3df tar(0, 0, 0);
		if (getCamera())
		{
			pos = getCamera()->getPosition();
			tar = getCamera()->getTarget();
		}

		// write the camera position and target
		writer->writeLineBreak();
		writer->writeElement(L"CAMERA", false,
			L"POSITION", stringw(vector3dfToStringc(pos)).c_str(),
			L"TARGET", stringw(vector3dfToStringc(tar)).c_str()
			);
		writer->writeLineBreak();
		writer->writeLineBreak();

		// run through thte list of objects
		CSObject* obj = getObjectFactory()->getObjectManager()->getNextObject(true);
		while (obj)
		{
			// if this is not a debug object, then save it to disk
			if (!obj->getDebugObject())
			{
				// write the node type
				stringw name("CSOBJECT");
				writer->writeElement(name.c_str(), false, L"TYPE", stringw(obj->getInfo()->getName()).c_str());
				writer->writeLineBreak();

				// let the object serialize itself into our attributes structure
				IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver());
				SAttributeReadWriteOptions options;
				obj->serializeAttributes(attr, &options);

				// if there are attributes
				if (attr->getAttributeCount() != 0)
				{
					// write the attributes to the xml file
					attr->write(writer);

					// make the file pretty
					writer->writeLineBreak();
				}

				// drop the pointer
				attr->drop();

				// finish writing the xml header / footer
				writer->writeClosingTag(name.c_str());
				writer->writeLineBreak();
				writer->writeLineBreak();
			}
			// get the next object
			obj = getObjectFactory()->getObjectManager()->getNextObject(false);
		}

		// drop the pointer
		writer->drop();

		// everything went fine
		return true;
	}
コード例 #9
0
			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)
					fxml3->drop();

				IReadFile* fRead3 = IFileSystem::createReadFile(
						"assets/io/fileXMLEmpty.xml");
				IXMLReader* fxmlR3 = IFileSystem::createXMLReader(fRead3);

				fxmlR3->read();

				if (fxmlR3->getAttributeCount() != 7)
					mes.append(
							"\n writeElement: correctly returns the number of attributes");

				//TODO attribute name can not be a 0
				if (fxmlR3->getAttributeName(3) == 0)
					mes.append(
							"\n writeElement: attribute name can not be a 0");

				//TODO attribute value can not be empty
				core::stringc strAV = core::stringc("");
				if (strAV.equalsn(fxmlR3->getAttributeValue(6), 1))
					mes.append(
							"\n writeElement: attribute value can not be empty");

				if (fxmlR3)
				{
					fxmlR3->drop();
				}

			}