4
4
* Regina - A Normal Surface Theory Calculator *
5
5
* Computational Engine *
7
* Copyright (c) 1999-2009, Ben Burton *
7
* Copyright (c) 1999-2011, Ben Burton *
8
8
* For further details contact Ben Burton (bab@debian.org). *
10
10
* This program is free software; you can redistribute it and/or *
29
/*! \file utilities/xmlutils.h
30
30
* \brief Various classes and routines for XML manipulation, some taken
31
31
* or modified from the libxml++ library. The libxml2 library is used
32
32
* to do most of the underlying work.
69
* Represents a hashed map from property names to property values.
69
* Represents a map from property names to property values.
71
71
* \ifacespython Not present.
73
class XMLPropertyDict : public stdhash::hash_map<std::string,
74
std::string, HashString> {
73
class REGINA_API XMLPropertyDict : private std::map<std::string, std::string> {
77
* Create a new hashed map.
82
81
* Return a value for the given key, even if the key does not
83
* exist in the hashed map.
85
84
* @param key the key to look up.
86
85
* @param defaultVal the value to return if the key does not exist.
87
86
* @return the value associated with the given key, or parameter
88
* \a default if the key does not exist in the hashed map.
87
* \a default if the key does not exist in the map.
90
89
const std::string& lookup(const std::string& key,
91
90
const std::string& defaultVal = std::string()) const;
92
using std::map<std::string, std::string>::const_iterator;
93
using std::map<std::string, std::string>::begin;
94
using std::map<std::string, std::string>::end;
95
using std::map<std::string, std::string>::find;
96
using std::map<std::string, std::string>::operator [];
105
110
* @author This class was taken and modified from the libxml++ library
106
111
* (<tt>http://lusis.org/~ari/xml++/</tt>).
108
class XMLParserCallback {
113
class REGINA_API XMLParserCallback {
111
116
* Default destructor that does nothing.
126
131
* Called when an element's opening tag is encountered.
128
133
* @param n the name of the tag.
129
* @param p a hashed dictionary of all the properties of the tag.
134
* @param p a dictionary of all the properties of the tag.
131
136
virtual void start_element(const std::string& n,
132
137
const regina::xml::XMLPropertyDict& p);
190
195
* @author This class was taken and modified from the libxml++ library
191
196
* (<tt>http://lusis.org/~ari/xml++/</tt>).
198
class REGINA_API XMLParser {
195
200
XMLParserCallback& _parser_callback;
196
201
/**< Provides the callback routines to use with this parser. */
291
296
* @return the converted string with special characters replaced by
294
std::string xmlEncodeSpecialChars(const std::string& original);
299
REGINA_API std::string xmlEncodeSpecialChars(const std::string& original);
297
302
* Returns the given string encoded so it is suitable for use inside an
306
311
* @return the string converted to be usable inside an XML comment.
308
std::string xmlEncodeComment(const std::string& comment);
313
REGINA_API std::string xmlEncodeComment(const std::string& comment);
311
316
* Returns an XML tag with a single property containing the given value.
397
402
inline void XMLParser::parse_chunk(const std::string& s) {
398
xmlParseChunk(_context, s.c_str(), s.length(), 0);
403
xmlParseChunk(_context, s.c_str(), static_cast<int>(s.length()), 0);
401
406
inline void XMLParser::finish() {