FictionBook2BlockContext.h Source File documentation

FictionBook2BlockContext.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 FICTIONBOOK2BLOCKCONTEXT_H_INCLUDED
11 #define FICTIONBOOK2BLOCKCONTEXT_H_INCLUDED
12
13 #include <string>
14
15 #include <boost/optional.hpp>
16
17 #include "FictionBook2ParserContext.h"
18
19 namespace libebook
20 {
21
22 class FictionBook2BodyContext : public FictionBook2NodeContextBase
23 {
24 public:
25 FictionBook2BodyContext(FictionBook2ParserContext *parentContext, FictionBook2Collector *collector);
26
27 private:
28 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
29 void startOfElement() override;
30 void endOfElement() override;
31 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
32
33 private:
34 boost::optional<std::string> m_lang;
35 };
36
37 class FictionBook2CiteContext : public FictionBook2BlockFormatContextBase
38 {
39 public:
40 FictionBook2CiteContext(FictionBook2ParserContext *parentContext, const FictionBook2BlockFormat &format);
41
42 private:
43 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
44 void endOfElement() override;
45 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
46 };
47
48 class FictionBook2EmptyLineContext : public FictionBook2DataContextBase
49 {
50 public:
51 explicit FictionBook2EmptyLineContext(FictionBook2ParserContext *parentContext);
52
53 private:
54 void endOfElement() override;
55 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
56 };
57
58 class FictionBook2EpigraphContext : public FictionBook2BlockFormatContextBase
59 {
60 public:
61 FictionBook2EpigraphContext(FictionBook2ParserContext *parentContext, const FictionBook2BlockFormat &format);
62
63 private:
64 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
65 void endOfElement() override;
66 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
67 };
68
69 class FictionBook2ImageContext : public FictionBook2NodeContextBase
70 {
71 public:
72 FictionBook2ImageContext(FictionBook2ParserContext *parentContext);
73
74 private:
75 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
76 void endOfElement() override;
77 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
78
79 private:
80 std::string m_href;
81 std::string m_altText;
82 bool m_valid;
83 };
84
85 class FictionBook2PoemContext : public FictionBook2BlockFormatContextBase
86 {
87 public:
88 FictionBook2PoemContext(FictionBook2ParserContext *parentContext, const FictionBook2BlockFormat &format);
89
90 private:
91 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
92 void startOfElement() override;
93 void endOfElement() override;
94 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
95 };
96
97 class FictionBook2SectionContext : public FictionBook2NodeContextBase
98 {
99 public:
100 FictionBook2SectionContext(FictionBook2ParserContext *parentContext, const boost::optional<std::string> &lang);
101 FictionBook2SectionContext(FictionBook2ParserContext *parentContext, uint8_t level, const boost::optional<std::string> &lang);
102
103 private:
104 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
105 void endOfElement() override;
106 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
107
108 FictionBook2BlockFormat makeBlockFormat() const;
109
110 private:
111 // The level of the section. A section directly in body is at level 1.
112 boost::optional<uint8_t> m_level;
113 boost::optional<std::string> m_lang;
114 };
115
116 class FictionBook2StanzaContext : public FictionBook2BlockFormatContextBase
117 {
118 public:
119 FictionBook2StanzaContext(FictionBook2ParserContext *parentContext, const FictionBook2BlockFormat &format);
120
121 private:
122 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
123 void endOfElement() override;
124 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
125 };
126
127 class FictionBook2TitleContext : public FictionBook2BlockFormatContextBase
128 {
129 public:
130 FictionBook2TitleContext(FictionBook2ParserContext *const parentContext, const FictionBook2BlockFormat &format);
131
132 private:
133 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
134 void endOfElement() override;
135 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
136 };
137
138 }
139
140 #endif // FICTIONBOOK2BLOCKCONTEXT_H_INCLUDED
141
142 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::FictionBook2TitleContext
Definition: FictionBook2BlockContext.h:127
libebook::FictionBook2BodyContext::FictionBook2BodyContext
FictionBook2BodyContext(FictionBook2ParserContext *parentContext, FictionBook2Collector *collector)
Definition: FictionBook2BlockContext.cpp:20
libebook::FictionBook2SectionContext::m_level
boost::optional< uint8_t > m_level
Definition: FictionBook2BlockContext.h:112
libebook::FictionBook2BodyContext::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition: FictionBook2BlockContext.cpp:52
libebook::EBOOKHTMLToken::lang
Definition: EBOOKHTMLToken.h:205
libebook::FictionBook2XMLParserContext
Definition: FictionBook2XMLParserContext.h:18
libebook::FictionBook2PoemContext
Definition: FictionBook2BlockContext.h:85
FictionBook2ParserContext.h
libebook::FictionBook2ImageContext
Definition: FictionBook2BlockContext.h:69
libebook::FictionBook2BlockFormatContextBase
Definition: FictionBook2ParserContext.h:151
libebook::FictionBook2BlockFormat
Definition: FictionBook2Style.h:35
libebook::FictionBook2TokenData
Definition: FictionBook2Token.h:133
libebook::FictionBook2EpigraphContext
Definition: FictionBook2BlockContext.h:58
libebook::FictionBook2ImageContext::m_altText
std::string m_altText
Definition: FictionBook2BlockContext.h:81
name
const char * name
Definition: EBOOKHTMLToken.cpp:44
libebook::FictionBook2BodyContext::m_lang
boost::optional< std::string > m_lang
Definition: FictionBook2BlockContext.h:34
libebook::FictionBook2ImageContext::m_href
std::string m_href
Definition: FictionBook2BlockContext.h:80
libebook::FictionBook2SectionContext
Definition: FictionBook2BlockContext.h:97
libebook::FictionBook2NodeContextBase
Base class for non-leaf element contexts.
Definition: FictionBook2ParserContext.h:61
libebook::FictionBook2BodyContext::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition: FictionBook2BlockContext.cpp:57
libebook::FictionBook2ImageContext::m_valid
bool m_valid
Definition: FictionBook2BlockContext.h:82
libebook::FictionBook2ParserContext
Base class for all contexts.
Definition: FictionBook2ParserContext.h:23
libebook::EBOOKOPFToken::format
Definition: EBOOKOPFToken.h:54
libebook::FictionBook2StanzaContext
Definition: FictionBook2BlockContext.h:116
libebook::FictionBook2Collector
Definition: FictionBook2Collector.h:22
libebook
Definition: BBeBCollector.cpp:18
value
qi::rule< Iterator, AttrValue_t, qi::space_type > value
Definition: TealDocParser.cpp:231
libebook::FictionBook2CiteContext
Definition: FictionBook2BlockContext.h:37
libebook::FictionBook2BodyContext::attribute
void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override
Process an attribute.
Definition: FictionBook2BlockContext.cpp:62
libebook::FictionBook2SectionContext::m_lang
boost::optional< std::string > m_lang
Definition: FictionBook2BlockContext.h:113
libebook::FictionBook2DataContextBase
Base class for leaf data element contexts.
Definition: FictionBook2ParserContext.h:81
libebook::FictionBook2BodyContext
Definition: FictionBook2BlockContext.h:22
libebook::FictionBook2BodyContext::element
FictionBook2XMLParserContext * element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition: FictionBook2BlockContext.cpp:26
libebook::FictionBook2EmptyLineContext
Definition: FictionBook2BlockContext.h:48