IWORKXMLContextBase.h Source File documentation

IWORKXMLContextBase.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 libetonyek 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 IWORKXMLCONTEXTBASE_H_INCLUDED
11#define IWORKXMLCONTEXTBASE_H_INCLUDED
12
13#include <boost/enable_shared_from_this.hpp>
14#include <boost/optional.hpp>
15
16#include "IWORKXMLContext.h"
17#include "IWORKTypes_fwd.h"
18
19namespace libetonyek
20{
21
22class IWORKXMLParserState;
23
24class IWORKCollector;
25
26template<class Base, class State, class Collector = IWORKCollector>
27 class IWORKXMLContextBase : public Base
28{
29public:
30 explicit IWORKXMLContextBase(State &state)
31 : Base(state)
32 , m_state(state)
33 {
34 }
35
36 template<typename T>
37 IWORKXMLContextBase(State &state, const T &a)
38 : Base(state, a)
39 , m_state(state)
40 {
41 }
42
43 State &getState()
44 {
45 return m_state;
46 }
47
48protected:
49 Collector &getCollector() const
50 {
51 return m_state.getCollector();
52 }
53
54 int getToken(const char *const value) const
55 {
56 return m_state.getTokenizer().getId(value);
57 }
58
59 bool isCollector() const
60 {
61 return m_state.m_enableCollector;
62 }
63
64protected:
65 State &m_state;
66};
67
68 class IWORKXMLContextMinimal : public IWORKXMLContext
69{
70protected:
71 IWORKXMLContextMinimal();
72
73 void startOfElement() override;
74 void endOfElement() override;
75};
76
77 class IWORKXMLContextElement : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextElement>
78{
79protected:
80 explicit IWORKXMLContextElement(IWORKXMLParserState &);
81
82 void attribute(int name, const char *value) override;
83 void text(const char *value) override;
84
85 const boost::optional<ID_t> &getId() const;
86 void setId(const char *value);
87
88private:
89 boost::optional<ID_t> m_id;
90};
91
92 class IWORKXMLContextText : public IWORKXMLContextMinimal
93{
94protected:
95 explicit IWORKXMLContextText(IWORKXMLParserState &);
96
97 IWORKXMLContextPtr_t element(int token) override;
98};
99
100 class IWORKXMLContextMixed : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextMixed>
101{
102protected:
103 explicit IWORKXMLContextMixed(IWORKXMLParserState &);
104};
105
106 class IWORKXMLContextEmpty : public IWORKXMLContextMinimal
107{
108protected:
109 explicit IWORKXMLContextEmpty(IWORKXMLParserState &);
110
111 void attribute(int name, const char *value) override;
112 IWORKXMLContextPtr_t element(int token) override;
113 void text(const char *value) override;
114
115 const boost::optional<ID_t> &getId() const;
116 void setId(const char *value);
117 const boost::optional<ID_t> &getRef() const;
118
119private:
120 boost::optional<ID_t> m_id;
121 boost::optional<ID_t> m_ref;
122};
123
124 typedef IWORKXMLContextBase<IWORKXMLContextElement, IWORKXMLParserState> IWORKXMLElementContextBase;
125 typedef IWORKXMLContextBase<IWORKXMLContextText, IWORKXMLParserState> IWORKXMLTextContextBase;
126 typedef IWORKXMLContextBase<IWORKXMLContextMixed, IWORKXMLParserState> IWORKXMLMixedContextBase;
127 typedef IWORKXMLContextBase<IWORKXMLContextEmpty, IWORKXMLParserState> IWORKXMLEmptyContextBase;
128
129}
130
131#endif // IWORKXMLCONTEXTBASE_H_INCLUDED
132
133/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
IWORKTypes_fwd.h
IWORKXMLContext.h
libetonyek::IWORKCollector
Definition IWORKCollector.h:42
libetonyek::IWORKXMLContextBase
Definition IWORKXMLContextBase.h:28
libetonyek::IWORKXMLContextBase< IWORKXMLContextElement, IWORKXMLParserState >::m_state
IWORKXMLParserState & m_state
Definition IWORKXMLContextBase.h:65
libetonyek::IWORKXMLContextBase::getToken
int getToken(const char *const value) const
Definition IWORKXMLContextBase.h:54
libetonyek::IWORKXMLContextBase::isCollector
bool isCollector() const
Definition IWORKXMLContextBase.h:59
libetonyek::IWORKXMLContextBase::IWORKXMLContextBase
IWORKXMLContextBase(State &state)
Definition IWORKXMLContextBase.h:30
libetonyek::IWORKXMLContextBase::getState
State & getState()
Definition IWORKXMLContextBase.h:43
libetonyek::IWORKXMLContextBase::IWORKXMLContextBase
IWORKXMLContextBase(State &state, const T &a)
Definition IWORKXMLContextBase.h:37
libetonyek::IWORKXMLContextBase::getCollector
Collector & getCollector() const
Definition IWORKXMLContextBase.h:49
libetonyek::IWORKXMLContextElement::text
void text(const char *value) override
Process textual content of an element.
Definition IWORKXMLContextBase.cpp:42
libetonyek::IWORKXMLContextElement::setId
void setId(const char *value)
Definition IWORKXMLContextBase.cpp:52
libetonyek::IWORKXMLContextElement::IWORKXMLContextElement
IWORKXMLContextElement(IWORKXMLParserState &)
Definition IWORKXMLContextBase.cpp:30
libetonyek::IWORKXMLContextElement::getId
const boost::optional< ID_t > & getId() const
Definition IWORKXMLContextBase.cpp:47
libetonyek::IWORKXMLContextElement::attribute
void attribute(int name, const char *value) override
Process an attribute.
Definition IWORKXMLContextBase.cpp:36
libetonyek::IWORKXMLContextElement::m_id
boost::optional< ID_t > m_id
Definition IWORKXMLContextBase.h:89
libetonyek::IWORKXMLContextEmpty::getRef
const boost::optional< ID_t > & getRef() const
Definition IWORKXMLContextBase.cpp:116
libetonyek::IWORKXMLContextEmpty::text
void text(const char *value) override
Process textual content of an element.
Definition IWORKXMLContextBase.cpp:101
libetonyek::IWORKXMLContextEmpty::getId
const boost::optional< ID_t > & getId() const
Definition IWORKXMLContextBase.cpp:106
libetonyek::IWORKXMLContextEmpty::m_ref
boost::optional< ID_t > m_ref
Definition IWORKXMLContextBase.h:121
libetonyek::IWORKXMLContextEmpty::attribute
void attribute(int name, const char *value) override
Process an attribute.
Definition IWORKXMLContextBase.cpp:80
libetonyek::IWORKXMLContextEmpty::IWORKXMLContextEmpty
IWORKXMLContextEmpty(IWORKXMLParserState &)
Definition IWORKXMLContextBase.cpp:73
libetonyek::IWORKXMLContextEmpty::m_id
boost::optional< ID_t > m_id
Definition IWORKXMLContextBase.h:120
libetonyek::IWORKXMLContextEmpty::element
IWORKXMLContextPtr_t element(int token) override
Create a context for parsing a child element.
Definition IWORKXMLContextBase.cpp:95
libetonyek::IWORKXMLContextEmpty::setId
void setId(const char *value)
Definition IWORKXMLContextBase.cpp:111
libetonyek::IWORKXMLContextMinimal::IWORKXMLContextMinimal
IWORKXMLContextMinimal()
Definition IWORKXMLContextBase.cpp:18
libetonyek::IWORKXMLContextMinimal::startOfElement
void startOfElement() override
Signalize the start of an element.
Definition IWORKXMLContextBase.cpp:22
libetonyek::IWORKXMLContextMinimal::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition IWORKXMLContextBase.cpp:26
libetonyek::IWORKXMLContextMixed::IWORKXMLContextMixed
IWORKXMLContextMixed(IWORKXMLParserState &)
Definition IWORKXMLContextBase.cpp:68
libetonyek::IWORKXMLContextText::IWORKXMLContextText
IWORKXMLContextText(IWORKXMLParserState &)
Definition IWORKXMLContextBase.cpp:57
libetonyek::IWORKXMLContextText::element
IWORKXMLContextPtr_t element(int token) override
Create a context for parsing a child element.
Definition IWORKXMLContextBase.cpp:62
libetonyek::IWORKXMLContext
Definition IWORKXMLContext.h:23
libetonyek::IWORKXMLParserState
Definition IWORKXMLParserState.h:32
libetonyek::IWORKToken::value
@ value
Definition IWORKToken.h:631
libetonyek::IWORKToken::a
@ a
Definition IWORKToken.h:508
libetonyek::IWORKToken::name
@ name
Definition IWORKToken.h:585
libetonyek
Definition IWORKBezierElement.cpp:21
libetonyek::IWORKXMLTextContextBase
IWORKXMLContextBase< IWORKXMLContextText, IWORKXMLParserState > IWORKXMLTextContextBase
Definition IWORKXMLContextBase.h:125
libetonyek::IWORKXMLContextPtr_t
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition IWORKXMLContext.h:20
libetonyek::IWORKXMLEmptyContextBase
IWORKXMLContextBase< IWORKXMLContextEmpty, IWORKXMLParserState > IWORKXMLEmptyContextBase
Definition IWORKXMLContextBase.h:127
libetonyek::IWORKXMLElementContextBase
IWORKXMLContextBase< IWORKXMLContextElement, IWORKXMLParserState > IWORKXMLElementContextBase
Definition IWORKXMLContextBase.h:124
libetonyek::IWORKXMLMixedContextBase
IWORKXMLContextBase< IWORKXMLContextMixed, IWORKXMLParserState > IWORKXMLMixedContextBase
Definition IWORKXMLContextBase.h:126