本文整理汇总了C++中pugi::xml_document::first_child方法的典型用法代码示例。如果您正苦于以下问题:C++ xml_document::first_child方法的具体用法?C++ xml_document::first_child怎么用?C++ xml_document::first_child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pugi::xml_document
的用法示例。
在下文中一共展示了xml_document::first_child方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConvertStoryboard
void ConvertStoryboard(pugi::xml_document& doc) {
pugi::xml_node curNode = doc.first_child();
// Storyboard XIB file - get topmost controller, then export it
const char* initialController = curNode.attribute("initialViewController").value();
for (; curNode; curNode = curNode.next_sibling()) {
if (curNode.type() == pugi::xml_node_type::node_element) {
XIBArray* root = new XIBArray();
root->ScanStoryObjects(curNode);
}
}
XIBObject::ParseAllStoryMembers();
// Print which XML nodes we did not handle during the parse for diagnostic purpose.
XIBObject::getDocumentCoverage(doc);
NIBWriter::ExportController(initialController);
Plist::dictionary_type viewControllerInfo;
viewControllerInfo[std::string("UIStoryboardDesignatedEntryPointIdentifier")] =
std::string("UIViewController-") + std::string(initialController);
viewControllerInfo[std::string("UIStoryboardVersion")] = (int)1;
Plist::dictionary_type viewControllerMappings;
for (auto curController : _g_exportedControllers) {
viewControllerMappings[curController.first] = curController.second;
}
viewControllerInfo[std::string("UIViewControllerIdentifiersToNibNames")] = viewControllerMappings;
printf("Writing %s\n", GetOutputFilename("Info.plist").c_str());
Plist::writePlistBinary(GetOutputFilename("Info.plist").c_str(), viewControllerInfo);
}
示例2: xml_header
void Device::xml_header(pugi::xml_document &doc)
{
char uid_c[sizeof(int)];
sprintf(uid_c, "%d", uid);
char battery_c[sizeof(int)];
sprintf(battery_c, "%d", battery);
pugi::xml_node node = doc.first_child();
// UID
pugi::xml_node node_uid = node.append_child("uid");
node_uid.append_child(pugi::node_pcdata).set_value(uid_c);
// msg_version
pugi::xml_node node_msg_version = node.append_child("msg_version");
node_msg_version.append_child(pugi::node_pcdata).set_value(msg_version);
// fw
pugi::xml_node node_fw = node.append_child("fw");
node_fw.append_child(pugi::node_pcdata).set_value(fw_version);
// battery
pugi::xml_node node_battery = node.append_child("battery");
node_battery.append_child(pugi::node_pcdata).set_value(battery_c);
pugi::xml_node node_shutdown = node.append_child("shut_down");
// shutdown
if(state == SHUTDOWN)
node_shutdown.append_child(pugi::node_pcdata).set_value("true");
else
node_shutdown.append_child(pugi::node_pcdata).set_value("false");
}
示例3: process_confirm_xml
int Device::process_confirm_xml(pugi::xml_document &doc)
{
std::stringstream ss;
ss << "Device " << uid << ": Parsing server message" << std::endl;
log(ss.str());
ss.str(std::string());
pugi::xml_node mother_node = doc.first_child();
std::string msg_v = mother_node.child("msg_version").child_value();
if((strcmp(mother_node.name(), "server") != 0) || \
(strcmp(msg_v.c_str(), " 1.0") != 0)) {
ss << "Device " << uid << ": Invalid message, parsing failed" << std::endl;
log(ss.str());
return 0;
}
int uid_test = atoi(mother_node.child("uid").child_value());
if(uid == -1)
update_uid(uid_test);
std::string shutdown = mother_node.child("shut_down").child_value();
if(strcmp(shutdown.c_str(), "true") == 0) {
std::cout << "Shutdown command received, shutting down." << std::endl;
state = SHUTDOWN;
save_readings();
}
int num_readings = atoi(mother_node.child("n_readings").child_value());
pugi::xml_node readings = mother_node.child("readings");
int readings_removed = 0;
for(int i = 0; i < num_readings; i++) {
ss << "reading" << i;
std::string time_c = readings.child(ss.str().c_str()).child("time").child_value();
struct tm tm;
strptime(time_c.c_str(), "%Y-%m-%d %H:%M:%S", &tm);
tm.tm_isdst = -1; // dst not set by strptime
time_t t = mktime(&tm);
if(rm_reading(t))
readings_removed++;
ss.str(std::string());
}
return readings_removed;
}
示例4: process_readings_xml
int Device::process_readings_xml(pugi::xml_document &doc)
{
std::stringstream ss;
ss << "Device " << uid << ": Parsing client message" << std::endl;
log(ss.str());
ss.str(std::string());
pugi::xml_node mother_node = doc.first_child();
std::string msg_v = mother_node.child("msg_version").child_value();
if((strcmp(mother_node.name(), "client") != 0) || \
(strcmp(msg_v.c_str(), " 1.0") != 0)) {
ss << "Device " << uid << ": Invalid message, parsing failed" << std::endl;
log(ss.str());
return 0;
}
int uid_test = atoi(mother_node.child("uid").child_value());
if(uid_test == -1)
update_uid(uid_counter++);
battery = atoi(mother_node.child("battery").child_value());
strncpy(fw_version, mother_node.child("fw").child_value(), 5);
std::string shutdown = mother_node.child("shut_down").child_value();
if(strcmp(shutdown.c_str(), "true") == 0) {
std::cout << "Device shut down" << std::endl;
state = SHUTDOWN;
}
int num_readings = atoi(mother_node.child("n_readings").child_value());
pugi::xml_node readings = mother_node.child("readings");
for(int i = 0; i < num_readings; i++) {
ss << "reading" << i;
std::string time_c = readings.child(ss.str().c_str()).child("time").child_value();
int reading = atoi(readings.child(ss.str().c_str()).child("reading").child_value());
struct tm tm;
strptime(time_c.c_str(), "%Y-%m-%d %H:%M:%S", &tm);
tm.tm_isdst = -1; // dst not set by strptime
time_t t = mktime(&tm);
add_reading(t, reading);
ss.str(std::string());
}
return num_readings;
}
示例5: ConvertXIB3ToNib
void ConvertXIB3ToNib(FILE* fpOut, pugi::xml_document& doc) {
pugi::xml_node curNode = doc.first_child();
// XIB3 file
XIBDocument* rootDocument = new XIBDocument(curNode);
XIBObject::ParseAllStoryMembers();
XIBObject::getDocumentCoverage(doc);
XIBArray* viewObjects = rootDocument->Objects();
if (viewObjects) {
NIBWriter* writer = new NIBWriter(fpOut, NULL, NULL);
XIBArray* arr = (XIBArray*)viewObjects;
for (int i = 0; i < arr->count(); i++) {
XIBObject* curObj = arr->objectAtIndex(i);
writer->ExportObject(curObj);
}
writer->WriteObjects();
}
}
示例6: xml_readings
void Device::xml_readings(pugi::xml_document &doc, bool time_only, int n_readings)
{
pugi::xml_node node = doc.first_child();
pugi::xml_node node_readings = node.append_child("readings");
// readings
std::map<time_t,int>::iterator it = readings.begin();
int i = 0;
while((i < n_readings) && (it != readings.end())) {
char time_c[20];
char reading_c[32];
std::stringstream ss;
format_time(it->first, time_c);
std::sprintf(reading_c, "%d", it->second);
ss << "reading" << i;
pugi::xml_node readingn = node_readings.append_child(ss.str().c_str());
pugi::xml_node time = readingn.append_child("time");
time.append_child(pugi::node_pcdata).set_value(time_c);
if(!time_only) {
pugi::xml_node reading = readingn.append_child("reading");
reading.append_child(pugi::node_pcdata).set_value(reading_c);
}
i++;
it++;
}
char num_readings_c[sizeof(int)];
sprintf(num_readings_c, "%d", i);
// n_readings
pugi::xml_node node_n_readings = node.append_child("n_readings");
node_n_readings.append_child(pugi::node_pcdata).set_value(num_readings_c);
}
示例7: getRootNodeOfDocument
inline XMLNode XMLDocument::getRootNodeOfDocument() const {
// Construct an XMLNode with the root node of the document
pugi::xml_node rootNode = m_document->first_child();
XMLNode rootXMLNode( rootNode );
return rootXMLNode;
}
示例8: loadAnimData
bool ResourceLoader::loadAnimData(AnimationData& aData, const pugi::xml_document &animXmlDoc, const SpriteSheet* sheet)
{
pugi::xml_node animationsXml = animXmlDoc.first_child();
aData.sheetName = animationsXml.attribute("spriteSheet").as_string();
// Iterate through all animations
for (auto& animXml : animationsXml.children()) {
string name = animXml.attribute("name").value();
int frameNum = (int)std::distance(animXml.children().begin(), animXml.children().end());
AnimationData::anim& a = aData.animations.emplace(make_pair(name, AnimationData::anim(frameNum))).first->second;
a.name = name;
a.loops = animXml.attribute("loops").as_uint();
// Iterate through cells in the current animation
int cellIndex = 0;
for (auto& cellXml : animXml.children()) {
AnimationData::frame& f = a.frames[cellIndex];
f.delay = max(1, cellXml.attribute("delay").as_int() * 30900);
std::multimap<int, AnimationData::sprite> zList;
// Iterate through sprites in the current cell
for (auto& spriteXml : cellXml.children()) {
int z = spriteXml.attribute("z").as_int();
std::pair<int, AnimationData::sprite> smap(z, {});
auto& s = smap.second;
string spriteName = spriteXml.attribute("name").as_string();
const auto& it = sheet->sprites.find(spriteName);
if (it == sheet->sprites.end()) {
// Couldn't find the requested sprite!
std::cerr << "ERROR: couldn't find sprite \"" << spriteName << "\" in sheet \"" << sheet->imageName << "\"\n";
return false;
}
// Get draw rect from sprite object, and offset data from anim file
s.draw = { it->second.left, it->second.top, it->second.width, it->second.height };
s.offset.x = spriteXml.attribute("x").as_float() - (int)(s.draw.width / 2.0f);
s.offset.y = spriteXml.attribute("y").as_float() - (int)(s.draw.height / 2.0f);
// Does it need to be flipped?
if (spriteXml.attribute("flipH").as_bool())
{
s.flipH = true;
}
if (spriteXml.attribute("flipV").as_bool())
{
s.flipV = true;
}
// Use an associative container to keep the sprites in this frame in z-order
zList.insert(smap);
}
// Create our vertex array from the collected rect data
f.sprites.resize(zList.size() * 4);
int i = 0;
for (auto z : zList) {
auto& s = z.second;
f.sprites[i].texCoords = { s.draw.left, s.draw.top };
f.sprites[i].position = { s.offset.x, s.offset.y };
f.sprites[i + 1].texCoords = { s.draw.left + s.draw.width, s.draw.top };
f.sprites[i + 1].position = { s.draw.width + s.offset.x, s.offset.y };
f.sprites[i + 2].texCoords = { s.draw.left + s.draw.width, s.draw.top + s.draw.height };
f.sprites[i + 2].position = { s.draw.width + s.offset.x, s.draw.height + s.offset.y };
f.sprites[i + 3].texCoords = { s.draw.left, s.draw.top + s.draw.height };
f.sprites[i + 3].position = { s.offset.x, s.draw.height + s.offset.y };
if (s.flipH)
{
std::swap(f.sprites[i].position, f.sprites[i + 1].position);
std::swap(f.sprites[i + 2].position, f.sprites[i + 3].position);
}
if (s.flipV)
{
std::swap(f.sprites[i].position, f.sprites[i + 3].position);
std::swap(f.sprites[i + 1].position, f.sprites[i + 2].position);
}
i += 4;
}
cellIndex++;
}
}
return true;
}