2 /// \file xmlcompactor.h
3 /// Compact an XML file into a map of pretty xpaths and content
7 Copyright (C) 2010-2012, Chris Frey <cdfrey@foursquare.net>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __XMLCOMPACTOR_H__
23 #define __XMLCOMPACTOR_H__
25 #include <libxml++/libxml++.h>
30 : public std::map
<Glib::ustring
, Glib::ustring
>
31 , public xmlpp::DomParser
34 typedef Glib::ustring string_type
;
35 typedef std::map
<string_type
, string_type
> base_map_type
;
36 typedef xmlpp::DomParser base_xml_type
;
37 typedef base_map_type::iterator iterator
;
38 typedef base_map_type::const_iterator const_iterator
;
39 typedef bool (XmlCompactor::*content_handler
)(xmlpp::ContentNode
*);
40 typedef std::vector
<Glib::ustring
> content_set
;
43 Glib::ustring m_skip_prefix
;
44 Glib::ustring m_common_prefix
;
47 Glib::ustring
HackPath(const Glib::ustring
&path
);
48 bool WalkNodes(xmlpp::Node
*node
, content_handler handler
);
49 bool DoMap(xmlpp::ContentNode
*content
);
50 bool ComparePrefix(xmlpp::ContentNode
*content
);
55 /// returns the common prefix of all entries, suitable for
56 /// use as an argument to Map()
57 Glib::ustring
FindCommonPrefix();
59 void Map(const Glib::ustring
&skip
);
60 Glib::ustring
Value(const Glib::ustring
&key
);
66 content_set
Find(const Glib::ustring
&xpath
) const;
68 void Dump(std::ostream
&os
) const;
71 std::ostream
& operator<<(std::ostream
&os
, XmlCompactor
&parser
);