[*_restore] Use a little wrapper class for the expat XML_Parser to ensure it gets destroyed.
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <expat.h>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
@ -10,6 +11,29 @@ using namespace std;
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace xml_utils {
|
||||
// Simple wrapper to ensure the parser gets freed if an exception
|
||||
// is thrown during parsing.
|
||||
class xml_parser {
|
||||
public:
|
||||
xml_parser()
|
||||
: parser_(XML_ParserCreate(NULL)) {
|
||||
|
||||
if (!parser_)
|
||||
throw runtime_error("couldn't create xml parser");
|
||||
}
|
||||
|
||||
~xml_parser() {
|
||||
XML_ParserFree(parser_);
|
||||
}
|
||||
|
||||
XML_Parser get_parser() {
|
||||
return parser_;
|
||||
}
|
||||
|
||||
private:
|
||||
XML_Parser parser_;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::string> attributes;
|
||||
|
||||
void build_attributes(attributes &a, char const **attr);
|
||||
|
Reference in New Issue
Block a user