Boostを使ったXMLの読み込みができない
Posted: 2015年11月26日(木) 06:17
はじめましてsbと言います。
よろしくお願いします
sc.xml
ScMng.cpp
ScMng.h
以上はsc.xmlからboostを使って各項目を読み取るクラスScMngです
動作環境はVisualStudio2015です
boostのバージョンは1.59.0です
読み取った値はScクラス(現段階ではゲッターとセッターのみなので割愛しました)のリストに格納します。
LoadXML()を呼ぶとScMng.cppの20行目あたり、chとphを取得するまではデバッグで確認できたのですが、scの属性がどうしても取得できません。
至らない点もあると思いますが、解答よろしくお願いします。
よろしくお願いします
sc.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<scs ch="H" ph="1">
<sc number="3" path="asdf" angle="3" first_x="23" first_y="34" end_x="45" end_y="12" />
<sc number="4" path="asdf" angle="3" first_x="23" first_y="34" end_x="45" end_y="12" />
<sc number="5" path="asdf" angle="3" first_x="23" first_y="34" end_x="45" end_y="12" />
</scs>
<scs ch="N" ph="1">
<sc number="1" path="asdf" angle="3" first_x="23" first_y="34" end_x="45" end_y="12" />
<sc number="2" path="asdf" angle="3" first_x="23" first_y="34" end_x="45" end_y="12" />
<sc number="3" path="asdf" angle="3" first_x="23" first_y="34" end_x="45" end_y="12" />
</scs>
</root>
#include "ScMng.h"
using namespace boost::property_tree;
//XMLロード
void ScMng::LoadXML() {
ptree pt;
//XML読込
read_xml("xml/sc.xml", pt , xml_parser::no_comments);
//rootの子供を全て確認
for( const ptree::value_type &child : pt.get_child("root") ){
const ptree scs = child.second;
//属性からchとphを取得
std::string ch = scs .get_optional<std::string>("<xmlattr>.ch").get();
int ph = std::atoi(scs .get_optional<std::string>("<xmlattr>.ph").get().c_str());
//リストを作成
std::list<Sc*> sc_list;
//sc分ループ
for ( ptree grand_child : scs .get_child("sc") ){
ptree sc = grand_child;
//必須情報
int number = std::atoi(sc .get<std::string>("<xmlattr>.number").c_str());
int first_x = std::atoi(sc .get<std::string>("first_x").c_str());
int first_y = std::atoi(sc .get_optional<std::string>("<xmlattr>.first_y").get().c_str());
int end_x = std::atoi(sc .get_optional<std::string>("<xmlattr>.end_x").get().c_str());
int end_y = std::atoi(sc .get_optional<std::string>("<xmlattr>.end_y").get().c_str());
std::string path = sc .get_optional<std::string>("<xmlattr>.path").get();
int angle = std::atoi(sc .get_optional<std::string>("<xmlattr>.angle").get().c_str());
sc_list.push_front(new Sc( first_x, first_y, end_x, end_y, path, angle , number));
}
//ハッシュマップにセット
this->sc_map[ch][ph] = sc_list;
}
}
#pragma once
#include <string>
#include <unordered_map>
#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/xml_parser.hpp"
#include "Sc.h"
class ScMng{
private:
std::unordered_map<std::string, std::unordered_map< int, std::list<Sc*> > > sc_map;
public:
//XMLロード
void LoadXML();
};
動作環境はVisualStudio2015です
boostのバージョンは1.59.0です
読み取った値はScクラス(現段階ではゲッターとセッターのみなので割愛しました)のリストに格納します。
LoadXML()を呼ぶとScMng.cppの20行目あたり、chとphを取得するまではデバッグで確認できたのですが、scの属性がどうしても取得できません。
至らない点もあると思いますが、解答よろしくお願いします。