summaryrefslogtreecommitdiff
path: root/skinengine/src/xml_cache.cpp
blob: 136d25714655bb7a32e3212a7923380afbf6aa35 (plain)
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
#include "headers.h"

CXmlCache g_XmlCache;

CXmlCache::CachedFile::CachedFile(const TCHAR *path, bool load)
{
	this->path = _tcsdup(path);
	if (load)
	{
	} else
	{
		hXmlRoot = NULL;
	}
}

CXmlCache::CachedFile::~CachedFile()
{
	free(path);
	if (hXmlRoot) xi.destroyNode(hXmlRoot);
}

CXmlCache::CXmlCache(): m_files(5, CachedFile::cmp), m_classes(10, CachedClass::cmp)
{
}

CXmlCache::~CXmlCache()
{
}

void CXmlCache::LoadXmlFile(const TCHAR *path)
{
	CachedFile *file = new CachedFile(path);
	if (!file->hXmlRoot)
	{
		delete file;
		return;
	}

	int count = xi.getChildCount(file->hXmlRoot);
	for (int i = 0; i < count; ++i)
	{
		HXML hXml = xi.getChild(file->hXmlRoot, i);
		if (!hXml) break;

		const TCHAR *tagName = xi.getName(hXml);
		if (!tagName || lstrcmp(tagName, _T("class"))) continue;

		const TCHAR *className = xi.getAttrValue(hXml, _T("name"));
		if (!className) continue;

		RegisterClass(className, file, hXml);
	}
}

void CXmlCache::UnloadXmlFile(const TCHAR *path)
{
}

void CXmlCache::RegisterClass(const TCHAR *name, CachedFile *file, HXML hXmlClass)
{
	CachedClass *cls = new CachedClass;
	cls->name = name;
	cls->file = file;
	cls->hXml = hXmlClass;
	m_classes.insert(cls);
}

ISkinElement *CXmlCache::CreateObject(const TCHAR *name)
{
	return NULL;
}