diff options
author | André Nusser <andre.nusser@googlemail.com> | 2016-03-22 00:40:15 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-03-29 22:19:49 +0200 |
commit | 0930fdc014bf36fb9e2715b3d14bff5fedf354a9 (patch) | |
tree | 9136c06ba9311f164e03156312ed449367acf20a /src/saxparser.h | |
parent | 866b09992668f97af063dcd77dc5dd0e3a512b94 (diff) |
Parser refactoring.
* Use new style
* Update to C++11
* Use more std::string than char*
Diffstat (limited to 'src/saxparser.h')
-rw-r--r-- | src/saxparser.h | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/saxparser.h b/src/saxparser.h index cc1800e..3222b4e 100644 --- a/src/saxparser.h +++ b/src/saxparser.h @@ -24,34 +24,37 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __DRUMGIZMO_SAXPARSER_H__ -#define __DRUMGIZMO_SAXPARSER_H__ +#pragma once #include <string> #include <map> #include <expat.h> -typedef std::map< std::string, std::string> attr_t; - class SAXParser { public: - SAXParser(); - virtual ~SAXParser(); + SAXParser(); + virtual ~SAXParser(); - int parse(); - int parse(std::string buffer); - - virtual void characterData(std::string &data) {} - virtual void startTag(std::string name, attr_t attr) {} - virtual void endTag(std::string name) {} + //! Parses the data obtained by readData in chunks. + int parse(); - virtual void parseError(char *buf, size_t len, std::string error, int lineno); + //! Parses all the data in the buffer. + int parse(const std::string& buffer); protected: - virtual int readData(char *data, size_t size) { return 0; } + using attr_t = std::map<std::string, std::string>; + + virtual void characterData(const std::string& data) {} + virtual void startTag(const std::string& name, attr_t& attr) {} + virtual void endTag(const std::string& name) {} + virtual void parseError(const std::string& buf, std::size_t len, const std::string& error, std::size_t lineno); + + virtual int readData(std::string& data, std::size_t size) { return 0; } private: - XML_Parser p; -}; + XML_Parser p; -#endif/*__DRUMGIZMO_SAXPARSER_H__*/ + static void character_hndl(void* p, const XML_Char* s, int len); + static void start_hndl(void* p, const char* el, const char** attr); + static void end_hndl(void* p, const char* el); +}; |