void OutputWriter::WriteToDoc(ResponseMsg response, XMLNode* node, const char* value){
	std::string path = CommandManager::getPathOut();
	tinyxml2::XMLDocument* doc = CommandManager::getDocOut();

	//Searching root
	XMLNode *root = node;
	while(strcmp(root->Value(),"command")!=0)
	{root=root->Parent();}

	XMLText* textCode = doc->NewText((Utils::convertInt(response.getCode()).c_str()));
	XMLText* textMessage = doc->NewText(response.getMessage());
	XMLText* valueMessage = doc->NewText(value);

	node->DeleteChildren();
	XMLElement* codeElement = doc->NewElement("code");
	node->InsertEndChild(codeElement);
	XMLElement* messageElement = doc->NewElement("message");
	node->InsertEndChild(messageElement);
	XMLElement* valueElement = doc->NewElement("value"); 	//Insert the value
	node->InsertEndChild(valueElement);

	codeElement->InsertEndChild(textCode);
	messageElement->InsertEndChild(textMessage);
	valueElement->InsertEndChild(valueMessage);

	XMLElement* commandsElement = doc->FirstChildElement("commands");
	commandsElement->InsertEndChild(root);
}
bool
MovementComponent::serialize(XMLElement &n) const
{
	if (!ComponentBase::serialize(n))
	    return(false);

	XMLElement *l_acceleration = n.GetDocument()->NewElement("acceleration");
	l_acceleration->SetAttribute("x", m_p->acceleration.x);
	l_acceleration->SetAttribute("y", m_p->acceleration.y);
	n.InsertEndChild(l_acceleration);

	XMLElement *l_limit = n.GetDocument()->NewElement("limit");
	l_limit->SetAttribute("x1", m_p->limit_x.first());
	l_limit->SetAttribute("x2", m_p->limit_x.second());
	l_limit->SetAttribute("y1", m_p->limit_y.first());
	l_limit->SetAttribute("y2", m_p->limit_y.second());
	n.InsertEndChild(l_limit);

	XMLElement *l_velocity = n.GetDocument()->NewElement("velocity");
	l_velocity->SetAttribute("x", m_p->velocity.x);
	l_velocity->SetAttribute("y", m_p->velocity.y);
	n.InsertEndChild(l_velocity);

	return(true);
}
Exemplo n.º 3
0
void emu::Settings::CreateDefaultXml(char const * filename)
{
    cpumode = "interpeter-slow";
    gerenderer = "pspe4all-hal.video.OGL4";

    XMLDocument xmlDoc;

    XMLNode * pRoot = xmlDoc.NewElement("pspe4all");
    xmlDoc.InsertFirstChild(pRoot);
    XMLElement * pElement = xmlDoc.NewElement("GeneralSettings");

    XMLElement * pListElement = xmlDoc.NewElement("CpuMode");
    pListElement->SetText(cpumode.c_str());

    pElement->InsertEndChild(pListElement);

    XMLElement * pListElement2 = xmlDoc.NewElement("GeRenderer");
    pListElement2->SetText(gerenderer.c_str());

    pElement->InsertEndChild(pListElement2);

    pRoot->InsertEndChild(pElement);

    xmlDoc.SaveFile(filename);
}
Exemplo n.º 4
0
void SystemSettings::save(const K::File& file) {

	XMLDocument doc;
	XMLElement* nRoot = doc.NewElement("KSynth");
	XMLElement* nSettings = doc.NewElement("Settings");

	doc.InsertFirstChild(nRoot);
	nRoot->InsertEndChild(nSettings);

	// the sound-sink
	XMLElement* nSink = doc.NewElement("SoundSink");
	nSink->SetAttribute("name", getSoundSink()->getName().c_str());
	nSettings->InsertEndChild(nSink);

	// refresh
	XMLElement* nGui = doc.NewElement("GUI");
	nSettings->InsertEndChild(nGui);
	XMLElement* nGuiRefresh = doc.NewElement("Refresh");
	nGuiRefresh->SetAttribute("ms", getGuiRefreshInterval());
	nGui->InsertEndChild(nGuiRefresh);



	doc.SaveFile( file.getAbsolutePath().c_str() );

}
Exemplo n.º 5
0
void highscore::newHighScore(score *newHighScore)
{
    // SAVE NEW SCORE DIRECTLY INTO XML FILE
    // Load XML file
    char scoreStr[10];

    XMLDocument doc;
    XMLElement *nodeTransversal;
    doc.LoadFile("score.xml");

    // Write its child first
    XMLText *nameText = doc.NewText(newHighScore->readPlayerName().c_str());
    XMLElement *name = doc.NewElement("name");
    name->InsertEndChild(nameText);

    sprintf(scoreStr, "%d", newHighScore->readScore());
    XMLText *scoreText = doc.NewText(scoreStr);
    XMLElement *score = doc.NewElement("score");
    score->InsertEndChild(scoreText);

    // Create new node
    XMLElement* hs = doc.NewElement("hs");
    hs->InsertEndChild(name);
    hs->InsertEndChild(score);

    doc.InsertEndChild(hs);

    doc.SaveFile("score.xml");
}
Exemplo n.º 6
0
bool Header::build(tinyxml2::XMLDocument &doc, tinyxml2::XMLElement *parent, const int number) const
{
    if(!isBuildable() || !m_destinationNames.isBuildable())
    return false;

    XMLElement *elm = doc.NewElement(HEADER_BALISE_NAME.c_str());
    if(elm == 0)
    return false;

    XMLElement* src = doc.NewElement(SRC_BALISE_NAME.c_str());
    if(src == 0)
    return false;

    XMLElement* cmd = doc.NewElement(CMD_BALISE_NAME.c_str());
    if(cmd == 0)
    return false;

    {
        string str(escapeCharacters(m_sourceName));
        src->SetText(str.c_str());
        str = escapeCharacters(m_commandName);
        cmd->SetText(str.c_str());
    }

    elm->InsertEndChild(src);

    if(!m_destinationNames.build(doc, elm))
    return false;

    elm->InsertEndChild(cmd);

    XMLElement *antecedant(0);
    antecedant = (parent != 0 ? parent->FirstChildElement(HEADER_BALISE_NAME.c_str()) : doc.FirstChildElement(HEADER_BALISE_NAME.c_str()));
    for(int i(0), c(number - 1); i < c && antecedant != 0; ++i)
    antecedant = antecedant->NextSiblingElement(HEADER_BALISE_NAME.c_str());


    if(parent != 0)
    {
        if(antecedant != 0)
        parent->InsertAfterChild(antecedant, elm);
        else
        parent->InsertEndChild(elm);
    }
    else
    {
        if(antecedant != 0)
        doc.InsertAfterChild(antecedant, elm);
        else
        doc.InsertEndChild(elm);
    }

    return true;
}
Exemplo n.º 7
0
void testPrintXML() {
	XMLDocument doc;
	XMLElement* root = doc.NewElement("root");
	XMLElement* path = doc.NewElement("status");
	XMLText* text = doc.NewText("0");
	doc.InsertEndChild(root);
	root->InsertEndChild(path);
	path->InsertEndChild(text);
	XMLPrinter printer(0, true);
	doc.Print(&printer);
	cout << printer.CStr() << endl;
}
Exemplo n.º 8
0
/**
 * Write the current object 
 */
void SessionTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Session* psession = dynamic_cast< const Session*>(pObject);
	if( psession == NULL) 
		throw TranslationException("SessionTranslator cannot cast Session object");
	else if( psession->Id().length() == 0)
		return;
	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	if( !psession->IsReference())
	{
		XMLElement* pelem;

		//Write scenario
		pelem = elem.GetDocument()->NewElement( "scenario");
		pelem->SetText( psession->Scenario().c_str());
		pelemc->InsertEndChild(pelem);
		
		//Write campaign
		pelem = elem.GetDocument()->NewElement( "campaign");
		pelem->SetText( psession->Campaign().c_str());
		pelemc->InsertEndChild(pelem);

		//Write location
		pelem = elem.GetDocument()->NewElement( "location");
		char buff[128];
		const Location& llh = psession->Location();
		sprintf(buff,"%0.8lf", llh.Latitude());
		pelem->SetAttribute("lat", buff);
		sprintf(buff,"%0.8lf", llh.Longitude());
		pelem->SetAttribute("lon", buff);
		sprintf(buff,"%0.3lf", llh.Height());
		pelem->SetAttribute("height", buff);
		pelemc->InsertEndChild(pelem);

		//Write conact
		pelem = elem.GetDocument()->NewElement( "contact");
		pelem->SetText( psession->Contact().c_str());
		pelemc->InsertEndChild(pelem);

		//Write poc
		pelem = elem.GetDocument()->NewElement( "poc");
		pelem->SetText( psession->Poc().c_str());
		pelemc->InsertEndChild(pelem);
	}
	
	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *psession, ctxt, *pelemc);
	elem.InsertEndChild( pelemc);
}
Exemplo n.º 9
0
void ComponentList::EditEntryInXML(Component& component)
{
	component.xmlElement->DeleteChildren();
	component.xmlElement->SetAttribute("name", component.name.c_str());
	for (int i = 0; i < component.fields.size(); ++i)
	{
		XMLElement* newField = m_componentXMLDocument.NewElement("Field");
		newField->SetAttribute("name", component.fields[i].name.c_str());
		newField->SetAttribute("type", component.fields[i].valueType.c_str());
		component.xmlElement->InsertEndChild(newField);
	}
	for (int i = 0; i < component.lists.size(); ++i)
	{
		XMLElement* newList = m_componentXMLDocument.NewElement("List");
		newList->SetAttribute("name", component.lists[i].name.c_str());
		newList->SetAttribute("entryname", component.lists[i].entryName.c_str());
		for (int j = 0; j < component.lists[i].entries[0].fields.size(); ++j)
		{
			XMLElement* newField = m_componentXMLDocument.NewElement("Field");
			newField->SetAttribute("name", component.lists[i].entries[0].fields[j].name.c_str());
			newField->SetAttribute("type", component.lists[i].entries[0].fields[j].valueType.c_str());
			newList->InsertEndChild(newField);
		}
		component.xmlElement->InsertEndChild(newList);
	}
	m_componentXMLDocument.SaveFile(m_xmlFilepath.c_str());
}
Exemplo n.º 10
0
/**
 * Write the current object 
 */
void ChannelTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Channel* pchannel = dynamic_cast< const Channel*>(pObject);
	if( pchannel == NULL) 
		throw TranslationException("ChannelTranslator cannot cast Channel object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	if( !pchannel->IsReference())
	{
		XMLElement* pelem;

		//Write CenterFrequency
		WriteElement( &pchannel->CenterFrequency(), "centerfreq", ctxt, *pelemc);
	
		//Write Translated Frequency
		WriteElement( &pchannel->TranslatedFrequency(), "translatedfreq", ctxt, *pelemc);

		//Inverted Element
		pelem = elem.GetDocument()->NewElement( "inverted");
		pelem->SetText( (pchannel->Inverted())? "true":"false");
		pelemc->InsertEndChild( pelem);

		//delaybias
		WriteElement( &pchannel->DelayBias(), "delaybias", ctxt, *pelemc);

		//System
		WriteElement( &pchannel->System(), "system", ctxt, *pelemc);
	}
	
	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *pchannel, ctxt, *pelemc);
	elem.InsertEndChild( pelemc);
}
Exemplo n.º 11
0
void testErrMsg() {
	XMLDocument doc;
	XMLElement* root;
	XMLElement* node;
	doc.InsertEndChild(root = doc.NewElement("root"));
	root->InsertEndChild(node = doc.NewElement("status"));
	node->InsertEndChild(doc.NewText("1"));
	root->InsertEndChild(node = doc.NewElement("error"));
	node->InsertEndChild(doc.NewText("hello world"));

	XMLPrinter printer(0, true);
	doc.Print(&printer);
	cout << printer.CStr() << endl;
	cout << printer.CStrSize() << endl;
	cout << strlen(printer.CStr()) << endl;
}
void OutputWriter::WriteCommandNotFormat(){
	std::string path = CommandManager::getPathOut();
	tinyxml2::XMLDocument* doc = CommandManager::getDocOut();

	XMLNode *root = doc->NewElement("command");

	XMLText* textCode = doc->NewText((Utils::convertInt(CAMERROR_VALUE_UNKNOWN)).c_str());

	XMLElement* codeElement = doc->NewElement("code");
	root->InsertEndChild(codeElement);

	codeElement->InsertEndChild(textCode);

	XMLElement* commandsElement = doc->FirstChildElement("commands");
	commandsElement->InsertEndChild(root);
}
Exemplo n.º 13
0
void Configure::writeDictItem(int item)
{
    if (item > DICTNODE_NUM_MAX)
        return;
    SpinLock lock(m_cs);
    XMLElement* dictElement = XMLHandle(m_doc.RootElement()).FirstChildElement("dict").ToElement();
    XMLElement* e = util::XMLUtil::Child(dictElement, item);
    if (e == NULL) {
        e = m_doc.NewElement("d");
        e->SetAttribute("open",   m_dictNodes[item].open.c_str());
        e->SetAttribute("en",     m_dictNodes[item].en);

        XMLElement* textE = m_doc.NewElement("summary");
	    textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].summary.c_str()));
		e->InsertFirstChild(textE);

    	textE = m_doc.NewElement("path");
    	textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].path.c_str()));
    	e->InsertFirstChild(textE);

    	textE = m_doc.NewElement("name");
    	textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].name.c_str()));
    	e->InsertFirstChild(textE);

    	textE = m_doc.NewElement("detlan");
    	textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].detlan.c_str()));
    	e->InsertFirstChild(textE);

    	textE = m_doc.NewElement("srclan");
    	textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].srclan.c_str()));
    	e->InsertFirstChild(textE);

        dictElement->InsertEndChild(e);
    } else {
        e->SetAttribute("open",   m_dictNodes[item].open.c_str());
        e->SetAttribute("en",     m_dictNodes[item].en);

        XMLText* txt = e->FirstChildElement("path")->FirstChild()->ToText();
    	txt->SetValue(m_dictNodes[item].path.c_str());

        txt = e->FirstChildElement("name")->FirstChild()->ToText();
    	txt->SetValue(m_dictNodes[item].name.c_str());

        txt = XMLHandle(e).FirstChildElement("detlan").FirstChild().ToText();
        if (txt)
    	    txt->SetValue(m_dictNodes[item].detlan.c_str());

        txt = XMLHandle(e).FirstChildElement("srclan").FirstChild().ToText();
        if (txt)
    	    txt->SetValue(m_dictNodes[item].srclan.c_str());

        txt = XMLHandle(e).FirstChildElement("summary").FirstChild().ToText();
        if (txt)
            txt->SetValue(m_dictNodes[item].summary.c_str());
    }
    /*printf("writeDictItem(%s): %d, %s -> %s\n", ndname.c_str(), 
           item, m_dictNodes[item].srclan.c_str(), m_dictNodes[item].detlan.c_str());*/
    m_dirty = true;
}
Exemplo n.º 14
0
void CSettings::writeToFile() {
  XMLDocument doc;
  XMLElement *pSettingsElem = doc.NewElement("settings");
  doc.InsertEndChild(pSettingsElem);

  // Input
  XMLElement *pInput = doc.NewElement("input");
  pSettingsElem->InsertEndChild(pInput);

  pInput->SetAttribute("map_editor_button_size",
		       m_InputSettings.m_fMapEditorButtonSize);
  
  XMLElement *pInputTouch = doc.NewElement("touch");
  pInput->InsertEndChild(pInputTouch);

  pInputTouch->SetAttribute("button_size", m_InputSettings.m_fTouchButtonSize);

  // video
  XMLElement *pVideo = doc.NewElement("video");
  pSettingsElem->InsertEndChild(pVideo);
  
  pVideo->SetAttribute("hud_size", m_VideoSettings.m_fHUDSize);

  // social gaming
  XMLElement *pSocialGaming = doc.NewElement("social_gaming");
  pSettingsElem->InsertEndChild(pSocialGaming);
  
  pSocialGaming->SetAttribute("login_on_start", m_SocialGamingSettings.m_bLoginOnStart ? "true" : "false");


  // do the output
  XMLPrinter xmlprinter;
  doc.Accept(&xmlprinter);

  std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  std::string text(xmlprinter.CStr());

  std::fstream stream;
  if (CFileManager::openFile(stream, SETTINGS_FILE_PATH, std::ofstream::out | std::ofstream::trunc)) {
    stream << header;
    stream << text;
    stream.close();
  }
}
void OutputWriter::WriteInitOutput(ResponseMsg response){
	std::string path = CommandManager::getPathOut();
	tinyxml2::XMLDocument* doc = CommandManager::getDocOut();

	doc->Clear(); //Clear all text
	XMLNode *root = doc->NewElement("init");
	
	XMLText* textCode = doc->NewText((Utils::convertInt(response.getCode()).c_str()));
	XMLText* textMessage = doc->NewText(response.getMessage());

	XMLElement* codeElement = doc->NewElement("code");
	root->InsertEndChild(codeElement);
	XMLElement* messageElement = doc->NewElement("message");
	root->InsertEndChild(messageElement);

	codeElement->InsertEndChild(textCode);
	messageElement->InsertEndChild(textMessage);

	doc->InsertEndChild(root);
	doc->SaveFile(path.c_str());
}
Exemplo n.º 16
0
void LevelParser::writeObjectLayer(XMLElement* pGroupElement, ObjectLayer* layer, string layerName)
{
	// write object group attributes
	pGroupElement->SetAttribute("name", layerName.c_str());

	// write objects
	XMLElement *pObjectElement;
	for (auto object : *layer->getGameObjects())
	{
		// object->writeXML(XMLElement);
		pObjectElement = pGroupElement->GetDocument()->NewElement("object");
		
		// write object attributes
		pObjectElement->SetAttribute("type", object->type().c_str());
		pObjectElement->SetAttribute("x", object->getPosition().x());
		pObjectElement->SetAttribute("y", object->getPosition().y());
		pObjectElement->SetAttribute("textureID", object->getTextureID().c_str());
		pObjectElement->SetAttribute("frameWidth", object->getWidth());
		pObjectElement->SetAttribute("frameHeight", object->getHeight());
		pObjectElement->SetAttribute("xBB", object->getCollider().x);
		pObjectElement->SetAttribute("yBB", object->getCollider().y);
		pObjectElement->SetAttribute("widthBB", object->getCollider().w);
		pObjectElement->SetAttribute("heightBB", object->getCollider().h);
		pObjectElement->SetAttribute("xSpeed", object->getXSpeed());
		pObjectElement->SetAttribute("ySpeed", object->getYSpeed());
		pObjectElement->SetAttribute("value", object->getValue());
		pObjectElement->SetAttribute("value2", object->getValue2());
		pObjectElement->SetAttribute("value3", object->getValue3());
		pObjectElement->SetAttribute("soundID", object->getSoundID().c_str());
		pObjectElement->SetAttribute("sound2ID", object->getSound2ID().c_str());

		// write animation nodes
		XMLElement *pAnimations= pGroupElement->GetDocument()->NewElement("animations");

		for (auto anim : object->getAnimations())
		{
			XMLElement *pAnimation = pGroupElement->GetDocument()->NewElement("animation");
			// Write the name of the animation
			pAnimation->SetAttribute("name", anim.first.c_str());
			// Write the remaining attributes of the animation
			writeAnimation(pAnimation, anim.second);
			// Insert animation node
			pAnimations->InsertEndChild(pAnimation);
		}		

		// Insert animations node
		pObjectElement->InsertEndChild(pAnimations);

		// Insert object node
		pGroupElement->InsertEndChild(pObjectElement);
	}
}
Exemplo n.º 17
0
void SimulationWriter::initialize()
{
  if (!_initialized)
  {
    XMLElement* rootnode = _doc.NewElement("simulation");
    XMLElement* ticknode = _doc.NewElement("ticks");

    _doc.InsertEndChild(rootnode);
    rootnode->InsertEndChild(ticknode);

    _initialized = true;
  }
}
Exemplo n.º 18
0
/**
 * Write the current object 
 */
void SourceTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Source* psource = dynamic_cast< const Source*>(pObject);
	if( psource == NULL) 
		throw TranslationException("SourceTranslator cannot cast Source object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	//Source object must have ID defined in order to support association
	//with bandsrc.
	WriteAttributedObject( *psource, ctxt, *pelemc, true);

	if( !psource->IsReference())
	{
		XMLElement* pelem;

		//Write type [0..1]
		pelem = elem.GetDocument()->NewElement( "type");
		pelem->SetText( _szSourceType[ psource->Type()] );
		pelemc->InsertEndChild( pelem);

		//Write polarization [0..1]
		pelem = elem.GetDocument()->NewElement( "polarization");
		pelem->SetText( _szSourcePolarization[ psource->Polarization()] );
		pelemc->InsertEndChild( pelem);

		//Write origin [0..1]
		WriteElement( &psource->Origin(), "origin", ctxt, *pelemc);

		//TODO Write rotation 

		//Write idcluster [0..1]
		WriteElement("idcluster",psource->IdCluster().c_str(), pelemc, false, "");
	}
	
	elem.InsertEndChild( pelemc);
}
Exemplo n.º 19
0
void SimulationWriter::writeOut(Crowd& c)
{
  XMLElement* ticknode = _doc.FirstChildElement("simulation")
    ->FirstChildElement("ticks")->ToElement();

  XMLElement* currenttick = _doc.NewElement("tick");
  currenttick->SetAttribute("num", c.age());
  ticknode->InsertEndChild(currenttick);

  for (size_t i = 0; i < c.size(); i++)
  {
    addVertex(currenttick, c.at(i));
  }
}
bool
Box2DSceneLayer::serialize(XMLElement &n) const
{
	if (!SceneLayerBase::serialize(n))
		return(false);

	XMLElement *l_child = n.GetDocument()->NewElement("gravity");
	b2Vec2 l_gravity = m_p->world.GetGravity();
	l_child->SetAttribute("x", l_gravity.x);
	l_child->SetAttribute("y", l_gravity.y);
	n.InsertEndChild(l_child);

	return(true);
}
Exemplo n.º 21
0
void emu::Settings::Save(char const * filename)
{
    XMLDocument xmlDoc;

    XMLNode * pRoot = xmlDoc.NewElement("pspe4all");
    xmlDoc.InsertFirstChild(pRoot);
    XMLElement * pElement = xmlDoc.NewElement("GeneralSettings");

    XMLElement * pListElement = xmlDoc.NewElement("CpuMode");
    pListElement->SetText(cpumode.c_str());

    pElement->InsertEndChild(pListElement);

    XMLElement * pListElement2 = xmlDoc.NewElement("GeRenderer");
    pListElement2->SetText(gerenderer.c_str());

    pElement->InsertEndChild(pListElement2);

    pRoot->InsertEndChild(pElement);


    xmlDoc.SaveFile(filename);
}
Exemplo n.º 22
0
/**
 * Write the current object 
 */
void StreamTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Stream* pstream = dynamic_cast< const Stream*>(pObject);
	if( pstream == NULL) 
		throw TranslationException("StreamTranslator cannot cast Stream object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *pstream, ctxt, *pelemc);

	if( !pstream->IsReference())
	{
		XMLElement* pelem;
		char buff[64];

		//Write ratefactor
		pelem = elem.GetDocument()->NewElement( "ratefactor");
		sprintf( buff, "%ld", pstream->RateFactor() );
		pelem->SetText( buff );
		pelemc->InsertEndChild( pelem);

		//Write quantization
		pelem = elem.GetDocument()->NewElement( "quantization");
		sprintf( buff, "%ld", pstream->Quantization() );
		pelem->SetText( buff );
		pelemc->InsertEndChild( pelem);

		//Write packedbits
		pelem = elem.GetDocument()->NewElement( "packedbits");
		sprintf( buff, "%ld", pstream->Packedbits() );
		pelem->SetText( buff );
		pelemc->InsertEndChild( pelem);

		//Write alignment
		pelem = elem.GetDocument()->NewElement( "alignment");
		pelem->SetText( _szAlignFmts[ pstream->Alignment()] );
		pelemc->InsertEndChild( pelem);

		//Write format
		pelem = elem.GetDocument()->NewElement( "format");
		pelem->SetText( _szSampleFmts[pstream->Format()] );
		pelemc->InsertEndChild( pelem);

		//Write encoding
		pelem = elem.GetDocument()->NewElement( "encoding");
		pelem->SetText( pstream->Encoding().c_str() );
		pelemc->InsertEndChild( pelem);

		//Write band
		WriteList<Band>( pstream->Bands(), "band", ctxt,*pelemc);

	}
	
	elem.InsertEndChild( pelemc);
}
Exemplo n.º 23
0
void LevelParser::writeTileLayer(XMLElement* pTileElement, TileLayer* layer, string layerName)
{
	// write tile layer attributes
	pTileElement->SetAttribute("name", layerName.c_str());	
	pTileElement->SetAttribute("width", layer->getMapWidth());
	pTileElement->SetAttribute("height", layer->getMapHeight());

	// write layer properties (if any)	
	XMLElement* pTileSubElement = pTileElement->GetDocument()->NewElement("properties");

	if (layer->isCollidable())
	{
		XMLElement* auxElement = pTileElement->GetDocument()->NewElement("property");
		auxElement->SetAttribute("name", "collidable");
		auxElement->SetAttribute("value", "true");
		pTileSubElement->InsertEndChild(auxElement);
		pTileElement->InsertEndChild(pTileSubElement);
	}

	// write tiles data
	pTileSubElement = pTileElement->GetDocument()->NewElement("data");

	XMLElement *pTileID;
	for (auto row : layer->getTileIDs())
	{
		for (auto id : row)
		{
			pTileID = pTileElement->GetDocument()->NewElement("tile");
			pTileID->SetAttribute("gid", id);

			pTileSubElement->InsertEndChild(pTileID);
		}
	}

	pTileElement->InsertEndChild(pTileSubElement);
}
Exemplo n.º 24
0
void SimulationWriter::addVertex(XMLElement* currenttick, Vertex& v)
{
  XMLElement* vertex = _doc.NewElement("vertex");
  XMLElement* position = _doc.NewElement("position");

  vertex->SetAttribute("id", v.id());
  vertex->SetAttribute("gid", v.label());
  vertex->SetAttribute("token", v.token());
  Point& pos = v.location();
  position->SetAttribute("x", pos.x());
  position->SetAttribute("y", pos.y());

  vertex->InsertEndChild(position);
  currenttick->InsertEndChild(vertex);
}
bool
RenderComponent::serialize(XMLElement &n) const
{
	if (!ComponentBase::serialize(n))
	    return(false);

	XMLElement *l_mesh = n.GetDocument()->NewElement("mesh");
	if (m_p->mesh && !m_p->mesh->serialize(*l_mesh)) {
		MMWARNING("Render component '" << id().str() << "' serialization failed to serialize mesh!");
		return(false);
	}
	n.InsertEndChild(l_mesh);

	return(true);
}
Exemplo n.º 26
0
bool
SceneBase::serialize(XMLElement &n) const
{
	n.SetAttribute("id", id().str().c_str());
	n.SetAttribute("type", type().str().c_str());

	SceneLayerList::const_reverse_iterator l_i;
	SceneLayerList::const_reverse_iterator l_c = m_p->layers.rend();
	for (l_i = m_p->layers.rbegin(); l_i != l_c; ++l_i) {
		XMLElement *l_element = n.GetDocument()->NewElement("layer");
		if ((*l_i)->serialize(*l_element))
			n.InsertEndChild(l_element);
	}
	
	return(true);
}
Exemplo n.º 27
0
bool CGBFile<GeomType, ValueType>::save(const std::string& directoryname, const std::string& fn, const Volume3d<GeomType, ValueType>& volume)
{	
	const std::string& filename = directoryname + "/" + fn;
	XMLDocument xml;
	XMLDeclaration* decl = xml.NewDeclaration();
	xml.InsertEndChild(decl);
	XMLNode* root = xml.NewElement("root");
	xml.InsertEndChild(root);

	{
		XMLElement* res = xml.NewElement(resStr.c_str());

		res->SetAttribute("x", volume.getResolutions()[0]);
		res->SetAttribute("y", volume.getResolutions()[1]);
		res->SetAttribute("z", volume.getResolutions()[2]);

		root->InsertEndChild(res);
	}

	root->InsertEndChild( create(xml, originStr, volume.getStart()) );
	root->InsertEndChild( create(xml, "length", volume.getSpace().getLengths()));

	imageFileNames.clear();
	{
		XMLElement* e = xml.NewElement("volume");

		e->SetAttribute("type", "unsigned char");
		e->SetAttribute("format", "png");

		VolumeFile vFile(directoryname);
		for (size_t i = 0; i < volume.getResolutions()[2]; ++i) {
			const auto iFile = vFile.toImageFile( "image", i, ImageFile::Type::PNG);
			XMLElement* elem = xml.NewElement("image");
			const auto& str = iFile.getFileNameIncludingPath();
			elem->SetAttribute("path", str.c_str());
			e->InsertEndChild(elem);
			imageFileNames.push_back(str);
		}

		root->InsertEndChild(e);
	}

	//for (size_t i = 0; i < )
	
	xml.SaveFile(filename.c_str());
	return true;
}
/**
 * Write the current object 
 */
void SessionTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Session* psession = dynamic_cast< const Session*>(pObject);
	if( psession == NULL) 
		throw TranslationException("SessionTranslator cannot cast Session object");
	else if( psession->Id().length() == 0)
		return;
	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *psession, ctxt, *pelemc);

	if( !psession->IsReference())
	{
		XMLElement* pelem;
		
		//Write toa
		pelem = elem.GetDocument()->NewElement( "toa");
		pelem->SetText( psession->Toa().toString().c_str());
		pelemc->InsertEndChild( pelem);

		//Write Position
		WriteElement( &psession->Position(), "position", ctxt, *pelemc);

		//TODO Write Attitude 

		//Write poc
		WriteElement("poc",psession->Poc().c_str(), pelemc, false, "");

		//Write conact
		WriteElement("contact",psession->Contact().c_str(), pelemc, false, "");

		//Write campaign
		WriteElement("campaign",psession->Campaign().c_str(), pelemc, false, "");

		//Write scenario
		WriteElement("scenario",psession->Scenario().c_str(), pelemc, false, "");

		//Write system
		WriteList<System>( psession->Systems(), "system", ctxt,*pelemc);		//Write location
	}
	

	elem.InsertEndChild( pelemc);
}
Exemplo n.º 29
0
void FileList::write() {
	XMLDocument doc;
	{
		XMLElement* filelist = doc.NewElement("filelist");
		filelist->SetAttribute("application", "video-organizer");
		filelist->SetAttribute("version", "1.0");
		for (unsigned i = 0; i < records.size(); i++) {
			XMLElement* record = doc.NewElement("record");
			record->SetAttribute("from", records[i].from.c_str());
			record->SetAttribute("to", records[i].to.c_str());
			record->SetAttribute("action", records[i].action);
			filelist->InsertEndChild(record);
		}
		doc.InsertEndChild(filelist);
	}
	XMLError ret = doc.SaveFile((dir + "filelist").c_str());
	if (ret) console.e("Error writing filelist: %s", ret);
}
Exemplo n.º 30
0
void CSessionParameters::save(std::string _filename){
    XMLDocument doc;
    char buffer[300], bufferLabel[100];


    XMLElement* root = doc.NewElement("configuration");
    doc.InsertEndChild(root);
    XMLElement* tmpEle = NULL;

    for( int idx = 1; idx < MAX_NUM_OF_VIDEOS; ++idx ){
        if( filename.count(idx) == 0 || zeroOffset.count(idx) == 0 ){
            continue;
        }
        // filename
        sprintf(bufferLabel, "filename%d", idx);
        XMLElement* tmpEle = doc.NewElement(bufferLabel);
        tmpEle->InsertEndChild( doc.NewText(filename.at(idx).c_str()) );
        root->InsertEndChild(tmpEle);
        // offset
        sprintf(bufferLabel, "offset%d", idx);
        tmpEle = doc.NewElement(bufferLabel);
        sprintf(buffer, "%d", zeroOffset[idx]);
        tmpEle->InsertEndChild( doc.NewText(buffer) );
        root->InsertEndChild(tmpEle);
    }

    // persons
    if( pPersons ){
        tmpEle = doc.NewElement("persons");
        root->InsertEndChild(tmpEle);
        for( std::map<int, CPerson*>::iterator iter = pPersons->begin();
             iter != pPersons->end(); ++iter )
        {
            CPerson* tmpPerson = iter->second;
            tmpPerson->toXml(&doc, tmpEle);
        }
    }

    // time marks
    if( pTimeMarks ){
        tmpEle = doc.NewElement("timeline");
        root->InsertEndChild(tmpEle);
        for( vector<CTimeMark>::iterator iter = pTimeMarks->begin();
             iter != pTimeMarks->end(); ++iter)
        {
            iter->toXml(&doc, tmpEle);
        }
    }

    doc.SaveFile(_filename.c_str());
}