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 protected:
60  State &m_state;
61 };
62 
64 {
65 protected:
67 
68  virtual void startOfElement();
69  virtual void endOfAttributes();
70  virtual void endOfElement();
71 };
72 
73 class IWORKXMLContextElement : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextElement>
74 {
75 protected:
77 
78  virtual void attribute(int name, const char *value);
79  virtual void text(const char *value);
80 
81  const boost::optional<ID_t> &getId() const;
82 
83 private:
84  boost::optional<ID_t> m_id;
85 };
86 
88 {
89 protected:
91 
92  virtual IWORKXMLContextPtr_t element(int token);
93 };
94 
95 class IWORKXMLContextMixed : public IWORKXMLContextMinimal, public boost::enable_shared_from_this<IWORKXMLContextMixed>
96 {
97 protected:
99 };
100 
102 {
103 protected:
105 
106  virtual void attribute(int name, const char *value);
107  virtual IWORKXMLContextPtr_t element(int token);
108  virtual void text(const char *value);
109 
110  const boost::optional<ID_t> &getId() const;
111  const boost::optional<ID_t> &getRef() const;
112 
113 private:
114  boost::optional<ID_t> m_id;
115  boost::optional<ID_t> m_ref;
116 };
117 
122 
123 }
124 
125 #endif // IWORKXMLCONTEXTBASE_H_INCLUDED
126 
127 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition: IWORKColorElement.cpp:19
IWORKXMLContextMixed(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:67
IWORKXMLContextBase< IWORKXMLContextEmpty, IWORKXMLParserState > IWORKXMLEmptyContextBase
Definition: IWORKXMLContextBase.h:121
const boost::optional< ID_t > & getId() const
Definition: IWORKXMLContextBase.cpp:101
const boost::optional< ID_t > & getRef() const
Definition: IWORKXMLContextBase.cpp:106
virtual void attribute(int name, const char *value)
Process an attribute.
Definition: IWORKXMLContextBase.cpp:40
IWORKXMLContextMinimal()
Definition: IWORKXMLContextBase.cpp:19
Definition: IWORKXMLContextBase.h:101
virtual IWORKXMLContextPtr_t element(int token)
Create a context for parsing a child element.
Definition: IWORKXMLContextBase.cpp:61
IWORKXMLContextEmpty(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:72
IWORKXMLContextElement(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:35
Collector * getCollector() const
Definition: IWORKXMLContextBase.h:49
Definition: IWORKXMLContextBase.h:73
Definition: IWORKToken.h:201
Definition: IWORKXMLContextBase.h:87
Definition: IWORKXMLContext.h:22
virtual void endOfAttributes()
Definition: IWORKXMLContextBase.cpp:27
IWORKXMLContextText(IWORKXMLParserState &)
Definition: IWORKXMLContextBase.cpp:56
boost::optional< ID_t > m_id
Definition: IWORKXMLContextBase.h:84
boost::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
IWORKXMLContextBase< IWORKXMLContextMixed, IWORKXMLParserState > IWORKXMLMixedContextBase
Definition: IWORKXMLContextBase.h:120
State & getState()
Definition: IWORKXMLContextBase.h:43
IWORKXMLContextBase(State &state)
Definition: IWORKXMLContextBase.h:30
Definition: IWORKXMLContextBase.h:95
virtual void attribute(int name, const char *value)
Process an attribute.
Definition: IWORKXMLContextBase.cpp:77
IWORKXMLContextBase< IWORKXMLContextElement, IWORKXMLParserState > IWORKXMLElementContextBase
Definition: IWORKXMLContextBase.h:118
const char * name
Definition: IWORKToken.cpp:43
IWORKXMLContextBase< IWORKXMLContextText, IWORKXMLParserState > IWORKXMLTextContextBase
Definition: IWORKXMLContextBase.h:119
virtual void startOfElement()
Signalize the start of an element.
Definition: IWORKXMLContextBase.cpp:23
const boost::optional< ID_t > & getId() const
Definition: IWORKXMLContextBase.cpp:51
IWORKXMLContextBase(State &state, const T &a)
Definition: IWORKXMLContextBase.h:37
Definition: IWORKXMLContextBase.h:63
virtual void text(const char *value)
Process textual content of an element.
Definition: IWORKXMLContextBase.cpp:96
Definition: IWORKXMLContextBase.h:27
Definition: IWORKXMLParserState.h:21
virtual void text(const char *value)
Process textual content of an element.
Definition: IWORKXMLContextBase.cpp:46
boost::optional< ID_t > m_id
Definition: IWORKXMLContextBase.h:114
boost::optional< ID_t > m_ref
Definition: IWORKXMLContextBase.h:115
int getToken(const char *const value) const
Definition: IWORKXMLContextBase.h:54
virtual void endOfElement()
Signalize the end of an element.
Definition: IWORKXMLContextBase.cpp:31
virtual IWORKXMLContextPtr_t element(int token)
Create a context for parsing a child element.
Definition: IWORKXMLContextBase.cpp:90
State & m_state
Definition: IWORKXMLContextBase.h:60

Generated for libetonyek by doxygen 1.8.8