FB2ParserContext.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libe-book project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef FB2PARSERCONTEXT_H_INCLUDED
11 #define FB2PARSERCONTEXT_H_INCLUDED
12
13 #include "FB2XMLParserContext.h"
14 #include "FB2Style.h"
15
16 namespace libebook
17 {
18
19 class FB2Collector;
20
23 class FB2ParserContext : public FB2XMLParserContext
24 {
25 // no copying
26 FB2ParserContext(const FB2ParserContext &other);
27 FB2ParserContext &operator=(const FB2ParserContext &other);
28
29 public:
35 explicit FB2ParserContext(FB2ParserContext *parentContext, FB2Collector *collector = 0);
36
37 virtual FB2XMLParserContext *leaveContext() const;
38
43 FB2Collector *getCollector() const;
44
49 FB2ParserContext *getParentContext() const;
50
51 private:
52 FB2Collector *const m_collector;
53 FB2ParserContext *const m_parentContext;
54 };
55
61 class FB2NodeContextBase : public FB2ParserContext
62 {
63 public:
64 explicit FB2NodeContextBase(FB2ParserContext *parentContext, FB2Collector *collector = 0);
65
66 private:
67 virtual void startOfElement();
68 virtual void endOfAttributes();
69 virtual void text(const char *value);
70 };
71
81 class FB2DataContextBase : public FB2ParserContext
82 {
83 public:
84 explicit FB2DataContextBase(FB2ParserContext *parentContext);
85
86 private:
87 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
88 virtual void startOfElement();
89 virtual void endOfAttributes();
90 virtual void text(const char *value);
91 };
92
98 class FB2TextContextBase : public FB2ParserContext
99 {
100 public:
101 explicit FB2TextContextBase(FB2ParserContext *parentContext);
102
103 private:
104 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
105 virtual void startOfElement();
106 virtual void endOfElement();
107 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
108 virtual void endOfAttributes();
109 };
110
113 class FB2SkipElementContext : public FB2ParserContext
114 {
115 public:
116 explicit FB2SkipElementContext(FB2ParserContext *parentContext);
117
118 private:
119 virtual FB2XMLParserContext *leaveContext() const;
120
121 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
122 virtual void startOfElement();
123 virtual void endOfElement();
124 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
125 virtual void endOfAttributes();
126 virtual void text(const char *value);
127
128 private:
129 unsigned m_level;
130 };
131
132 class FB2StyleContextBase : public FB2ParserContext
133 {
134 public:
135 FB2StyleContextBase(FB2ParserContext *parentContext, const FB2Style &style);
136
137 protected:
138 FB2Style &getStyle();
139 FB2TextFormat &getTextFormat();
140
141 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
142 virtual void endOfElement();
143 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
144 virtual void endOfAttributes();
145 virtual void text(const char *value);
146
147 private:
148 FB2Style m_style;
149 };
150
151 class FB2BlockFormatContextBase : public FB2NodeContextBase
152 {
153 public:
154 FB2BlockFormatContextBase(FB2ParserContext *parentContext, const FB2BlockFormat &format);
155
156 FB2BlockFormat &getBlockFormat();
157 const FB2BlockFormat &getBlockFormat() const;
158
159 void setLang(const char *lang);
160
161 private:
162 FB2BlockFormat m_format;
163 };
164
165 }
166
167 #endif // FB2PARSERCONTEXT_H_INCLUDED
168
169 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::FB2ParserContext::getParentContext
FB2ParserContext * getParentContext() const
Get the parent context.
Definition: FB2ParserContext.cpp:36
style
optional< Style > style
Definition: TDParser.cpp:106
libebook::FB2NodeContextBase
Base class for non-leaf element contexts.
Definition: FB2ParserContext.h:61
libebook::FB2ParserContext::operator=
FB2ParserContext & operator=(const FB2ParserContext &other)
libebook::FB2DataContextBase
Base class for leaf data element contexts.
Definition: FB2ParserContext.h:81
libebook::FB2XMLParserContext::endOfAttributes
virtual void endOfAttributes()=0
Signalize the end of attributes.
libebook::FB2XMLParserContext::endOfElement
virtual void endOfElement()=0
Signalize the end of an element.
libebook::FB2Collector
Definition: FB2Collector.h:19
libebook::FB2ParserContext::m_parentContext
FB2ParserContext *const m_parentContext
Definition: FB2ParserContext.h:53
libebook::FB2XMLParserContext
Definition: FB2XMLParserContext.h:18
libebook::FB2TokenData
Definition: FB2Token.h:135
libebook::FB2Style
Definition: FB2Style.h:55
libebook::FB2SkipElementContext::m_level
unsigned m_level
Definition: FB2ParserContext.h:129
libebook::EBOOKHTMLToken::value
Definition: EBOOKHTMLToken.h:263
libebook::FB2StyleContextBase::m_style
FB2Style m_style
Definition: FB2ParserContext.h:148
FB2Style.h
libebook::FB2ParserContext::FB2ParserContext
FB2ParserContext(const FB2ParserContext &other)
libebook::FB2XMLParserContext::text
virtual void text(const char *value)=0
Process textual content of an element.
libebook::FB2TextFormat
Definition: FB2Style.h:21
libebook::FB2BlockFormatContextBase
Definition: FB2ParserContext.h:151
libebook::FB2ParserContext::leaveContext
virtual FB2XMLParserContext * leaveContext() const
Destroy this context and return parent.
Definition: FB2ParserContext.cpp:24
name
string name
Definition: CHMStream.cpp:80
libebook::FB2SkipElementContext
Context for skipping element hierarchies.
Definition: FB2ParserContext.h:113
libebook::EBOOKHTMLToken::lang
Definition: EBOOKHTMLToken.h:207
libebook::EBOOKOPFToken::format
Definition: EBOOKOPFToken.h:56
libebook::FB2ParserContext::m_collector
FB2Collector *const m_collector
Definition: FB2ParserContext.h:52
libebook::FB2XMLParserContext::attribute
virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value)=0
Process an attribute.
libebook::FB2BlockFormatContextBase::m_format
FB2BlockFormat m_format
Definition: FB2ParserContext.h:162
libebook
Definition: CHMParser.cpp:20
libebook::FB2TextContextBase
Base class for leaf textual element contexts.
Definition: FB2ParserContext.h:98
libebook::FB2XMLParserContext::element
virtual FB2XMLParserContext * element(const FB2TokenData &name, const FB2TokenData &ns)=0
Create a context for parsing a child element.
libebook::FB2StyleContextBase
Definition: FB2ParserContext.h:132
libebook::FB2BlockFormat
Definition: FB2Style.h:35
FB2XMLParserContext.h
libebook::FB2ParserContext::getCollector
FB2Collector * getCollector() const
Get the collector.
Definition: FB2ParserContext.cpp:31
libebook::FB2ParserContext
Base class for all contexts.
Definition: FB2ParserContext.h:23
libebook::FB2XMLParserContext::startOfElement
virtual void startOfElement()=0
Signalize the start of an element.