IWORKXMLContextBase.h Source File documentation

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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
19 namespace libetonyek
20 {
21
22 class IWORKXMLParserState;
23
24 class IWORKCollector;
25
26 template<class Base, class State, class Collector = IWORKCollector>
27 class IWORKXMLContextBase : public Base
28 {
29 public:
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
48 protected:
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
64 protected:
65 State &m_state;
66 };
67
68 class IWORKXMLContextMinimal : public IWORKXMLContext
69 {
70 protected:
71 IWORKXMLContextMinimal();
72
73 virtual void startOfElement();
74 virtual void endOfAttributes();
75 virtual void endOfElement();
76 };
77
78 class IWORKXMLContextElement : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextElement>
79 {
80 protected:
81 explicit IWORKXMLContextElement(IWORKXMLParserState &);
82
83 virtual void attribute(int name, const char *value);
84 virtual void text(const char *value);
85
86 const boost::optional<ID_t> &getId() const;
87
88 private:
89 boost::optional<ID_t> m_id;
90 };
91
92 class IWORKXMLContextText : public IWORKXMLContextMinimal
93 {
94 protected:
95 explicit IWORKXMLContextText(IWORKXMLParserState &);
96
97 virtual IWORKXMLContextPtr_t element(int token);
98 };
99
100 class IWORKXMLContextMixed : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextMixed>
101 {
102 protected:
103 explicit IWORKXMLContextMixed(IWORKXMLParserState &);
104 };
105
106 class IWORKXMLContextEmpty : public IWORKXMLContextMinimal
107 {
108 protected:
109 explicit IWORKXMLContextEmpty(IWORKXMLParserState &);
110
111 virtual void attribute(int name, const char *value);
112 virtual IWORKXMLContextPtr_t element(int token);
113 virtual void text(const char *value);
114
115 const boost::optional<ID_t> &getId() const;
116 const boost::optional<ID_t> &getRef() const;
117
118 private:
119 boost::optional<ID_t> m_id;
120 boost::optional<ID_t> m_ref;
121 };
122
123 typedef IWORKXMLContextBase<IWORKXMLContextElement, IWORKXMLParserState> IWORKXMLElementContextBase;
124 typedef IWORKXMLContextBase<IWORKXMLContextText, IWORKXMLParserState> IWORKXMLTextContextBase;
125 typedef IWORKXMLContextBase<IWORKXMLContextMixed, IWORKXMLParserState> IWORKXMLMixedContextBase;
126 typedef IWORKXMLContextBase<IWORKXMLContextEmpty, IWORKXMLParserState> IWORKXMLEmptyContextBase;
127
128 }
129
130 #endif // IWORKXMLCONTEXTBASE_H_INCLUDED
131
132 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek
Definition: IWORKBezierElement.cpp:18
libetonyek::IWORKXMLEmptyContextBase
IWORKXMLContextBase< IWORKXMLContextEmpty, IWORKXMLParserState > IWORKXMLEmptyContextBase
Definition: IWORKXMLContextBase.h:126
libetonyek::IWORKXMLContextEmpty
Definition: IWORKXMLContextBase.h:106
libetonyek::IWORKXMLContextBase::isCollector
bool isCollector() const
Definition: IWORKXMLContextBase.h:59
libetonyek::IWORKXMLContextElement
Definition: IWORKXMLContextBase.h:78
libetonyek::IWORKXMLContextText
Definition: IWORKXMLContextBase.h:92
libetonyek::IWORKXMLContext
Definition: IWORKXMLContext.h:22
libetonyek::IWORKXMLContextElement::m_id
boost::optional< ID_t > m_id
Definition: IWORKXMLContextBase.h:89
libetonyek::IWORKToken::text
Definition: IWORKToken.h:270
IWORKTypes_fwd.h
libetonyek::IWORKXMLContextPtr_t
boost::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
libetonyek::IWORKXMLMixedContextBase
IWORKXMLContextBase< IWORKXMLContextMixed, IWORKXMLParserState > IWORKXMLMixedContextBase
Definition: IWORKXMLContextBase.h:125
libetonyek::IWORKXMLContextBase::getState
State & getState()
Definition: IWORKXMLContextBase.h:43
libetonyek::IWORKXMLContextBase::IWORKXMLContextBase
IWORKXMLContextBase(State &state)
Definition: IWORKXMLContextBase.h:30
libetonyek::IWORKXMLContextBase::getCollector
Collector & getCollector() const
Definition: IWORKXMLContextBase.h:49
libetonyek::IWORKXMLContextMixed
Definition: IWORKXMLContextBase.h:100
libetonyek::IWORKXMLElementContextBase
IWORKXMLContextBase< IWORKXMLContextElement, IWORKXMLParserState > IWORKXMLElementContextBase
Definition: IWORKXMLContextBase.h:123
name
const char * name
Definition: IWORKToken.cpp:43
libetonyek::IWORKXMLTextContextBase
IWORKXMLContextBase< IWORKXMLContextText, IWORKXMLParserState > IWORKXMLTextContextBase
Definition: IWORKXMLContextBase.h:124
libetonyek::IWORKToken::a
Definition: IWORKToken.h:293
libetonyek::IWORKXMLContextBase::IWORKXMLContextBase
IWORKXMLContextBase(State &state, const T &a)
Definition: IWORKXMLContextBase.h:37
libetonyek::IWORKXMLContextMinimal
Definition: IWORKXMLContextBase.h:68
libetonyek::IWORKXMLContextBase
Definition: IWORKXMLContextBase.h:27
libetonyek::IWORKXMLParserState
Definition: IWORKXMLParserState.h:30
libetonyek::IWORKXMLContextEmpty::m_id
boost::optional< ID_t > m_id
Definition: IWORKXMLContextBase.h:119
libetonyek::IWORKXMLContextEmpty::m_ref
boost::optional< ID_t > m_ref
Definition: IWORKXMLContextBase.h:120
libetonyek::IWORKToken::element
Definition: IWORKToken.h:105
libetonyek::IWORKXMLContextBase::getToken
int getToken(const char *const value) const
Definition: IWORKXMLContextBase.h:54
IWORKXMLContext.h
libetonyek::IWORKXMLContextBase::m_state
State & m_state
Definition: IWORKXMLContextBase.h:65