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 
69 {
70 protected:
72 
73  void startOfElement() override;
74  virtual void endOfAttributes();
75  void endOfElement() override;
76 };
77 
78 class IWORKXMLContextElement : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextElement>
79 {
80 protected:
82 
83  void attribute(int name, const char *value) override;
84  void text(const char *value) override;
85 
86  const boost::optional<ID_t> &getId() const;
87  void setId(const char *value);
88 
89 private:
90  boost::optional<ID_t> m_id;
91 };
92 
94 {
95 protected:
97 
98  IWORKXMLContextPtr_t element(int token) override;
99 };
100 
101 class IWORKXMLContextMixed : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextMixed>
102 {
103 protected:
105 };
106 
108 {
109 protected:
111 
112  void attribute(int name, const char *value) override;
113  IWORKXMLContextPtr_t element(int token) override;
114  void text(const char *value) override;
115 
116  const boost::optional<ID_t> &getId() const;
117  void setId(const char *value);
118  const boost::optional<ID_t> &getRef() const;
119 
120 private:
121  boost::optional<ID_t> m_id;
122  boost::optional<ID_t> m_ref;
123 };
124 
129 
130 }
131 
132 #endif // IWORKXMLCONTEXTBASE_H_INCLUDED
133 
134 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek::IWORKXMLContextBase::IWORKXMLContextBase
IWORKXMLContextBase(State &state, const T &a)
Definition: IWORKXMLContextBase.h:37
libetonyek::IWORKXMLEmptyContextBase
IWORKXMLContextBase< IWORKXMLContextEmpty, IWORKXMLParserState > IWORKXMLEmptyContextBase
Definition: IWORKXMLContextBase.h:128
libetonyek
Definition: IWORKBezierElement.cpp:20
libetonyek::IWORKToken::ID
@ ID
Definition: IWORKToken.h:499
libetonyek::IWORKXMLContextEmpty::element
IWORKXMLContextPtr_t element(int token) override
Create a context for parsing a child element.
Definition: IWORKXMLContextBase.cpp:99
libetonyek::IWORKXMLContextPtr_t
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
libetonyek::IWORKToken::NS_URI_SFA
@ NS_URI_SFA
Definition: IWORKToken.h:689
libetonyek::IWORKXMLContextEmpty::m_id
boost::optional< ID_t > m_id
Definition: IWORKXMLContextBase.h:121
libetonyek::IWORKXMLContextEmpty::m_ref
boost::optional< ID_t > m_ref
Definition: IWORKXMLContextBase.h:122
libetonyek::IWORKXMLContextElement
Definition: IWORKXMLContextBase.h:78
IWORKXMLContext.h
libetonyek::IWORKXMLContextElement::setId
void setId(const char *value)
Definition: IWORKXMLContextBase.cpp:56
ETONYEK_DEBUG_MSG
#define ETONYEK_DEBUG_MSG(M)
Definition: libetonyek_utils.h:54
libetonyek::IWORKXMLContextElement::getId
const boost::optional< ID_t > & getId() const
Definition: IWORKXMLContextBase.cpp:51
IWORKTypes_fwd.h
libetonyek::IWORKXMLContextEmpty
Definition: IWORKXMLContextBase.h:107
libetonyek::IWORKXMLContextBase::isCollector
bool isCollector() const
Definition: IWORKXMLContextBase.h:59
libetonyek::IWORKXMLParserState
Definition: IWORKXMLParserState.h:31
libetonyek::IWORKXMLContextText
Definition: IWORKXMLContextBase.h:93
libetonyek::IWORKXMLContextEmpty::text
void text(const char *value) override
Process textual content of an element.
Definition: IWORKXMLContextBase.cpp:105
libetonyek::IWORKXMLContextBase::IWORKXMLContextBase
IWORKXMLContextBase(State &state)
Definition: IWORKXMLContextBase.h:30
libetonyek::IWORKXMLContextBase::getCollector
Collector & getCollector() const
Definition: IWORKXMLContextBase.h:49
libetonyek::IWORKXMLContextMinimal
Definition: IWORKXMLContextBase.h:68
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::IWORKXMLContextElement::m_id
boost::optional< ID_t > m_id
Definition: IWORKXMLContextBase.h:90
libetonyek::IWORKXMLContextEmpty::setId
void setId(const char *value)
Definition: IWORKXMLContextBase.cpp:115
libetonyek_utils.h
libetonyek::IWORKXMLContextMixed
Definition: IWORKXMLContextBase.h:101
libetonyek::IWORKXMLContextElement::attribute
void attribute(int name, const char *value) override
Process an attribute.
Definition: IWORKXMLContextBase.cpp:40
libetonyek::IWORKXMLContextMixed::IWORKXMLContextMixed
IWORKXMLContextMixed(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:72
libetonyek::IWORKXMLContextMinimal::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition: IWORKXMLContextBase.cpp:30
libetonyek::IWORKXMLContextElement::IWORKXMLContextElement
IWORKXMLContextElement(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:34
libetonyek::IWORKXMLContextEmpty::IWORKXMLContextEmpty
IWORKXMLContextEmpty(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:77
libetonyek::IWORKXMLContextBase
Definition: IWORKXMLContextBase.h:27
IWORKXMLParserState.h
libetonyek::IWORKXMLElementContextBase
IWORKXMLContextBase< IWORKXMLContextElement, IWORKXMLParserState > IWORKXMLElementContextBase
Definition: IWORKXMLContextBase.h:125
libetonyek::IWORKXMLContextBase::m_state
State & m_state
Definition: IWORKXMLContextBase.h:65
libetonyek::IWORKToken::IDREF
@ IDREF
Definition: IWORKToken.h:500
libetonyek::IWORKToken::a
@ a
Definition: IWORKToken.h:501
libetonyek::IWORKXMLContext
Definition: IWORKXMLContext.h:22
libetonyek::IWORKXMLContextText::IWORKXMLContextText
IWORKXMLContextText(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:61
libetonyek::IWORKXMLContextElement::text
void text(const char *value) override
Process textual content of an element.
Definition: IWORKXMLContextBase.cpp:46
IWORKXMLContextBase.h
libetonyek::IWORKXMLContextEmpty::getId
const boost::optional< ID_t > & getId() const
Definition: IWORKXMLContextBase.cpp:110
libetonyek::IWORKXMLContextMinimal::endOfAttributes
virtual void endOfAttributes()
Definition: IWORKXMLContextBase.cpp:26
m_id
boost::optional< ID_t > m_id
Definition: IWORKLineEndElement.cpp:34
IWORKToken.h
libetonyek::IWORKXMLTextContextBase
IWORKXMLContextBase< IWORKXMLContextText, IWORKXMLParserState > IWORKXMLTextContextBase
Definition: IWORKXMLContextBase.h:126
m_ref
boost::optional< ID_t > m_ref
Definition: IWORKPathElement.cpp:285
libetonyek::IWORKXMLContextBase::getToken
int getToken(const char *const value) const
Definition: IWORKXMLContextBase.h:54
libetonyek::IWORKXMLContextText::element
IWORKXMLContextPtr_t element(int token) override
Create a context for parsing a child element.
Definition: IWORKXMLContextBase.cpp:66
libetonyek::IWORKXMLContextEmpty::attribute
void attribute(int name, const char *value) override
Process an attribute.
Definition: IWORKXMLContextBase.cpp:84
libetonyek::IWORKXMLContextEmpty::getRef
const boost::optional< ID_t > & getRef() const
Definition: IWORKXMLContextBase.cpp:120
libetonyek::IWORKXMLMixedContextBase
IWORKXMLContextBase< IWORKXMLContextMixed, IWORKXMLParserState > IWORKXMLMixedContextBase
Definition: IWORKXMLContextBase.h:127
libetonyek::IWORKToken::name
@ name
Definition: IWORKToken.h:578
libetonyek::IWORKToken::value
@ value
Definition: IWORKToken.h:624
libetonyek::IWORKXMLContextBase::getState
State & getState()
Definition: IWORKXMLContextBase.h:43

Generated for libetonyek by doxygen 1.8.17