libexpatpp 0.1.8
state.hpp
Go to the documentation of this file.
1
9#ifndef xmlpp_state_hpp
10#define xmlpp_state_hpp
11
12#include <list>
13#include <stack>
14#include <functional>
15
16#include "delegate.hpp"
17
18namespace xmlpp {
19
20struct State {
21 explicit State(const std::string& _tag,
22 std::function<void (const XML_Char **atts)> _pfStart = nullptr,
23 std::function<void ()> _pfEnd = nullptr,
24 std::function<void (const char *pBuf, int len)> _pfText = nullptr
25 ) noexcept
26 : pfStart{_pfStart},
27 pfEnd{_pfEnd},
28 pfText{_pfText},
29 tag{_tag}
30 {}
31
32 virtual ~State()=default;
33
34 void addState(State* s) { substates_.push_back(s); }
35 State* addState(const std::string& tagname)
36 {
37 auto s = new State(tagname);
38 substates_.push_back(s);
39 return s;
40 }
41 const std::list<State*>& substates() { return substates_; }
42 std::function<void (const XML_Char **atts)> pfStart{nullptr};
43 std::function<void ()> pfEnd{nullptr};
44 std::function<void (const char *pBuf, int len)> pfText{nullptr};
45
46 std::string tag{};
47private:
48 std::list<State*> substates_;
49};
50
51struct RootState: public State {
52 State root{"root"};
53 std::stack<State*> parseStates;
54};
55
57public:
59 void add_state(State* state);
60 State* current_element() const { return parseStates.top(); }
61protected:
62 void onStartElement(const XML_Char *fullname, const XML_Char **atts) override;
63 void onEndElement(const XML_Char *fullname) override;
64 void onCharacterData(const char * pBuf, int len) override;
65private:
66 State root{"root"};
67 std::stack<State*> parseStates;
68};
69
70}
71#endif // #ifndef xmlpp_state_hpp
Definition state.hpp:56
void onCharacterData(const char *pBuf, int len) override
callback is called with parsed character data inside of an xml element.
Definition state.cpp:59
void onStartElement(const XML_Char *fullname, const XML_Char **atts) override
this callback is called after parsing the starting tag of an xml element.
Definition state.cpp:26
void onEndElement(const XML_Char *fullname) override
callback is called after parsing the end tag of an xml element
Definition state.cpp:46
default base class for delegates.
Definition delegate.hpp:217
contains the xml parsers delegate interface
Definition state.hpp:51
Definition state.hpp:20