FictionBook2ParserContext.h Source File documentation

FictionBook2ParserContext.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 FICTIONBOOK2PARSERCONTEXT_H_INCLUDED
11 #define FICTIONBOOK2PARSERCONTEXT_H_INCLUDED
12
13 #include "FictionBook2XMLParserContext.h"
14 #include "FictionBook2Style.h"
15
16 namespace libebook
17 {
18
19 class FictionBook2Collector;
20
23 class FictionBook2ParserContext : public FictionBook2XMLParserContext
24 {
25 // no copying
26 FictionBook2ParserContext(const FictionBook2ParserContext &other);
27 FictionBook2ParserContext &operator=(const FictionBook2ParserContext &other);
28
29 public:
35 explicit FictionBook2ParserContext(FictionBook2ParserContext *parentContext, FictionBook2Collector *collector = nullptr);
36
37 FictionBook2XMLParserContext *leaveContext() const override;
38
43 FictionBook2Collector *getCollector() const;
44
49 FictionBook2ParserContext *getParentContext() const;
50
51 private:
52 FictionBook2Collector *const m_collector;
53 FictionBook2ParserContext *const m_parentContext;
54 };
55
61 class FictionBook2NodeContextBase : public FictionBook2ParserContext
62 {
63 public:
64 explicit FictionBook2NodeContextBase(FictionBook2ParserContext *parentContext, FictionBook2Collector *collector = nullptr);
65
66 private:
67 void startOfElement() override;
68 void endOfAttributes() override;
69 void text(const char *value) override;
70 };
71
81 class FictionBook2DataContextBase : public FictionBook2ParserContext
82 {
83 public:
84 explicit FictionBook2DataContextBase(FictionBook2ParserContext *parentContext);
85
86 private:
87 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
88 void startOfElement() override;
89 void endOfAttributes() override;
90 void text(const char *value) override;
91 };
92
98 class FictionBook2TextContextBase : public FictionBook2ParserContext
99 {
100 public:
101 explicit FictionBook2TextContextBase(FictionBook2ParserContext *parentContext);
102
103 private:
104 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
105 void startOfElement() override;
106 void endOfElement() override;
107 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
108 void endOfAttributes() override;
109 };
110
113 class FictionBook2SkipElementContext : public FictionBook2ParserContext
114 {
115 public:
116 explicit FictionBook2SkipElementContext(FictionBook2ParserContext *parentContext);
117
118 private:
119 FictionBook2XMLParserContext *leaveContext() const override;
120
121 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
122 void startOfElement() override;
123 void endOfElement() override;
124 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
125 void endOfAttributes() override;
126 void text(const char *value) override;
127
128 private:
129 unsigned m_level;
130 };
131
132 class FictionBook2StyleContextBase : public FictionBook2ParserContext
133 {
134 public:
135 FictionBook2StyleContextBase(FictionBook2ParserContext *parentContext, const FictionBook2Style &style);
136
137 protected:
138 FictionBook2Style &getStyle();
139 FictionBook2TextFormat &getTextFormat();
140
141 FictionBook2XMLParserContext *element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
142 void endOfElement() override;
143 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
144 void endOfAttributes() override;
145 void text(const char *value) override;
146
147 private:
148 FictionBook2Style m_style;
149 };
150
151 class FictionBook2BlockFormatContextBase : public FictionBook2NodeContextBase
152 {
153 public:
154 FictionBook2BlockFormatContextBase(FictionBook2ParserContext *parentContext, const FictionBook2BlockFormat &format);
155
156 FictionBook2BlockFormat &getBlockFormat();
157 const FictionBook2BlockFormat &getBlockFormat() const;
158
159 void setLang(const char *lang);
160
161 private:
162 FictionBook2BlockFormat m_format;
163 };
164
165 }
166
167 #endif // FICTIONBOOK2PARSERCONTEXT_H_INCLUDED
168
169 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::FictionBook2TextContextBase::element
FictionBook2XMLParserContext * element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition: FictionBook2ParserContext.cpp:85
libebook::FictionBook2SkipElementContext::leaveContext
FictionBook2XMLParserContext * leaveContext() const override
Destroy this context and return parent.
Definition: FictionBook2ParserContext.cpp:112
libebook::FictionBook2BlockFormatContextBase::getBlockFormat
FictionBook2BlockFormat & getBlockFormat()
Definition: FictionBook2ParserContext.cpp:224
libebook::FictionBook2SkipElementContext::m_level
unsigned m_level
Definition: FictionBook2ParserContext.h:129
libebook::FictionBook2ParserContext::getParentContext
FictionBook2ParserContext * getParentContext() const
Get the parent context.
Definition: FictionBook2ParserContext.cpp:36
libebook::FictionBook2TextContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition: FictionBook2ParserContext.cpp:102
libebook::FictionBook2StyleContextBase::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition: FictionBook2ParserContext.cpp:197
libebook::FictionBook2ParserContext::m_collector
FictionBook2Collector *const m_collector
Definition: FictionBook2ParserContext.h:52
libebook::FictionBook2ParserContext::getCollector
FictionBook2Collector * getCollector() const
Get the collector.
Definition: FictionBook2ParserContext.cpp:31
libebook::FictionBook2DataContextBase::FictionBook2DataContextBase
FictionBook2DataContextBase(FictionBook2ParserContext *parentContext)
Definition: FictionBook2ParserContext.cpp:58
libebook::FictionBook2StyleContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition: FictionBook2ParserContext.cpp:201
libebook::FictionBook2NodeContextBase::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition: FictionBook2ParserContext.cpp:46
libebook::FictionBook2TextContextBase::FictionBook2TextContextBase
FictionBook2TextContextBase(FictionBook2ParserContext *parentContext)
Definition: FictionBook2ParserContext.cpp:80
libebook::FictionBook2Style
Definition: FictionBook2Style.h:55
libebook::FictionBook2StyleContextBase
Definition: FictionBook2ParserContext.h:132
libebook::FictionBook2StyleContextBase::getStyle
FictionBook2Style & getStyle()
Definition: FictionBook2ParserContext.cpp:155
libebook::FictionBook2StyleContextBase::element
FictionBook2XMLParserContext * element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition: FictionBook2ParserContext.cpp:165
libebook::FictionBook2SkipElementContext::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition: FictionBook2ParserContext.cpp:132
libebook::EBOOKHTMLToken::lang
Definition: EBOOKHTMLToken.h:205
libebook::FictionBook2XMLParserContext
Definition: FictionBook2XMLParserContext.h:18
libebook::FictionBook2BlockFormatContextBase::m_format
FictionBook2BlockFormat m_format
Definition: FictionBook2ParserContext.h:162
libebook::FictionBook2SkipElementContext::FictionBook2SkipElementContext
FictionBook2SkipElementContext(FictionBook2ParserContext *parentContext)
Definition: FictionBook2ParserContext.cpp:106
libebook::FictionBook2SkipElementContext::element
FictionBook2XMLParserContext * element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition: FictionBook2ParserContext.cpp:122
libebook::FictionBook2SkipElementContext::attribute
void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override
Process an attribute.
Definition: FictionBook2ParserContext.cpp:137
libebook::FictionBook2SkipElementContext::text
void text(const char *value) override
Process textual content of an element.
Definition: FictionBook2ParserContext.cpp:145
libebook::FictionBook2DataContextBase::text
void text(const char *value) override
Process textual content of an element.
Definition: FictionBook2ParserContext.cpp:76
libebook::FictionBook2NodeContextBase::FictionBook2NodeContextBase
FictionBook2NodeContextBase(FictionBook2ParserContext *parentContext, FictionBook2Collector *collector=nullptr)
Definition: FictionBook2ParserContext.cpp:41
libebook::FictionBook2BlockFormatContextBase
Definition: FictionBook2ParserContext.h:151
libebook::FictionBook2DataContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition: FictionBook2ParserContext.cpp:72
libebook::FictionBook2BlockFormat
Definition: FictionBook2Style.h:35
FictionBook2XMLParserContext.h
libebook::FictionBook2TokenData
Definition: FictionBook2Token.h:133
libebook::FictionBook2SkipElementContext
Context for skipping element hierarchies.
Definition: FictionBook2ParserContext.h:113
libebook::FictionBook2StyleContextBase::getTextFormat
FictionBook2TextFormat & getTextFormat()
Definition: FictionBook2ParserContext.cpp:160
libebook::FictionBook2DataContextBase::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition: FictionBook2ParserContext.cpp:68
name
const char * name
Definition: EBOOKHTMLToken.cpp:44
libebook::FictionBook2StyleContextBase::text
void text(const char *value) override
Process textual content of an element.
Definition: FictionBook2ParserContext.cpp:211
libebook::FictionBook2StyleContextBase::FictionBook2StyleContextBase
FictionBook2StyleContextBase(FictionBook2ParserContext *parentContext, const FictionBook2Style &style)
Definition: FictionBook2ParserContext.cpp:149
libebook::FictionBook2BlockFormatContextBase::setLang
void setLang(const char *lang)
Definition: FictionBook2ParserContext.cpp:234
libebook::FictionBook2TextContextBase
Base class for leaf textual element contexts.
Definition: FictionBook2ParserContext.h:98
libebook::FictionBook2NodeContextBase
Base class for non-leaf element contexts.
Definition: FictionBook2ParserContext.h:61
FictionBook2Style.h
libebook::FictionBook2StyleContextBase::m_style
FictionBook2Style m_style
Definition: FictionBook2ParserContext.h:148
libebook::FictionBook2ParserContext::m_parentContext
FictionBook2ParserContext *const m_parentContext
Definition: FictionBook2ParserContext.h:53
libebook::FictionBook2ParserContext
Base class for all contexts.
Definition: FictionBook2ParserContext.h:23
libebook::FictionBook2SkipElementContext::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition: FictionBook2ParserContext.cpp:141
libebook::FictionBook2TextContextBase::attribute
void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override
Process an attribute.
Definition: FictionBook2ParserContext.cpp:98
libebook::EBOOKOPFToken::format
Definition: EBOOKOPFToken.h:54
libebook::FictionBook2ParserContext::operator=
FictionBook2ParserContext & operator=(const FictionBook2ParserContext &other)
libebook::FictionBook2TextContextBase::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition: FictionBook2ParserContext.cpp:90
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::FictionBook2ParserContext::FictionBook2ParserContext
FictionBook2ParserContext(const FictionBook2ParserContext &other)
libebook::FictionBook2TextContextBase::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition: FictionBook2ParserContext.cpp:94
style
optional< Style > style
Definition: TealDocParser.cpp:105
libebook::FictionBook2StyleContextBase::attribute
void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override
Process an attribute.
Definition: FictionBook2ParserContext.cpp:205
libebook::FictionBook2BlockFormatContextBase::FictionBook2BlockFormatContextBase
FictionBook2BlockFormatContextBase(FictionBook2ParserContext *parentContext, const FictionBook2BlockFormat &format)
Definition: FictionBook2ParserContext.cpp:218
libebook::FictionBook2NodeContextBase::text
void text(const char *value) override
Process textual content of an element.
Definition: FictionBook2ParserContext.cpp:54
libebook::FictionBook2TextFormat
Definition: FictionBook2Style.h:21
libebook::FictionBook2DataContextBase
Base class for leaf data element contexts.
Definition: FictionBook2ParserContext.h:81
libebook::FictionBook2DataContextBase::element
FictionBook2XMLParserContext * element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition: FictionBook2ParserContext.cpp:63
libebook::FictionBook2ParserContext::leaveContext
FictionBook2XMLParserContext * leaveContext() const override
Destroy this context and return parent.
Definition: FictionBook2ParserContext.cpp:24
libebook::FictionBook2SkipElementContext::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition: FictionBook2ParserContext.cpp:128
libebook::FictionBook2NodeContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition: FictionBook2ParserContext.cpp:50