1
boost::property_tree
라이브러리를 사용하여 XML 파일에서 enum-class를 어떻게 읽습니까?boost :: property_tree를 사용하여 XML에서 C++ 프로그램으로 enum 입력
문자열로 읽고 문자열을 내 프로그램의 열거 형 클래스에 매핑하는 것을 피하고 싶습니다.
boost::property_tree
라이브러리를 사용하여 XML 파일에서 enum-class를 어떻게 읽습니까?boost :: property_tree를 사용하여 XML에서 C++ 프로그램으로 enum 입력
문자열로 읽고 문자열을 내 프로그램의 열거 형 클래스에 매핑하는 것을 피하고 싶습니다.
property_tree/xml_parser.hpp
헤더 파일을 읽습니다. 꽤 간단합니다. 여기
모든 boost::property_tree::xml_parser
네임 스페이스에, 가장 중요한 부분입니다
/**
* Reads XML from an input stream and translates it to property tree.
* @note Clears existing contents of property tree. In case of error the
* property tree unmodified.
* @note XML attributes are placed under keys named @c \<xmlattr\>.
* @throw xml_parser_error In case of error deserializing the property tree.
* @param stream Stream from which to read in the property tree.
* @param[out] pt The property tree to populate.
* @param flags Flags controlling the behaviour of the parser.
* The following flags are supported:
* @li @c no_concat_text -- Prevents concatenation of text nodes into
* datastring of property tree. Puts them in
* separate @c \<xmltext\> strings instead.
* @li @c no_comments -- Skip XML comments.
* @li @c trim_whitespace -- Trim leading and trailing whitespace from text,
* and collapse sequences of whitespace.
*/
template<class Ptree>
void read_xml(std::basic_istream<
typename Ptree::key_type::value_type
> &stream,
Ptree &pt,
int flags = 0)
{
read_xml_internal(stream, pt, flags, std::string());
}
/**
* Reads XML from a file using the given locale and translates it to
* property tree.
* @note Clears existing contents of property tree. In case of error the
* property tree unmodified.
* @note XML attributes are placed under keys named @c \<xmlattr\>.
* @throw xml_parser_error In case of error deserializing the property tree.
* @param filename The file from which to read in the property tree.
* @param[out] pt The property tree to populate.
* @param flags Flags controlling the bahviour of the parser.
* The following flags are supported:
* @li @c no_concat_text -- Prevents concatenation of text nodes into
* datastring of property tree. Puts them in
* separate @c \<xmltext\> strings instead.
* @li @c no_comments -- Skip XML comments.
* @param loc The locale to use when reading in the file contents.
*/
template<class Ptree>
void read_xml(const std::string &filename,
Ptree &pt,
int flags = 0,
const std::locale &loc = std::locale())
{
BOOST_ASSERT(validate_flags(flags));
std::basic_ifstream<typename Ptree::key_type::value_type>
stream(filename.c_str());
if (!stream)
BOOST_PROPERTY_TREE_THROW(xml_parser_error(
"cannot open file", filename, 0));
stream.imbue(loc);
read_xml_internal(stream, pt, flags, filename);
}
링크를 액세스 할 수없는 사람들을 위해 더 정교한 수 있습니까? – 0x499602D2
거기. 더 단순 할 수는 없습니다. – Julius
고마워요! : ==) – 0x499602D2