本文整理汇总了C++中TiXmlDocument::SetTabSize方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlDocument::SetTabSize方法的具体用法?C++ TiXmlDocument::SetTabSize怎么用?C++ TiXmlDocument::SetTabSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlDocument
的用法示例。
在下文中一共展示了TiXmlDocument::SetTabSize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
void HouseManager::save(const std::string& fileName)
{
try {
TiXmlDocument doc;
doc.SetTabSize(2);
TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", "");
doc.LinkEndChild(decl);
TiXmlElement* root = new TiXmlElement("houses");
doc.LinkEndChild(root);
for(auto house : m_houses) {
TiXmlElement *elem = new TiXmlElement("house");
house->save(elem);
root->LinkEndChild(elem);
}
std::string savePath = g_resources.getRealPath(fileName);
if(!doc.SaveFile(savePath))
stdext::throw_exception(stdext::format("failed to save houses XML %s: %s", savePath, doc.ErrorDesc()));
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
}
示例2: Schema
Elements::Schema*
Parser::Parse(const std::string& rUri) const throw(XMLException) {
/* search if the document has already been parsed */
if (HasDocument(rUri)) {
return new Elements::Schema(*(GetDocument(rUri)->RootElement()), *this, rUri);
} else {
m_docLst.push_back(new DocumentRecord(new TiXmlDocument(), rUri));
TiXmlDocument * pDoc = m_docLst.back()->m_pDocument;
pDoc->SetTabSize(4);
/* parse protocol portion */
if (0 == rUri.find(PROTO_FILE)) {
std::string path = rUri.substr(sizeof(PROTO_FILE) - 1);
if( !pDoc->LoadFile(path, TIXML_ENCODING_UTF8) ) {
throw XMLException(*pDoc);
}
return new Elements::Schema(*pDoc->RootElement(), *this, rUri);
} else if (std::string::npos == rUri.find("://")) {
/* if no protocol specified then assume it is a local file */
if( !pDoc->LoadFile(rUri, TIXML_ENCODING_UTF8) ) {
throw XMLException(*pDoc);
}
return new Elements::Schema(*pDoc->RootElement(), *this, rUri);
}
}
return NULL;
}
示例3: save
void HouseManager::save(const std::string& fileName)
{
TiXmlDocument doc;
doc.SetTabSize(2);
TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", "");
doc.LinkEndChild(decl);
TiXmlElement* root = new TiXmlElement("houses");
doc.LinkEndChild(root);
for(auto house : m_houses) {
TiXmlElement *elem = new TiXmlElement("house");
house->save(elem);
root->LinkEndChild(elem);
}
if(!doc.SaveFile(fileName))
stdext::throw_exception(stdext::format("failed to save houses XML %s: %s", fileName, doc.ErrorDesc()));
}
示例4: saveSpawns
void CreatureManager::saveSpawns(const std::string& fileName)
{
try {
TiXmlDocument doc;
doc.SetTabSize(2);
TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", "");
doc.LinkEndChild(decl);
TiXmlElement* root = new TiXmlElement("spawns");
doc.LinkEndChild(root);
for(auto pair : m_spawns) {
TiXmlElement* elem = new TiXmlElement("spawn");
pair.second->save(elem);
root->LinkEndChild(elem);
}
if(!doc.SaveFile("data"+fileName))
stdext::throw_exception(stdext::format("failed to save spawns XML %s: %s", fileName, doc.ErrorDesc()));
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
}
示例5: main
//.........这里部分代码省略.........
result = ele->QueryIntAttribute( "bar", &iVal );
XmlTest( "Query attribute: does not exist", result, TIXML_NO_ATTRIBUTE );
}
{
const char* str = "<doc/>";
TiXmlDocument doc;
doc.Parse( str );
TiXmlElement* ele = doc.FirstChildElement();
int iVal;
double dVal;
ele->SetAttribute( "str", "strValue" );
ele->SetAttribute( "int", 1 );
ele->SetDoubleAttribute( "double", -1.0 );
const char* cStr = ele->Attribute( "str" );
ele->QueryIntAttribute( "int", &iVal );
ele->QueryDoubleAttribute( "double", &dVal );
XmlTest( "Attribute round trip. c-string.", "strValue", cStr );
XmlTest( "Attribute round trip. int.", 1, iVal );
XmlTest( "Attribute round trip. double.", -1, (int)dVal );
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
"</room>";
TiXmlDocument doc;
doc.SetTabSize( 8 );
doc.Parse( str );
TiXmlHandle docHandle( &doc );
TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
assert( docHandle.Node() );
assert( roomHandle.Element() );
TiXmlElement* room = roomHandle.Element();
assert( room );
TiXmlAttribute* doors = room->FirstAttribute();
assert( doors );
XmlTest( "Location tracking: Tab 8: room row", room->Row(), 1 );
XmlTest( "Location tracking: Tab 8: room col", room->Column(), 49 );
XmlTest( "Location tracking: Tab 8: doors row", doors->Row(), 1 );
XmlTest( "Location tracking: Tab 8: doors col", doors->Column(), 55 );
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
" <!-- Silly example -->\n"
" <door wall='north'>A great door!</door>\n"
"\t<door wall='east'/>"
"</room>";
TiXmlDocument doc;
doc.Parse( str );
TiXmlHandle docHandle( &doc );
TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
TiXmlHandle commentHandle = docHandle.FirstChildElement( "room" ).FirstChild();
示例6: loadActorsData
void loadActorsData(char *filaname)
{
TiXmlDocument doc;
doc.SetTabSize(8);
doc.LoadFile(filaname);
TiXmlNode *unit = doc.FirstChild("units");
unit = unit->FirstChild("unit");
while (unit)
{
ActorData* actorData = new ActorData();
actorData->ActorType = ActorsData.size();
ActorsData.push_back(actorData);
actorData->Caption = unit->FirstChildElement("name")->GetText();
actorData->Name = unit->FirstChildElement("id")->GetText();
actorData->Price = atoi(unit->FirstChildElement("price")->GetText());
actorData->RequireUpgrade = atoi(unit->FirstChildElement("RequireUpgrade")->GetText());
actorData->BattleUpgradeClass = unit->FirstChildElement("BattleUpgradeClass")->GetText();
actorData->Damage[ActorData::DamageLight] = (float)atof(unit->FirstChildElement("DamageLight")->GetText());
actorData->Damage[ActorData::DamageArmored] = (float)atof(unit->FirstChildElement("DamageArmored")->GetText());
actorData->Damage[ActorData::DamageMassive] = (float)atof(unit->FirstChildElement("DamageMassive")->GetText());
actorData->Damage[ActorData::DamageShield] = (float)atof(unit->FirstChildElement("DamageShield")->GetText());
actorData->Damage[ActorData::DamageOrganic] = (float)atof(unit->FirstChildElement("DamageOrganic")->GetText());
actorData->Damage[ActorData::DamageBuilding] = (float)atof(unit->FirstChildElement("DamageBuilding")->GetText());
actorData->Damage[ActorData::DamageLightAir] = (float)atof(unit->FirstChildElement("DamageLightAir")->GetText());
actorData->Damage[ActorData::DamageArmoredAir] = (float)atof(unit->FirstChildElement("DamageArmoredAir")->GetText());
actorData->Damage[ActorData::DamageMassiveAir] = (float)atof(unit->FirstChildElement("DamageMassiveAir")->GetText());
actorData->Damage[ActorData::DamageShieldAir] = (float)atof(unit->FirstChildElement("DamageShieldAir")->GetText());
actorData->Damage[ActorData::DamageOrganicAir] = (float)atof(unit->FirstChildElement("DamageOrganicAir")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageLight] = (float)atof(unit->FirstChildElement("DamageLightUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageArmored] = (float)atof(unit->FirstChildElement("DamageArmoredUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageMassive] = (float)atof(unit->FirstChildElement("DamageMassiveUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageShield] = (float)atof(unit->FirstChildElement("DamageShieldUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageOrganic] = (float)atof(unit->FirstChildElement("DamageOrganicUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageBuilding] = (float)atof(unit->FirstChildElement("DamageBuildingUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageLightAir] = (float)atof(unit->FirstChildElement("DamageLightAirUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageArmoredAir] = (float)atof(unit->FirstChildElement("DamageArmoredAirUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageMassiveAir] = (float)atof(unit->FirstChildElement("DamageMassiveAirUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageShieldAir] = (float)atof(unit->FirstChildElement("DamageShieldAirUpgradeFactor")->GetText());
actorData->DamageUpgradeFactor[ActorData::DamageOrganicAir] = (float)atof(unit->FirstChildElement("DamageOrganicAirUpgradeFactor")->GetText());
actorData->SplashDamage = (float)atof(unit->FirstChildElement("SplashDamage")->GetText());
actorData->SplashDamageShield = (float)atof(unit->FirstChildElement("SplashDamageShield")->GetText());
actorData->SplashType = unit->FirstChildElement("SplashType")->GetText();
actorData->DistanceSplash = (float)atof(unit->FirstChildElement("DistanceSplash")->GetText());
actorData->AttackDelayAir = 1000.0f * TIME_SCALE * (float)atof(unit->FirstChildElement("AttackDelayAir")->GetText());
actorData->AttackDelayGround = 1000.0f * TIME_SCALE * (float)atof(unit->FirstChildElement("AttackDelayGround")->GetText());
actorData->armour = (float)atof(unit->FirstChildElement("armour")->GetText());
actorData->shield = (float)atof(unit->FirstChildElement("shield")->GetText());
actorData->HP = (float)atof(unit->FirstChildElement("HP")->GetText());
actorData->mana = (float)atof(unit->FirstChildElement("mana")->GetText());
actorData->MoveSpeed = (float)atof(unit->FirstChildElement("MoveSpeed")->GetText());
actorData->UndergroundSpeed = (float)atof(unit->FirstChildElement("UndergroundSpeed")->GetText());
actorData->ImmediateAttack = (bool)atoi(unit->FirstChildElement("ImmediateAttack")->GetText());
actorData->DistanceGround = (float)atof(unit->FirstChildElement("DistanceGround")->GetText());
actorData->DistanceAir = (float)atof(unit->FirstChildElement("DistanceAir")->GetText());
actorData->DetectionDistance = DETECTION_DISTANCE;
actorData->AttackCountGround = atoi(unit->FirstChildElement("AttackCountGround")->GetText());
actorData->AttackCountAir = atoi(unit->FirstChildElement("AttackCountAir")->GetText());
actorData->Detection = (float)atof(unit->FirstChildElement("Detection")->GetText());
actorData->TargetGround = (bool)atoi(unit->FirstChildElement("TargetGround")->GetText());
actorData->TargetAir = (bool)atoi(unit->FirstChildElement("TargetAir")->GetText());
actorData->MovementGround = (bool)atoi(unit->FirstChildElement("MovementGround")->GetText());
actorData->MovementAir = (bool)atoi(unit->FirstChildElement("MovementAir")->GetText());
actorData->LightArmor = (bool)atoi(unit->FirstChildElement("LightArmor")->GetText());
actorData->HavyArmor = (bool)atoi(unit->FirstChildElement("HavyArmor")->GetText());
actorData->Organic = (bool)atoi(unit->FirstChildElement("Organic")->GetText());
actorData->Psionic = (bool)atoi(unit->FirstChildElement("Psionic")->GetText());
actorData->Mechanic = (bool)atoi(unit->FirstChildElement("Mechanic")->GetText());
actorData->Massive = (bool)atoi(unit->FirstChildElement("Massive")->GetText());
actorData->Building = (bool)atoi(unit->FirstChildElement("Building")->GetText());
actorData->effectivity = unit->FirstChildElement("effectivity")->GetText();
actorData->noneffectivity = unit->FirstChildElement("noneffectivity")->GetText();
actorData->GeometryRadius = (float)atof(unit->FirstChildElement("GeometryRadius")->GetText());
unit = unit->NextSibling("unit");
}
//empty data
ActorData* actorData = new ActorData();
ActorsData.push_back(actorData);
}
示例7: main
//.........这里部分代码省略.........
TiXmlDeclaration* declaration = doc.FirstChild()->ToDeclaration();
assert( declaration );
TiXmlElement* room = roomHandle.Element();
assert( room );
TiXmlAttribute* doors = room->FirstAttribute();
assert( doors );
TiXmlText* text = textHandle.Text();
TiXmlComment* comment = commentHandle.Node()->ToComment();
assert( comment );
TiXmlElement* door0 = door0Handle.Element();
TiXmlElement* door1 = door1Handle.Element();
XmlTest( "Location tracking: Declaration row", declaration->Row(), 1 );
XmlTest( "Location tracking: Declaration col", declaration->Column(), 5 );
XmlTest( "Location tracking: room row", room->Row(), 1 );
XmlTest( "Location tracking: room col", room->Column(), 45 );
XmlTest( "Location tracking: doors row", doors->Row(), 1 );
XmlTest( "Location tracking: doors col", doors->Column(), 51 );
XmlTest( "Location tracking: Comment row", comment->Row(), 2 );
XmlTest( "Location tracking: Comment col", comment->Column(), 3 );
XmlTest( "Location tracking: text row", text->Row(), 3 );
XmlTest( "Location tracking: text col", text->Column(), 24 );
XmlTest( "Location tracking: door0 row", door0->Row(), 3 );
XmlTest( "Location tracking: door0 col", door0->Column(), 5 );
XmlTest( "Location tracking: door1 row", door1->Row(), 4 );
XmlTest( "Location tracking: door1 col", door1->Column(), 5 );
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
"</room>";
TiXmlDocument doc;
doc.SetTabSize( 8 );
doc.Parse( str );
TiXmlHandle docHandle( &doc );
TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
assert( docHandle.Node() );
assert( roomHandle.Element() );
TiXmlElement* room = roomHandle.Element();
assert( room );
TiXmlAttribute* doors = room->FirstAttribute();
assert( doors );
XmlTest( "Location tracking: Tab 8: room row", room->Row(), 1 );
XmlTest( "Location tracking: Tab 8: room col", room->Column(), 49 );
XmlTest( "Location tracking: Tab 8: doors row", doors->Row(), 1 );
XmlTest( "Location tracking: Tab 8: doors col", doors->Column(), 55 );
}
{
const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />";
TiXmlDocument doc;
doc.Parse( str );
TiXmlElement* ele = doc.FirstChildElement();
int iVal, result;
double dVal;
result = ele->QueryDoubleAttribute( "attr0", &dVal );
XmlTest( "Query attribute: int as double", result, TIXML_SUCCESS );
示例8: main
//.........这里部分代码省略.........
TiXmlDeclaration* declaration = doc.FirstChild()->ToDeclaration();
assert( declaration );
TiXmlElement* room = roomHandle.Element();
assert( room );
TiXmlAttribute* doors = room->FirstAttribute();
assert( doors );
TiXmlText* text = textHandle.Text();
TiXmlComment* comment = commentHandle.Node()->ToComment();
assert( comment );
TiXmlElement* door0 = door0Handle.Element();
TiXmlElement* door1 = door1Handle.Element();
XmlTest( "Location tracking: Declaration row", declaration->Row(), 1 );
XmlTest( "Location tracking: Declaration col", declaration->Column(), 5 );
XmlTest( "Location tracking: room row", room->Row(), 1 );
XmlTest( "Location tracking: room col", room->Column(), 45 );
XmlTest( "Location tracking: doors row", doors->Row(), 1 );
XmlTest( "Location tracking: doors col", doors->Column(), 51 );
XmlTest( "Location tracking: Comment row", comment->Row(), 2 );
XmlTest( "Location tracking: Comment col", comment->Column(), 3 );
XmlTest( "Location tracking: text row", text->Row(), 3 );
XmlTest( "Location tracking: text col", text->Column(), 24 );
XmlTest( "Location tracking: door0 row", door0->Row(), 3 );
XmlTest( "Location tracking: door0 col", door0->Column(), 5 );
XmlTest( "Location tracking: door1 row", door1->Row(), 4 );
XmlTest( "Location tracking: door1 col", door1->Column(), 5 );
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
"</room>";
TiXmlDocument doc;
doc.SetTabSize( 8 );
doc.Parse( str );
TiXmlHandle docHandle( &doc );
TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
assert( docHandle.Node() );
assert( roomHandle.Element() );
TiXmlElement* room = roomHandle.Element();
assert( room );
TiXmlAttribute* doors = room->FirstAttribute();
assert( doors );
XmlTest( "Location tracking: Tab 8: room row", room->Row(), 1 );
XmlTest( "Location tracking: Tab 8: room col", room->Column(), 49 );
XmlTest( "Location tracking: Tab 8: doors row", doors->Row(), 1 );
XmlTest( "Location tracking: Tab 8: doors col", doors->Column(), 55 );
}
{
const char* str = "<doc attr0='1' attr1='2.0' attr2='foo' />";
TiXmlDocument doc;
doc.Parse( str );
TiXmlElement* ele = doc.FirstChildElement();
int iVal, result;
double dVal;
result = ele->QueryDoubleAttribute( "attr0", &dVal );
XmlTest( "Query attribute: int as double", result, TIXML_SUCCESS );