FB2BlockContext.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 FB2BLOCKCONTEXT_H_INCLUDED
11 #define FB2BLOCKCONTEXT_H_INCLUDED
12
13 #include <string>
14
15 #include <boost/optional.hpp>
16
17 #include "FB2ParserContext.h"
18
19 namespace libebook
20 {
21
22 class FB2BodyContext : public FB2NodeContextBase
23 {
24 public:
25 FB2BodyContext(FB2ParserContext *parentContext, FB2Collector *collector, bool collectHeadings);
26
27 private:
28 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
29 virtual void startOfElement();
30 virtual void endOfElement();
31 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
32
33 private:
34 const bool m_collectHeadings;
35 boost::optional<std::string> m_lang;
36 };
37
38 class FB2CiteContext : public FB2BlockFormatContextBase
39 {
40 public:
41 FB2CiteContext(FB2ParserContext *parentContext, const FB2BlockFormat &format);
42
43 private:
44 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
45 virtual void endOfElement();
46 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
47 };
48
49 class FB2EmptyLineContext : public FB2DataContextBase
50 {
51 public:
52 explicit FB2EmptyLineContext(FB2ParserContext *parentContext);
53
54 private:
55 virtual void endOfElement();
56 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
57 };
58
59 class FB2EpigraphContext : public FB2BlockFormatContextBase
60 {
61 public:
62 FB2EpigraphContext(FB2ParserContext *parentContext, const FB2BlockFormat &format);
63
64 private:
65 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
66 virtual void endOfElement();
67 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
68 };
69
70 class FB2ImageContext : public FB2NodeContextBase
71 {
72 public:
73 FB2ImageContext(FB2ParserContext *parentContext);
74
75 private:
76 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
77 virtual void endOfElement();
78 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
79
80 private:
81 std::string m_href;
82 std::string m_altText;
83 bool m_valid;
84 };
85
86 class FB2PoemContext : public FB2BlockFormatContextBase
87 {
88 public:
89 FB2PoemContext(FB2ParserContext *parentContext, const FB2BlockFormat &format);
90
91 private:
92 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
93 virtual void startOfElement();
94 virtual void endOfElement();
95 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
96 };
97
98 class FB2SectionContext : public FB2NodeContextBase
99 {
100 public:
101 FB2SectionContext(FB2ParserContext *parentContext, const boost::optional<std::string> &lang);
102 FB2SectionContext(FB2ParserContext *parentContext, uint8_t level, const boost::optional<std::string> &lang);
103
104 private:
105 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
106 virtual void endOfElement();
107 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
108
109 FB2BlockFormat makeBlockFormat() const;
110
111 private:
112 // The level of the section. A section directly in body is at level 1.
113 boost::optional<uint8_t> m_level;
114 boost::optional<std::string> m_lang;
115 };
116
117 class FB2StanzaContext : public FB2BlockFormatContextBase
118 {
119 public:
120 FB2StanzaContext(FB2ParserContext *parentContext, const FB2BlockFormat &format);
121
122 private:
123 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
124 virtual void endOfElement();
125 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
126 };
127
128 class FB2TitleContext : public FB2BlockFormatContextBase
129 {
130 public:
131 FB2TitleContext(FB2ParserContext *const parentContext, const FB2BlockFormat &format);
132
133 private:
134 virtual FB2XMLParserContext *element(const FB2TokenData &name, const FB2TokenData &ns);
135 virtual void endOfElement();
136 virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value);
137 };
138
139 }
140
141 #endif // FB2BLOCKCONTEXT_H_INCLUDED
142
143 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::FB2ImageContext::m_altText
std::string m_altText
Definition: FB2BlockContext.h:82
libebook::FB2NodeContextBase
Base class for non-leaf element contexts.
Definition: FB2ParserContext.h:61
FB2ParserContext.h
libebook::FB2DataContextBase
Base class for leaf data element contexts.
Definition: FB2ParserContext.h:81
libebook::FB2BodyContext::startOfElement
virtual void startOfElement()
Signalize the start of an element.
Definition: FB2BlockContext.cpp:57
libebook::FB2Collector
Definition: FB2Collector.h:19
libebook::FB2XMLParserContext
Definition: FB2XMLParserContext.h:18
libebook::FB2TokenData
Definition: FB2Token.h:135
libebook::EBOOKHTMLToken::value
Definition: EBOOKHTMLToken.h:263
libebook::FB2BodyContext::endOfElement
virtual void endOfElement()
Signalize the end of an element.
Definition: FB2BlockContext.cpp:62
libebook::FB2BodyContext::m_collectHeadings
const bool m_collectHeadings
Definition: FB2BlockContext.h:34
libebook::FB2TitleContext
Definition: FB2BlockContext.h:128
libebook::FB2SectionContext::m_lang
boost::optional< std::string > m_lang
Definition: FB2BlockContext.h:114
libebook::FB2ImageContext
Definition: FB2BlockContext.h:70
libebook::FB2BodyContext::m_lang
boost::optional< std::string > m_lang
Definition: FB2BlockContext.h:35
libebook::FB2ImageContext::m_href
std::string m_href
Definition: FB2BlockContext.h:81
libebook::FB2BlockFormatContextBase
Definition: FB2ParserContext.h:151
libebook::FB2ImageContext::m_valid
bool m_valid
Definition: FB2BlockContext.h:83
name
string name
Definition: CHMStream.cpp:80
libebook::FB2BodyContext::attribute
virtual void attribute(const FB2TokenData &name, const FB2TokenData *ns, const char *value)
Process an attribute.
Definition: FB2BlockContext.cpp:67
libebook::FB2StanzaContext
Definition: FB2BlockContext.h:117
libebook::FB2SectionContext
Definition: FB2BlockContext.h:98
libebook::EBOOKHTMLToken::lang
Definition: EBOOKHTMLToken.h:207
libebook::EBOOKOPFToken::format
Definition: EBOOKOPFToken.h:56
libebook::FB2BodyContext::element
virtual FB2XMLParserContext * element(const FB2TokenData &name, const FB2TokenData &ns)
Create a context for parsing a child element.
Definition: FB2BlockContext.cpp:27
libebook::FB2BodyContext::FB2BodyContext
FB2BodyContext(FB2ParserContext *parentContext, FB2Collector *collector, bool collectHeadings)
Definition: FB2BlockContext.cpp:20
libebook::FB2EpigraphContext
Definition: FB2BlockContext.h:59
libebook::FB2EmptyLineContext
Definition: FB2BlockContext.h:49
libebook
Definition: CHMParser.cpp:20
libebook::FB2SectionContext::m_level
boost::optional< uint8_t > m_level
Definition: FB2BlockContext.h:113
libebook::FB2BlockFormat
Definition: FB2Style.h:35
libebook::FB2ParserContext
Base class for all contexts.
Definition: FB2ParserContext.h:23
libebook::FB2BodyContext
Definition: FB2BlockContext.h:22
libebook::FB2PoemContext
Definition: FB2BlockContext.h:86
libebook::FB2CiteContext
Definition: FB2BlockContext.h:38