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
16namespace libebook
17{
18
19class FictionBook2Collector;
20
23 class FictionBook2ParserContext : public FictionBook2XMLParserContext, public std::enable_shared_from_this<FictionBook2ParserContext>
24{
25 // no copying
26 FictionBook2ParserContext(const FictionBook2ParserContext &other);
27 FictionBook2ParserContext &operator=(const FictionBook2ParserContext &other);
28
29public:
35 explicit FictionBook2ParserContext(std::shared_ptr<FictionBook2ParserContext> parentContext, FictionBook2Collector *collector = nullptr);
36
37 virtual ~FictionBook2ParserContext();
38
39 std::shared_ptr<FictionBook2XMLParserContext> leaveContext() const override;
40
45 FictionBook2Collector *getCollector() const;
46
51 std::shared_ptr<FictionBook2ParserContext> getParentContext() const;
52
53private:
54 FictionBook2Collector *const m_collector;
55 std::shared_ptr<FictionBook2ParserContext> const m_parentContext;
56};
57
63 class FictionBook2NodeContextBase : public FictionBook2ParserContext
64{
65public:
66 explicit FictionBook2NodeContextBase(std::shared_ptr<FictionBook2ParserContext> parentContext, FictionBook2Collector *collector = nullptr);
67
68private:
69 void startOfElement() override;
70 void endOfAttributes() override;
71 void text(const char *value) override;
72};
73
83 class FictionBook2DataContextBase : public FictionBook2ParserContext
84{
85public:
86 explicit FictionBook2DataContextBase(std::shared_ptr<FictionBook2ParserContext> parentContext);
87
88private:
89 std::shared_ptr<FictionBook2XMLParserContext> element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
90 void startOfElement() override;
91 void endOfAttributes() override;
92 void text(const char *value) override;
93};
94
100 class FictionBook2TextContextBase : public FictionBook2ParserContext
101{
102public:
103 explicit FictionBook2TextContextBase(std::shared_ptr<FictionBook2ParserContext> parentContext);
104
105private:
106 std::shared_ptr<FictionBook2XMLParserContext> element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
107 void startOfElement() override;
108 void endOfElement() override;
109 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
110 void endOfAttributes() override;
111};
112
115 class FictionBook2SkipElementContext : public FictionBook2ParserContext
116{
117public:
118 explicit FictionBook2SkipElementContext(std::shared_ptr<FictionBook2ParserContext> parentContext);
119
120private:
121 std::shared_ptr<FictionBook2XMLParserContext> leaveContext() const override;
122
123 std::shared_ptr<FictionBook2XMLParserContext> element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
124 void startOfElement() override;
125 void endOfElement() override;
126 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
127 void endOfAttributes() override;
128 void text(const char *value) override;
129
130private:
131 unsigned m_level;
132};
133
134 class FictionBook2StyleContextBase : public FictionBook2ParserContext
135{
136public:
137 FictionBook2StyleContextBase(std::shared_ptr<FictionBook2ParserContext> parentContext, const FictionBook2Style &style);
138
139protected:
140 FictionBook2Style &getStyle();
141 FictionBook2TextFormat &getTextFormat();
142
143 std::shared_ptr<FictionBook2XMLParserContext> element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override;
144 void endOfElement() override;
145 void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override;
146 void endOfAttributes() override;
147 void text(const char *value) override;
148
149private:
150 FictionBook2Style m_style;
151};
152
153 class FictionBook2BlockFormatContextBase : public FictionBook2NodeContextBase
154{
155public:
156 FictionBook2BlockFormatContextBase(std::shared_ptr<FictionBook2ParserContext> parentContext, const FictionBook2BlockFormat &format);
157
158 FictionBook2BlockFormat &getBlockFormat();
159 const FictionBook2BlockFormat &getBlockFormat() const;
160
161 void setLang(const char *lang);
162
163private:
164 FictionBook2BlockFormat m_format;
165};
166
167}
168
169#endif // FICTIONBOOK2PARSERCONTEXT_H_INCLUDED
170
171/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
FictionBook2Style.h
FictionBook2XMLParserContext.h
libebook::FictionBook2BlockFormatContextBase::m_format
FictionBook2BlockFormat m_format
Definition FictionBook2ParserContext.h:164
libebook::FictionBook2BlockFormatContextBase::getBlockFormat
FictionBook2BlockFormat & getBlockFormat()
Definition FictionBook2ParserContext.cpp:223
libebook::FictionBook2BlockFormatContextBase::setLang
void setLang(const char *lang)
Definition FictionBook2ParserContext.cpp:233
libebook::FictionBook2BlockFormatContextBase::FictionBook2BlockFormatContextBase
FictionBook2BlockFormatContextBase(std::shared_ptr< FictionBook2ParserContext > parentContext, const FictionBook2BlockFormat &format)
Definition FictionBook2ParserContext.cpp:217
libebook::FictionBook2Collector
Definition FictionBook2Collector.h:23
libebook::FictionBook2DataContextBase::element
std::shared_ptr< FictionBook2XMLParserContext > element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition FictionBook2ParserContext.cpp:65
libebook::FictionBook2DataContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition FictionBook2ParserContext.cpp:74
libebook::FictionBook2DataContextBase::FictionBook2DataContextBase
FictionBook2DataContextBase(std::shared_ptr< FictionBook2ParserContext > parentContext)
Definition FictionBook2ParserContext.cpp:60
libebook::FictionBook2DataContextBase::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition FictionBook2ParserContext.cpp:70
libebook::FictionBook2NodeContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition FictionBook2ParserContext.cpp:52
libebook::FictionBook2NodeContextBase::FictionBook2NodeContextBase
FictionBook2NodeContextBase(std::shared_ptr< FictionBook2ParserContext > parentContext, FictionBook2Collector *collector=nullptr)
Definition FictionBook2ParserContext.cpp:43
libebook::FictionBook2NodeContextBase::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition FictionBook2ParserContext.cpp:48
libebook::FictionBook2ParserContext::~FictionBook2ParserContext
virtual ~FictionBook2ParserContext()
Definition FictionBook2ParserContext.cpp:24
libebook::FictionBook2ParserContext::getCollector
FictionBook2Collector * getCollector() const
Get the collector.
Definition FictionBook2ParserContext.cpp:33
libebook::FictionBook2ParserContext::m_parentContext
std::shared_ptr< FictionBook2ParserContext > const m_parentContext
Definition FictionBook2ParserContext.h:55
libebook::FictionBook2ParserContext::FictionBook2ParserContext
FictionBook2ParserContext(const FictionBook2ParserContext &other)
libebook::FictionBook2ParserContext::m_collector
FictionBook2Collector *const m_collector
Definition FictionBook2ParserContext.h:54
libebook::FictionBook2ParserContext::operator=
FictionBook2ParserContext & operator=(const FictionBook2ParserContext &other)
libebook::FictionBook2ParserContext::getParentContext
std::shared_ptr< FictionBook2ParserContext > getParentContext() const
Get the parent context.
Definition FictionBook2ParserContext.cpp:38
libebook::FictionBook2ParserContext::leaveContext
std::shared_ptr< FictionBook2XMLParserContext > leaveContext() const override
Destroy this context and return parent.
Definition FictionBook2ParserContext.cpp:28
libebook::FictionBook2SkipElementContext::attribute
void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override
Process an attribute.
Definition FictionBook2ParserContext.cpp:136
libebook::FictionBook2SkipElementContext::FictionBook2SkipElementContext
FictionBook2SkipElementContext(std::shared_ptr< FictionBook2ParserContext > parentContext)
Definition FictionBook2ParserContext.cpp:108
libebook::FictionBook2SkipElementContext::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition FictionBook2ParserContext.cpp:131
libebook::FictionBook2SkipElementContext::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition FictionBook2ParserContext.cpp:140
libebook::FictionBook2SkipElementContext::leaveContext
std::shared_ptr< FictionBook2XMLParserContext > leaveContext() const override
Destroy this context and return parent.
Definition FictionBook2ParserContext.cpp:114
libebook::FictionBook2SkipElementContext::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition FictionBook2ParserContext.cpp:127
libebook::FictionBook2SkipElementContext::m_level
unsigned m_level
Definition FictionBook2ParserContext.h:131
libebook::FictionBook2SkipElementContext::element
std::shared_ptr< FictionBook2XMLParserContext > element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition FictionBook2ParserContext.cpp:121
libebook::FictionBook2StyleContextBase::getStyle
FictionBook2Style & getStyle()
Definition FictionBook2ParserContext.cpp:154
libebook::FictionBook2StyleContextBase::FictionBook2StyleContextBase
FictionBook2StyleContextBase(std::shared_ptr< FictionBook2ParserContext > parentContext, const FictionBook2Style &style)
Definition FictionBook2ParserContext.cpp:148
libebook::FictionBook2StyleContextBase::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition FictionBook2ParserContext.cpp:196
libebook::FictionBook2StyleContextBase::m_style
FictionBook2Style m_style
Definition FictionBook2ParserContext.h:150
libebook::FictionBook2StyleContextBase::element
std::shared_ptr< FictionBook2XMLParserContext > element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition FictionBook2ParserContext.cpp:164
libebook::FictionBook2StyleContextBase::getTextFormat
FictionBook2TextFormat & getTextFormat()
Definition FictionBook2ParserContext.cpp:159
libebook::FictionBook2StyleContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition FictionBook2ParserContext.cpp:200
libebook::FictionBook2StyleContextBase::attribute
void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override
Process an attribute.
Definition FictionBook2ParserContext.cpp:204
libebook::FictionBook2Style
Definition FictionBook2Style.h:56
libebook::FictionBook2TextContextBase::endOfAttributes
void endOfAttributes() override
Signalize the end of attributes.
Definition FictionBook2ParserContext.cpp:104
libebook::FictionBook2TextContextBase::FictionBook2TextContextBase
FictionBook2TextContextBase(std::shared_ptr< FictionBook2ParserContext > parentContext)
Definition FictionBook2ParserContext.cpp:82
libebook::FictionBook2TextContextBase::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition FictionBook2ParserContext.cpp:92
libebook::FictionBook2TextContextBase::element
std::shared_ptr< FictionBook2XMLParserContext > element(const FictionBook2TokenData &name, const FictionBook2TokenData &ns) override
Create a context for parsing a child element.
Definition FictionBook2ParserContext.cpp:87
libebook::FictionBook2TextContextBase::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition FictionBook2ParserContext.cpp:96
libebook::FictionBook2TextContextBase::attribute
void attribute(const FictionBook2TokenData &name, const FictionBook2TokenData *ns, const char *value) override
Process an attribute.
Definition FictionBook2ParserContext.cpp:100
libebook::FictionBook2XMLParserContext
Definition FictionBook2XMLParserContext.h:21
libebook::EBOOKHTMLToken::lang
@ lang
Definition EBOOKHTMLToken.h:205
libebook::EBOOKHTMLToken::value
@ value
Definition EBOOKHTMLToken.h:261
libebook::EBOOKHTMLToken::style
@ style
Definition EBOOKHTMLToken.h:135
libebook::EBOOKHTMLToken::name
@ name
Definition EBOOKHTMLToken.h:214
libebook::EBOOKHTMLToken::text
@ text
Definition EBOOKHTMLToken.h:257
libebook::EBOOKOPFToken::format
@ format
Definition EBOOKOPFToken.h:54
libebook
Definition BBeBCollector.cpp:20
libebook::FictionBook2BlockFormat
Definition FictionBook2Style.h:36
libebook::FictionBook2TextFormat
Definition FictionBook2Style.h:22
libebook::FictionBook2TokenData
Definition FictionBook2Token.h:134