This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XMLEvent.cpp
147 lines (122 loc) · 3.16 KB
/
XMLEvent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* Copyright (C) 2017-2018 Stephan Kreutzer
*
* This file is part of CppStAX.
*
* CppStAX is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 or any later
* version of the license, as published by the Free Software Foundation.
*
* CppStAX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License 3 for more details.
*
* You should have received a copy of the GNU Affero General Public License 3
* along with CppStAX. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file $/XMLEvent.cpp
* @author Stephan Kreutzer
* @since 2017-08-24
*/
#include "XMLEvent.h"
namespace cppstax
{
XMLEvent::XMLEvent(std::unique_ptr<StartElement> pStartElement,
std::unique_ptr<EndElement> pEndElement,
std::unique_ptr<Characters> pCharacters,
std::unique_ptr<Comment> pComment,
std::unique_ptr<ProcessingInstruction> pProcessingInstruction):
m_pStartElement(std::move(pStartElement)),
m_pEndElement(std::move(pEndElement)),
m_pCharacters(std::move(pCharacters)),
m_pComment(std::move(pComment)),
m_pProcessingInstruction(std::move(pProcessingInstruction))
{
int nPointerCount = 0;
if (m_pStartElement != nullptr)
{
++nPointerCount;
}
if (m_pEndElement != nullptr)
{
++nPointerCount;
}
if (m_pCharacters != nullptr)
{
++nPointerCount;
}
if (m_pComment != nullptr)
{
++nPointerCount;
}
if (m_pProcessingInstruction != nullptr)
{
++nPointerCount;
}
if (nPointerCount != 1)
{
throw new std::invalid_argument("XMLEvent constructor expects exactly 1 parameter to be set.");
}
}
bool XMLEvent::isStartElement()
{
return m_pStartElement != nullptr;
}
StartElement& XMLEvent::asStartElement()
{
if (m_pStartElement == nullptr)
{
throw new std::logic_error("Isn't a StartElement.");
}
return *m_pStartElement;
}
bool XMLEvent::isEndElement()
{
return m_pEndElement != nullptr;
}
EndElement& XMLEvent::asEndElement()
{
if (m_pEndElement == nullptr)
{
throw new std::logic_error("Isn't an EndElement.");
}
return *m_pEndElement;
}
bool XMLEvent::isCharacters()
{
return m_pCharacters != nullptr;
}
Characters& XMLEvent::asCharacters()
{
if (m_pCharacters == nullptr)
{
throw new std::logic_error("Isn't Characters.");
}
return *m_pCharacters;
}
bool XMLEvent::isComment()
{
return m_pComment != nullptr;
}
Comment& XMLEvent::asComment()
{
if (m_pComment == nullptr)
{
throw new std::logic_error("Isn't Comment.");
}
return *m_pComment;
}
bool XMLEvent::isProcessingInstruction()
{
return m_pProcessingInstruction != nullptr;
}
ProcessingInstruction& XMLEvent::asProcessingInstruction()
{
if (m_pProcessingInstruction == nullptr)
{
throw new std::logic_error("Isn't ProcessingInstruction.");
}
return *m_pProcessingInstruction;
}
}