File: xmlhandler.h

package info (click to toggle)
libopenraw 0.0.9-3.5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,068 kB
  • ctags: 1,830
  • sloc: sh: 11,089; cpp: 9,341; ansic: 1,535; makefile: 566; xml: 507; perl: 42
file content (109 lines) | stat: -rw-r--r-- 2,272 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * libopenraw - xmlhandler.h
 *
 * Copyright (C) 2008 Hubert Figuiere
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */


#ifndef _XML_HANDLER_H_
#define _XML_HANDLER_H_

#include <stdint.h>
#include <libxml/xmlreader.h>
#include <stack>
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>

namespace xml {


class LtString
{
public:
	bool operator()(const xmlChar* s1, const xmlChar* s2) const;
};


class Handler;
typedef boost::shared_ptr<Handler> HandlerPtr;

class Context;
typedef boost::shared_ptr<Context> ContextPtr;

class Context
	: public boost::enable_shared_from_this<Context>
{
public:
	Context(const HandlerPtr & handler);
	virtual ~Context();

	virtual ContextPtr startElement(int32_t element);
	virtual void endElement(int32_t element);
	virtual void appendText(const xmlChar * content);
protected:
	HandlerPtr m_handler;
};



struct tag_map_definition_t;

class Handler
	: public Context
{
public:
	typedef std::map<const xmlChar *, int32_t, xml::LtString> tag_map_t;

	Handler(const std::string & filename);
	~Handler();

	int32_t getTagId(const xmlChar * tag);
	bool process();

protected:
	void mapTags(const tag_map_definition_t * map);

private:
	std::stack<ContextPtr> m_contexts;
	tag_map_t              m_tag_map;
	xmlTextReaderPtr       m_reader;
};


struct tag_map_definition_t
{
	const char * first;
	int32_t second;
};


class SimpleElementContext
	: public Context
{
public:
	SimpleElementContext(const HandlerPtr & handler, std::string & content);
	virtual void appendText(const xmlChar * content);
private:
	std::string & m_content;
};

}


#endif