File: IncludeNodeHandler.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (59 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download | duplicates (2)
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
//
//

#include "IncludeNodeHandler.h"

#include "globalincs/pstypes.h"

// Our Assert conflicts with the definitions inside libRocket
#pragma push_macro("Assert")
#undef Assert

#include <Rocket/Core/Element.h>
#include <Rocket/Core/ElementDocument.h>
#include <Rocket/Core/Log.h>
#include <Rocket/Core/StreamFile.h>
#include <Rocket/Core/XMLParseTools.h>

#pragma pop_macro("Assert")

using namespace Rocket;
using namespace Rocket::Core;

namespace scpui {

Element* IncludeNodeHandler::ElementStart(XMLParser* parser, const String& name, const XMLAttributes& attributes)
{
	Assertion(name == "include", "IncludeNodeHandler used with invalid tag '%s'!", name.CString());

	String include_src;
	if (!attributes.GetInto("src", include_src)) {
		Log::ParseError(parser->GetParseFrame()->element->GetOwnerDocument()->GetSourceURL(), parser->GetLineNumber(),
		                "'include' requires a 'src' attribute!");
		return parser->GetParseFrame()->element;
	}

	auto stream = new StreamFile();

	if (!stream->Open(include_src)) {
		Log::ParseError(parser->GetParseFrame()->element->GetOwnerDocument()->GetSourceURL(), parser->GetLineNumber(),
		                "Failed to open file '%s'!", include_src.CString());
		stream->RemoveReference();
		return parser->GetParseFrame()->element;
	}

	XMLParser include_parser(parser->GetParseFrame()->element);
	include_parser.Parse(stream);

	stream->RemoveReference();

	// Tell the parser to use the element handler for all child nodes
	parser->PushDefaultHandler();

	return parser->GetParseFrame()->element;
}
bool IncludeNodeHandler::ElementEnd(XMLParser* /*parser*/, const String& /*name*/) { return true; }
bool IncludeNodeHandler::ElementData(XMLParser* /*parser*/, const String& /*data*/) { return true; }
void IncludeNodeHandler::Release() { delete this; }

} // namespace scpui